1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include <linux/icmpv6.h>
5 #include "alloc-util.h"
6 #include "conf-parser.h"
7 #include "in-addr-util.h"
8 #include "netlink-util.h"
9 #include "networkd-manager.h"
10 #include "networkd-route.h"
11 #include "parse-util.h"
13 #include "string-util.h"
14 #include "sysctl-util.h"
17 #define ROUTES_DEFAULT_MAX_PER_FAMILY 4096U
19 static unsigned routes_max(void) {
20 static thread_local
unsigned cached
= 0;
22 _cleanup_free_
char *s4
= NULL
, *s6
= NULL
;
23 unsigned val4
= ROUTES_DEFAULT_MAX_PER_FAMILY
, val6
= ROUTES_DEFAULT_MAX_PER_FAMILY
;
28 if (sysctl_read("net/ipv4/route/max_size", &s4
) >= 0) {
30 if (safe_atou(s4
, &val4
) >= 0 &&
32 /* This is the default "no limit" value in the kernel */
33 val4
= ROUTES_DEFAULT_MAX_PER_FAMILY
;
36 if (sysctl_read("net/ipv6/route/max_size", &s6
) >= 0) {
38 (void) safe_atou(s6
, &val6
);
41 cached
= MAX(ROUTES_DEFAULT_MAX_PER_FAMILY
, val4
) +
42 MAX(ROUTES_DEFAULT_MAX_PER_FAMILY
, val6
);
46 int route_new(Route
**ret
) {
47 _cleanup_(route_freep
) Route
*route
= NULL
;
49 route
= new(Route
, 1);
55 .scope
= RT_SCOPE_UNIVERSE
,
56 .protocol
= RTPROT_UNSPEC
,
58 .table
= RT_TABLE_MAIN
,
59 .lifetime
= USEC_INFINITY
,
63 *ret
= TAKE_PTR(route
);
68 int route_new_static(Network
*network
, const char *filename
, unsigned section_line
, Route
**ret
) {
69 _cleanup_(network_config_section_freep
) NetworkConfigSection
*n
= NULL
;
70 _cleanup_(route_freep
) Route
*route
= NULL
;
75 assert(!!filename
== (section_line
> 0));
78 r
= network_config_section_new(filename
, section_line
, &n
);
82 route
= hashmap_get(network
->routes_by_section
, n
);
84 *ret
= TAKE_PTR(route
);
90 if (network
->n_static_routes
>= routes_max())
93 r
= route_new(&route
);
97 route
->protocol
= RTPROT_STATIC
;
98 route
->network
= network
;
99 LIST_PREPEND(routes
, network
->static_routes
, route
);
100 network
->n_static_routes
++;
103 route
->section
= TAKE_PTR(n
);
105 r
= hashmap_ensure_allocated(&network
->routes_by_section
, &network_config_hash_ops
);
109 r
= hashmap_put(network
->routes_by_section
, route
->section
, route
);
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 Route
*route
, struct siphash
*state
) {
148 siphash24_compress(&route
->family
, sizeof(route
->family
), state
);
150 switch (route
->family
) {
153 /* Equality of routes are given by the 4-touple
154 (dst_prefix,dst_prefixlen,tos,priority,table) */
155 siphash24_compress(&route
->dst
, FAMILY_ADDRESS_SIZE(route
->family
), state
);
156 siphash24_compress(&route
->dst_prefixlen
, sizeof(route
->dst_prefixlen
), state
);
157 siphash24_compress(&route
->tos
, sizeof(route
->tos
), state
);
158 siphash24_compress(&route
->priority
, sizeof(route
->priority
), state
);
159 siphash24_compress(&route
->table
, sizeof(route
->table
), state
);
163 /* treat any other address family as AF_UNSPEC */
168 static int route_compare_func(const Route
*a
, const Route
*b
) {
171 r
= CMP(a
->family
, b
->family
);
178 r
= CMP(a
->dst_prefixlen
, b
->dst_prefixlen
);
182 r
= CMP(a
->tos
, b
->tos
);
186 r
= CMP(a
->priority
, b
->priority
);
190 r
= CMP(a
->table
, b
->table
);
194 return memcmp(&a
->dst
, &b
->dst
, FAMILY_ADDRESS_SIZE(a
->family
));
196 /* treat any other address family as AF_UNSPEC */
201 DEFINE_PRIVATE_HASH_OPS(route_hash_ops
, Route
, route_hash_func
, route_compare_func
);
203 bool route_equal(Route
*r1
, Route
*r2
) {
210 return route_compare_func(r1
, r2
) == 0;
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
: IN_ADDR_NULL
;
367 route
->src_prefixlen
= src_prefixlen
;
368 route
->gw
= gw
? *gw
: IN_ADDR_NULL
;
369 route
->prefsrc
= prefsrc
? *prefsrc
: IN_ADDR_NULL
;
370 route
->scope
= scope
;
371 route
->protocol
= protocol
;
375 static int route_remove_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
380 assert(link
->ifname
);
382 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
385 r
= sd_netlink_message_get_errno(m
);
386 if (r
< 0 && r
!= -ESRCH
)
387 log_link_warning_errno(link
, r
, "Could not drop route: %m");
392 int route_remove(Route
*route
, Link
*link
,
393 link_netlink_message_handler_t callback
) {
395 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
399 assert(link
->manager
);
400 assert(link
->manager
->rtnl
);
401 assert(link
->ifindex
> 0);
402 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
404 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
405 RTM_DELROUTE
, route
->family
,
408 return log_error_errno(r
, "Could not create RTM_DELROUTE message: %m");
410 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
411 if (route
->family
== AF_INET
)
412 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
413 else if (route
->family
== AF_INET6
)
414 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
416 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
419 if (route
->dst_prefixlen
) {
420 if (route
->family
== AF_INET
)
421 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
422 else if (route
->family
== AF_INET6
)
423 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
425 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
427 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
429 return log_error_errno(r
, "Could not set destination prefix length: %m");
432 if (route
->src_prefixlen
) {
433 if (route
->family
== AF_INET
)
434 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
435 else if (route
->family
== AF_INET6
)
436 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
438 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
440 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
442 return log_error_errno(r
, "Could not set source prefix length: %m");
445 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
446 if (route
->family
== AF_INET
)
447 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
448 else if (route
->family
== AF_INET6
)
449 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
451 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
454 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
456 return log_error_errno(r
, "Could not set scope: %m");
458 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
460 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
462 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
, RTN_THROW
)) {
463 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
465 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
468 r
= netlink_call_async(link
->manager
->rtnl
, NULL
, req
,
469 callback
?: route_remove_handler
,
470 link_netlink_destroy_callback
, link
);
472 return log_error_errno(r
, "Could not send rtnetlink message: %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
, NULL
);
487 log_warning_errno(r
, "Could not remove route: %m");
497 link_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
));
511 if (route_get(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, NULL
) <= 0 &&
512 set_size(link
->routes
) >= routes_max())
515 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
516 RTM_NEWROUTE
, route
->family
,
519 return log_error_errno(r
, "Could not create RTM_NEWROUTE message: %m");
521 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
522 if (route
->family
== AF_INET
)
523 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
524 else if (route
->family
== AF_INET6
)
525 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
527 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
529 r
= sd_rtnl_message_route_set_family(req
, route
->family
);
531 return log_error_errno(r
, "Could not set route family: %m");
534 if (route
->dst_prefixlen
) {
535 if (route
->family
== AF_INET
)
536 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
537 else if (route
->family
== AF_INET6
)
538 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
540 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
542 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
544 return log_error_errno(r
, "Could not set destination prefix length: %m");
547 if (route
->src_prefixlen
) {
548 if (route
->family
== AF_INET
)
549 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
550 else if (route
->family
== AF_INET6
)
551 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
553 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
555 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
557 return log_error_errno(r
, "Could not set source prefix length: %m");
560 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
561 if (route
->family
== AF_INET
)
562 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
563 else if (route
->family
== AF_INET6
)
564 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
566 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
569 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
571 return log_error_errno(r
, "Could not set scope: %m");
573 r
= sd_rtnl_message_route_set_flags(req
, route
->flags
);
575 return log_error_errno(r
, "Could not set flags: %m");
577 if (route
->table
!= RT_TABLE_MAIN
) {
578 if (route
->table
< 256) {
579 r
= sd_rtnl_message_route_set_table(req
, route
->table
);
581 return log_error_errno(r
, "Could not set route table: %m");
583 r
= sd_rtnl_message_route_set_table(req
, RT_TABLE_UNSPEC
);
585 return log_error_errno(r
, "Could not set route table: %m");
587 /* Table attribute to allow more than 256. */
588 r
= sd_netlink_message_append_data(req
, RTA_TABLE
, &route
->table
, sizeof(route
->table
));
590 return log_error_errno(r
, "Could not append RTA_TABLE attribute: %m");
594 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
596 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
598 r
= sd_netlink_message_append_u8(req
, RTA_PREF
, route
->pref
);
600 return log_error_errno(r
, "Could not append RTA_PREF attribute: %m");
602 if (route
->lifetime
!= USEC_INFINITY
&& kernel_route_expiration_supported()) {
603 r
= sd_netlink_message_append_u32(req
, RTA_EXPIRES
,
604 DIV_ROUND_UP(usec_sub_unsigned(route
->lifetime
, now(clock_boottime_or_monotonic())), USEC_PER_SEC
));
606 return log_error_errno(r
, "Could not append RTA_EXPIRES attribute: %m");
609 r
= sd_rtnl_message_route_set_type(req
, route
->type
);
611 return log_error_errno(r
, "Could not set route type: %m");
613 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
, RTN_THROW
)) {
614 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
616 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
619 r
= sd_netlink_message_open_container(req
, RTA_METRICS
);
621 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
623 if (route
->mtu
> 0) {
624 r
= sd_netlink_message_append_u32(req
, RTAX_MTU
, route
->mtu
);
626 return log_error_errno(r
, "Could not append RTAX_MTU attribute: %m");
629 if (route
->initcwnd
> 0) {
630 r
= sd_netlink_message_append_u32(req
, RTAX_INITCWND
, route
->initcwnd
);
632 return log_error_errno(r
, "Could not append RTAX_INITCWND attribute: %m");
635 if (route
->initrwnd
> 0) {
636 r
= sd_netlink_message_append_u32(req
, RTAX_INITRWND
, route
->initrwnd
);
638 return log_error_errno(r
, "Could not append RTAX_INITRWND attribute: %m");
641 if (route
->quickack
!= -1) {
642 r
= sd_netlink_message_append_u32(req
, RTAX_QUICKACK
, route
->quickack
);
644 return log_error_errno(r
, "Could not append RTAX_QUICKACK attribute: %m");
647 r
= sd_netlink_message_close_container(req
);
649 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
651 r
= netlink_call_async(link
->manager
->rtnl
, NULL
, req
, callback
,
652 link_netlink_destroy_callback
, link
);
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(
682 const char *filename
,
685 unsigned section_line
,
692 Network
*network
= userdata
;
693 _cleanup_(route_freep
) Route
*n
= NULL
;
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
, &n
->family
, &n
->gw
);
714 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Route is invalid, ignoring assignment: %s", rvalue
);
723 int config_parse_preferred_src(
725 const char *filename
,
728 unsigned section_line
,
735 Network
*network
= userdata
;
736 _cleanup_(route_freep
) Route
*n
= NULL
;
745 r
= route_new_static(network
, filename
, section_line
, &n
);
749 r
= in_addr_from_string_auto(rvalue
, &n
->family
, &n
->prefsrc
);
751 log_syntax(unit
, LOG_ERR
, filename
, line
, EINVAL
,
752 "Preferred source is invalid, ignoring assignment: %s", rvalue
);
761 int config_parse_destination(
763 const char *filename
,
766 unsigned section_line
,
773 Network
*network
= userdata
;
774 _cleanup_(route_freep
) Route
*n
= NULL
;
775 union in_addr_union
*buffer
;
776 unsigned char *prefixlen
;
785 r
= route_new_static(network
, filename
, section_line
, &n
);
789 if (streq(lvalue
, "Destination")) {
791 prefixlen
= &n
->dst_prefixlen
;
792 } else if (streq(lvalue
, "Source")) {
794 prefixlen
= &n
->src_prefixlen
;
796 assert_not_reached(lvalue
);
798 r
= in_addr_prefix_from_string_auto(rvalue
, &n
->family
, buffer
, prefixlen
);
800 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
801 "Route %s= prefix is invalid, ignoring assignment: %s",
810 int config_parse_route_priority(
812 const char *filename
,
815 unsigned section_line
,
822 Network
*network
= userdata
;
823 _cleanup_(route_freep
) Route
*n
= NULL
;
832 r
= route_new_static(network
, filename
, section_line
, &n
);
836 r
= safe_atou32(rvalue
, &n
->priority
);
838 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
839 "Could not parse route priority \"%s\", ignoring assignment: %m", rvalue
);
847 int config_parse_route_scope(
849 const char *filename
,
852 unsigned section_line
,
859 Network
*network
= userdata
;
860 _cleanup_(route_freep
) Route
*n
= NULL
;
869 r
= route_new_static(network
, filename
, section_line
, &n
);
873 if (streq(rvalue
, "host"))
874 n
->scope
= RT_SCOPE_HOST
;
875 else if (streq(rvalue
, "link"))
876 n
->scope
= RT_SCOPE_LINK
;
877 else if (streq(rvalue
, "global"))
878 n
->scope
= RT_SCOPE_UNIVERSE
;
880 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route scope: %s", rvalue
);
888 int config_parse_route_table(
890 const char *filename
,
893 unsigned section_line
,
900 _cleanup_(route_freep
) Route
*n
= NULL
;
901 Network
*network
= userdata
;
910 r
= route_new_static(network
, filename
, section_line
, &n
);
914 r
= safe_atou32(rvalue
, &n
->table
);
916 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
917 "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue
);
925 int config_parse_gateway_onlink(
927 const char *filename
,
930 unsigned section_line
,
937 Network
*network
= userdata
;
938 _cleanup_(route_freep
) Route
*n
= NULL
;
947 r
= route_new_static(network
, filename
, section_line
, &n
);
951 r
= parse_boolean(rvalue
);
953 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
954 "Could not parse gateway onlink \"%s\", ignoring assignment: %m", rvalue
);
958 SET_FLAG(n
->flags
, RTNH_F_ONLINK
, r
);
963 int config_parse_ipv6_route_preference(
965 const char *filename
,
968 unsigned section_line
,
975 Network
*network
= userdata
;
976 _cleanup_(route_freep
) Route
*n
= NULL
;
979 r
= route_new_static(network
, filename
, section_line
, &n
);
983 if (streq(rvalue
, "low"))
984 n
->pref
= ICMPV6_ROUTER_PREF_LOW
;
985 else if (streq(rvalue
, "medium"))
986 n
->pref
= ICMPV6_ROUTER_PREF_MEDIUM
;
987 else if (streq(rvalue
, "high"))
988 n
->pref
= ICMPV6_ROUTER_PREF_HIGH
;
990 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route preference: %s", rvalue
);
998 int config_parse_route_protocol(
1000 const char *filename
,
1002 const char *section
,
1003 unsigned section_line
,
1010 Network
*network
= userdata
;
1011 _cleanup_(route_freep
) Route
*n
= NULL
;
1014 r
= route_new_static(network
, filename
, section_line
, &n
);
1018 if (streq(rvalue
, "kernel"))
1019 n
->protocol
= RTPROT_KERNEL
;
1020 else if (streq(rvalue
, "boot"))
1021 n
->protocol
= RTPROT_BOOT
;
1022 else if (streq(rvalue
, "static"))
1023 n
->protocol
= RTPROT_STATIC
;
1025 r
= safe_atou8(rvalue
, &n
->protocol
);
1027 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route protocol \"%s\", ignoring assignment: %m", rvalue
);
1036 int config_parse_route_type(
1038 const char *filename
,
1040 const char *section
,
1041 unsigned section_line
,
1048 Network
*network
= userdata
;
1049 _cleanup_(route_freep
) Route
*n
= NULL
;
1052 r
= route_new_static(network
, filename
, section_line
, &n
);
1056 if (streq(rvalue
, "unicast"))
1057 n
->type
= RTN_UNICAST
;
1058 else if (streq(rvalue
, "blackhole"))
1059 n
->type
= RTN_BLACKHOLE
;
1060 else if (streq(rvalue
, "unreachable"))
1061 n
->type
= RTN_UNREACHABLE
;
1062 else if (streq(rvalue
, "prohibit"))
1063 n
->type
= RTN_PROHIBIT
;
1064 else if (streq(rvalue
, "throw"))
1065 n
->type
= RTN_THROW
;
1067 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route type \"%s\", ignoring assignment: %m", rvalue
);
1075 int config_parse_tcp_window(
1077 const char *filename
,
1079 const char *section
,
1080 unsigned section_line
,
1087 _cleanup_(route_freep
) Route
*n
= NULL
;
1088 Network
*network
= userdata
;
1098 r
= route_new_static(network
, filename
, section_line
, &n
);
1102 r
= parse_size(rvalue
, 1024, &k
);
1103 if (r
< 0 || k
> UINT32_MAX
) {
1104 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1105 "Could not parse TCP %s \"%s\" bytes, ignoring assignment: %m", rvalue
, lvalue
);
1109 if (streq(lvalue
, "InitialCongestionWindow"))
1111 else if (streq(lvalue
, "InitialAdvertisedReceiveWindow"))
1114 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse TCP %s: %s", lvalue
, rvalue
);
1122 int config_parse_quickack(
1124 const char *filename
,
1126 const char *section
,
1127 unsigned section_line
,
1134 _cleanup_(route_freep
) Route
*n
= NULL
;
1135 Network
*network
= userdata
;
1144 r
= route_new_static(network
, filename
, section_line
, &n
);
1148 k
= parse_boolean(rvalue
);
1150 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse TCP quickack, ignoring: %s", rvalue
);
1159 int config_parse_route_mtu(
1161 const char *filename
,
1163 const char *section
,
1164 unsigned section_line
,
1171 Network
*network
= userdata
;
1172 _cleanup_(route_freep
) Route
*n
= NULL
;
1181 r
= route_new_static(network
, filename
, section_line
, &n
);
1185 r
= config_parse_mtu(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &n
->mtu
, userdata
);