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 void *b
, struct siphash
*state
) {
146 const Route
*route
= b
;
150 siphash24_compress(&route
->family
, sizeof(route
->family
), state
);
152 switch (route
->family
) {
155 /* Equality of routes are given by the 4-touple
156 (dst_prefix,dst_prefixlen,tos,priority,table) */
157 siphash24_compress(&route
->dst
, FAMILY_ADDRESS_SIZE(route
->family
), state
);
158 siphash24_compress(&route
->dst_prefixlen
, sizeof(route
->dst_prefixlen
), state
);
159 siphash24_compress(&route
->tos
, sizeof(route
->tos
), state
);
160 siphash24_compress(&route
->priority
, sizeof(route
->priority
), state
);
161 siphash24_compress(&route
->table
, sizeof(route
->table
), state
);
165 /* treat any other address family as AF_UNSPEC */
170 static int route_compare_func(const void *_a
, const void *_b
) {
171 const Route
*a
= _a
, *b
= _b
;
174 r
= CMP(a
->family
, b
->family
);
181 r
= CMP(a
->dst_prefixlen
, b
->dst_prefixlen
);
185 r
= CMP(a
->tos
, b
->tos
);
189 r
= CMP(a
->priority
, b
->priority
);
193 r
= CMP(a
->table
, b
->table
);
197 return memcmp(&a
->dst
, &b
->dst
, FAMILY_ADDRESS_SIZE(a
->family
));
199 /* treat any other address family as AF_UNSPEC */
204 static const struct hash_ops route_hash_ops
= {
205 .hash
= route_hash_func
,
206 .compare
= route_compare_func
209 bool route_equal(Route
*r1
, Route
*r2
) {
216 return route_compare_func(r1
, r2
) == 0;
219 int route_get(Link
*link
,
221 const union in_addr_union
*dst
,
222 unsigned char dst_prefixlen
,
228 Route route
, *existing
;
236 .dst_prefixlen
= dst_prefixlen
,
238 .priority
= priority
,
242 existing
= set_get(link
->routes
, &route
);
249 existing
= set_get(link
->routes_foreign
, &route
);
259 static int route_add_internal(
263 const union in_addr_union
*dst
,
264 unsigned char dst_prefixlen
,
270 _cleanup_(route_freep
) Route
*route
= NULL
;
277 r
= route_new(&route
);
281 route
->family
= family
;
283 route
->dst_prefixlen
= dst_prefixlen
;
285 route
->priority
= priority
;
286 route
->table
= table
;
288 r
= set_ensure_allocated(routes
, &route_hash_ops
);
292 r
= set_put(*routes
, route
);
306 int route_add_foreign(
309 const union in_addr_union
*dst
,
310 unsigned char dst_prefixlen
,
316 return route_add_internal(link
, &link
->routes_foreign
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, ret
);
319 int route_add(Link
*link
,
321 const union in_addr_union
*dst
,
322 unsigned char dst_prefixlen
,
331 r
= route_get(link
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
333 /* Route does not exist, create a new one */
334 r
= route_add_internal(link
, &link
->routes
, family
, dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
338 /* Take over a foreign route */
339 r
= set_ensure_allocated(&link
->routes
, &route_hash_ops
);
343 r
= set_put(link
->routes
, route
);
347 set_remove(link
->routes_foreign
, route
);
349 /* Route exists, do nothing */
360 void route_update(Route
*route
,
361 const union in_addr_union
*src
,
362 unsigned char src_prefixlen
,
363 const union in_addr_union
*gw
,
364 const union in_addr_union
*prefsrc
,
366 unsigned char protocol
,
367 unsigned char type
) {
370 assert(src
|| src_prefixlen
== 0);
372 route
->src
= src
? *src
: IN_ADDR_NULL
;
373 route
->src_prefixlen
= src_prefixlen
;
374 route
->gw
= gw
? *gw
: IN_ADDR_NULL
;
375 route
->prefsrc
= prefsrc
? *prefsrc
: IN_ADDR_NULL
;
376 route
->scope
= scope
;
377 route
->protocol
= protocol
;
381 int route_remove(Route
*route
, Link
*link
,
382 sd_netlink_message_handler_t callback
) {
384 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
388 assert(link
->manager
);
389 assert(link
->manager
->rtnl
);
390 assert(link
->ifindex
> 0);
391 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
393 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
394 RTM_DELROUTE
, route
->family
,
397 return log_error_errno(r
, "Could not create RTM_DELROUTE message: %m");
399 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
400 if (route
->family
== AF_INET
)
401 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
402 else if (route
->family
== AF_INET6
)
403 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
405 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
408 if (route
->dst_prefixlen
) {
409 if (route
->family
== AF_INET
)
410 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
411 else if (route
->family
== AF_INET6
)
412 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
414 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
416 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
418 return log_error_errno(r
, "Could not set destination prefix length: %m");
421 if (route
->src_prefixlen
) {
422 if (route
->family
== AF_INET
)
423 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
424 else if (route
->family
== AF_INET6
)
425 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
427 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
429 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
431 return log_error_errno(r
, "Could not set source prefix length: %m");
434 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
435 if (route
->family
== AF_INET
)
436 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
437 else if (route
->family
== AF_INET6
)
438 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
440 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
443 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
445 return log_error_errno(r
, "Could not set scope: %m");
447 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
449 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
451 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
, RTN_THROW
)) {
452 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
454 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
457 r
= sd_netlink_call_async(link
->manager
->rtnl
, NULL
, req
, callback
,
458 link_netlink_destroy_callback
, link
, 0, __func__
);
460 return log_error_errno(r
, "Could not send rtnetlink message: %m");
467 int route_expire_handler(sd_event_source
*s
, uint64_t usec
, void *userdata
) {
468 Route
*route
= userdata
;
473 r
= route_remove(route
, route
->link
, link_route_remove_handler
);
475 log_warning_errno(r
, "Could not remove route: %m");
485 sd_netlink_message_handler_t callback
) {
487 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
;
488 _cleanup_(sd_event_source_unrefp
) sd_event_source
*expire
= NULL
;
493 assert(link
->manager
);
494 assert(link
->manager
->rtnl
);
495 assert(link
->ifindex
> 0);
496 assert(IN_SET(route
->family
, AF_INET
, AF_INET6
));
498 if (route_get(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, NULL
) <= 0 &&
499 set_size(link
->routes
) >= routes_max())
502 r
= sd_rtnl_message_new_route(link
->manager
->rtnl
, &req
,
503 RTM_NEWROUTE
, route
->family
,
506 return log_error_errno(r
, "Could not create RTM_NEWROUTE message: %m");
508 if (!in_addr_is_null(route
->family
, &route
->gw
)) {
509 if (route
->family
== AF_INET
)
510 r
= sd_netlink_message_append_in_addr(req
, RTA_GATEWAY
, &route
->gw
.in
);
511 else if (route
->family
== AF_INET6
)
512 r
= sd_netlink_message_append_in6_addr(req
, RTA_GATEWAY
, &route
->gw
.in6
);
514 return log_error_errno(r
, "Could not append RTA_GATEWAY attribute: %m");
516 r
= sd_rtnl_message_route_set_family(req
, route
->family
);
518 return log_error_errno(r
, "Could not set route family: %m");
521 if (route
->dst_prefixlen
) {
522 if (route
->family
== AF_INET
)
523 r
= sd_netlink_message_append_in_addr(req
, RTA_DST
, &route
->dst
.in
);
524 else if (route
->family
== AF_INET6
)
525 r
= sd_netlink_message_append_in6_addr(req
, RTA_DST
, &route
->dst
.in6
);
527 return log_error_errno(r
, "Could not append RTA_DST attribute: %m");
529 r
= sd_rtnl_message_route_set_dst_prefixlen(req
, route
->dst_prefixlen
);
531 return log_error_errno(r
, "Could not set destination prefix length: %m");
534 if (route
->src_prefixlen
) {
535 if (route
->family
== AF_INET
)
536 r
= sd_netlink_message_append_in_addr(req
, RTA_SRC
, &route
->src
.in
);
537 else if (route
->family
== AF_INET6
)
538 r
= sd_netlink_message_append_in6_addr(req
, RTA_SRC
, &route
->src
.in6
);
540 return log_error_errno(r
, "Could not append RTA_SRC attribute: %m");
542 r
= sd_rtnl_message_route_set_src_prefixlen(req
, route
->src_prefixlen
);
544 return log_error_errno(r
, "Could not set source prefix length: %m");
547 if (!in_addr_is_null(route
->family
, &route
->prefsrc
)) {
548 if (route
->family
== AF_INET
)
549 r
= sd_netlink_message_append_in_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in
);
550 else if (route
->family
== AF_INET6
)
551 r
= sd_netlink_message_append_in6_addr(req
, RTA_PREFSRC
, &route
->prefsrc
.in6
);
553 return log_error_errno(r
, "Could not append RTA_PREFSRC attribute: %m");
556 r
= sd_rtnl_message_route_set_scope(req
, route
->scope
);
558 return log_error_errno(r
, "Could not set scope: %m");
560 r
= sd_rtnl_message_route_set_flags(req
, route
->flags
);
562 return log_error_errno(r
, "Could not set flags: %m");
564 if (route
->table
!= RT_TABLE_MAIN
) {
565 if (route
->table
< 256) {
566 r
= sd_rtnl_message_route_set_table(req
, route
->table
);
568 return log_error_errno(r
, "Could not set route table: %m");
570 r
= sd_rtnl_message_route_set_table(req
, RT_TABLE_UNSPEC
);
572 return log_error_errno(r
, "Could not set route table: %m");
574 /* Table attribute to allow more than 256. */
575 r
= sd_netlink_message_append_data(req
, RTA_TABLE
, &route
->table
, sizeof(route
->table
));
577 return log_error_errno(r
, "Could not append RTA_TABLE attribute: %m");
581 r
= sd_netlink_message_append_u32(req
, RTA_PRIORITY
, route
->priority
);
583 return log_error_errno(r
, "Could not append RTA_PRIORITY attribute: %m");
585 r
= sd_netlink_message_append_u8(req
, RTA_PREF
, route
->pref
);
587 return log_error_errno(r
, "Could not append RTA_PREF attribute: %m");
589 if (route
->lifetime
!= USEC_INFINITY
&& kernel_route_expiration_supported()) {
590 r
= sd_netlink_message_append_u32(req
, RTA_EXPIRES
,
591 DIV_ROUND_UP(usec_sub_unsigned(route
->lifetime
, now(clock_boottime_or_monotonic())), USEC_PER_SEC
));
593 return log_error_errno(r
, "Could not append RTA_EXPIRES attribute: %m");
596 r
= sd_rtnl_message_route_set_type(req
, route
->type
);
598 return log_error_errno(r
, "Could not set route type: %m");
600 if (!IN_SET(route
->type
, RTN_UNREACHABLE
, RTN_PROHIBIT
, RTN_BLACKHOLE
, RTN_THROW
)) {
601 r
= sd_netlink_message_append_u32(req
, RTA_OIF
, link
->ifindex
);
603 return log_error_errno(r
, "Could not append RTA_OIF attribute: %m");
606 r
= sd_netlink_message_open_container(req
, RTA_METRICS
);
608 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
610 if (route
->mtu
> 0) {
611 r
= sd_netlink_message_append_u32(req
, RTAX_MTU
, route
->mtu
);
613 return log_error_errno(r
, "Could not append RTAX_MTU attribute: %m");
616 if (route
->initcwnd
> 0) {
617 r
= sd_netlink_message_append_u32(req
, RTAX_INITCWND
, route
->initcwnd
);
619 return log_error_errno(r
, "Could not append RTAX_INITCWND attribute: %m");
622 if (route
->initrwnd
> 0) {
623 r
= sd_netlink_message_append_u32(req
, RTAX_INITRWND
, route
->initrwnd
);
625 return log_error_errno(r
, "Could not append RTAX_INITRWND attribute: %m");
628 if (route
->quickack
!= -1) {
629 r
= sd_netlink_message_append_u32(req
, RTAX_QUICKACK
, route
->quickack
);
631 return log_error_errno(r
, "Could not append RTAX_QUICKACK attribute: %m");
634 r
= sd_netlink_message_close_container(req
);
636 return log_error_errno(r
, "Could not append RTA_METRICS attribute: %m");
638 r
= sd_netlink_call_async(link
->manager
->rtnl
, NULL
, req
, callback
,
639 link_netlink_destroy_callback
, link
, 0, __func__
);
641 return log_error_errno(r
, "Could not send rtnetlink message: %m");
645 lifetime
= route
->lifetime
;
647 r
= route_add(link
, route
->family
, &route
->dst
, route
->dst_prefixlen
, route
->tos
, route
->priority
, route
->table
, &route
);
649 return log_error_errno(r
, "Could not add route: %m");
651 /* TODO: drop expiration handling once it can be pushed into the kernel */
652 route
->lifetime
= lifetime
;
654 if (route
->lifetime
!= USEC_INFINITY
&& !kernel_route_expiration_supported()) {
655 r
= sd_event_add_time(link
->manager
->event
, &expire
, clock_boottime_or_monotonic(),
656 route
->lifetime
, 0, route_expire_handler
, route
);
658 return log_error_errno(r
, "Could not arm expiration timer: %m");
661 sd_event_source_unref(route
->expire
);
662 route
->expire
= TAKE_PTR(expire
);
667 int config_parse_gateway(
669 const char *filename
,
672 unsigned section_line
,
679 Network
*network
= userdata
;
680 _cleanup_(route_freep
) Route
*n
= NULL
;
681 union in_addr_union buffer
;
690 if (streq(section
, "Network")) {
691 /* we are not in an Route section, so treat
692 * this as the special '0' section */
693 r
= route_new_static(network
, NULL
, 0, &n
);
695 r
= route_new_static(network
, filename
, section_line
, &n
);
700 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
702 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Route is invalid, ignoring assignment: %s", rvalue
);
713 int config_parse_preferred_src(
715 const char *filename
,
718 unsigned section_line
,
725 Network
*network
= userdata
;
726 _cleanup_(route_freep
) Route
*n
= NULL
;
727 union in_addr_union buffer
;
736 r
= route_new_static(network
, filename
, section_line
, &n
);
740 r
= in_addr_from_string_auto(rvalue
, &f
, &buffer
);
742 log_syntax(unit
, LOG_ERR
, filename
, line
, EINVAL
,
743 "Preferred source is invalid, ignoring assignment: %s", rvalue
);
754 int config_parse_destination(
756 const char *filename
,
759 unsigned section_line
,
766 Network
*network
= userdata
;
767 _cleanup_(route_freep
) Route
*n
= NULL
;
768 union in_addr_union buffer
;
769 unsigned char prefixlen
;
778 r
= route_new_static(network
, filename
, section_line
, &n
);
782 r
= in_addr_prefix_from_string(rvalue
, AF_INET
, &buffer
, &prefixlen
);
784 r
= in_addr_prefix_from_string(rvalue
, AF_INET6
, &buffer
, &prefixlen
);
786 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
787 "Route %s= prefix is invalid, ignoring assignment: %s",
792 n
->family
= AF_INET6
;
796 if (streq(lvalue
, "Destination")) {
798 n
->dst_prefixlen
= prefixlen
;
799 } else if (streq(lvalue
, "Source")) {
801 n
->src_prefixlen
= prefixlen
;
803 assert_not_reached(lvalue
);
809 int config_parse_route_priority(
811 const char *filename
,
814 unsigned section_line
,
821 Network
*network
= userdata
;
822 _cleanup_(route_freep
) Route
*n
= NULL
;
831 r
= route_new_static(network
, filename
, section_line
, &n
);
835 r
= safe_atou32(rvalue
, &n
->priority
);
837 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
838 "Could not parse route priority \"%s\", ignoring assignment: %m", rvalue
);
846 int config_parse_route_scope(
848 const char *filename
,
851 unsigned section_line
,
858 Network
*network
= userdata
;
859 _cleanup_(route_freep
) Route
*n
= NULL
;
868 r
= route_new_static(network
, filename
, section_line
, &n
);
872 if (streq(rvalue
, "host"))
873 n
->scope
= RT_SCOPE_HOST
;
874 else if (streq(rvalue
, "link"))
875 n
->scope
= RT_SCOPE_LINK
;
876 else if (streq(rvalue
, "global"))
877 n
->scope
= RT_SCOPE_UNIVERSE
;
879 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route scope: %s", rvalue
);
887 int config_parse_route_table(
889 const char *filename
,
892 unsigned section_line
,
899 _cleanup_(route_freep
) Route
*n
= NULL
;
900 Network
*network
= userdata
;
909 r
= route_new_static(network
, filename
, section_line
, &n
);
913 r
= safe_atou32(rvalue
, &n
->table
);
915 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
916 "Could not parse route table number \"%s\", ignoring assignment: %m", rvalue
);
924 int config_parse_gateway_onlink(
926 const char *filename
,
929 unsigned section_line
,
936 Network
*network
= userdata
;
937 _cleanup_(route_freep
) Route
*n
= NULL
;
946 r
= route_new_static(network
, filename
, section_line
, &n
);
950 r
= parse_boolean(rvalue
);
952 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
953 "Could not parse gateway onlink \"%s\", ignoring assignment: %m", rvalue
);
957 SET_FLAG(n
->flags
, RTNH_F_ONLINK
, r
);
962 int config_parse_ipv6_route_preference(
964 const char *filename
,
967 unsigned section_line
,
974 Network
*network
= userdata
;
975 _cleanup_(route_freep
) Route
*n
= NULL
;
978 r
= route_new_static(network
, filename
, section_line
, &n
);
982 if (streq(rvalue
, "low"))
983 n
->pref
= ICMPV6_ROUTER_PREF_LOW
;
984 else if (streq(rvalue
, "medium"))
985 n
->pref
= ICMPV6_ROUTER_PREF_MEDIUM
;
986 else if (streq(rvalue
, "high"))
987 n
->pref
= ICMPV6_ROUTER_PREF_HIGH
;
989 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Unknown route preference: %s", rvalue
);
997 int config_parse_route_protocol(
999 const char *filename
,
1001 const char *section
,
1002 unsigned section_line
,
1009 Network
*network
= userdata
;
1010 _cleanup_(route_freep
) Route
*n
= NULL
;
1013 r
= route_new_static(network
, filename
, section_line
, &n
);
1017 if (streq(rvalue
, "kernel"))
1018 n
->protocol
= RTPROT_KERNEL
;
1019 else if (streq(rvalue
, "boot"))
1020 n
->protocol
= RTPROT_BOOT
;
1021 else if (streq(rvalue
, "static"))
1022 n
->protocol
= RTPROT_STATIC
;
1024 r
= safe_atou8(rvalue
, &n
->protocol
);
1026 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route protocol \"%s\", ignoring assignment: %m", rvalue
);
1035 int config_parse_route_type(
1037 const char *filename
,
1039 const char *section
,
1040 unsigned section_line
,
1047 Network
*network
= userdata
;
1048 _cleanup_(route_freep
) Route
*n
= NULL
;
1051 r
= route_new_static(network
, filename
, section_line
, &n
);
1055 if (streq(rvalue
, "unicast"))
1056 n
->type
= RTN_UNICAST
;
1057 else if (streq(rvalue
, "blackhole"))
1058 n
->type
= RTN_BLACKHOLE
;
1059 else if (streq(rvalue
, "unreachable"))
1060 n
->type
= RTN_UNREACHABLE
;
1061 else if (streq(rvalue
, "prohibit"))
1062 n
->type
= RTN_PROHIBIT
;
1063 else if (streq(rvalue
, "throw"))
1064 n
->type
= RTN_THROW
;
1066 log_syntax(unit
, LOG_ERR
, filename
, line
, r
, "Could not parse route type \"%s\", ignoring assignment: %m", rvalue
);
1074 int config_parse_tcp_window(
1076 const char *filename
,
1078 const char *section
,
1079 unsigned section_line
,
1086 _cleanup_(route_freep
) Route
*n
= NULL
;
1087 Network
*network
= userdata
;
1097 r
= route_new_static(network
, filename
, section_line
, &n
);
1101 r
= parse_size(rvalue
, 1024, &k
);
1102 if (r
< 0 || k
> UINT32_MAX
) {
1103 log_syntax(unit
, LOG_ERR
, filename
, line
, r
,
1104 "Could not parse TCP %s \"%s\" bytes, ignoring assignment: %m", rvalue
, lvalue
);
1108 if (streq(lvalue
, "InitialCongestionWindow"))
1110 else if (streq(lvalue
, "InitialAdvertisedReceiveWindow"))
1113 log_syntax(unit
, LOG_ERR
, filename
, line
, 0, "Failed to parse TCP %s: %s", lvalue
, rvalue
);
1121 int config_parse_quickack(
1123 const char *filename
,
1125 const char *section
,
1126 unsigned section_line
,
1133 _cleanup_(route_freep
) Route
*n
= NULL
;
1134 Network
*network
= userdata
;
1143 r
= route_new_static(network
, filename
, section_line
, &n
);
1147 k
= parse_boolean(rvalue
);
1149 log_syntax(unit
, LOG_ERR
, filename
, line
, k
, "Failed to parse TCP quickack, ignoring: %s", rvalue
);
1158 int config_parse_route_mtu(
1160 const char *filename
,
1162 const char *section
,
1163 unsigned section_line
,
1170 Network
*network
= userdata
;
1171 _cleanup_(route_freep
) Route
*n
= NULL
;
1180 r
= route_new_static(network
, filename
, section_line
, &n
);
1184 r
= config_parse_mtu(unit
, filename
, line
, section
, section_line
, lvalue
, ltype
, rvalue
, &n
->mtu
, userdata
);