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
= new0(Route
, 1);
53 route
->family
= AF_UNSPEC
;
54 route
->scope
= RT_SCOPE_UNIVERSE
;
55 route
->protocol
= RTPROT_UNSPEC
;
56 route
->type
= RTN_UNICAST
;
57 route
->table
= RT_TABLE_MAIN
;
58 route
->lifetime
= USEC_INFINITY
;
61 *ret
= TAKE_PTR(route
);
66 int route_new_static(Network
*network
, const char *filename
, unsigned section_line
, Route
**ret
) {
67 _cleanup_(network_config_section_freep
) NetworkConfigSection
*n
= NULL
;
68 _cleanup_(route_freep
) Route
*route
= NULL
;
73 assert(!!filename
== (section_line
> 0));
76 r
= network_config_section_new(filename
, section_line
, &n
);
80 route
= hashmap_get(network
->routes_by_section
, n
);
82 *ret
= TAKE_PTR(route
);
88 if (network
->n_static_routes
>= routes_max())
91 r
= route_new(&route
);
95 route
->protocol
= RTPROT_STATIC
;
98 route
->section
= TAKE_PTR(n
);
100 r
= hashmap_put(network
->routes_by_section
, route
->section
, route
);
105 route
->network
= network
;
106 LIST_PREPEND(routes
, network
->static_routes
, route
);
107 network
->n_static_routes
++;
109 *ret
= TAKE_PTR(route
);
114 void route_free(Route
*route
) {
118 if (route
->network
) {
119 LIST_REMOVE(routes
, route
->network
->static_routes
, route
);
121 assert(route
->network
->n_static_routes
> 0);
122 route
->network
->n_static_routes
--;
125 hashmap_remove(route
->network
->routes_by_section
, route
->section
);
128 network_config_section_free(route
->section
);
131 set_remove(route
->link
->routes
, route
);
132 set_remove(route
->link
->routes_foreign
, route
);
135 sd_event_source_unref(route
->expire
);
140 static void route_hash_func(const void *b
, struct siphash
*state
) {
141 const Route
*route
= b
;
145 siphash24_compress(&route
->family
, sizeof(route
->family
), state
);
147 switch (route
->family
) {
150 /* Equality of routes are given by the 4-touple
151 (dst_prefix,dst_prefixlen,tos,priority,table) */
152 siphash24_compress(&route
->dst
, FAMILY_ADDRESS_SIZE(route
->family
), state
);
153 siphash24_compress(&route
->dst_prefixlen
, sizeof(route
->dst_prefixlen
), state
);
154 siphash24_compress(&route
->tos
, sizeof(route
->tos
), state
);
155 siphash24_compress(&route
->priority
, sizeof(route
->priority
), state
);
156 siphash24_compress(&route
->table
, sizeof(route
->table
), state
);
160 /* treat any other address family as AF_UNSPEC */
165 static int route_compare_func(const void *_a
, const void *_b
) {
166 const Route
*a
= _a
, *b
= _b
;
169 r
= CMP(a
->family
, b
->family
);
176 r
= CMP(a
->dst_prefixlen
, b
->dst_prefixlen
);
180 r
= CMP(a
->tos
, b
->tos
);
184 r
= CMP(a
->priority
, b
->priority
);
188 r
= CMP(a
->table
, b
->table
);
192 return memcmp(&a
->dst
, &b
->dst
, FAMILY_ADDRESS_SIZE(a
->family
));
194 /* treat any other address family as AF_UNSPEC */
199 static const struct hash_ops route_hash_ops
= {
200 .hash
= route_hash_func
,
201 .compare
= route_compare_func
204 int route_get(Link
*link
,
206 const union in_addr_union
*dst
,
207 unsigned char dst_prefixlen
,
213 Route route
, *existing
;
221 .dst_prefixlen
= dst_prefixlen
,
223 .priority
= priority
,
227 existing
= set_get(link
->routes
, &route
);
234 existing
= set_get(link
->routes_foreign
, &route
);
244 static int route_add_internal(
248 const union in_addr_union
*dst
,
249 unsigned char dst_prefixlen
,
255 _cleanup_(route_freep
) Route
*route
= NULL
;
262 r
= route_new(&route
);
266 route
->family
= family
;
268 route
->dst_prefixlen
= dst_prefixlen
;
270 route
->priority
= priority
;
271 route
->table
= table
;
273 r
= set_ensure_allocated(routes
, &route_hash_ops
);
277 r
= set_put(*routes
, route
);
291 int route_add_foreign(
294 const union in_addr_union
*dst
,
295 unsigned char dst_prefixlen
,
301 return route_add_internal(link
, &link
->routes_foreign
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, ret
);
304 int route_add(Link
*link
,
306 const union in_addr_union
*dst
,
307 unsigned char dst_prefixlen
,
316 r
= route_get(link
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
318 /* Route does not exist, create a new one */
319 r
= route_add_internal(link
, &link
->routes
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
323 /* Take over a foreign route */
324 r
= set_ensure_allocated(&link
->routes
, &route_hash_ops
);
328 r
= set_put(link
->routes
, route
);
332 set_remove(link
->routes_foreign
, route
);
334 /* Route exists, do nothing */
345 void route_update(Route
*route
,
346 const union in_addr_union
*src
,
347 unsigned char src_prefixlen
,
348 const union in_addr_union
*gw
,
349 const union in_addr_union
*prefsrc
,
351 unsigned char protocol
,
352 unsigned char type
) {
355 assert(src
|| src_prefixlen
== 0);
357 route
->src
= src
? *src
: (union in_addr_union
) {};
358 route
->src_prefixlen
= src_prefixlen
;
359 route
->gw
= gw
? *gw
: (union in_addr_union
) {};
360 route
->prefsrc
= prefsrc
? *prefsrc
: (union in_addr_union
) {};
361 route
->scope
= scope
;
362 route
->protocol
= protocol
;
366 int route_remove(Route
*route
, Link
*link
,
367 sd_netlink_message_handler_t callback
) {
369 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
373 assert(link
->manager
);
374 assert(link
->manager
->rtnl
);
375 assert(link
->ifindex
> 0);
376 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
378 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
379 RTM_DELROUTE
, route
->family
,
382 return log_error_errno(r
, "Could not create RTM_DELROUTE message: %m");
384 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
385 if (route
->family
== AF_INET
)
386 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
387 else if (route
->family
== AF_INET6
)
388 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
390 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
393 if (route
->dst_prefixlen
) {
394 if (route
->family
== AF_INET
)
395 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
396 else if (route
->family
== AF_INET6
)
397 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
399 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
401 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
403 return log_error_errno(r
, "Could not set destination prefix length: %m");
406 if (route
->src_prefixlen
) {
407 if (route
->family
== AF_INET
)
408 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
409 else if (route
->family
== AF_INET6
)
410 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
412 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
414 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
416 return log_error_errno(r
, "Could not set source prefix length: %m");
419 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
420 if (route
->family
== AF_INET
)
421 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
422 else if (route
->family
== AF_INET6
)
423 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
425 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
428 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
430 return log_error_errno(r
, "Could not set scope: %m");
432 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
434 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
436 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
)) {
437 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
439 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
442 r
= sd_netlink_call_async(link
->manager
->rtnl
, req
, callback
,
443 link_netlink_destroy_callback
, link
, 0, NULL
);
445 return log_error_errno(r
, "Could not send rtnetlink message: %m");
452 int route_expire_handler(sd_event_source
*s
, uint64_t usec
, void *userdata
) {
453 Route
*route
= userdata
;
458 r
= route_remove(route
, route
->link
, link_route_remove_handler
);
460 log_warning_errno(r
, "Could not remove route: %m");
470 sd_netlink_message_handler_t callback
) {
472 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
473 _cleanup_(sd_event_source_unrefp
) sd_event_source
*expire
= NULL
;
478 assert(link
->manager
);
479 assert(link
->manager
->rtnl
);
480 assert(link
->ifindex
> 0);
481 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
483 if (route_get(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, NULL
) <= 0 &&
484 set_size(link
->routes
) >= routes_max())
487 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
488 RTM_NEWROUTE
, route
->family
,
491 return log_error_errno(r
, "Could not create RTM_NEWROUTE message: %m");
493 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
494 if (route
->family
== AF_INET
)
495 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
496 else if (route
->family
== AF_INET6
)
497 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
499 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
501 r
= sd_rtnl_message_route_set_family(req
, route
->family
);
503 return log_error_errno(r
, "Could not set route family: %m");
506 if (route
->dst_prefixlen
) {
507 if (route
->family
== AF_INET
)
508 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
509 else if (route
->family
== AF_INET6
)
510 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
512 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
514 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
516 return log_error_errno(r
, "Could not set destination prefix length: %m");
519 if (route
->src_prefixlen
) {
520 if (route
->family
== AF_INET
)
521 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
522 else if (route
->family
== AF_INET6
)
523 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
525 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
527 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
529 return log_error_errno(r
, "Could not set source prefix length: %m");
532 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
533 if (route
->family
== AF_INET
)
534 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
535 else if (route
->family
== AF_INET6
)
536 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
538 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
541 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
543 return log_error_errno(r
, "Could not set scope: %m");
545 r
= sd_rtnl_message_route_set_flags(req
, route
->flags
);
547 return log_error_errno(r
, "Could not set flags: %m");
549 if (route
->table
!= RT_TABLE_MAIN
) {
550 if (route
->table
< 256) {
551 r
= sd_rtnl_message_route_set_table(req
, route
->table
);
553 return log_error_errno(r
, "Could not set route table: %m");
555 r
= sd_rtnl_message_route_set_table(req
, RT_TABLE_UNSPEC
);
557 return log_error_errno(r
, "Could not set route table: %m");
559 /* Table attribute to allow more than 256. */
560 r
= sd_netlink_message_append_data(req
, RTA_TABLE
, &route
->table
, sizeof(route
->table
));
562 return log_error_errno(r
, "Could not append RTA_TABLE attribute: %m");
566 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
568 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
570 r
= sd_netlink_message_append_u8(req
, RTA_PREF
, route
->pref
);
572 return log_error_errno(r
, "Could not append RTA_PREF attribute: %m");
574 if (route
->lifetime
!= USEC_INFINITY
&& kernel_route_expiration_supported()) {
575 r
= sd_netlink_message_append_u32(req
, RTA_EXPIRES
,
576 DIV_ROUND_UP(usec_sub_unsigned(route
->lifetime
, now(clock_boottime_or_monotonic())), USEC_PER_SEC
));
578 return log_error_errno(r
, "Could not append RTA_EXPIRES attribute: %m");
581 r
= sd_rtnl_message_route_set_type(req
, route
->type
);
583 return log_error_errno(r
, "Could not set route type: %m");
585 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
)) {
586 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
588 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
591 r
= sd_netlink_message_open_container(req
, RTA_METRICS
);
593 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
595 if (route
->mtu
> 0) {
596 r
= sd_netlink_message_append_u32(req
, RTAX_MTU
, route
->mtu
);
598 return log_error_errno(r
, "Could not append RTAX_MTU attribute: %m");
601 if (route
->initcwnd
> 0) {
602 r
= sd_netlink_message_append_u32(req
, RTAX_INITCWND
, route
->initcwnd
);
604 return log_error_errno(r
, "Could not append RTAX_INITCWND attribute: %m");
607 if (route
->initrwnd
> 0) {
608 r
= sd_netlink_message_append_u32(req
, RTAX_INITRWND
, route
->initrwnd
);
610 return log_error_errno(r
, "Could not append RTAX_INITRWND attribute: %m");
613 if (route
->quickack
!= -1) {
614 r
= sd_netlink_message_append_u32(req
, RTAX_QUICKACK
, route
->quickack
);
616 return log_error_errno(r
, "Could not append RTAX_QUICKACK attribute: %m");
619 r
= sd_netlink_message_close_container(req
);
621 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
623 r
= sd_netlink_call_async(link
->manager
->rtnl
, req
, callback
,
624 link_netlink_destroy_callback
, link
, 0, NULL
);
626 return log_error_errno(r
, "Could not send rtnetlink message: %m");
630 lifetime
= route
->lifetime
;
632 r
= route_add(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, &route
);
634 return log_error_errno(r
, "Could not add route: %m");
636 /* TODO: drop expiration handling once it can be pushed into the kernel */
637 route
->lifetime
= lifetime
;
639 if (route
->lifetime
!= USEC_INFINITY
&& !kernel_route_expiration_supported()) {
640 r
= sd_event_add_time(link
->manager
->event
, &expire
, clock_boottime_or_monotonic(),
641 route
->lifetime
, 0, route_expire_handler
, route
);
643 return log_error_errno(r
, "Could not arm expiration timer: %m");
646 sd_event_source_unref(route
->expire
);
647 route
->expire
= TAKE_PTR(expire
);
652 int config_parse_gateway(
654 const char *filename
,
657 unsigned section_line
,
664 Network
*network
= userdata
;
665 _cleanup_(route_freep
) Route
*n
= NULL
;
666 union in_addr_union buffer
;
675 if (streq(section
, "Network")) {
676 /* we are not in an Route section, so treat
677 * this as the special '0' section */
678 r
= route_new_static(network
, NULL
, 0, &n
);
680 r
= route_new_static(network
, filename
, section_line
, &n
);
685 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
687 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Route is invalid, ignoring assignment: %s", rvalue
);
698 int config_parse_preferred_src(
700 const char *filename
,
703 unsigned section_line
,
710 Network
*network
= userdata
;
711 _cleanup_(route_freep
) Route
*n
= NULL
;
712 union in_addr_union buffer
;
721 r
= route_new_static(network
, filename
, section_line
, &n
);
725 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
727 log_syntax(unit
, LOG_ERR
, filename
, line
, EINVAL
,
728 "Preferred source is invalid, ignoring assignment: %s", rvalue
);
739 int config_parse_destination(
741 const char *filename
,
744 unsigned section_line
,
751 Network
*network
= userdata
;
752 _cleanup_(route_freep
) Route
*n
= NULL
;
753 union in_addr_union buffer
;
754 unsigned char prefixlen
;
763 r
= route_new_static(network
, filename
, section_line
, &n
);
767 r
= in_addr_prefix_from_string(rvalue
, AF_INET
, &buffer
, &prefixlen
);
769 r
= in_addr_prefix_from_string(rvalue
, AF_INET6
, &buffer
, &prefixlen
);
771 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
772 "Route %s= prefix is invalid, ignoring assignment: %s",
777 n
->family
= AF_INET6
;
781 if (streq(lvalue
, "Destination")) {
783 n
->dst_prefixlen
= prefixlen
;
784 } else if (streq(lvalue
, "Source")) {
786 n
->src_prefixlen
= prefixlen
;
788 assert_not_reached(lvalue
);
794 int config_parse_route_priority(
796 const char *filename
,
799 unsigned section_line
,
806 Network
*network
= userdata
;
807 _cleanup_(route_freep
) Route
*n
= NULL
;
816 r
= route_new_static(network
, filename
, section_line
, &n
);
820 r
= safe_atou32(rvalue
, &n
->priority
);
822 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
823 "Could not parse route priority \"%s\", ignoring assignment: %m", rvalue
);
831 int config_parse_route_scope(
833 const char *filename
,
836 unsigned section_line
,
843 Network
*network
= userdata
;
844 _cleanup_(route_freep
) Route
*n
= NULL
;
853 r
= route_new_static(network
, filename
, section_line
, &n
);
857 if (streq(rvalue
, "host"))
858 n
->scope
= RT_SCOPE_HOST
;
859 else if (streq(rvalue
, "link"))
860 n
->scope
= RT_SCOPE_LINK
;
861 else if (streq(rvalue
, "global"))
862 n
->scope
= RT_SCOPE_UNIVERSE
;
864 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route scope: %s", rvalue
);
872 int config_parse_route_table(
874 const char *filename
,
877 unsigned section_line
,
884 _cleanup_(route_freep
) Route
*n
= NULL
;
885 Network
*network
= userdata
;
894 r
= route_new_static(network
, filename
, section_line
, &n
);
898 r
= safe_atou32(rvalue
, &n
->table
);
900 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
901 "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue
);
909 int config_parse_gateway_onlink(
911 const char *filename
,
914 unsigned section_line
,
921 Network
*network
= userdata
;
922 _cleanup_(route_freep
) Route
*n
= NULL
;
931 r
= route_new_static(network
, filename
, section_line
, &n
);
935 r
= parse_boolean(rvalue
);
937 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
938 "Could not parse gateway onlink \"%s\", ignoring assignment: %m", rvalue
);
942 SET_FLAG(n
->flags
, RTNH_F_ONLINK
, r
);
947 int config_parse_ipv6_route_preference(
949 const char *filename
,
952 unsigned section_line
,
959 Network
*network
= userdata
;
960 _cleanup_(route_freep
) Route
*n
= NULL
;
963 r
= route_new_static(network
, filename
, section_line
, &n
);
967 if (streq(rvalue
, "low"))
968 n
->pref
= ICMPV6_ROUTER_PREF_LOW
;
969 else if (streq(rvalue
, "medium"))
970 n
->pref
= ICMPV6_ROUTER_PREF_MEDIUM
;
971 else if (streq(rvalue
, "high"))
972 n
->pref
= ICMPV6_ROUTER_PREF_HIGH
;
974 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route preference: %s", rvalue
);
982 int config_parse_route_protocol(
984 const char *filename
,
987 unsigned section_line
,
994 Network
*network
= userdata
;
995 _cleanup_(route_freep
) Route
*n
= NULL
;
998 r
= route_new_static(network
, filename
, section_line
, &n
);
1002 if (streq(rvalue
, "kernel"))
1003 n
->protocol
= RTPROT_KERNEL
;
1004 else if (streq(rvalue
, "boot"))
1005 n
->protocol
= RTPROT_BOOT
;
1006 else if (streq(rvalue
, "static"))
1007 n
->protocol
= RTPROT_STATIC
;
1009 r
= safe_atou8(rvalue
, &n
->protocol
);
1011 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route protocol \"%s\", ignoring assignment: %m", rvalue
);
1020 int config_parse_route_type(
1022 const char *filename
,
1024 const char *section
,
1025 unsigned section_line
,
1032 Network
*network
= userdata
;
1033 _cleanup_(route_freep
) Route
*n
= NULL
;
1036 r
= route_new_static(network
, filename
, section_line
, &n
);
1040 if (streq(rvalue
, "unicast"))
1041 n
->type
= RTN_UNICAST
;
1042 else if (streq(rvalue
, "blackhole"))
1043 n
->type
= RTN_BLACKHOLE
;
1044 else if (streq(rvalue
, "unreachable"))
1045 n
->type
= RTN_UNREACHABLE
;
1046 else if (streq(rvalue
, "prohibit"))
1047 n
->type
= RTN_PROHIBIT
;
1049 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route type \"%s\", ignoring assignment: %m", rvalue
);
1057 int config_parse_tcp_window(
1059 const char *filename
,
1061 const char *section
,
1062 unsigned section_line
,
1069 _cleanup_(route_freep
) Route
*n
= NULL
;
1070 Network
*network
= userdata
;
1080 r
= route_new_static(network
, filename
, section_line
, &n
);
1084 r
= parse_size(rvalue
, 1024, &k
);
1085 if (r
< 0 || k
> UINT32_MAX
) {
1086 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1087 "Could not parse TCP %s \"%s\" bytes, ignoring assignment: %m", rvalue
, lvalue
);
1091 if (streq(lvalue
, "InitialCongestionWindow"))
1093 else if (streq(lvalue
, "InitialAdvertisedReceiveWindow"))
1096 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse TCP %s: %s", lvalue
, rvalue
);
1104 int config_parse_quickack(
1106 const char *filename
,
1108 const char *section
,
1109 unsigned section_line
,
1116 _cleanup_(route_freep
) Route
*n
= NULL
;
1117 Network
*network
= userdata
;
1126 r
= route_new_static(network
, filename
, section_line
, &n
);
1130 k
= parse_boolean(rvalue
);
1132 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse TCP quickack, ignoring: %s", rvalue
);
1141 int config_parse_route_mtu(
1143 const char *filename
,
1145 const char *section
,
1146 unsigned section_line
,
1153 Network
*network
= userdata
;
1154 _cleanup_(route_freep
) Route
*n
= NULL
;
1163 r
= route_new_static(network
, filename
, section_line
, &n
);
1167 r
= config_parse_mtu(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &n
->mtu
, userdata
);