1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2013 Tom Gundersen <teg@jklm.no>
6 #include <linux/icmpv6.h>
8 #include "alloc-util.h"
9 #include "conf-parser.h"
10 #include "in-addr-util.h"
11 #include "netlink-util.h"
12 #include "networkd-manager.h"
13 #include "networkd-route.h"
14 #include "parse-util.h"
16 #include "string-util.h"
17 #include "sysctl-util.h"
20 #define ROUTES_DEFAULT_MAX_PER_FAMILY 4096U
22 static unsigned routes_max(void) {
23 static thread_local
unsigned cached
= 0;
25 _cleanup_free_
char *s4
= NULL
, *s6
= NULL
;
26 unsigned val4
= ROUTES_DEFAULT_MAX_PER_FAMILY
, val6
= ROUTES_DEFAULT_MAX_PER_FAMILY
;
31 if (sysctl_read("net/ipv4/route/max_size", &s4
) >= 0) {
33 if (safe_atou(s4
, &val4
) >= 0 &&
35 /* This is the default "no limit" value in the kernel */
36 val4
= ROUTES_DEFAULT_MAX_PER_FAMILY
;
39 if (sysctl_read("net/ipv6/route/max_size", &s6
) >= 0) {
41 (void) safe_atou(s6
, &val6
);
44 cached
= MAX(ROUTES_DEFAULT_MAX_PER_FAMILY
, val4
) +
45 MAX(ROUTES_DEFAULT_MAX_PER_FAMILY
, val6
);
49 int route_new(Route
**ret
) {
50 _cleanup_(route_freep
) Route
*route
= NULL
;
52 route
= new0(Route
, 1);
56 route
->family
= AF_UNSPEC
;
57 route
->scope
= RT_SCOPE_UNIVERSE
;
58 route
->protocol
= RTPROT_UNSPEC
;
59 route
->type
= RTN_UNICAST
;
60 route
->table
= RT_TABLE_MAIN
;
61 route
->lifetime
= USEC_INFINITY
;
64 *ret
= TAKE_PTR(route
);
69 int route_new_static(Network
*network
, const char *filename
, unsigned section_line
, Route
**ret
) {
70 _cleanup_(network_config_section_freep
) NetworkConfigSection
*n
= NULL
;
71 _cleanup_(route_freep
) Route
*route
= NULL
;
76 assert(!!filename
== (section_line
> 0));
79 r
= network_config_section_new(filename
, section_line
, &n
);
83 route
= hashmap_get(network
->routes_by_section
, n
);
85 *ret
= TAKE_PTR(route
);
91 if (network
->n_static_routes
>= routes_max())
94 r
= route_new(&route
);
98 route
->protocol
= RTPROT_STATIC
;
101 route
->section
= TAKE_PTR(n
);
103 r
= hashmap_put(network
->routes_by_section
, route
->section
, route
);
108 route
->network
= network
;
109 LIST_PREPEND(routes
, network
->static_routes
, route
);
110 network
->n_static_routes
++;
112 *ret
= TAKE_PTR(route
);
117 void route_free(Route
*route
) {
121 if (route
->network
) {
122 LIST_REMOVE(routes
, route
->network
->static_routes
, route
);
124 assert(route
->network
->n_static_routes
> 0);
125 route
->network
->n_static_routes
--;
128 hashmap_remove(route
->network
->routes_by_section
, route
->section
);
131 network_config_section_free(route
->section
);
134 set_remove(route
->link
->routes
, route
);
135 set_remove(route
->link
->routes_foreign
, route
);
138 sd_event_source_unref(route
->expire
);
143 static void route_hash_func(const void *b
, struct siphash
*state
) {
144 const Route
*route
= b
;
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 void *_a
, const void *_b
) {
169 const Route
*a
= _a
, *b
= _b
;
171 if (a
->family
< b
->family
)
173 if (a
->family
> b
->family
)
179 if (a
->dst_prefixlen
< b
->dst_prefixlen
)
181 if (a
->dst_prefixlen
> b
->dst_prefixlen
)
189 if (a
->priority
< b
->priority
)
191 if (a
->priority
> b
->priority
)
194 if (a
->table
< b
->table
)
196 if (a
->table
> b
->table
)
199 return memcmp(&a
->dst
, &b
->dst
, FAMILY_ADDRESS_SIZE(a
->family
));
201 /* treat any other address family as AF_UNSPEC */
206 static const struct hash_ops route_hash_ops
= {
207 .hash
= route_hash_func
,
208 .compare
= route_compare_func
211 int route_get(Link
*link
,
213 const union in_addr_union
*dst
,
214 unsigned char dst_prefixlen
,
220 Route route
, *existing
;
228 .dst_prefixlen
= dst_prefixlen
,
230 .priority
= priority
,
234 existing
= set_get(link
->routes
, &route
);
241 existing
= set_get(link
->routes_foreign
, &route
);
251 static int route_add_internal(
255 const union in_addr_union
*dst
,
256 unsigned char dst_prefixlen
,
262 _cleanup_(route_freep
) Route
*route
= NULL
;
269 r
= route_new(&route
);
273 route
->family
= family
;
275 route
->dst_prefixlen
= dst_prefixlen
;
277 route
->priority
= priority
;
278 route
->table
= table
;
280 r
= set_ensure_allocated(routes
, &route_hash_ops
);
284 r
= set_put(*routes
, route
);
298 int route_add_foreign(
301 const union in_addr_union
*dst
,
302 unsigned char dst_prefixlen
,
308 return route_add_internal(link
, &link
->routes_foreign
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, ret
);
311 int route_add(Link
*link
,
313 const union in_addr_union
*dst
,
314 unsigned char dst_prefixlen
,
323 r
= route_get(link
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
325 /* Route does not exist, create a new one */
326 r
= route_add_internal(link
, &link
->routes
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
330 /* Take over a foreign route */
331 r
= set_ensure_allocated(&link
->routes
, &route_hash_ops
);
335 r
= set_put(link
->routes
, route
);
339 set_remove(link
->routes_foreign
, route
);
341 /* Route exists, do nothing */
352 void route_update(Route
*route
,
353 const union in_addr_union
*src
,
354 unsigned char src_prefixlen
,
355 const union in_addr_union
*gw
,
356 const union in_addr_union
*prefsrc
,
358 unsigned char protocol
,
359 unsigned char type
) {
362 assert(src
|| src_prefixlen
== 0);
364 route
->src
= src
? *src
: (union in_addr_union
) {};
365 route
->src_prefixlen
= src_prefixlen
;
366 route
->gw
= gw
? *gw
: (union in_addr_union
) {};
367 route
->prefsrc
= prefsrc
? *prefsrc
: (union in_addr_union
) {};
368 route
->scope
= scope
;
369 route
->protocol
= protocol
;
373 int route_remove(Route
*route
, Link
*link
,
374 sd_netlink_message_handler_t callback
) {
376 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
380 assert(link
->manager
);
381 assert(link
->manager
->rtnl
);
382 assert(link
->ifindex
> 0);
383 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
385 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
386 RTM_DELROUTE
, route
->family
,
389 return log_error_errno(r
, "Could not create RTM_DELROUTE message: %m");
391 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
392 if (route
->family
== AF_INET
)
393 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
394 else if (route
->family
== AF_INET6
)
395 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
397 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
400 if (route
->dst_prefixlen
) {
401 if (route
->family
== AF_INET
)
402 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
403 else if (route
->family
== AF_INET6
)
404 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
406 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
408 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
410 return log_error_errno(r
, "Could not set destination prefix length: %m");
413 if (route
->src_prefixlen
) {
414 if (route
->family
== AF_INET
)
415 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
416 else if (route
->family
== AF_INET6
)
417 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
419 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
421 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
423 return log_error_errno(r
, "Could not set source prefix length: %m");
426 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
427 if (route
->family
== AF_INET
)
428 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
429 else if (route
->family
== AF_INET6
)
430 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
432 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
435 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
437 return log_error_errno(r
, "Could not set scope: %m");
439 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
441 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
443 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
)) {
444 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
446 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
449 r
= sd_netlink_call_async(link
->manager
->rtnl
, req
, callback
, link
, 0, NULL
);
451 return log_error_errno(r
, "Could not send rtnetlink message: %m");
458 static int route_expire_callback(sd_netlink
*rtnl
, sd_netlink_message
*m
, void *userdata
) {
459 Link
*link
= userdata
;
465 assert(link
->ifname
);
467 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
470 r
= sd_netlink_message_get_errno(m
);
471 if (r
< 0 && r
!= -EEXIST
)
472 log_link_warning_errno(link
, r
, "could not remove route: %m");
477 int route_expire_handler(sd_event_source
*s
, uint64_t usec
, void *userdata
) {
478 Route
*route
= userdata
;
483 r
= route_remove(route
, route
->link
, route_expire_callback
);
485 log_warning_errno(r
, "Could not remove route: %m");
495 sd_netlink_message_handler_t callback
) {
497 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
498 _cleanup_(sd_event_source_unrefp
) sd_event_source
*expire
= NULL
;
503 assert(link
->manager
);
504 assert(link
->manager
->rtnl
);
505 assert(link
->ifindex
> 0);
506 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
508 if (route_get(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, NULL
) <= 0 &&
509 set_size(link
->routes
) >= routes_max())
512 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
513 RTM_NEWROUTE
, route
->family
,
516 return log_error_errno(r
, "Could not create RTM_NEWROUTE message: %m");
518 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
519 if (route
->family
== AF_INET
)
520 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
521 else if (route
->family
== AF_INET6
)
522 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
524 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
526 r
= sd_rtnl_message_route_set_family(req
, route
->family
);
528 return log_error_errno(r
, "Could not set route family: %m");
531 if (route
->dst_prefixlen
) {
532 if (route
->family
== AF_INET
)
533 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
534 else if (route
->family
== AF_INET6
)
535 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
537 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
539 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
541 return log_error_errno(r
, "Could not set destination prefix length: %m");
544 if (route
->src_prefixlen
) {
545 if (route
->family
== AF_INET
)
546 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
547 else if (route
->family
== AF_INET6
)
548 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
550 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
552 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
554 return log_error_errno(r
, "Could not set source prefix length: %m");
557 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
558 if (route
->family
== AF_INET
)
559 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
560 else if (route
->family
== AF_INET6
)
561 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
563 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
566 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
568 return log_error_errno(r
, "Could not set scope: %m");
570 r
= sd_rtnl_message_route_set_flags(req
, route
->flags
);
572 return log_error_errno(r
, "Could not set flags: %m");
574 if (route
->table
!= RT_TABLE_MAIN
) {
575 if (route
->table
< 256) {
576 r
= sd_rtnl_message_route_set_table(req
, route
->table
);
578 return log_error_errno(r
, "Could not set route table: %m");
580 r
= sd_rtnl_message_route_set_table(req
, RT_TABLE_UNSPEC
);
582 return log_error_errno(r
, "Could not set route table: %m");
584 /* Table attribute to allow more than 256. */
585 r
= sd_netlink_message_append_data(req
, RTA_TABLE
, &route
->table
, sizeof(route
->table
));
587 return log_error_errno(r
, "Could not append RTA_TABLE attribute: %m");
591 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
593 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
595 r
= sd_netlink_message_append_u8(req
, RTA_PREF
, route
->pref
);
597 return log_error_errno(r
, "Could not append RTA_PREF attribute: %m");
599 if (route
->lifetime
!= USEC_INFINITY
&& kernel_route_expiration_supported()) {
600 r
= sd_netlink_message_append_u32(req
, RTA_EXPIRES
,
601 DIV_ROUND_UP(usec_sub_unsigned(route
->lifetime
, now(clock_boottime_or_monotonic())), USEC_PER_SEC
));
603 return log_error_errno(r
, "Could not append RTA_EXPIRES attribute: %m");
606 r
= sd_rtnl_message_route_set_type(req
, route
->type
);
608 return log_error_errno(r
, "Could not set route type: %m");
610 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
)) {
611 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
613 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
616 r
= sd_netlink_message_open_container(req
, RTA_METRICS
);
618 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
620 if (route
->mtu
> 0) {
621 r
= sd_netlink_message_append_u32(req
, RTAX_MTU
, route
->mtu
);
623 return log_error_errno(r
, "Could not append RTAX_MTU attribute: %m");
626 if (route
->initcwnd
> 0) {
627 r
= sd_netlink_message_append_u32(req
, RTAX_INITCWND
, route
->initcwnd
);
629 return log_error_errno(r
, "Could not append RTAX_INITCWND attribute: %m");
632 if (route
->initrwnd
> 0) {
633 r
= sd_netlink_message_append_u32(req
, RTAX_INITRWND
, route
->initrwnd
);
635 return log_error_errno(r
, "Could not append RTAX_INITRWND attribute: %m");
638 if (route
->quickack
!= -1) {
639 r
= sd_netlink_message_append_u32(req
, RTAX_QUICKACK
, route
->quickack
);
641 return log_error_errno(r
, "Could not append RTAX_QUICKACK attribute: %m");
644 r
= sd_netlink_message_close_container(req
);
646 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
648 r
= sd_netlink_call_async(link
->manager
->rtnl
, req
, callback
, link
, 0, NULL
);
650 return log_error_errno(r
, "Could not send rtnetlink message: %m");
654 lifetime
= route
->lifetime
;
656 r
= route_add(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, &route
);
658 return log_error_errno(r
, "Could not add route: %m");
660 /* TODO: drop expiration handling once it can be pushed into the kernel */
661 route
->lifetime
= lifetime
;
663 if (route
->lifetime
!= USEC_INFINITY
&& !kernel_route_expiration_supported()) {
664 r
= sd_event_add_time(link
->manager
->event
, &expire
, clock_boottime_or_monotonic(),
665 route
->lifetime
, 0, route_expire_handler
, route
);
667 return log_error_errno(r
, "Could not arm expiration timer: %m");
670 sd_event_source_unref(route
->expire
);
671 route
->expire
= TAKE_PTR(expire
);
676 int config_parse_gateway(
678 const char *filename
,
681 unsigned section_line
,
688 Network
*network
= userdata
;
689 _cleanup_(route_freep
) Route
*n
= NULL
;
690 union in_addr_union buffer
;
699 if (streq(section
, "Network")) {
700 /* we are not in an Route section, so treat
701 * this as the special '0' section */
702 r
= route_new_static(network
, NULL
, 0, &n
);
704 r
= route_new_static(network
, filename
, section_line
, &n
);
709 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
711 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Route is invalid, ignoring assignment: %s", rvalue
);
722 int config_parse_preferred_src(
724 const char *filename
,
727 unsigned section_line
,
734 Network
*network
= userdata
;
735 _cleanup_(route_freep
) Route
*n
= NULL
;
736 union in_addr_union buffer
;
745 r
= route_new_static(network
, filename
, section_line
, &n
);
749 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
751 log_syntax(unit
, LOG_ERR
, filename
, line
, EINVAL
,
752 "Preferred source is invalid, ignoring assignment: %s", rvalue
);
763 int config_parse_destination(
765 const char *filename
,
768 unsigned section_line
,
775 Network
*network
= userdata
;
776 _cleanup_(route_freep
) Route
*n
= NULL
;
777 union in_addr_union buffer
;
778 unsigned char prefixlen
;
787 r
= route_new_static(network
, filename
, section_line
, &n
);
791 r
= in_addr_prefix_from_string(rvalue
, AF_INET
, &buffer
, &prefixlen
);
793 r
= in_addr_prefix_from_string(rvalue
, AF_INET6
, &buffer
, &prefixlen
);
795 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
796 "Route %s= prefix is invalid, ignoring assignment: %s",
801 n
->family
= AF_INET6
;
805 if (streq(lvalue
, "Destination")) {
807 n
->dst_prefixlen
= prefixlen
;
808 } else if (streq(lvalue
, "Source")) {
810 n
->src_prefixlen
= prefixlen
;
812 assert_not_reached(lvalue
);
818 int config_parse_route_priority(
820 const char *filename
,
823 unsigned section_line
,
830 Network
*network
= userdata
;
831 _cleanup_(route_freep
) Route
*n
= NULL
;
840 r
= route_new_static(network
, filename
, section_line
, &n
);
844 r
= safe_atou32(rvalue
, &n
->priority
);
846 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
847 "Could not parse route priority \"%s\", ignoring assignment: %m", rvalue
);
855 int config_parse_route_scope(
857 const char *filename
,
860 unsigned section_line
,
867 Network
*network
= userdata
;
868 _cleanup_(route_freep
) Route
*n
= NULL
;
877 r
= route_new_static(network
, filename
, section_line
, &n
);
881 if (streq(rvalue
, "host"))
882 n
->scope
= RT_SCOPE_HOST
;
883 else if (streq(rvalue
, "link"))
884 n
->scope
= RT_SCOPE_LINK
;
885 else if (streq(rvalue
, "global"))
886 n
->scope
= RT_SCOPE_UNIVERSE
;
888 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route scope: %s", rvalue
);
896 int config_parse_route_table(
898 const char *filename
,
901 unsigned section_line
,
908 _cleanup_(route_freep
) Route
*n
= NULL
;
909 Network
*network
= userdata
;
918 r
= route_new_static(network
, filename
, section_line
, &n
);
922 r
= safe_atou32(rvalue
, &n
->table
);
924 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
925 "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue
);
933 int config_parse_gateway_onlink(
935 const char *filename
,
938 unsigned section_line
,
945 Network
*network
= userdata
;
946 _cleanup_(route_freep
) Route
*n
= NULL
;
955 r
= route_new_static(network
, filename
, section_line
, &n
);
959 r
= parse_boolean(rvalue
);
961 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
962 "Could not parse gateway onlink \"%s\", ignoring assignment: %m", rvalue
);
966 SET_FLAG(n
->flags
, RTNH_F_ONLINK
, r
);
971 int config_parse_ipv6_route_preference(
973 const char *filename
,
976 unsigned section_line
,
983 Network
*network
= userdata
;
984 _cleanup_(route_freep
) Route
*n
= NULL
;
987 r
= route_new_static(network
, filename
, section_line
, &n
);
991 if (streq(rvalue
, "low"))
992 n
->pref
= ICMPV6_ROUTER_PREF_LOW
;
993 else if (streq(rvalue
, "medium"))
994 n
->pref
= ICMPV6_ROUTER_PREF_MEDIUM
;
995 else if (streq(rvalue
, "high"))
996 n
->pref
= ICMPV6_ROUTER_PREF_HIGH
;
998 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route preference: %s", rvalue
);
1006 int config_parse_route_protocol(
1008 const char *filename
,
1010 const char *section
,
1011 unsigned section_line
,
1018 Network
*network
= userdata
;
1019 _cleanup_(route_freep
) 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
);
1044 int config_parse_route_type(
1046 const char *filename
,
1048 const char *section
,
1049 unsigned section_line
,
1056 Network
*network
= userdata
;
1057 _cleanup_(route_freep
) Route
*n
= NULL
;
1060 r
= route_new_static(network
, filename
, section_line
, &n
);
1064 if (streq(rvalue
, "unicast"))
1065 n
->type
= RTN_UNICAST
;
1066 else if (streq(rvalue
, "blackhole"))
1067 n
->type
= RTN_BLACKHOLE
;
1068 else if (streq(rvalue
, "unreachable"))
1069 n
->type
= RTN_UNREACHABLE
;
1070 else if (streq(rvalue
, "prohibit"))
1071 n
->type
= RTN_PROHIBIT
;
1073 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route type \"%s\", ignoring assignment: %m", rvalue
);
1081 int config_parse_tcp_window(
1083 const char *filename
,
1085 const char *section
,
1086 unsigned section_line
,
1093 _cleanup_(route_freep
) Route
*n
= NULL
;
1094 Network
*network
= userdata
;
1104 r
= route_new_static(network
, filename
, section_line
, &n
);
1108 r
= parse_size(rvalue
, 1024, &k
);
1109 if (r
< 0 || k
> UINT32_MAX
) {
1110 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1111 "Could not parse TCP %s \"%s\" bytes, ignoring assignment: %m", rvalue
, lvalue
);
1115 if (streq(lvalue
, "InitialCongestionWindow"))
1117 else if (streq(lvalue
, "InitialAdvertisedReceiveWindow"))
1120 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse TCP %s: %s", lvalue
, rvalue
);
1128 int config_parse_quickack(
1130 const char *filename
,
1132 const char *section
,
1133 unsigned section_line
,
1140 _cleanup_(route_freep
) Route
*n
= NULL
;
1141 Network
*network
= userdata
;
1150 r
= route_new_static(network
, filename
, section_line
, &n
);
1154 k
= parse_boolean(rvalue
);
1156 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse TCP quickack, ignoring: %s", rvalue
);
1165 int config_parse_route_mtu(
1167 const char *filename
,
1169 const char *section
,
1170 unsigned section_line
,
1177 Network
*network
= userdata
;
1178 _cleanup_(route_freep
) Route
*n
= NULL
;
1187 r
= route_new_static(network
, filename
, section_line
, &n
);
1191 r
= config_parse_mtu(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &n
->mtu
, userdata
);