]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-route.c
0d2a5bb83d21f37a5bef59830f2a1a21e0265277
[thirdparty/systemd.git] / src / network / networkd-route.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2013 Tom Gundersen <teg@jklm.no>
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include "alloc-util.h"
21 #include "conf-parser.h"
22 #include "in-addr-util.h"
23 #include "netlink-util.h"
24 #include "networkd-route.h"
25 #include "networkd.h"
26 #include "parse-util.h"
27 #include "set.h"
28 #include "string-util.h"
29 #include "util.h"
30
31 #define ROUTES_PER_LINK_MAX 2048U
32 #define STATIC_ROUTES_PER_NETWORK_MAX 1024U
33
34 int route_new(Route **ret) {
35 _cleanup_route_free_ Route *route = NULL;
36
37 route = new0(Route, 1);
38 if (!route)
39 return -ENOMEM;
40
41 route->family = AF_UNSPEC;
42 route->scope = RT_SCOPE_UNIVERSE;
43 route->protocol = RTPROT_UNSPEC;
44 route->table = RT_TABLE_DEFAULT;
45 route->lifetime = USEC_INFINITY;
46
47 *ret = route;
48 route = NULL;
49
50 return 0;
51 }
52
53 int route_new_static(Network *network, unsigned section, Route **ret) {
54 _cleanup_route_free_ Route *route = NULL;
55 int r;
56
57 assert(network);
58 assert(ret);
59
60 if (section) {
61 route = hashmap_get(network->routes_by_section, UINT_TO_PTR(section));
62 if (route) {
63 *ret = route;
64 route = NULL;
65
66 return 0;
67 }
68 }
69
70 if (network->n_static_routes >= STATIC_ROUTES_PER_NETWORK_MAX)
71 return -E2BIG;
72
73 r = route_new(&route);
74 if (r < 0)
75 return r;
76
77 route->protocol = RTPROT_STATIC;
78
79 if (section) {
80 route->section = section;
81
82 r = hashmap_put(network->routes_by_section, UINT_TO_PTR(route->section), route);
83 if (r < 0)
84 return r;
85 }
86
87 route->network = network;
88 LIST_PREPEND(routes, network->static_routes, route);
89 network->n_static_routes++;
90
91 *ret = route;
92 route = NULL;
93
94 return 0;
95 }
96
97 void route_free(Route *route) {
98 if (!route)
99 return;
100
101 if (route->network) {
102 LIST_REMOVE(routes, route->network->static_routes, route);
103
104 assert(route->network->n_static_routes > 0);
105 route->network->n_static_routes--;
106
107 if (route->section)
108 hashmap_remove(route->network->routes_by_section, UINT_TO_PTR(route->section));
109 }
110
111 if (route->link) {
112 set_remove(route->link->routes, route);
113 set_remove(route->link->routes_foreign, route);
114 }
115
116 sd_event_source_unref(route->expire);
117
118 free(route);
119 }
120
121 static void route_hash_func(const void *b, struct siphash *state) {
122 const Route *route = b;
123
124 assert(route);
125
126 siphash24_compress(&route->family, sizeof(route->family), state);
127
128 switch (route->family) {
129 case AF_INET:
130 case AF_INET6:
131 /* Equality of routes are given by the 4-touple
132 (dst_prefix,dst_prefixlen,tos,priority,table) */
133 siphash24_compress(&route->dst, FAMILY_ADDRESS_SIZE(route->family), state);
134 siphash24_compress(&route->dst_prefixlen, sizeof(route->dst_prefixlen), state);
135 siphash24_compress(&route->tos, sizeof(route->tos), state);
136 siphash24_compress(&route->priority, sizeof(route->priority), state);
137 siphash24_compress(&route->table, sizeof(route->table), state);
138
139 break;
140 default:
141 /* treat any other address family as AF_UNSPEC */
142 break;
143 }
144 }
145
146 static int route_compare_func(const void *_a, const void *_b) {
147 const Route *a = _a, *b = _b;
148
149 if (a->family < b->family)
150 return -1;
151 if (a->family > b->family)
152 return 1;
153
154 switch (a->family) {
155 case AF_INET:
156 case AF_INET6:
157 if (a->dst_prefixlen < b->dst_prefixlen)
158 return -1;
159 if (a->dst_prefixlen > b->dst_prefixlen)
160 return 1;
161
162 if (a->tos < b->tos)
163 return -1;
164 if (a->tos > b->tos)
165 return 1;
166
167 if (a->priority < b->priority)
168 return -1;
169 if (a->priority > b->priority)
170 return 1;
171
172 if (a->table < b->table)
173 return -1;
174 if (a->table > b->table)
175 return 1;
176
177 return memcmp(&a->dst, &b->dst, FAMILY_ADDRESS_SIZE(a->family));
178 default:
179 /* treat any other address family as AF_UNSPEC */
180 return 0;
181 }
182 }
183
184 static const struct hash_ops route_hash_ops = {
185 .hash = route_hash_func,
186 .compare = route_compare_func
187 };
188
189 int route_get(Link *link,
190 int family,
191 const union in_addr_union *dst,
192 unsigned char dst_prefixlen,
193 unsigned char tos,
194 uint32_t priority,
195 unsigned char table,
196 Route **ret) {
197
198 Route route, *existing;
199
200 assert(link);
201 assert(dst);
202
203 route = (Route) {
204 .family = family,
205 .dst = *dst,
206 .dst_prefixlen = dst_prefixlen,
207 .tos = tos,
208 .priority = priority,
209 .table = table,
210 };
211
212 existing = set_get(link->routes, &route);
213 if (existing) {
214 if (ret)
215 *ret = existing;
216 return 1;
217 }
218
219 existing = set_get(link->routes_foreign, &route);
220 if (existing) {
221 if (ret)
222 *ret = existing;
223 return 0;
224 }
225
226 return -ENOENT;
227 }
228
229 static int route_add_internal(Link *link, Set **routes,
230 int family,
231 union in_addr_union *dst,
232 unsigned char dst_prefixlen,
233 unsigned char tos,
234 uint32_t priority,
235 unsigned char table, Route **ret) {
236 _cleanup_route_free_ Route *route = NULL;
237 int r;
238
239 assert(link);
240 assert(routes);
241 assert(dst);
242
243 r = route_new(&route);
244 if (r < 0)
245 return r;
246
247 route->family = family;
248 route->dst = *dst;
249 route->dst_prefixlen = dst_prefixlen;
250 route->tos = tos;
251 route->priority = priority;
252 route->table = table;
253
254 r = set_ensure_allocated(routes, &route_hash_ops);
255 if (r < 0)
256 return r;
257
258 r = set_put(*routes, route);
259 if (r < 0)
260 return r;
261
262 route->link = link;
263
264 if (ret)
265 *ret = route;
266
267 route = NULL;
268
269 return 0;
270 }
271
272 int route_add_foreign(Link *link,
273 int family,
274 union in_addr_union *dst,
275 unsigned char dst_prefixlen,
276 unsigned char tos,
277 uint32_t priority,
278 unsigned char table, Route **ret) {
279 return route_add_internal(link, &link->routes_foreign, family, dst, dst_prefixlen, tos, priority, table, ret);
280 }
281
282 int route_add(Link *link,
283 int family,
284 union in_addr_union *dst,
285 unsigned char dst_prefixlen,
286 unsigned char tos,
287 uint32_t priority,
288 unsigned char table, Route **ret) {
289 Route *route;
290 int r;
291
292 r = route_get(link, family, dst, dst_prefixlen, tos, priority, table, &route);
293 if (r == -ENOENT) {
294 /* Route does not exist, create a new one */
295 r = route_add_internal(link, &link->routes, family, dst, dst_prefixlen, tos, priority, table, &route);
296 if (r < 0)
297 return r;
298 } else if (r == 0) {
299 /* Take over a foreign route */
300 r = set_ensure_allocated(&link->routes, &route_hash_ops);
301 if (r < 0)
302 return r;
303
304 r = set_put(link->routes, route);
305 if (r < 0)
306 return r;
307
308 set_remove(link->routes_foreign, route);
309 } else if (r == 1) {
310 /* Route exists, do nothing */
311 ;
312 } else
313 return r;
314
315 *ret = route;
316
317 return 0;
318 }
319
320 int route_update(Route *route,
321 union in_addr_union *src,
322 unsigned char src_prefixlen,
323 union in_addr_union *gw,
324 union in_addr_union *prefsrc,
325 unsigned char scope,
326 unsigned char protocol) {
327 assert(route);
328 assert(src);
329 assert(gw);
330 assert(prefsrc);
331
332 route->src = *src;
333 route->src_prefixlen = src_prefixlen;
334 route->gw = *gw;
335 route->prefsrc = *prefsrc;
336 route->scope = scope;
337 route->protocol = protocol;
338
339 return 0;
340 }
341
342 int route_remove(Route *route, Link *link,
343 sd_netlink_message_handler_t callback) {
344 _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
345 int r;
346
347 assert(link);
348 assert(link->manager);
349 assert(link->manager->rtnl);
350 assert(link->ifindex > 0);
351 assert(route->family == AF_INET || route->family == AF_INET6);
352
353 r = sd_rtnl_message_new_route(link->manager->rtnl, &req,
354 RTM_DELROUTE, route->family,
355 route->protocol);
356 if (r < 0)
357 return log_error_errno(r, "Could not create RTM_DELROUTE message: %m");
358
359 if (!in_addr_is_null(route->family, &route->gw)) {
360 if (route->family == AF_INET)
361 r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
362 else if (route->family == AF_INET6)
363 r = sd_netlink_message_append_in6_addr(req, RTA_GATEWAY, &route->gw.in6);
364 if (r < 0)
365 return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
366 }
367
368 if (route->dst_prefixlen) {
369 if (route->family == AF_INET)
370 r = sd_netlink_message_append_in_addr(req, RTA_DST, &route->dst.in);
371 else if (route->family == AF_INET6)
372 r = sd_netlink_message_append_in6_addr(req, RTA_DST, &route->dst.in6);
373 if (r < 0)
374 return log_error_errno(r, "Could not append RTA_DST attribute: %m");
375
376 r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
377 if (r < 0)
378 return log_error_errno(r, "Could not set destination prefix length: %m");
379 }
380
381 if (route->src_prefixlen) {
382 if (route->family == AF_INET)
383 r = sd_netlink_message_append_in_addr(req, RTA_SRC, &route->src.in);
384 else if (route->family == AF_INET6)
385 r = sd_netlink_message_append_in6_addr(req, RTA_SRC, &route->src.in6);
386 if (r < 0)
387 return log_error_errno(r, "Could not append RTA_SRC attribute: %m");
388
389 r = sd_rtnl_message_route_set_src_prefixlen(req, route->src_prefixlen);
390 if (r < 0)
391 return log_error_errno(r, "Could not set source prefix length: %m");
392 }
393
394 if (!in_addr_is_null(route->family, &route->prefsrc)) {
395 if (route->family == AF_INET)
396 r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
397 else if (route->family == AF_INET6)
398 r = sd_netlink_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc.in6);
399 if (r < 0)
400 return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
401 }
402
403 r = sd_rtnl_message_route_set_scope(req, route->scope);
404 if (r < 0)
405 return log_error_errno(r, "Could not set scope: %m");
406
407 r = sd_netlink_message_append_u32(req, RTA_PRIORITY, route->priority);
408 if (r < 0)
409 return log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m");
410
411 r = sd_netlink_message_append_u32(req, RTA_OIF, link->ifindex);
412 if (r < 0)
413 return log_error_errno(r, "Could not append RTA_OIF attribute: %m");
414
415 r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
416 if (r < 0)
417 return log_error_errno(r, "Could not send rtnetlink message: %m");
418
419 link_ref(link);
420
421 return 0;
422 }
423
424 static int route_expire_callback(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
425 Link *link = userdata;
426 int r;
427
428 assert(rtnl);
429 assert(m);
430 assert(link);
431 assert(link->ifname);
432 assert(link->link_messages > 0);
433
434 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
435 return 1;
436
437 link->link_messages--;
438
439 r = sd_netlink_message_get_errno(m);
440 if (r < 0 && r != -EEXIST)
441 log_link_warning_errno(link, r, "could not remove route: %m");
442
443 if (link->link_messages == 0)
444 log_link_debug(link, "route removed");
445
446 return 1;
447 }
448
449 int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata) {
450 Route *route = userdata;
451 int r;
452
453 assert(route);
454
455 r = route_remove(route, route->link, route_expire_callback);
456 if (r < 0)
457 log_warning_errno(r, "Could not remove route: %m");
458 else {
459 /* route may not be exist in kernel. If we fail still remove it */
460 route->link->link_messages++;
461 route_free(route);
462 }
463
464 return 1;
465 }
466
467 int route_configure(
468 Route *route,
469 Link *link,
470 sd_netlink_message_handler_t callback) {
471
472 _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
473 _cleanup_(sd_event_source_unrefp) sd_event_source *expire = NULL;
474 usec_t lifetime;
475 int r;
476
477 assert(link);
478 assert(link->manager);
479 assert(link->manager->rtnl);
480 assert(link->ifindex > 0);
481 assert(route->family == AF_INET || route->family == AF_INET6);
482
483 if (route_get(link, route->family, &route->dst, route->dst_prefixlen, route->tos, route->priority, route->table, NULL) <= 0 &&
484 set_size(route->link->routes) >= ROUTES_PER_LINK_MAX)
485 return -E2BIG;
486
487 r = sd_rtnl_message_new_route(link->manager->rtnl, &req,
488 RTM_NEWROUTE, route->family,
489 route->protocol);
490 if (r < 0)
491 return log_error_errno(r, "Could not create RTM_NEWROUTE message: %m");
492
493 if (!in_addr_is_null(route->family, &route->gw)) {
494 if (route->family == AF_INET)
495 r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
496 else if (route->family == AF_INET6)
497 r = sd_netlink_message_append_in6_addr(req, RTA_GATEWAY, &route->gw.in6);
498 if (r < 0)
499 return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
500
501 r = sd_rtnl_message_route_set_family(req, route->family);
502 if (r < 0)
503 return log_error_errno(r, "Could not set route family: %m");
504 }
505
506 if (route->dst_prefixlen) {
507 if (route->family == AF_INET)
508 r = sd_netlink_message_append_in_addr(req, RTA_DST, &route->dst.in);
509 else if (route->family == AF_INET6)
510 r = sd_netlink_message_append_in6_addr(req, RTA_DST, &route->dst.in6);
511 if (r < 0)
512 return log_error_errno(r, "Could not append RTA_DST attribute: %m");
513
514 r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
515 if (r < 0)
516 return log_error_errno(r, "Could not set destination prefix length: %m");
517 }
518
519 if (route->src_prefixlen) {
520 if (route->family == AF_INET)
521 r = sd_netlink_message_append_in_addr(req, RTA_SRC, &route->src.in);
522 else if (route->family == AF_INET6)
523 r = sd_netlink_message_append_in6_addr(req, RTA_SRC, &route->src.in6);
524 if (r < 0)
525 return log_error_errno(r, "Could not append RTA_SRC attribute: %m");
526
527 r = sd_rtnl_message_route_set_src_prefixlen(req, route->src_prefixlen);
528 if (r < 0)
529 return log_error_errno(r, "Could not set source prefix length: %m");
530 }
531
532 if (!in_addr_is_null(route->family, &route->prefsrc)) {
533 if (route->family == AF_INET)
534 r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
535 else if (route->family == AF_INET6)
536 r = sd_netlink_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc.in6);
537 if (r < 0)
538 return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
539 }
540
541 r = sd_rtnl_message_route_set_scope(req, route->scope);
542 if (r < 0)
543 return log_error_errno(r, "Could not set scope: %m");
544
545 r = sd_rtnl_message_route_set_flags(req, route->flags);
546 if (r < 0)
547 return log_error_errno(r, "Could not set flags: %m");
548
549 if (route->table != RT_TABLE_DEFAULT) {
550
551 if (route->table < 256) {
552 r = sd_rtnl_message_route_set_table(req, route->table);
553 if (r < 0)
554 return log_error_errno(r, "Could not set route table: %m");
555 } else {
556
557 r = sd_rtnl_message_route_set_table(req, RT_TABLE_UNSPEC);
558 if (r < 0)
559 return log_error_errno(r, "Could not set route table: %m");
560
561 /* Table attribute to allow more than 256. */
562 r = sd_netlink_message_append_data(req, RTA_TABLE, &route->table, sizeof(route->table));
563 if (r < 0)
564 return log_error_errno(r, "Could not append RTA_TABLE attribute: %m");
565 }
566 }
567
568 r = sd_netlink_message_append_u32(req, RTA_PRIORITY, route->priority);
569 if (r < 0)
570 return log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m");
571
572 r = sd_netlink_message_append_u8(req, RTA_PREF, route->pref);
573 if (r < 0)
574 return log_error_errno(r, "Could not append RTA_PREF attribute: %m");
575
576 r = sd_netlink_message_append_u32(req, RTA_OIF, link->ifindex);
577 if (r < 0)
578 return log_error_errno(r, "Could not append RTA_OIF attribute: %m");
579
580 r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
581 if (r < 0)
582 return log_error_errno(r, "Could not send rtnetlink message: %m");
583
584 link_ref(link);
585
586 lifetime = route->lifetime;
587
588 r = route_add(link, route->family, &route->dst, route->dst_prefixlen, route->tos, route->priority, route->table, &route);
589 if (r < 0)
590 return log_error_errno(r, "Could not add route: %m");
591
592 /* TODO: drop expiration handling once it can be pushed into the kernel */
593 route->lifetime = lifetime;
594
595 if (route->lifetime != USEC_INFINITY) {
596 r = sd_event_add_time(link->manager->event, &expire, clock_boottime_or_monotonic(),
597 route->lifetime, 0, route_expire_handler, route);
598 if (r < 0)
599 return log_error_errno(r, "Could not arm expiration timer: %m");
600 }
601
602 sd_event_source_unref(route->expire);
603 route->expire = expire;
604 expire = NULL;
605
606 return 0;
607 }
608
609 int config_parse_gateway(const char *unit,
610 const char *filename,
611 unsigned line,
612 const char *section,
613 unsigned section_line,
614 const char *lvalue,
615 int ltype,
616 const char *rvalue,
617 void *data,
618 void *userdata) {
619
620 Network *network = userdata;
621 _cleanup_route_free_ Route *n = NULL;
622 union in_addr_union buffer;
623 int r, f;
624
625 assert(filename);
626 assert(section);
627 assert(lvalue);
628 assert(rvalue);
629 assert(data);
630
631 if (streq(section, "Network")) {
632 /* we are not in an Route section, so treat
633 * this as the special '0' section */
634 section_line = 0;
635 }
636
637 r = route_new_static(network, section_line, &n);
638 if (r < 0)
639 return r;
640
641 r = in_addr_from_string_auto(rvalue, &f, &buffer);
642 if (r < 0) {
643 log_syntax(unit, LOG_ERR, filename, line, r, "Route is invalid, ignoring assignment: %s", rvalue);
644 return 0;
645 }
646
647 n->family = f;
648 n->gw = buffer;
649 n = NULL;
650
651 return 0;
652 }
653
654 int config_parse_preferred_src(const char *unit,
655 const char *filename,
656 unsigned line,
657 const char *section,
658 unsigned section_line,
659 const char *lvalue,
660 int ltype,
661 const char *rvalue,
662 void *data,
663 void *userdata) {
664
665 Network *network = userdata;
666 _cleanup_route_free_ Route *n = NULL;
667 union in_addr_union buffer;
668 int r, f;
669
670 assert(filename);
671 assert(section);
672 assert(lvalue);
673 assert(rvalue);
674 assert(data);
675
676 r = route_new_static(network, section_line, &n);
677 if (r < 0)
678 return r;
679
680 r = in_addr_from_string_auto(rvalue, &f, &buffer);
681 if (r < 0) {
682 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
683 "Preferred source is invalid, ignoring assignment: %s", rvalue);
684 return 0;
685 }
686
687 n->family = f;
688 n->prefsrc = buffer;
689 n = NULL;
690
691 return 0;
692 }
693
694 int config_parse_destination(const char *unit,
695 const char *filename,
696 unsigned line,
697 const char *section,
698 unsigned section_line,
699 const char *lvalue,
700 int ltype,
701 const char *rvalue,
702 void *data,
703 void *userdata) {
704
705 Network *network = userdata;
706 _cleanup_route_free_ Route *n = NULL;
707 const char *address, *e;
708 union in_addr_union buffer;
709 unsigned char prefixlen;
710 int r, f;
711
712 assert(filename);
713 assert(section);
714 assert(lvalue);
715 assert(rvalue);
716 assert(data);
717
718 r = route_new_static(network, section_line, &n);
719 if (r < 0)
720 return r;
721
722 /* Destination|Source=address/prefixlen */
723
724 /* address */
725 e = strchr(rvalue, '/');
726 if (e)
727 address = strndupa(rvalue, e - rvalue);
728 else
729 address = rvalue;
730
731 r = in_addr_from_string_auto(address, &f, &buffer);
732 if (r < 0) {
733 log_syntax(unit, LOG_ERR, filename, line, r, "Destination is invalid, ignoring assignment: %s", address);
734 return 0;
735 }
736
737 if (f != AF_INET && f != AF_INET6) {
738 log_syntax(unit, LOG_ERR, filename, line, 0, "Unknown address family, ignoring assignment: %s", address);
739 return 0;
740 }
741
742 /* prefixlen */
743 if (e) {
744 r = safe_atou8(e + 1, &prefixlen);
745 if (r < 0) {
746 log_syntax(unit, LOG_ERR, filename, line, r, "Route destination prefix length is invalid, ignoring assignment: %s", e + 1);
747 return 0;
748 }
749 } else {
750 switch (f) {
751 case AF_INET:
752 prefixlen = 32;
753 break;
754 case AF_INET6:
755 prefixlen = 128;
756 break;
757 }
758 }
759
760 n->family = f;
761 if (streq(lvalue, "Destination")) {
762 n->dst = buffer;
763 n->dst_prefixlen = prefixlen;
764 } else if (streq(lvalue, "Source")) {
765 n->src = buffer;
766 n->src_prefixlen = prefixlen;
767 } else
768 assert_not_reached(lvalue);
769
770 n = NULL;
771
772 return 0;
773 }
774
775 int config_parse_route_priority(const char *unit,
776 const char *filename,
777 unsigned line,
778 const char *section,
779 unsigned section_line,
780 const char *lvalue,
781 int ltype,
782 const char *rvalue,
783 void *data,
784 void *userdata) {
785 Network *network = userdata;
786 _cleanup_route_free_ Route *n = NULL;
787 int r;
788
789 assert(filename);
790 assert(section);
791 assert(lvalue);
792 assert(rvalue);
793 assert(data);
794
795 r = route_new_static(network, section_line, &n);
796 if (r < 0)
797 return r;
798
799 r = config_parse_uint32(unit, filename, line, section,
800 section_line, lvalue, ltype,
801 rvalue, &n->priority, userdata);
802 if (r < 0)
803 return r;
804
805 n = NULL;
806
807 return 0;
808 }
809
810 int config_parse_route_scope(const char *unit,
811 const char *filename,
812 unsigned line,
813 const char *section,
814 unsigned section_line,
815 const char *lvalue,
816 int ltype,
817 const char *rvalue,
818 void *data,
819 void *userdata) {
820 Network *network = userdata;
821 _cleanup_route_free_ Route *n = NULL;
822 int r;
823
824 assert(filename);
825 assert(section);
826 assert(lvalue);
827 assert(rvalue);
828 assert(data);
829
830 r = route_new_static(network, section_line, &n);
831 if (r < 0)
832 return r;
833
834 if (streq(rvalue, "host"))
835 n->scope = RT_SCOPE_HOST;
836 else if (streq(rvalue, "link"))
837 n->scope = RT_SCOPE_LINK;
838 else if (streq(rvalue, "global"))
839 n->scope = RT_SCOPE_UNIVERSE;
840 else {
841 log_syntax(unit, LOG_ERR, filename, line, 0, "Unknown route scope: %s", rvalue);
842 return 0;
843 }
844
845 n = NULL;
846
847 return 0;
848 }
849
850 int config_parse_route_table(const char *unit,
851 const char *filename,
852 unsigned line,
853 const char *section,
854 unsigned section_line,
855 const char *lvalue,
856 int ltype,
857 const char *rvalue,
858 void *data,
859 void *userdata) {
860 _cleanup_route_free_ Route *n = NULL;
861 Network *network = userdata;
862 uint32_t k;
863 int r;
864
865 assert(filename);
866 assert(section);
867 assert(lvalue);
868 assert(rvalue);
869 assert(data);
870
871 r = route_new_static(network, section_line, &n);
872 if (r < 0)
873 return r;
874
875 r = safe_atou32(rvalue, &k);
876 if (r < 0) {
877 log_syntax(unit, LOG_ERR, filename, line, r,
878 "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue);
879 return 0;
880 }
881
882 n->table = k;
883
884 n = NULL;
885
886 return 0;
887 }