]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-route.c
networkd: constify more things
[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(
230 Link *link,
231 Set **routes,
232 int family,
233 const union in_addr_union *dst,
234 unsigned char dst_prefixlen,
235 unsigned char tos,
236 uint32_t priority,
237 unsigned char table,
238 Route **ret) {
239
240 _cleanup_route_free_ Route *route = NULL;
241 int r;
242
243 assert(link);
244 assert(routes);
245 assert(dst);
246
247 r = route_new(&route);
248 if (r < 0)
249 return r;
250
251 route->family = family;
252 route->dst = *dst;
253 route->dst_prefixlen = dst_prefixlen;
254 route->tos = tos;
255 route->priority = priority;
256 route->table = table;
257
258 r = set_ensure_allocated(routes, &route_hash_ops);
259 if (r < 0)
260 return r;
261
262 r = set_put(*routes, route);
263 if (r < 0)
264 return r;
265
266 route->link = link;
267
268 if (ret)
269 *ret = route;
270
271 route = NULL;
272
273 return 0;
274 }
275
276 int route_add_foreign(
277 Link *link,
278 int family,
279 const union in_addr_union *dst,
280 unsigned char dst_prefixlen,
281 unsigned char tos,
282 uint32_t priority,
283 unsigned char table,
284 Route **ret) {
285
286 return route_add_internal(link, &link->routes_foreign, family, dst, dst_prefixlen, tos, priority, table, ret);
287 }
288
289 int route_add(
290 Link *link,
291 int family,
292 const union in_addr_union *dst,
293 unsigned char dst_prefixlen,
294 unsigned char tos,
295 uint32_t priority,
296 unsigned char table,
297 Route **ret) {
298
299 Route *route;
300 int r;
301
302 r = route_get(link, family, dst, dst_prefixlen, tos, priority, table, &route);
303 if (r == -ENOENT) {
304 /* Route does not exist, create a new one */
305 r = route_add_internal(link, &link->routes, family, dst, dst_prefixlen, tos, priority, table, &route);
306 if (r < 0)
307 return r;
308 } else if (r == 0) {
309 /* Take over a foreign route */
310 r = set_ensure_allocated(&link->routes, &route_hash_ops);
311 if (r < 0)
312 return r;
313
314 r = set_put(link->routes, route);
315 if (r < 0)
316 return r;
317
318 set_remove(link->routes_foreign, route);
319 } else if (r == 1) {
320 /* Route exists, do nothing */
321 ;
322 } else
323 return r;
324
325 *ret = route;
326
327 return 0;
328 }
329
330 int route_update(Route *route,
331 const union in_addr_union *src,
332 unsigned char src_prefixlen,
333 const union in_addr_union *gw,
334 const union in_addr_union *prefsrc,
335 unsigned char scope,
336 unsigned char protocol) {
337
338 assert(route);
339 assert(src);
340 assert(gw);
341 assert(prefsrc);
342
343 route->src = *src;
344 route->src_prefixlen = src_prefixlen;
345 route->gw = *gw;
346 route->prefsrc = *prefsrc;
347 route->scope = scope;
348 route->protocol = protocol;
349
350 return 0;
351 }
352
353 int route_remove(Route *route, Link *link,
354 sd_netlink_message_handler_t callback) {
355 _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
356 int r;
357
358 assert(link);
359 assert(link->manager);
360 assert(link->manager->rtnl);
361 assert(link->ifindex > 0);
362 assert(route->family == AF_INET || route->family == AF_INET6);
363
364 r = sd_rtnl_message_new_route(link->manager->rtnl, &req,
365 RTM_DELROUTE, route->family,
366 route->protocol);
367 if (r < 0)
368 return log_error_errno(r, "Could not create RTM_DELROUTE message: %m");
369
370 if (!in_addr_is_null(route->family, &route->gw)) {
371 if (route->family == AF_INET)
372 r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
373 else if (route->family == AF_INET6)
374 r = sd_netlink_message_append_in6_addr(req, RTA_GATEWAY, &route->gw.in6);
375 if (r < 0)
376 return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
377 }
378
379 if (route->dst_prefixlen) {
380 if (route->family == AF_INET)
381 r = sd_netlink_message_append_in_addr(req, RTA_DST, &route->dst.in);
382 else if (route->family == AF_INET6)
383 r = sd_netlink_message_append_in6_addr(req, RTA_DST, &route->dst.in6);
384 if (r < 0)
385 return log_error_errno(r, "Could not append RTA_DST attribute: %m");
386
387 r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
388 if (r < 0)
389 return log_error_errno(r, "Could not set destination prefix length: %m");
390 }
391
392 if (route->src_prefixlen) {
393 if (route->family == AF_INET)
394 r = sd_netlink_message_append_in_addr(req, RTA_SRC, &route->src.in);
395 else if (route->family == AF_INET6)
396 r = sd_netlink_message_append_in6_addr(req, RTA_SRC, &route->src.in6);
397 if (r < 0)
398 return log_error_errno(r, "Could not append RTA_SRC attribute: %m");
399
400 r = sd_rtnl_message_route_set_src_prefixlen(req, route->src_prefixlen);
401 if (r < 0)
402 return log_error_errno(r, "Could not set source prefix length: %m");
403 }
404
405 if (!in_addr_is_null(route->family, &route->prefsrc)) {
406 if (route->family == AF_INET)
407 r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
408 else if (route->family == AF_INET6)
409 r = sd_netlink_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc.in6);
410 if (r < 0)
411 return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
412 }
413
414 r = sd_rtnl_message_route_set_scope(req, route->scope);
415 if (r < 0)
416 return log_error_errno(r, "Could not set scope: %m");
417
418 r = sd_netlink_message_append_u32(req, RTA_PRIORITY, route->priority);
419 if (r < 0)
420 return log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m");
421
422 r = sd_netlink_message_append_u32(req, RTA_OIF, link->ifindex);
423 if (r < 0)
424 return log_error_errno(r, "Could not append RTA_OIF attribute: %m");
425
426 r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
427 if (r < 0)
428 return log_error_errno(r, "Could not send rtnetlink message: %m");
429
430 link_ref(link);
431
432 return 0;
433 }
434
435 static int route_expire_callback(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
436 Link *link = userdata;
437 int r;
438
439 assert(rtnl);
440 assert(m);
441 assert(link);
442 assert(link->ifname);
443 assert(link->link_messages > 0);
444
445 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
446 return 1;
447
448 link->link_messages--;
449
450 r = sd_netlink_message_get_errno(m);
451 if (r < 0 && r != -EEXIST)
452 log_link_warning_errno(link, r, "could not remove route: %m");
453
454 if (link->link_messages == 0)
455 log_link_debug(link, "route removed");
456
457 return 1;
458 }
459
460 int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata) {
461 Route *route = userdata;
462 int r;
463
464 assert(route);
465
466 r = route_remove(route, route->link, route_expire_callback);
467 if (r < 0)
468 log_warning_errno(r, "Could not remove route: %m");
469 else {
470 /* route may not be exist in kernel. If we fail still remove it */
471 route->link->link_messages++;
472 route_free(route);
473 }
474
475 return 1;
476 }
477
478 int route_configure(
479 Route *route,
480 Link *link,
481 sd_netlink_message_handler_t callback) {
482
483 _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
484 _cleanup_(sd_event_source_unrefp) sd_event_source *expire = NULL;
485 usec_t lifetime;
486 int r;
487
488 assert(link);
489 assert(link->manager);
490 assert(link->manager->rtnl);
491 assert(link->ifindex > 0);
492 assert(route->family == AF_INET || route->family == AF_INET6);
493
494 if (route_get(link, route->family, &route->dst, route->dst_prefixlen, route->tos, route->priority, route->table, NULL) <= 0 &&
495 set_size(route->link->routes) >= ROUTES_PER_LINK_MAX)
496 return -E2BIG;
497
498 r = sd_rtnl_message_new_route(link->manager->rtnl, &req,
499 RTM_NEWROUTE, route->family,
500 route->protocol);
501 if (r < 0)
502 return log_error_errno(r, "Could not create RTM_NEWROUTE message: %m");
503
504 if (!in_addr_is_null(route->family, &route->gw)) {
505 if (route->family == AF_INET)
506 r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
507 else if (route->family == AF_INET6)
508 r = sd_netlink_message_append_in6_addr(req, RTA_GATEWAY, &route->gw.in6);
509 if (r < 0)
510 return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
511
512 r = sd_rtnl_message_route_set_family(req, route->family);
513 if (r < 0)
514 return log_error_errno(r, "Could not set route family: %m");
515 }
516
517 if (route->dst_prefixlen) {
518 if (route->family == AF_INET)
519 r = sd_netlink_message_append_in_addr(req, RTA_DST, &route->dst.in);
520 else if (route->family == AF_INET6)
521 r = sd_netlink_message_append_in6_addr(req, RTA_DST, &route->dst.in6);
522 if (r < 0)
523 return log_error_errno(r, "Could not append RTA_DST attribute: %m");
524
525 r = sd_rtnl_message_route_set_dst_prefixlen(req, route->dst_prefixlen);
526 if (r < 0)
527 return log_error_errno(r, "Could not set destination prefix length: %m");
528 }
529
530 if (route->src_prefixlen) {
531 if (route->family == AF_INET)
532 r = sd_netlink_message_append_in_addr(req, RTA_SRC, &route->src.in);
533 else if (route->family == AF_INET6)
534 r = sd_netlink_message_append_in6_addr(req, RTA_SRC, &route->src.in6);
535 if (r < 0)
536 return log_error_errno(r, "Could not append RTA_SRC attribute: %m");
537
538 r = sd_rtnl_message_route_set_src_prefixlen(req, route->src_prefixlen);
539 if (r < 0)
540 return log_error_errno(r, "Could not set source prefix length: %m");
541 }
542
543 if (!in_addr_is_null(route->family, &route->prefsrc)) {
544 if (route->family == AF_INET)
545 r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
546 else if (route->family == AF_INET6)
547 r = sd_netlink_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc.in6);
548 if (r < 0)
549 return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
550 }
551
552 r = sd_rtnl_message_route_set_scope(req, route->scope);
553 if (r < 0)
554 return log_error_errno(r, "Could not set scope: %m");
555
556 r = sd_rtnl_message_route_set_flags(req, route->flags);
557 if (r < 0)
558 return log_error_errno(r, "Could not set flags: %m");
559
560 if (route->table != RT_TABLE_DEFAULT) {
561
562 if (route->table < 256) {
563 r = sd_rtnl_message_route_set_table(req, route->table);
564 if (r < 0)
565 return log_error_errno(r, "Could not set route table: %m");
566 } else {
567
568 r = sd_rtnl_message_route_set_table(req, RT_TABLE_UNSPEC);
569 if (r < 0)
570 return log_error_errno(r, "Could not set route table: %m");
571
572 /* Table attribute to allow more than 256. */
573 r = sd_netlink_message_append_data(req, RTA_TABLE, &route->table, sizeof(route->table));
574 if (r < 0)
575 return log_error_errno(r, "Could not append RTA_TABLE attribute: %m");
576 }
577 }
578
579 r = sd_netlink_message_append_u32(req, RTA_PRIORITY, route->priority);
580 if (r < 0)
581 return log_error_errno(r, "Could not append RTA_PRIORITY attribute: %m");
582
583 r = sd_netlink_message_append_u8(req, RTA_PREF, route->pref);
584 if (r < 0)
585 return log_error_errno(r, "Could not append RTA_PREF attribute: %m");
586
587 r = sd_netlink_message_append_u32(req, RTA_OIF, link->ifindex);
588 if (r < 0)
589 return log_error_errno(r, "Could not append RTA_OIF attribute: %m");
590
591 r = sd_netlink_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
592 if (r < 0)
593 return log_error_errno(r, "Could not send rtnetlink message: %m");
594
595 link_ref(link);
596
597 lifetime = route->lifetime;
598
599 r = route_add(link, route->family, &route->dst, route->dst_prefixlen, route->tos, route->priority, route->table, &route);
600 if (r < 0)
601 return log_error_errno(r, "Could not add route: %m");
602
603 /* TODO: drop expiration handling once it can be pushed into the kernel */
604 route->lifetime = lifetime;
605
606 if (route->lifetime != USEC_INFINITY) {
607 r = sd_event_add_time(link->manager->event, &expire, clock_boottime_or_monotonic(),
608 route->lifetime, 0, route_expire_handler, route);
609 if (r < 0)
610 return log_error_errno(r, "Could not arm expiration timer: %m");
611 }
612
613 sd_event_source_unref(route->expire);
614 route->expire = expire;
615 expire = NULL;
616
617 return 0;
618 }
619
620 int config_parse_gateway(const char *unit,
621 const char *filename,
622 unsigned line,
623 const char *section,
624 unsigned section_line,
625 const char *lvalue,
626 int ltype,
627 const char *rvalue,
628 void *data,
629 void *userdata) {
630
631 Network *network = userdata;
632 _cleanup_route_free_ Route *n = NULL;
633 union in_addr_union buffer;
634 int r, f;
635
636 assert(filename);
637 assert(section);
638 assert(lvalue);
639 assert(rvalue);
640 assert(data);
641
642 if (streq(section, "Network")) {
643 /* we are not in an Route section, so treat
644 * this as the special '0' section */
645 section_line = 0;
646 }
647
648 r = route_new_static(network, section_line, &n);
649 if (r < 0)
650 return r;
651
652 r = in_addr_from_string_auto(rvalue, &f, &buffer);
653 if (r < 0) {
654 log_syntax(unit, LOG_ERR, filename, line, r, "Route is invalid, ignoring assignment: %s", rvalue);
655 return 0;
656 }
657
658 n->family = f;
659 n->gw = buffer;
660 n = NULL;
661
662 return 0;
663 }
664
665 int config_parse_preferred_src(const char *unit,
666 const char *filename,
667 unsigned line,
668 const char *section,
669 unsigned section_line,
670 const char *lvalue,
671 int ltype,
672 const char *rvalue,
673 void *data,
674 void *userdata) {
675
676 Network *network = userdata;
677 _cleanup_route_free_ Route *n = NULL;
678 union in_addr_union buffer;
679 int r, f;
680
681 assert(filename);
682 assert(section);
683 assert(lvalue);
684 assert(rvalue);
685 assert(data);
686
687 r = route_new_static(network, section_line, &n);
688 if (r < 0)
689 return r;
690
691 r = in_addr_from_string_auto(rvalue, &f, &buffer);
692 if (r < 0) {
693 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
694 "Preferred source is invalid, ignoring assignment: %s", rvalue);
695 return 0;
696 }
697
698 n->family = f;
699 n->prefsrc = buffer;
700 n = NULL;
701
702 return 0;
703 }
704
705 int config_parse_destination(const char *unit,
706 const char *filename,
707 unsigned line,
708 const char *section,
709 unsigned section_line,
710 const char *lvalue,
711 int ltype,
712 const char *rvalue,
713 void *data,
714 void *userdata) {
715
716 Network *network = userdata;
717 _cleanup_route_free_ Route *n = NULL;
718 const char *address, *e;
719 union in_addr_union buffer;
720 unsigned char prefixlen;
721 int r, f;
722
723 assert(filename);
724 assert(section);
725 assert(lvalue);
726 assert(rvalue);
727 assert(data);
728
729 r = route_new_static(network, section_line, &n);
730 if (r < 0)
731 return r;
732
733 /* Destination|Source=address/prefixlen */
734
735 /* address */
736 e = strchr(rvalue, '/');
737 if (e)
738 address = strndupa(rvalue, e - rvalue);
739 else
740 address = rvalue;
741
742 r = in_addr_from_string_auto(address, &f, &buffer);
743 if (r < 0) {
744 log_syntax(unit, LOG_ERR, filename, line, r, "Destination is invalid, ignoring assignment: %s", address);
745 return 0;
746 }
747
748 if (f != AF_INET && f != AF_INET6) {
749 log_syntax(unit, LOG_ERR, filename, line, 0, "Unknown address family, ignoring assignment: %s", address);
750 return 0;
751 }
752
753 /* prefixlen */
754 if (e) {
755 r = safe_atou8(e + 1, &prefixlen);
756 if (r < 0) {
757 log_syntax(unit, LOG_ERR, filename, line, r, "Route destination prefix length is invalid, ignoring assignment: %s", e + 1);
758 return 0;
759 }
760 } else {
761 switch (f) {
762 case AF_INET:
763 prefixlen = 32;
764 break;
765 case AF_INET6:
766 prefixlen = 128;
767 break;
768 }
769 }
770
771 n->family = f;
772 if (streq(lvalue, "Destination")) {
773 n->dst = buffer;
774 n->dst_prefixlen = prefixlen;
775 } else if (streq(lvalue, "Source")) {
776 n->src = buffer;
777 n->src_prefixlen = prefixlen;
778 } else
779 assert_not_reached(lvalue);
780
781 n = NULL;
782
783 return 0;
784 }
785
786 int config_parse_route_priority(const char *unit,
787 const char *filename,
788 unsigned line,
789 const char *section,
790 unsigned section_line,
791 const char *lvalue,
792 int ltype,
793 const char *rvalue,
794 void *data,
795 void *userdata) {
796 Network *network = userdata;
797 _cleanup_route_free_ Route *n = NULL;
798 int r;
799
800 assert(filename);
801 assert(section);
802 assert(lvalue);
803 assert(rvalue);
804 assert(data);
805
806 r = route_new_static(network, section_line, &n);
807 if (r < 0)
808 return r;
809
810 r = config_parse_uint32(unit, filename, line, section,
811 section_line, lvalue, ltype,
812 rvalue, &n->priority, userdata);
813 if (r < 0)
814 return r;
815
816 n = NULL;
817
818 return 0;
819 }
820
821 int config_parse_route_scope(const char *unit,
822 const char *filename,
823 unsigned line,
824 const char *section,
825 unsigned section_line,
826 const char *lvalue,
827 int ltype,
828 const char *rvalue,
829 void *data,
830 void *userdata) {
831 Network *network = userdata;
832 _cleanup_route_free_ Route *n = NULL;
833 int r;
834
835 assert(filename);
836 assert(section);
837 assert(lvalue);
838 assert(rvalue);
839 assert(data);
840
841 r = route_new_static(network, section_line, &n);
842 if (r < 0)
843 return r;
844
845 if (streq(rvalue, "host"))
846 n->scope = RT_SCOPE_HOST;
847 else if (streq(rvalue, "link"))
848 n->scope = RT_SCOPE_LINK;
849 else if (streq(rvalue, "global"))
850 n->scope = RT_SCOPE_UNIVERSE;
851 else {
852 log_syntax(unit, LOG_ERR, filename, line, 0, "Unknown route scope: %s", rvalue);
853 return 0;
854 }
855
856 n = NULL;
857
858 return 0;
859 }
860
861 int config_parse_route_table(const char *unit,
862 const char *filename,
863 unsigned line,
864 const char *section,
865 unsigned section_line,
866 const char *lvalue,
867 int ltype,
868 const char *rvalue,
869 void *data,
870 void *userdata) {
871 _cleanup_route_free_ Route *n = NULL;
872 Network *network = userdata;
873 uint32_t k;
874 int r;
875
876 assert(filename);
877 assert(section);
878 assert(lvalue);
879 assert(rvalue);
880 assert(data);
881
882 r = route_new_static(network, section_line, &n);
883 if (r < 0)
884 return r;
885
886 r = safe_atou32(rvalue, &k);
887 if (r < 0) {
888 log_syntax(unit, LOG_ERR, filename, line, r,
889 "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue);
890 return 0;
891 }
892
893 n->table = k;
894
895 n = NULL;
896
897 return 0;
898 }