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