From 007cac09a2e3e7e5c067f93948fb33f37166c9bb Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Thu, 7 Jan 2021 16:17:17 +0100 Subject: [PATCH] network: route - add support to configure tcp advmss --- man/systemd.network.xml | 8 +++ src/network/networkd-network-gperf.gperf | 1 + src/network/networkd-route.c | 69 +++++++++++++++++++ src/network/networkd-route.h | 2 + .../fuzz-network-parser/directives.network | 1 + 5 files changed, 81 insertions(+) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 422268b0f7..542743aa5b 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -1482,6 +1482,14 @@ IPv6Token=prefixstable:2002:da8:1:: service type to CS6 (network control) or CS4 (Realtime). Defaults to CS6. + + TCPAdvertisedMaximumSegmentSize= + + Specifies the Path MSS (in bytes) hints given on TCP layer. The usual suffixes K, M, G, are + supported and are understood to the base of 1024. An unsigned integer in the range 1–4294967294. + When unset, the kernel's default will be used. + + MultiPathRoute=address[@name] [weight] diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 444c6c78bc..81878dcea1 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -179,6 +179,7 @@ Route.Protocol, config_parse_route_protocol, Route.Type, config_parse_route_type, 0, 0 Route.InitialCongestionWindow, config_parse_tcp_window, 0, 0 Route.InitialAdvertisedReceiveWindow, config_parse_tcp_window, 0, 0 +Route.TCPAdvertisedMaximumSegmentSize, config_parse_tcp_advmss, 0, 0 Route.QuickAck, config_parse_route_boolean, 0, 0 Route.FastOpenNoCookie, config_parse_route_boolean, 0, 0 Route.TTLPropagate, config_parse_route_boolean, 0, 0 diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 0c15fc53f4..b6bf9803b4 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -310,6 +310,8 @@ void route_hash_func(const Route *route, struct siphash *state) { siphash24_compress(&route->initcwnd, sizeof(route->initcwnd), state); siphash24_compress(&route->initrwnd, sizeof(route->initrwnd), state); + siphash24_compress(&route->advmss, sizeof(route->advmss), state); + break; default: /* treat any other address family as AF_UNSPEC */ @@ -393,6 +395,10 @@ int route_compare_func(const Route *a, const Route *b) { if (r != 0) return r; + r = CMP(a->advmss, b->advmss); + if (r != 0) + return r; + return 0; default: /* treat any other address family as AF_UNSPEC */ @@ -475,6 +481,7 @@ static void route_copy(Route *dest, const Route *src, const MultipathRoute *m) { dest->initcwnd = src->initcwnd; dest->initrwnd = src->initrwnd; dest->lifetime = src->lifetime; + dest->advmss= src->advmss; if (m) { dest->gw_family = m->gateway.family; @@ -1122,6 +1129,12 @@ int route_configure( return log_link_error_errno(link, r, "Could not append RTAX_FASTOPEN_NO_COOKIE attribute: %m"); } + if (route->advmss > 0) { + r = sd_netlink_message_append_u32(req, RTAX_ADVMSS, route->advmss); + if (r < 0) + return log_link_error_errno(link, r, "Could not append RTAX_ADVMSS attribute: %m"); + } + r = sd_netlink_message_close_container(req); if (r < 0) return log_link_error_errno(link, r, "Could not append RTA_METRICS attribute: %m"); @@ -2074,6 +2087,62 @@ int config_parse_route_type( return 0; } +int config_parse_tcp_advmss( + 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; + uint64_t u; + 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->advmss = 0; + return 0; + } + + r = parse_size(rvalue, 1024, &u); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Could not parse TCPAdvertisedMaximumSegmentSize= \"%s\", ignoring assignment: %m", rvalue); + return 0; + } + + if (u == 0 || u > UINT32_MAX) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid TCPAdvertisedMaximumSegmentSize= \"%s\", ignoring assignment: %m", rvalue); + return 0; + } + + n->advmss = u; + + TAKE_PTR(n); + return 0; +} + int config_parse_tcp_window( const char *unit, const char *filename, diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index 82ef4ee2a0..8923966ddf 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -40,6 +40,7 @@ typedef struct Route { uint32_t mtu; uint32_t initcwnd; uint32_t initrwnd; + uint32_t advmss; unsigned char pref; unsigned flags; int gateway_onlink; @@ -98,3 +99,4 @@ CONFIG_PARSER_PROTOTYPE(config_parse_route_type); CONFIG_PARSER_PROTOTYPE(config_parse_tcp_window); CONFIG_PARSER_PROTOTYPE(config_parse_route_mtu); CONFIG_PARSER_PROTOTYPE(config_parse_multipath_route); +CONFIG_PARSER_PROTOTYPE(config_parse_tcp_advmss); diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network index e7860702c6..c8435a0a84 100644 --- a/test/fuzz/fuzz-network-parser/directives.network +++ b/test/fuzz/fuzz-network-parser/directives.network @@ -163,6 +163,7 @@ Source= Metric= TTLPropagate= MultiPathRoute= +TCPAdvertisedMaximumSegmentSize= [Network] IPv6DuplicateAddressDetection= IPMasquerade=