From: Susant Sahani Date: Wed, 16 Aug 2023 17:07:48 +0000 (+0530) Subject: network: static route - Allow to configure per route hop liimt X-Git-Tag: v255-rc1~687^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88c0642358398240a54d242e812439fcd0564b05;p=thirdparty%2Fsystemd.git network: static route - Allow to configure per route hop liimt --- diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 2d9596dfe46..db9a9ac25d4 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -1617,6 +1617,13 @@ allow my_server_t localnet_peer_t:peer recv; + + HopLimit= + + Configures per route hop limit. See also IPv6HopLimit=. + + + Protocol= diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index d0214d131a1..c3f286e8bd3 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -197,6 +197,7 @@ Route.IPv6Preference, config_parse_ipv6_route_preference, Route.Protocol, config_parse_route_protocol, 0, 0 Route.Type, config_parse_route_type, 0, 0 Route.TCPRetransmissionTimeOutSec, config_parse_route_tcp_rto, 0, 0 +Route.HopLimit, config_parse_route_hop_limit, 0, 0 Route.InitialCongestionWindow, config_parse_route_tcp_window, 0, 0 Route.InitialAdvertisedReceiveWindow, config_parse_route_tcp_window, 0, 0 Route.TCPAdvertisedMaximumSegmentSize, config_parse_tcp_advmss, 0, 0 diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index a13ec818069..7af697c16d2 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -2532,6 +2532,67 @@ int config_parse_route_type( return 0; } +int config_parse_route_hop_limit( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + _cleanup_(route_free_or_set_invalidp) Route *n = NULL; + Network *network = userdata; + uint32_t k; + int r; + + assert(filename); + assert(section); + assert(lvalue); + assert(rvalue); + assert(data); + + r = route_new_static(network, filename, section_line, &n); + if (r == -ENOMEM) + return log_oom(); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Failed to allocate route, ignoring assignment: %m"); + return 0; + } + + if (isempty(rvalue)) { + n->hop_limit = 0; + TAKE_PTR(n); + return 0; + } + + r = safe_atou32(rvalue, &k); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Could not parse route hop limit %s \"%s\", ignoring assignment: %m", lvalue, rvalue); + return 0; + } + if (k > 255) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Specified route hop limit %s \"%s\" is too large, ignoring assignment: %m", lvalue, rvalue); + return 0; + } + if (k == 0) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid route hop limit %s \"%s\", ignoring assignment: %m", lvalue, rvalue); + return 0; + } + + n->hop_limit = k; + + TAKE_PTR(n); + return 0; +} + int config_parse_tcp_congestion( const char *unit, const char *filename, diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index f64d081fe26..3d85889a2fa 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -125,6 +125,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_route_preference); CONFIG_PARSER_PROTOTYPE(config_parse_route_protocol); CONFIG_PARSER_PROTOTYPE(config_parse_route_type); CONFIG_PARSER_PROTOTYPE(config_parse_route_tcp_window); +CONFIG_PARSER_PROTOTYPE(config_parse_route_hop_limit); CONFIG_PARSER_PROTOTYPE(config_parse_tcp_window); CONFIG_PARSER_PROTOTYPE(config_parse_route_tcp_rto); CONFIG_PARSER_PROTOTYPE(config_parse_route_mtu);