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 "missing_network.h"
9 #include "netlink-util.h"
10 #include "networkd-manager.h"
11 #include "networkd-route.h"
12 #include "parse-util.h"
14 #include "string-util.h"
15 #include "sysctl-util.h"
18 #define ROUTES_DEFAULT_MAX_PER_FAMILY 4096U
20 static unsigned routes_max(void) {
21 static thread_local
unsigned cached
= 0;
23 _cleanup_free_
char *s4
= NULL
, *s6
= NULL
;
24 unsigned val4
= ROUTES_DEFAULT_MAX_PER_FAMILY
, val6
= ROUTES_DEFAULT_MAX_PER_FAMILY
;
29 if (sysctl_read("net/ipv4/route/max_size", &s4
) >= 0) {
31 if (safe_atou(s4
, &val4
) >= 0 &&
33 /* This is the default "no limit" value in the kernel */
34 val4
= ROUTES_DEFAULT_MAX_PER_FAMILY
;
37 if (sysctl_read("net/ipv6/route/max_size", &s6
) >= 0) {
39 (void) safe_atou(s6
, &val6
);
42 cached
= MAX(ROUTES_DEFAULT_MAX_PER_FAMILY
, val4
) +
43 MAX(ROUTES_DEFAULT_MAX_PER_FAMILY
, val6
);
47 int route_new(Route
**ret
) {
48 _cleanup_(route_freep
) Route
*route
= NULL
;
50 route
= new(Route
, 1);
56 .scope
= RT_SCOPE_UNIVERSE
,
57 .protocol
= RTPROT_UNSPEC
,
59 .table
= RT_TABLE_MAIN
,
60 .lifetime
= USEC_INFINITY
,
65 *ret
= TAKE_PTR(route
);
70 static int route_new_static(Network
*network
, const char *filename
, unsigned section_line
, Route
**ret
) {
71 _cleanup_(network_config_section_freep
) NetworkConfigSection
*n
= NULL
;
72 _cleanup_(route_freep
) Route
*route
= NULL
;
77 assert(!!filename
== (section_line
> 0));
80 r
= network_config_section_new(filename
, section_line
, &n
);
84 route
= hashmap_get(network
->routes_by_section
, n
);
86 *ret
= TAKE_PTR(route
);
92 if (network
->n_static_routes
>= routes_max())
95 r
= route_new(&route
);
99 route
->protocol
= RTPROT_STATIC
;
100 route
->network
= network
;
101 LIST_PREPEND(routes
, network
->static_routes
, route
);
102 network
->n_static_routes
++;
105 route
->section
= TAKE_PTR(n
);
107 r
= hashmap_ensure_allocated(&network
->routes_by_section
, &network_config_hash_ops
);
111 r
= hashmap_put(network
->routes_by_section
, route
->section
, route
);
116 *ret
= TAKE_PTR(route
);
121 void route_free(Route
*route
) {
125 if (route
->network
) {
126 LIST_REMOVE(routes
, route
->network
->static_routes
, route
);
128 assert(route
->network
->n_static_routes
> 0);
129 route
->network
->n_static_routes
--;
132 hashmap_remove(route
->network
->routes_by_section
, route
->section
);
135 network_config_section_free(route
->section
);
138 set_remove(route
->link
->routes
, route
);
139 set_remove(route
->link
->routes_foreign
, route
);
142 sd_event_source_unref(route
->expire
);
147 static void route_hash_func(const Route
*route
, struct siphash
*state
) {
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 Route
*a
, const Route
*b
) {
173 r
= CMP(a
->family
, b
->family
);
180 r
= CMP(a
->dst_prefixlen
, b
->dst_prefixlen
);
184 r
= CMP(a
->tos
, b
->tos
);
188 r
= CMP(a
->priority
, b
->priority
);
192 r
= CMP(a
->table
, b
->table
);
196 return memcmp(&a
->dst
, &b
->dst
, FAMILY_ADDRESS_SIZE(a
->family
));
198 /* treat any other address family as AF_UNSPEC */
203 DEFINE_PRIVATE_HASH_OPS(route_hash_ops
, Route
, route_hash_func
, route_compare_func
);
205 bool route_equal(Route
*r1
, Route
*r2
) {
212 return route_compare_func(r1
, r2
) == 0;
215 int route_get(Link
*link
,
217 const union in_addr_union
*dst
,
218 unsigned char dst_prefixlen
,
224 Route route
, *existing
;
232 .dst_prefixlen
= dst_prefixlen
,
234 .priority
= priority
,
238 existing
= set_get(link
->routes
, &route
);
245 existing
= set_get(link
->routes_foreign
, &route
);
255 static int route_add_internal(
259 const union in_addr_union
*dst
,
260 unsigned char dst_prefixlen
,
266 _cleanup_(route_freep
) Route
*route
= NULL
;
273 r
= route_new(&route
);
277 route
->family
= family
;
279 route
->dst_prefixlen
= dst_prefixlen
;
281 route
->priority
= priority
;
282 route
->table
= table
;
284 r
= set_ensure_allocated(routes
, &route_hash_ops
);
288 r
= set_put(*routes
, route
);
302 int route_add_foreign(
305 const union in_addr_union
*dst
,
306 unsigned char dst_prefixlen
,
312 return route_add_internal(link
, &link
->routes_foreign
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, ret
);
315 int route_add(Link
*link
,
317 const union in_addr_union
*dst
,
318 unsigned char dst_prefixlen
,
327 r
= route_get(link
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
329 /* Route does not exist, create a new one */
330 r
= route_add_internal(link
, &link
->routes
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
334 /* Take over a foreign route */
335 r
= set_ensure_allocated(&link
->routes
, &route_hash_ops
);
339 r
= set_put(link
->routes
, route
);
343 set_remove(link
->routes_foreign
, route
);
345 /* Route exists, do nothing */
356 void route_update(Route
*route
,
357 const union in_addr_union
*src
,
358 unsigned char src_prefixlen
,
359 const union in_addr_union
*gw
,
360 const union in_addr_union
*prefsrc
,
362 unsigned char protocol
,
363 unsigned char type
) {
366 assert(src
|| src_prefixlen
== 0);
368 route
->src
= src
? *src
: IN_ADDR_NULL
;
369 route
->src_prefixlen
= src_prefixlen
;
370 route
->gw
= gw
? *gw
: IN_ADDR_NULL
;
371 route
->prefsrc
= prefsrc
? *prefsrc
: IN_ADDR_NULL
;
372 route
->scope
= scope
;
373 route
->protocol
= protocol
;
377 static int route_remove_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
382 assert(link
->ifname
);
384 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
387 r
= sd_netlink_message_get_errno(m
);
388 if (r
< 0 && r
!= -ESRCH
)
389 log_link_warning_errno(link
, r
, "Could not drop route: %m");
394 int route_remove(Route
*route
, Link
*link
,
395 link_netlink_message_handler_t callback
) {
397 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
401 assert(link
->manager
);
402 assert(link
->manager
->rtnl
);
403 assert(link
->ifindex
> 0);
404 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
406 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
407 RTM_DELROUTE
, route
->family
,
410 return log_link_error_errno(link
, r
, "Could not create RTM_DELROUTE message: %m");
412 if (in_addr_is_null(route
->family
, &route
->gw
) == 0) {
413 r
= netlink_message_append_in_addr_union(req
, RTA_GATEWAY
, route
->family
, &route
->gw
);
415 return log_link_error_errno(link
, r
, "Could not append RTA_GATEWAY attribute: %m");
418 if (route
->dst_prefixlen
) {
419 r
= netlink_message_append_in_addr_union(req
, RTA_DST
, route
->family
, &route
->dst
);
421 return log_link_error_errno(link
, r
, "Could not append RTA_DST attribute: %m");
423 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
425 return log_link_error_errno(link
, r
, "Could not set destination prefix length: %m");
428 if (route
->src_prefixlen
) {
429 r
= netlink_message_append_in_addr_union(req
, RTA_SRC
, route
->family
, &route
->src
);
431 return log_link_error_errno(link
, r
, "Could not append RTA_SRC attribute: %m");
433 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
435 return log_link_error_errno(link
, r
, "Could not set source prefix length: %m");
438 if (in_addr_is_null(route
->family
, &route
->prefsrc
) == 0) {
439 r
= netlink_message_append_in_addr_union(req
, RTA_PREFSRC
, route
->family
, &route
->prefsrc
);
441 return log_link_error_errno(link
, r
, "Could not append RTA_PREFSRC attribute: %m");
444 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
446 return log_link_error_errno(link
, r
, "Could not set scope: %m");
448 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
450 return log_link_error_errno(link
, r
, "Could not append RTA_PRIORITY attribute: %m");
452 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
, RTN_THROW
)) {
453 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
455 return log_link_error_errno(link
, r
, "Could not append RTA_OIF attribute: %m");
458 r
= netlink_call_async(link
->manager
->rtnl
, NULL
, req
,
459 callback
?: route_remove_handler
,
460 link_netlink_destroy_callback
, link
);
462 return log_link_error_errno(link
, r
, "Could not send rtnetlink message: %m");
469 int route_expire_handler(sd_event_source
*s
, uint64_t usec
, void *userdata
) {
470 Route
*route
= userdata
;
475 r
= route_remove(route
, route
->link
, NULL
);
477 log_warning_errno(r
, "Could not remove route: %m");
487 link_netlink_message_handler_t callback
) {
489 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
490 _cleanup_(sd_event_source_unrefp
) sd_event_source
*expire
= NULL
;
495 assert(link
->manager
);
496 assert(link
->manager
->rtnl
);
497 assert(link
->ifindex
> 0);
498 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
501 if (route_get(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, NULL
) <= 0 &&
502 set_size(link
->routes
) >= routes_max())
503 return log_link_error_errno(link
, SYNTHETIC_ERRNO(E2BIG
),
504 "Too many routes are configured, refusing: %m");
507 _cleanup_free_
char *dst
= NULL
, *dst_prefixlen
= NULL
, *src
= NULL
, *gw
= NULL
, *prefsrc
= NULL
;
509 if (!in_addr_is_null(route
->family
, &route
->dst
)) {
510 (void) in_addr_to_string(route
->family
, &route
->dst
, &dst
);
511 (void) asprintf(&dst_prefixlen
, "/%u", route
->dst_prefixlen
);
513 if (!in_addr_is_null(route
->family
, &route
->src
))
514 (void) in_addr_to_string(route
->family
, &route
->src
, &src
);
515 if (!in_addr_is_null(route
->family
, &route
->gw
))
516 (void) in_addr_to_string(route
->family
, &route
->gw
, &gw
);
517 if (!in_addr_is_null(route
->family
, &route
->prefsrc
))
518 (void) in_addr_to_string(route
->family
, &route
->prefsrc
, &prefsrc
);
520 log_link_debug(link
, "Configuring route: dst: %s%s, src: %s, gw: %s, prefsrc: %s",
521 strna(dst
), strempty(dst_prefixlen
), strna(src
), strna(gw
), strna(prefsrc
));
524 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
525 RTM_NEWROUTE
, route
->family
,
528 return log_link_error_errno(link
, r
, "Could not create RTM_NEWROUTE message: %m");
530 if (in_addr_is_null(route
->family
, &route
->gw
) == 0) {
531 r
= netlink_message_append_in_addr_union(req
, RTA_GATEWAY
, route
->family
, &route
->gw
);
533 return log_link_error_errno(link
, r
, "Could not append RTA_GATEWAY attribute: %m");
535 r
= sd_rtnl_message_route_set_family(req
, route
->family
);
537 return log_link_error_errno(link
, r
, "Could not set route family: %m");
540 if (route
->dst_prefixlen
) {
541 r
= netlink_message_append_in_addr_union(req
, RTA_DST
, route
->family
, &route
->dst
);
543 return log_link_error_errno(link
, r
, "Could not append RTA_DST attribute: %m");
545 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
547 return log_link_error_errno(link
, r
, "Could not set destination prefix length: %m");
550 if (route
->src_prefixlen
) {
551 r
= netlink_message_append_in_addr_union(req
, RTA_SRC
, route
->family
, &route
->src
);
553 return log_link_error_errno(link
, r
, "Could not append RTA_SRC attribute: %m");
555 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
557 return log_link_error_errno(link
, r
, "Could not set source prefix length: %m");
560 if (in_addr_is_null(route
->family
, &route
->prefsrc
) == 0) {
561 r
= netlink_message_append_in_addr_union(req
, RTA_PREFSRC
, route
->family
, &route
->prefsrc
);
563 return log_link_error_errno(link
, r
, "Could not append RTA_PREFSRC attribute: %m");
566 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
568 return log_link_error_errno(link
, r
, "Could not set scope: %m");
570 if (route
->gateway_onlink
>= 0)
571 SET_FLAG(route
->flags
, RTNH_F_ONLINK
, route
->gateway_onlink
);
573 r
= sd_rtnl_message_route_set_flags(req
, route
->flags
);
575 return log_link_error_errno(link
, 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_link_error_errno(link
, r
, "Could not set route table: %m");
583 r
= sd_rtnl_message_route_set_table(req
, RT_TABLE_UNSPEC
);
585 return log_link_error_errno(link
, 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_link_error_errno(link
, r
, "Could not append RTA_TABLE attribute: %m");
594 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
596 return log_link_error_errno(link
, r
, "Could not append RTA_PRIORITY attribute: %m");
598 r
= sd_netlink_message_append_u8(req
, RTA_PREF
, route
->pref
);
600 return log_link_error_errno(link
, 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_link_error_errno(link
, r
, "Could not append RTA_EXPIRES attribute: %m");
609 r
= sd_rtnl_message_route_set_type(req
, route
->type
);
611 return log_link_error_errno(link
, 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_link_error_errno(link
, r
, "Could not append RTA_OIF attribute: %m");
619 r
= sd_netlink_message_open_container(req
, RTA_METRICS
);
621 return log_link_error_errno(link
, 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_link_error_errno(link
, 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_link_error_errno(link
, 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_link_error_errno(link
, 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_link_error_errno(link
, r
, "Could not append RTAX_QUICKACK attribute: %m");
647 r
= sd_netlink_message_close_container(req
);
649 return log_link_error_errno(link
, 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_link_error_errno(link
, 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_link_error_errno(link
, 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_link_error_errno(link
, r
, "Could not arm expiration timer: %m");
674 sd_event_source_unref(route
->expire
);
675 route
->expire
= TAKE_PTR(expire
);
680 int network_add_ipv4ll_route(Network
*network
) {
681 _cleanup_(route_freep
) Route
*n
= NULL
;
686 if (!network
->ipv4ll_route
)
689 /* IPv4LLRoute= is in [Network] section. */
690 r
= route_new_static(network
, NULL
, 0, &n
);
694 r
= in_addr_from_string(AF_INET
, "169.254.0.0", &n
->dst
);
699 n
->dst_prefixlen
= 16;
700 n
->scope
= RT_SCOPE_LINK
;
701 n
->priority
= IPV4LL_ROUTE_METRIC
;
702 n
->protocol
= RTPROT_STATIC
;
708 int config_parse_gateway(
710 const char *filename
,
713 unsigned section_line
,
720 Network
*network
= userdata
;
721 _cleanup_(route_freep
) Route
*n
= NULL
;
730 if (streq(section
, "Network")) {
731 /* we are not in an Route section, so treat
732 * this as the special '0' section */
733 r
= route_new_static(network
, NULL
, 0, &n
);
735 r
= route_new_static(network
, filename
, section_line
, &n
);
739 if (n
->family
== AF_UNSPEC
)
740 r
= in_addr_from_string_auto(rvalue
, &n
->family
, &n
->gw
);
742 r
= in_addr_from_string(n
->family
, rvalue
, &n
->gw
);
744 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
745 "Invalid %s='%s', ignoring assignment: %m", lvalue
, rvalue
);
753 int config_parse_preferred_src(
755 const char *filename
,
758 unsigned section_line
,
765 Network
*network
= userdata
;
766 _cleanup_(route_freep
) Route
*n
= NULL
;
775 r
= route_new_static(network
, filename
, section_line
, &n
);
779 if (n
->family
== AF_UNSPEC
)
780 r
= in_addr_from_string_auto(rvalue
, &n
->family
, &n
->prefsrc
);
782 r
= in_addr_from_string(n
->family
, rvalue
, &n
->prefsrc
);
784 log_syntax(unit
, LOG_ERR
, filename
, line
, EINVAL
,
785 "Invalid %s='%s', ignoring assignment: %m", lvalue
, rvalue
);
793 int config_parse_destination(
795 const char *filename
,
798 unsigned section_line
,
805 Network
*network
= userdata
;
806 _cleanup_(route_freep
) Route
*n
= NULL
;
807 union in_addr_union
*buffer
;
808 unsigned char *prefixlen
;
817 r
= route_new_static(network
, filename
, section_line
, &n
);
821 if (streq(lvalue
, "Destination")) {
823 prefixlen
= &n
->dst_prefixlen
;
824 } else if (streq(lvalue
, "Source")) {
826 prefixlen
= &n
->src_prefixlen
;
828 assert_not_reached(lvalue
);
830 if (n
->family
== AF_UNSPEC
)
831 r
= in_addr_prefix_from_string_auto(rvalue
, &n
->family
, buffer
, prefixlen
);
833 r
= in_addr_prefix_from_string(rvalue
, n
->family
, buffer
, prefixlen
);
835 log_syntax(unit
, LOG_ERR
, filename
, line
, EINVAL
,
836 "Invalid %s='%s', ignoring assignment: %m", lvalue
, rvalue
);
844 int config_parse_route_priority(
846 const char *filename
,
849 unsigned section_line
,
856 Network
*network
= userdata
;
857 _cleanup_(route_freep
) Route
*n
= NULL
;
866 r
= route_new_static(network
, filename
, section_line
, &n
);
870 r
= safe_atou32(rvalue
, &n
->priority
);
872 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
873 "Could not parse route priority \"%s\", ignoring assignment: %m", rvalue
);
881 int config_parse_route_scope(
883 const char *filename
,
886 unsigned section_line
,
893 Network
*network
= userdata
;
894 _cleanup_(route_freep
) Route
*n
= NULL
;
903 r
= route_new_static(network
, filename
, section_line
, &n
);
907 if (streq(rvalue
, "host"))
908 n
->scope
= RT_SCOPE_HOST
;
909 else if (streq(rvalue
, "link"))
910 n
->scope
= RT_SCOPE_LINK
;
911 else if (streq(rvalue
, "global"))
912 n
->scope
= RT_SCOPE_UNIVERSE
;
914 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route scope: %s", rvalue
);
922 int config_parse_route_table(
924 const char *filename
,
927 unsigned section_line
,
934 _cleanup_(route_freep
) Route
*n
= NULL
;
935 Network
*network
= userdata
;
944 r
= route_new_static(network
, filename
, section_line
, &n
);
948 r
= safe_atou32(rvalue
, &n
->table
);
950 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
951 "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue
);
959 int config_parse_gateway_onlink(
961 const char *filename
,
964 unsigned section_line
,
971 Network
*network
= userdata
;
972 _cleanup_(route_freep
) Route
*n
= NULL
;
981 r
= route_new_static(network
, filename
, section_line
, &n
);
985 r
= parse_boolean(rvalue
);
987 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
988 "Could not parse %s=\"%s\", ignoring assignment: %m", lvalue
, rvalue
);
992 n
->gateway_onlink
= r
;
998 int config_parse_ipv6_route_preference(
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
, "low"))
1019 n
->pref
= ICMPV6_ROUTER_PREF_LOW
;
1020 else if (streq(rvalue
, "medium"))
1021 n
->pref
= ICMPV6_ROUTER_PREF_MEDIUM
;
1022 else if (streq(rvalue
, "high"))
1023 n
->pref
= ICMPV6_ROUTER_PREF_HIGH
;
1025 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route preference: %s", rvalue
);
1033 int config_parse_route_protocol(
1035 const char *filename
,
1037 const char *section
,
1038 unsigned section_line
,
1045 Network
*network
= userdata
;
1046 _cleanup_(route_freep
) Route
*n
= NULL
;
1049 r
= route_new_static(network
, filename
, section_line
, &n
);
1053 if (streq(rvalue
, "kernel"))
1054 n
->protocol
= RTPROT_KERNEL
;
1055 else if (streq(rvalue
, "boot"))
1056 n
->protocol
= RTPROT_BOOT
;
1057 else if (streq(rvalue
, "static"))
1058 n
->protocol
= RTPROT_STATIC
;
1060 r
= safe_atou8(rvalue
, &n
->protocol
);
1062 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1063 "Could not parse route protocol \"%s\", ignoring assignment: %m", rvalue
);
1072 int config_parse_route_type(
1074 const char *filename
,
1076 const char *section
,
1077 unsigned section_line
,
1084 Network
*network
= userdata
;
1085 _cleanup_(route_freep
) Route
*n
= NULL
;
1088 r
= route_new_static(network
, filename
, section_line
, &n
);
1092 if (streq(rvalue
, "unicast"))
1093 n
->type
= RTN_UNICAST
;
1094 else if (streq(rvalue
, "blackhole"))
1095 n
->type
= RTN_BLACKHOLE
;
1096 else if (streq(rvalue
, "unreachable"))
1097 n
->type
= RTN_UNREACHABLE
;
1098 else if (streq(rvalue
, "prohibit"))
1099 n
->type
= RTN_PROHIBIT
;
1100 else if (streq(rvalue
, "throw"))
1101 n
->type
= RTN_THROW
;
1103 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1104 "Could not parse route type \"%s\", ignoring assignment: %m", rvalue
);
1112 int config_parse_tcp_window(
1114 const char *filename
,
1116 const char *section
,
1117 unsigned section_line
,
1124 _cleanup_(route_freep
) Route
*n
= NULL
;
1125 Network
*network
= userdata
;
1135 r
= route_new_static(network
, filename
, section_line
, &n
);
1139 r
= parse_size(rvalue
, 1024, &k
);
1141 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1142 "Could not parse TCP %s \"%s\", ignoring assignment: %m", lvalue
, rvalue
);
1145 if (k
> UINT32_MAX
) {
1146 log_syntax(unit
, LOG_ERR
, filename
, line
, 0,
1147 "Specified TCP %s \"%s\" is too large, ignoring assignment: %m", lvalue
, rvalue
);
1151 if (streq(lvalue
, "InitialCongestionWindow"))
1153 else if (streq(lvalue
, "InitialAdvertisedReceiveWindow"))
1156 assert_not_reached("Invalid TCP window type.");
1162 int config_parse_quickack(
1164 const char *filename
,
1166 const char *section
,
1167 unsigned section_line
,
1174 _cleanup_(route_freep
) Route
*n
= NULL
;
1175 Network
*network
= userdata
;
1184 r
= route_new_static(network
, filename
, section_line
, &n
);
1188 k
= parse_boolean(rvalue
);
1190 log_syntax(unit
, LOG_ERR
, filename
, line
, k
,
1191 "Failed to parse TCP quickack, ignoring: %s", rvalue
);
1200 int config_parse_route_mtu(
1202 const char *filename
,
1204 const char *section
,
1205 unsigned section_line
,
1212 Network
*network
= userdata
;
1213 _cleanup_(route_freep
) Route
*n
= NULL
;
1222 r
= route_new_static(network
, filename
, section_line
, &n
);
1226 r
= config_parse_mtu(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &n
->mtu
, userdata
);