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_free_ 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_free_ NetworkConfigSection
*n
= NULL
;
73 _cleanup_route_free_ 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_free_ 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
);
316 const union in_addr_union
*dst
,
317 unsigned char dst_prefixlen
,
326 r
= route_get(link
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
328 /* Route does not exist, create a new one */
329 r
= route_add_internal(link
, &link
->routes
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
333 /* Take over a foreign route */
334 r
= set_ensure_allocated(&link
->routes
, &route_hash_ops
);
338 r
= set_put(link
->routes
, route
);
342 set_remove(link
->routes_foreign
, route
);
344 /* Route exists, do nothing */
355 void route_update(Route
*route
,
356 const union in_addr_union
*src
,
357 unsigned char src_prefixlen
,
358 const union in_addr_union
*gw
,
359 const union in_addr_union
*prefsrc
,
361 unsigned char protocol
,
362 unsigned char type
) {
370 route
->src_prefixlen
= src_prefixlen
;
372 route
->prefsrc
= *prefsrc
;
373 route
->scope
= scope
;
374 route
->protocol
= protocol
;
378 int route_remove(Route
*route
, Link
*link
,
379 sd_netlink_message_handler_t callback
) {
380 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
384 assert(link
->manager
);
385 assert(link
->manager
->rtnl
);
386 assert(link
->ifindex
> 0);
387 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
389 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
390 RTM_DELROUTE
, route
->family
,
393 return log_error_errno(r
, "Could not create RTM_DELROUTE message: %m");
395 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
396 if (route
->family
== AF_INET
)
397 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
398 else if (route
->family
== AF_INET6
)
399 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
401 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
404 if (route
->dst_prefixlen
) {
405 if (route
->family
== AF_INET
)
406 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
407 else if (route
->family
== AF_INET6
)
408 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
410 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
412 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
414 return log_error_errno(r
, "Could not set destination prefix length: %m");
417 if (route
->src_prefixlen
) {
418 if (route
->family
== AF_INET
)
419 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
420 else if (route
->family
== AF_INET6
)
421 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
423 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
425 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
427 return log_error_errno(r
, "Could not set source prefix length: %m");
430 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
431 if (route
->family
== AF_INET
)
432 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
433 else if (route
->family
== AF_INET6
)
434 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
436 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
439 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
441 return log_error_errno(r
, "Could not set scope: %m");
443 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
445 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
447 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
)) {
448 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
450 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
453 r
= sd_netlink_call_async(link
->manager
->rtnl
, req
, callback
, link
, 0, NULL
);
455 return log_error_errno(r
, "Could not send rtnetlink message: %m");
462 static int route_expire_callback(sd_netlink
*rtnl
, sd_netlink_message
*m
, void *userdata
) {
463 Link
*link
= userdata
;
469 assert(link
->ifname
);
471 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
474 r
= sd_netlink_message_get_errno(m
);
475 if (r
< 0 && r
!= -EEXIST
)
476 log_link_warning_errno(link
, r
, "could not remove route: %m");
481 int route_expire_handler(sd_event_source
*s
, uint64_t usec
, void *userdata
) {
482 Route
*route
= userdata
;
487 r
= route_remove(route
, route
->link
, route_expire_callback
);
489 log_warning_errno(r
, "Could not remove route: %m");
499 sd_netlink_message_handler_t callback
) {
501 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
502 _cleanup_(sd_event_source_unrefp
) sd_event_source
*expire
= NULL
;
507 assert(link
->manager
);
508 assert(link
->manager
->rtnl
);
509 assert(link
->ifindex
> 0);
510 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
512 if (route_get(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, NULL
) <= 0 &&
513 set_size(link
->routes
) >= routes_max())
516 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
517 RTM_NEWROUTE
, route
->family
,
520 return log_error_errno(r
, "Could not create RTM_NEWROUTE message: %m");
522 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
523 if (route
->family
== AF_INET
)
524 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
525 else if (route
->family
== AF_INET6
)
526 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
528 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
530 r
= sd_rtnl_message_route_set_family(req
, route
->family
);
532 return log_error_errno(r
, "Could not set route family: %m");
535 if (route
->dst_prefixlen
) {
536 if (route
->family
== AF_INET
)
537 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
538 else if (route
->family
== AF_INET6
)
539 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
541 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
543 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
545 return log_error_errno(r
, "Could not set destination prefix length: %m");
548 if (route
->src_prefixlen
) {
549 if (route
->family
== AF_INET
)
550 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
551 else if (route
->family
== AF_INET6
)
552 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
554 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
556 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
558 return log_error_errno(r
, "Could not set source prefix length: %m");
561 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
562 if (route
->family
== AF_INET
)
563 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
564 else if (route
->family
== AF_INET6
)
565 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
567 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
570 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
572 return log_error_errno(r
, "Could not set scope: %m");
574 r
= sd_rtnl_message_route_set_flags(req
, route
->flags
);
576 return log_error_errno(r
, "Could not set flags: %m");
578 if (route
->table
!= RT_TABLE_MAIN
) {
579 if (route
->table
< 256) {
580 r
= sd_rtnl_message_route_set_table(req
, route
->table
);
582 return log_error_errno(r
, "Could not set route table: %m");
584 r
= sd_rtnl_message_route_set_table(req
, RT_TABLE_UNSPEC
);
586 return log_error_errno(r
, "Could not set route table: %m");
588 /* Table attribute to allow more than 256. */
589 r
= sd_netlink_message_append_data(req
, RTA_TABLE
, &route
->table
, sizeof(route
->table
));
591 return log_error_errno(r
, "Could not append RTA_TABLE attribute: %m");
595 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
597 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
599 r
= sd_netlink_message_append_u8(req
, RTA_PREF
, route
->pref
);
601 return log_error_errno(r
, "Could not append RTA_PREF attribute: %m");
603 if (route
->lifetime
!= USEC_INFINITY
&& kernel_route_expiration_supported()) {
604 r
= sd_netlink_message_append_u32(req
, RTA_EXPIRES
,
605 DIV_ROUND_UP(usec_sub_unsigned(route
->lifetime
, now(clock_boottime_or_monotonic())), USEC_PER_SEC
));
607 return log_error_errno(r
, "Could not append RTA_EXPIRES attribute: %m");
610 r
= sd_rtnl_message_route_set_type(req
, route
->type
);
612 return log_error_errno(r
, "Could not set route type: %m");
614 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
)) {
615 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
617 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
620 r
= sd_netlink_message_open_container(req
, RTA_METRICS
);
622 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
624 if (route
->mtu
> 0) {
625 r
= sd_netlink_message_append_u32(req
, RTAX_MTU
, route
->mtu
);
627 return log_error_errno(r
, "Could not append RTAX_MTU attribute: %m");
630 if (route
->initcwnd
> 0) {
631 r
= sd_netlink_message_append_u32(req
, RTAX_INITCWND
, route
->initcwnd
);
633 return log_error_errno(r
, "Could not append RTAX_INITCWND attribute: %m");
636 if (route
->initrwnd
> 0) {
637 r
= sd_netlink_message_append_u32(req
, RTAX_INITRWND
, route
->initrwnd
);
639 return log_error_errno(r
, "Could not append RTAX_INITRWND attribute: %m");
642 if (route
->quickack
!= -1) {
643 r
= sd_netlink_message_append_u32(req
, RTAX_QUICKACK
, route
->quickack
);
645 return log_error_errno(r
, "Could not append RTAX_QUICKACK attribute: %m");
648 r
= sd_netlink_message_close_container(req
);
650 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
652 r
= sd_netlink_call_async(link
->manager
->rtnl
, req
, callback
, link
, 0, NULL
);
654 return log_error_errno(r
, "Could not send rtnetlink message: %m");
658 lifetime
= route
->lifetime
;
660 r
= route_add(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, &route
);
662 return log_error_errno(r
, "Could not add route: %m");
664 /* TODO: drop expiration handling once it can be pushed into the kernel */
665 route
->lifetime
= lifetime
;
667 if (route
->lifetime
!= USEC_INFINITY
&& !kernel_route_expiration_supported()) {
668 r
= sd_event_add_time(link
->manager
->event
, &expire
, clock_boottime_or_monotonic(),
669 route
->lifetime
, 0, route_expire_handler
, route
);
671 return log_error_errno(r
, "Could not arm expiration timer: %m");
674 sd_event_source_unref(route
->expire
);
675 route
->expire
= TAKE_PTR(expire
);
680 int config_parse_gateway(const char *unit
,
681 const char *filename
,
684 unsigned section_line
,
691 Network
*network
= userdata
;
692 _cleanup_route_free_ Route
*n
= NULL
;
693 union in_addr_union buffer
;
702 if (streq(section
, "Network")) {
703 /* we are not in an Route section, so treat
704 * this as the special '0' section */
705 r
= route_new_static(network
, NULL
, 0, &n
);
707 r
= route_new_static(network
, filename
, section_line
, &n
);
712 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
714 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Route is invalid, ignoring assignment: %s", rvalue
);
725 int config_parse_preferred_src(const char *unit
,
726 const char *filename
,
729 unsigned section_line
,
736 Network
*network
= userdata
;
737 _cleanup_route_free_ 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(const char *unit
,
766 const char *filename
,
769 unsigned section_line
,
776 Network
*network
= userdata
;
777 _cleanup_route_free_ Route
*n
= NULL
;
778 union in_addr_union buffer
;
779 unsigned char prefixlen
;
788 r
= route_new_static(network
, filename
, section_line
, &n
);
792 r
= in_addr_prefix_from_string(rvalue
, AF_INET
, &buffer
, &prefixlen
);
794 r
= in_addr_prefix_from_string(rvalue
, AF_INET6
, &buffer
, &prefixlen
);
796 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
797 "Route %s= prefix is invalid, ignoring assignment: %s",
802 n
->family
= AF_INET6
;
806 if (streq(lvalue
, "Destination")) {
808 n
->dst_prefixlen
= prefixlen
;
809 } else if (streq(lvalue
, "Source")) {
811 n
->src_prefixlen
= prefixlen
;
813 assert_not_reached(lvalue
);
820 int config_parse_route_priority(const char *unit
,
821 const char *filename
,
824 unsigned section_line
,
830 Network
*network
= userdata
;
831 _cleanup_route_free_ Route
*n
= NULL
;
841 r
= route_new_static(network
, filename
, section_line
, &n
);
845 r
= safe_atou32(rvalue
, &k
);
847 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
848 "Could not parse route priority \"%s\", ignoring assignment: %m", rvalue
);
858 int config_parse_route_scope(const char *unit
,
859 const char *filename
,
862 unsigned section_line
,
868 Network
*network
= userdata
;
869 _cleanup_route_free_ Route
*n
= NULL
;
878 r
= route_new_static(network
, filename
, section_line
, &n
);
882 if (streq(rvalue
, "host"))
883 n
->scope
= RT_SCOPE_HOST
;
884 else if (streq(rvalue
, "link"))
885 n
->scope
= RT_SCOPE_LINK
;
886 else if (streq(rvalue
, "global"))
887 n
->scope
= RT_SCOPE_UNIVERSE
;
889 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route scope: %s", rvalue
);
898 int config_parse_route_table(const char *unit
,
899 const char *filename
,
902 unsigned section_line
,
908 _cleanup_route_free_ Route
*n
= NULL
;
909 Network
*network
= userdata
;
919 r
= route_new_static(network
, filename
, section_line
, &n
);
923 r
= safe_atou32(rvalue
, &k
);
925 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
926 "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue
);
937 int config_parse_gateway_onlink(const char *unit
,
938 const char *filename
,
941 unsigned section_line
,
947 Network
*network
= userdata
;
948 _cleanup_route_free_ 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
);
974 int config_parse_ipv6_route_preference(const char *unit
,
975 const char *filename
,
978 unsigned section_line
,
984 Network
*network
= userdata
;
985 _cleanup_route_free_ Route
*n
= NULL
;
988 r
= route_new_static(network
, filename
, section_line
, &n
);
992 if (streq(rvalue
, "low"))
993 n
->pref
= ICMPV6_ROUTER_PREF_LOW
;
994 else if (streq(rvalue
, "medium"))
995 n
->pref
= ICMPV6_ROUTER_PREF_MEDIUM
;
996 else if (streq(rvalue
, "high"))
997 n
->pref
= ICMPV6_ROUTER_PREF_HIGH
;
999 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route preference: %s", rvalue
);
1008 int config_parse_route_protocol(const char *unit
,
1009 const char *filename
,
1011 const char *section
,
1012 unsigned section_line
,
1018 Network
*network
= userdata
;
1019 _cleanup_route_free_ Route
*n
= NULL
;
1022 r
= route_new_static(network
, filename
, section_line
, &n
);
1026 if (streq(rvalue
, "kernel"))
1027 n
->protocol
= RTPROT_KERNEL
;
1028 else if (streq(rvalue
, "boot"))
1029 n
->protocol
= RTPROT_BOOT
;
1030 else if (streq(rvalue
, "static"))
1031 n
->protocol
= RTPROT_STATIC
;
1033 r
= safe_atou8(rvalue
, &n
->protocol
);
1035 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route protocol \"%s\", ignoring assignment: %m", rvalue
);
1045 int config_parse_route_type(const char *unit
,
1046 const char *filename
,
1048 const char *section
,
1049 unsigned section_line
,
1055 Network
*network
= userdata
;
1056 _cleanup_route_free_ Route
*n
= NULL
;
1059 r
= route_new_static(network
, filename
, section_line
, &n
);
1063 if (streq(rvalue
, "unicast"))
1064 n
->type
= RTN_UNICAST
;
1065 else if (streq(rvalue
, "blackhole"))
1066 n
->type
= RTN_BLACKHOLE
;
1067 else if (streq(rvalue
, "unreachable"))
1068 n
->type
= RTN_UNREACHABLE
;
1069 else if (streq(rvalue
, "prohibit"))
1070 n
->type
= RTN_PROHIBIT
;
1072 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route type \"%s\", ignoring assignment: %m", rvalue
);
1081 int config_parse_tcp_window(const char *unit
,
1082 const char *filename
,
1084 const char *section
,
1085 unsigned section_line
,
1091 _cleanup_route_free_ Route
*n
= NULL
;
1092 Network
*network
= userdata
;
1102 r
= route_new_static(network
, filename
, section_line
, &n
);
1106 r
= parse_size(rvalue
, 1024, &k
);
1107 if (r
< 0 || k
> UINT32_MAX
) {
1108 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1109 "Could not parse TCP %s \"%s\" bytes, ignoring assignment: %m", rvalue
, lvalue
);
1113 if (streq(lvalue
, "InitialCongestionWindow"))
1115 else if (streq(lvalue
, "InitialAdvertisedReceiveWindow"))
1118 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse TCP %s: %s", lvalue
, rvalue
);
1127 int config_parse_quickack(const char *unit
,
1128 const char *filename
,
1130 const char *section
,
1131 unsigned section_line
,
1137 _cleanup_route_free_ Route
*n
= NULL
;
1138 Network
*network
= userdata
;
1147 r
= route_new_static(network
, filename
, section_line
, &n
);
1151 k
= parse_boolean(rvalue
);
1153 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse TCP quickack, ignoring: %s", rvalue
);