1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2013 Tom Gundersen <teg@jklm.no>
8 #include <linux/icmpv6.h>
10 #include "alloc-util.h"
11 #include "conf-parser.h"
12 #include "in-addr-util.h"
13 #include "netlink-util.h"
14 #include "networkd-manager.h"
15 #include "networkd-route.h"
16 #include "parse-util.h"
18 #include "string-util.h"
19 #include "sysctl-util.h"
22 #define ROUTES_DEFAULT_MAX_PER_FAMILY 4096U
24 static unsigned routes_max(void) {
25 static thread_local
unsigned cached
= 0;
27 _cleanup_free_
char *s4
= NULL
, *s6
= NULL
;
28 unsigned val4
= ROUTES_DEFAULT_MAX_PER_FAMILY
, val6
= ROUTES_DEFAULT_MAX_PER_FAMILY
;
33 if (sysctl_read("net/ipv4/route/max_size", &s4
) >= 0) {
35 if (safe_atou(s4
, &val4
) >= 0 &&
37 /* This is the default "no limit" value in the kernel */
38 val4
= ROUTES_DEFAULT_MAX_PER_FAMILY
;
41 if (sysctl_read("net/ipv6/route/max_size", &s6
) >= 0) {
43 (void) safe_atou(s6
, &val6
);
46 cached
= MAX(ROUTES_DEFAULT_MAX_PER_FAMILY
, val4
) +
47 MAX(ROUTES_DEFAULT_MAX_PER_FAMILY
, val6
);
51 int route_new(Route
**ret
) {
52 _cleanup_(route_freep
) Route
*route
= NULL
;
54 route
= new0(Route
, 1);
58 route
->family
= AF_UNSPEC
;
59 route
->scope
= RT_SCOPE_UNIVERSE
;
60 route
->protocol
= RTPROT_UNSPEC
;
61 route
->type
= RTN_UNICAST
;
62 route
->table
= RT_TABLE_MAIN
;
63 route
->lifetime
= USEC_INFINITY
;
66 *ret
= TAKE_PTR(route
);
71 int route_new_static(Network
*network
, const char *filename
, unsigned section_line
, Route
**ret
) {
72 _cleanup_(network_config_section_freep
) NetworkConfigSection
*n
= NULL
;
73 _cleanup_(route_freep
) Route
*route
= NULL
;
78 assert(!!filename
== (section_line
> 0));
81 r
= network_config_section_new(filename
, section_line
, &n
);
85 route
= hashmap_get(network
->routes_by_section
, n
);
87 *ret
= TAKE_PTR(route
);
93 if (network
->n_static_routes
>= routes_max())
96 r
= route_new(&route
);
100 route
->protocol
= RTPROT_STATIC
;
103 route
->section
= TAKE_PTR(n
);
105 r
= hashmap_put(network
->routes_by_section
, route
->section
, route
);
110 route
->network
= network
;
111 LIST_PREPEND(routes
, network
->static_routes
, route
);
112 network
->n_static_routes
++;
114 *ret
= TAKE_PTR(route
);
119 void route_free(Route
*route
) {
123 if (route
->network
) {
124 LIST_REMOVE(routes
, route
->network
->static_routes
, route
);
126 assert(route
->network
->n_static_routes
> 0);
127 route
->network
->n_static_routes
--;
130 hashmap_remove(route
->network
->routes_by_section
, route
->section
);
133 network_config_section_free(route
->section
);
136 set_remove(route
->link
->routes
, route
);
137 set_remove(route
->link
->routes_foreign
, route
);
140 sd_event_source_unref(route
->expire
);
145 static void route_hash_func(const void *b
, struct siphash
*state
) {
146 const Route
*route
= b
;
150 siphash24_compress(&route
->family
, sizeof(route
->family
), state
);
152 switch (route
->family
) {
155 /* Equality of routes are given by the 4-touple
156 (dst_prefix,dst_prefixlen,tos,priority,table) */
157 siphash24_compress(&route
->dst
, FAMILY_ADDRESS_SIZE(route
->family
), state
);
158 siphash24_compress(&route
->dst_prefixlen
, sizeof(route
->dst_prefixlen
), state
);
159 siphash24_compress(&route
->tos
, sizeof(route
->tos
), state
);
160 siphash24_compress(&route
->priority
, sizeof(route
->priority
), state
);
161 siphash24_compress(&route
->table
, sizeof(route
->table
), state
);
165 /* treat any other address family as AF_UNSPEC */
170 static int route_compare_func(const void *_a
, const void *_b
) {
171 const Route
*a
= _a
, *b
= _b
;
173 if (a
->family
< b
->family
)
175 if (a
->family
> b
->family
)
181 if (a
->dst_prefixlen
< b
->dst_prefixlen
)
183 if (a
->dst_prefixlen
> b
->dst_prefixlen
)
191 if (a
->priority
< b
->priority
)
193 if (a
->priority
> b
->priority
)
196 if (a
->table
< b
->table
)
198 if (a
->table
> b
->table
)
201 return memcmp(&a
->dst
, &b
->dst
, FAMILY_ADDRESS_SIZE(a
->family
));
203 /* treat any other address family as AF_UNSPEC */
208 static const struct hash_ops route_hash_ops
= {
209 .hash
= route_hash_func
,
210 .compare
= route_compare_func
213 int route_get(Link
*link
,
215 const union in_addr_union
*dst
,
216 unsigned char dst_prefixlen
,
222 Route route
, *existing
;
230 .dst_prefixlen
= dst_prefixlen
,
232 .priority
= priority
,
236 existing
= set_get(link
->routes
, &route
);
243 existing
= set_get(link
->routes_foreign
, &route
);
253 static int route_add_internal(
257 const union in_addr_union
*dst
,
258 unsigned char dst_prefixlen
,
264 _cleanup_(route_freep
) Route
*route
= NULL
;
271 r
= route_new(&route
);
275 route
->family
= family
;
277 route
->dst_prefixlen
= dst_prefixlen
;
279 route
->priority
= priority
;
280 route
->table
= table
;
282 r
= set_ensure_allocated(routes
, &route_hash_ops
);
286 r
= set_put(*routes
, route
);
300 int route_add_foreign(
303 const union in_addr_union
*dst
,
304 unsigned char dst_prefixlen
,
310 return route_add_internal(link
, &link
->routes_foreign
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, ret
);
313 int route_add(Link
*link
,
315 const union in_addr_union
*dst
,
316 unsigned char dst_prefixlen
,
325 r
= route_get(link
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
327 /* Route does not exist, create a new one */
328 r
= route_add_internal(link
, &link
->routes
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
332 /* Take over a foreign route */
333 r
= set_ensure_allocated(&link
->routes
, &route_hash_ops
);
337 r
= set_put(link
->routes
, route
);
341 set_remove(link
->routes_foreign
, route
);
343 /* Route exists, do nothing */
354 void route_update(Route
*route
,
355 const union in_addr_union
*src
,
356 unsigned char src_prefixlen
,
357 const union in_addr_union
*gw
,
358 const union in_addr_union
*prefsrc
,
360 unsigned char protocol
,
361 unsigned char type
) {
364 assert(src
|| src_prefixlen
== 0);
366 route
->src
= src
? *src
: (union in_addr_union
) {};
367 route
->src_prefixlen
= src_prefixlen
;
368 route
->gw
= gw
? *gw
: (union in_addr_union
) {};
369 route
->prefsrc
= prefsrc
? *prefsrc
: (union in_addr_union
) {};
370 route
->scope
= scope
;
371 route
->protocol
= protocol
;
375 int route_remove(Route
*route
, Link
*link
,
376 sd_netlink_message_handler_t callback
) {
378 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
382 assert(link
->manager
);
383 assert(link
->manager
->rtnl
);
384 assert(link
->ifindex
> 0);
385 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
387 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
388 RTM_DELROUTE
, route
->family
,
391 return log_error_errno(r
, "Could not create RTM_DELROUTE message: %m");
393 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
394 if (route
->family
== AF_INET
)
395 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
396 else if (route
->family
== AF_INET6
)
397 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
399 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
402 if (route
->dst_prefixlen
) {
403 if (route
->family
== AF_INET
)
404 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
405 else if (route
->family
== AF_INET6
)
406 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
408 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
410 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
412 return log_error_errno(r
, "Could not set destination prefix length: %m");
415 if (route
->src_prefixlen
) {
416 if (route
->family
== AF_INET
)
417 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
418 else if (route
->family
== AF_INET6
)
419 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
421 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
423 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
425 return log_error_errno(r
, "Could not set source prefix length: %m");
428 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
429 if (route
->family
== AF_INET
)
430 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
431 else if (route
->family
== AF_INET6
)
432 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
434 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
437 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
439 return log_error_errno(r
, "Could not set scope: %m");
441 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
443 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
445 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
)) {
446 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
448 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
451 r
= sd_netlink_call_async(link
->manager
->rtnl
, req
, callback
, link
, 0, NULL
);
453 return log_error_errno(r
, "Could not send rtnetlink message: %m");
460 static int route_expire_callback(sd_netlink
*rtnl
, sd_netlink_message
*m
, void *userdata
) {
461 Link
*link
= userdata
;
467 assert(link
->ifname
);
469 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
472 r
= sd_netlink_message_get_errno(m
);
473 if (r
< 0 && r
!= -EEXIST
)
474 log_link_warning_errno(link
, r
, "could not remove route: %m");
479 int route_expire_handler(sd_event_source
*s
, uint64_t usec
, void *userdata
) {
480 Route
*route
= userdata
;
485 r
= route_remove(route
, route
->link
, route_expire_callback
);
487 log_warning_errno(r
, "Could not remove route: %m");
497 sd_netlink_message_handler_t callback
) {
499 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
500 _cleanup_(sd_event_source_unrefp
) sd_event_source
*expire
= NULL
;
505 assert(link
->manager
);
506 assert(link
->manager
->rtnl
);
507 assert(link
->ifindex
> 0);
508 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
510 if (route_get(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, NULL
) <= 0 &&
511 set_size(link
->routes
) >= routes_max())
514 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
515 RTM_NEWROUTE
, route
->family
,
518 return log_error_errno(r
, "Could not create RTM_NEWROUTE message: %m");
520 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
521 if (route
->family
== AF_INET
)
522 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
523 else if (route
->family
== AF_INET6
)
524 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
526 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
528 r
= sd_rtnl_message_route_set_family(req
, route
->family
);
530 return log_error_errno(r
, "Could not set route family: %m");
533 if (route
->dst_prefixlen
) {
534 if (route
->family
== AF_INET
)
535 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
536 else if (route
->family
== AF_INET6
)
537 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
539 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
541 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
543 return log_error_errno(r
, "Could not set destination prefix length: %m");
546 if (route
->src_prefixlen
) {
547 if (route
->family
== AF_INET
)
548 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
549 else if (route
->family
== AF_INET6
)
550 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
552 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
554 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
556 return log_error_errno(r
, "Could not set source prefix length: %m");
559 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
560 if (route
->family
== AF_INET
)
561 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
562 else if (route
->family
== AF_INET6
)
563 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
565 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
568 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
570 return log_error_errno(r
, "Could not set scope: %m");
572 r
= sd_rtnl_message_route_set_flags(req
, route
->flags
);
574 return log_error_errno(r
, "Could not set flags: %m");
576 if (route
->table
!= RT_TABLE_MAIN
) {
577 if (route
->table
< 256) {
578 r
= sd_rtnl_message_route_set_table(req
, route
->table
);
580 return log_error_errno(r
, "Could not set route table: %m");
582 r
= sd_rtnl_message_route_set_table(req
, RT_TABLE_UNSPEC
);
584 return log_error_errno(r
, "Could not set route table: %m");
586 /* Table attribute to allow more than 256. */
587 r
= sd_netlink_message_append_data(req
, RTA_TABLE
, &route
->table
, sizeof(route
->table
));
589 return log_error_errno(r
, "Could not append RTA_TABLE attribute: %m");
593 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
595 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
597 r
= sd_netlink_message_append_u8(req
, RTA_PREF
, route
->pref
);
599 return log_error_errno(r
, "Could not append RTA_PREF attribute: %m");
601 if (route
->lifetime
!= USEC_INFINITY
&& kernel_route_expiration_supported()) {
602 r
= sd_netlink_message_append_u32(req
, RTA_EXPIRES
,
603 DIV_ROUND_UP(usec_sub_unsigned(route
->lifetime
, now(clock_boottime_or_monotonic())), USEC_PER_SEC
));
605 return log_error_errno(r
, "Could not append RTA_EXPIRES attribute: %m");
608 r
= sd_rtnl_message_route_set_type(req
, route
->type
);
610 return log_error_errno(r
, "Could not set route type: %m");
612 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
)) {
613 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
615 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
618 r
= sd_netlink_message_open_container(req
, RTA_METRICS
);
620 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
622 if (route
->mtu
> 0) {
623 r
= sd_netlink_message_append_u32(req
, RTAX_MTU
, route
->mtu
);
625 return log_error_errno(r
, "Could not append RTAX_MTU attribute: %m");
628 if (route
->initcwnd
> 0) {
629 r
= sd_netlink_message_append_u32(req
, RTAX_INITCWND
, route
->initcwnd
);
631 return log_error_errno(r
, "Could not append RTAX_INITCWND attribute: %m");
634 if (route
->initrwnd
> 0) {
635 r
= sd_netlink_message_append_u32(req
, RTAX_INITRWND
, route
->initrwnd
);
637 return log_error_errno(r
, "Could not append RTAX_INITRWND attribute: %m");
640 if (route
->quickack
!= -1) {
641 r
= sd_netlink_message_append_u32(req
, RTAX_QUICKACK
, route
->quickack
);
643 return log_error_errno(r
, "Could not append RTAX_QUICKACK attribute: %m");
646 r
= sd_netlink_message_close_container(req
);
648 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
650 r
= sd_netlink_call_async(link
->manager
->rtnl
, req
, callback
, link
, 0, NULL
);
652 return log_error_errno(r
, "Could not send rtnetlink message: %m");
656 lifetime
= route
->lifetime
;
658 r
= route_add(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, &route
);
660 return log_error_errno(r
, "Could not add route: %m");
662 /* TODO: drop expiration handling once it can be pushed into the kernel */
663 route
->lifetime
= lifetime
;
665 if (route
->lifetime
!= USEC_INFINITY
&& !kernel_route_expiration_supported()) {
666 r
= sd_event_add_time(link
->manager
->event
, &expire
, clock_boottime_or_monotonic(),
667 route
->lifetime
, 0, route_expire_handler
, route
);
669 return log_error_errno(r
, "Could not arm expiration timer: %m");
672 sd_event_source_unref(route
->expire
);
673 route
->expire
= TAKE_PTR(expire
);
678 int config_parse_gateway(
680 const char *filename
,
683 unsigned section_line
,
690 Network
*network
= userdata
;
691 _cleanup_(route_freep
) Route
*n
= NULL
;
692 union in_addr_union buffer
;
701 if (streq(section
, "Network")) {
702 /* we are not in an Route section, so treat
703 * this as the special '0' section */
704 r
= route_new_static(network
, NULL
, 0, &n
);
706 r
= route_new_static(network
, filename
, section_line
, &n
);
711 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
713 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Route is invalid, ignoring assignment: %s", rvalue
);
724 int config_parse_preferred_src(
726 const char *filename
,
729 unsigned section_line
,
736 Network
*network
= userdata
;
737 _cleanup_(route_freep
) Route
*n
= NULL
;
738 union in_addr_union buffer
;
747 r
= route_new_static(network
, filename
, section_line
, &n
);
751 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
753 log_syntax(unit
, LOG_ERR
, filename
, line
, EINVAL
,
754 "Preferred source is invalid, ignoring assignment: %s", rvalue
);
765 int config_parse_destination(
767 const char *filename
,
770 unsigned section_line
,
777 Network
*network
= userdata
;
778 _cleanup_(route_freep
) Route
*n
= NULL
;
779 union in_addr_union buffer
;
780 unsigned char prefixlen
;
789 r
= route_new_static(network
, filename
, section_line
, &n
);
793 r
= in_addr_prefix_from_string(rvalue
, AF_INET
, &buffer
, &prefixlen
);
795 r
= in_addr_prefix_from_string(rvalue
, AF_INET6
, &buffer
, &prefixlen
);
797 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
798 "Route %s= prefix is invalid, ignoring assignment: %s",
803 n
->family
= AF_INET6
;
807 if (streq(lvalue
, "Destination")) {
809 n
->dst_prefixlen
= prefixlen
;
810 } else if (streq(lvalue
, "Source")) {
812 n
->src_prefixlen
= prefixlen
;
814 assert_not_reached(lvalue
);
820 int config_parse_route_priority(
822 const char *filename
,
825 unsigned section_line
,
832 Network
*network
= userdata
;
833 _cleanup_(route_freep
) Route
*n
= NULL
;
842 r
= route_new_static(network
, filename
, section_line
, &n
);
846 r
= safe_atou32(rvalue
, &n
->priority
);
848 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
849 "Could not parse route priority \"%s\", ignoring assignment: %m", rvalue
);
857 int config_parse_route_scope(
859 const char *filename
,
862 unsigned section_line
,
869 Network
*network
= userdata
;
870 _cleanup_(route_freep
) Route
*n
= NULL
;
879 r
= route_new_static(network
, filename
, section_line
, &n
);
883 if (streq(rvalue
, "host"))
884 n
->scope
= RT_SCOPE_HOST
;
885 else if (streq(rvalue
, "link"))
886 n
->scope
= RT_SCOPE_LINK
;
887 else if (streq(rvalue
, "global"))
888 n
->scope
= RT_SCOPE_UNIVERSE
;
890 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route scope: %s", rvalue
);
898 int config_parse_route_table(
900 const char *filename
,
903 unsigned section_line
,
910 _cleanup_(route_freep
) Route
*n
= NULL
;
911 Network
*network
= userdata
;
920 r
= route_new_static(network
, filename
, section_line
, &n
);
924 r
= safe_atou32(rvalue
, &n
->table
);
926 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
927 "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue
);
935 int config_parse_gateway_onlink(
937 const char *filename
,
940 unsigned section_line
,
947 Network
*network
= userdata
;
948 _cleanup_(route_freep
) Route
*n
= NULL
;
957 r
= route_new_static(network
, filename
, section_line
, &n
);
961 r
= parse_boolean(rvalue
);
963 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
964 "Could not parse gateway onlink \"%s\", ignoring assignment: %m", rvalue
);
968 SET_FLAG(n
->flags
, RTNH_F_ONLINK
, r
);
973 int config_parse_ipv6_route_preference(
975 const char *filename
,
978 unsigned section_line
,
985 Network
*network
= userdata
;
986 _cleanup_(route_freep
) Route
*n
= NULL
;
989 r
= route_new_static(network
, filename
, section_line
, &n
);
993 if (streq(rvalue
, "low"))
994 n
->pref
= ICMPV6_ROUTER_PREF_LOW
;
995 else if (streq(rvalue
, "medium"))
996 n
->pref
= ICMPV6_ROUTER_PREF_MEDIUM
;
997 else if (streq(rvalue
, "high"))
998 n
->pref
= ICMPV6_ROUTER_PREF_HIGH
;
1000 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route preference: %s", rvalue
);
1008 int config_parse_route_protocol(
1010 const char *filename
,
1012 const char *section
,
1013 unsigned section_line
,
1020 Network
*network
= userdata
;
1021 _cleanup_(route_freep
) Route
*n
= NULL
;
1024 r
= route_new_static(network
, filename
, section_line
, &n
);
1028 if (streq(rvalue
, "kernel"))
1029 n
->protocol
= RTPROT_KERNEL
;
1030 else if (streq(rvalue
, "boot"))
1031 n
->protocol
= RTPROT_BOOT
;
1032 else if (streq(rvalue
, "static"))
1033 n
->protocol
= RTPROT_STATIC
;
1035 r
= safe_atou8(rvalue
, &n
->protocol
);
1037 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route protocol \"%s\", ignoring assignment: %m", rvalue
);
1046 int config_parse_route_type(
1048 const char *filename
,
1050 const char *section
,
1051 unsigned section_line
,
1058 Network
*network
= userdata
;
1059 _cleanup_(route_freep
) Route
*n
= NULL
;
1062 r
= route_new_static(network
, filename
, section_line
, &n
);
1066 if (streq(rvalue
, "unicast"))
1067 n
->type
= RTN_UNICAST
;
1068 else if (streq(rvalue
, "blackhole"))
1069 n
->type
= RTN_BLACKHOLE
;
1070 else if (streq(rvalue
, "unreachable"))
1071 n
->type
= RTN_UNREACHABLE
;
1072 else if (streq(rvalue
, "prohibit"))
1073 n
->type
= RTN_PROHIBIT
;
1075 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route type \"%s\", ignoring assignment: %m", rvalue
);
1083 int config_parse_tcp_window(
1085 const char *filename
,
1087 const char *section
,
1088 unsigned section_line
,
1095 _cleanup_(route_freep
) Route
*n
= NULL
;
1096 Network
*network
= userdata
;
1106 r
= route_new_static(network
, filename
, section_line
, &n
);
1110 r
= parse_size(rvalue
, 1024, &k
);
1111 if (r
< 0 || k
> UINT32_MAX
) {
1112 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1113 "Could not parse TCP %s \"%s\" bytes, ignoring assignment: %m", rvalue
, lvalue
);
1117 if (streq(lvalue
, "InitialCongestionWindow"))
1119 else if (streq(lvalue
, "InitialAdvertisedReceiveWindow"))
1122 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse TCP %s: %s", lvalue
, rvalue
);
1130 int config_parse_quickack(
1132 const char *filename
,
1134 const char *section
,
1135 unsigned section_line
,
1142 _cleanup_(route_freep
) Route
*n
= NULL
;
1143 Network
*network
= userdata
;
1152 r
= route_new_static(network
, filename
, section_line
, &n
);
1156 k
= parse_boolean(rvalue
);
1158 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse TCP quickack, ignoring: %s", rvalue
);
1167 int config_parse_route_mtu(
1169 const char *filename
,
1171 const char *section
,
1172 unsigned section_line
,
1179 Network
*network
= userdata
;
1180 _cleanup_(route_freep
) Route
*n
= NULL
;
1189 r
= route_new_static(network
, filename
, section_line
, &n
);
1193 r
= config_parse_mtu(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &n
->mtu
, userdata
);