From: Susant Sahani <145210+ssahani@users.noreply.github.com> Date: Fri, 29 Dec 2017 14:18:05 +0000 (+0530) Subject: networkd: allow to configure default/initial send/recv congestion window and store... X-Git-Tag: v237~168 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=323d9329e7a3d62a76d2f60b6884e1aa69bfe685;p=thirdparty%2Fsystemd.git networkd: allow to configure default/initial send/recv congestion window and store persistentl (#7750) Currently we can only change initcwnd/initrwnd in the following way, and it does not store persistently: sudo ip route change default via 192.168.1.1 dev tun0 initcwnd 20 sudo ip route change default via 192.168.1.1 dev tun0 initrwnd 20 For more details about initcwnd/initrwnd, please look at: http://hjzhao.blogspot.com/2012/05/increase-initcwnd-for-performance.html http://www.cdnplanet.com/blog/tune-tcp-initcwnd-for-optimum-performance or google 'initcwnd initrwnd' This work allows to configure the initcwnd and initrwnd. Closes #2118 --- diff --git a/man/systemd.network.xml b/man/systemd.network.xml index f78beaa7dc7..bdf8d9e0d90 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -1067,6 +1067,25 @@ + + InitialCongestionWindow= + + The TCP initial congestion window or InitialCongestionWindow is used during the start + of a TCP connection. During the start of a TCP session, when a client requests for a resource, the server's initial congestion window + determines how many data packets will be sent during the initial burst of data. Takes a number between between 1 and 4294967295 (2^32 - 1). + Defaults to unset. + + + + + InitialAdvertisedReceiveWindow= + + The TCP receive window size or InitialAdvertisedReceiveWindow is the amount of receive data (in bytes) + that can be buffered at one time on a connection. The sending host can send only that amount of data before waiting for + an acknowledgment and window update from the receiving host. Takes a number between 1 and 4294967295 (2^32 - 1). Defaults to unset. + + + diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c index 49a2f2a1e4b..7cc4a144461 100644 --- a/src/libsystemd/sd-netlink/netlink-types.c +++ b/src/libsystemd/sd-netlink/netlink-types.c @@ -553,6 +553,7 @@ static const NLType rtnl_route_metrics_types[] = { [RTAX_INITCWND] = { .type = NETLINK_TYPE_U32 }, [RTAX_FEATURES] = { .type = NETLINK_TYPE_U32 }, [RTAX_RTO_MIN] = { .type = NETLINK_TYPE_U32 }, + [RTAX_INITRWND] = { .type = NETLINK_TYPE_U32 }, }; static const NLTypeSystem rtnl_route_metrics_type_system = { diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index cb0c01fbe74..e1990b03024 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -108,6 +108,8 @@ Route.GatewayOnlink, config_parse_gateway_onlink, Route.IPv6Preference, config_parse_ipv6_route_preference, 0, 0 Route.Protocol, config_parse_route_protocol, 0, 0 Route.Type, config_parse_route_type, 0, 0 +Route.InitialCongestionWindow, config_parse_tcp_window, 0, 0 +Route.InitialAdvertisedReceiveWindow, config_parse_tcp_window, 0, 0 DHCP.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier) DHCP.UseDNS, config_parse_bool, 0, offsetof(Network, dhcp_use_dns) DHCP.UseNTP, config_parse_bool, 0, offsetof(Network, dhcp_use_ntp) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index b0ad707811b..f06cc82717c 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -636,6 +636,18 @@ int route_configure( return log_error_errno(r, "Could not append RTAX_MTU attribute: %m"); } + if (route->initcwnd) { + r = sd_netlink_message_append_u32(req, RTAX_INITCWND, route->initcwnd); + if (r < 0) + return log_error_errno(r, "Could not append RTAX_INITCWND attribute: %m"); + } + + if (route->initrwnd) { + r = sd_netlink_message_append_u32(req, RTAX_INITRWND, route->initrwnd); + if (r < 0) + return log_error_errno(r, "Could not append RTAX_INITRWND attribute: %m"); + } + r = sd_netlink_message_close_container(req); if (r < 0) return log_error_errno(r, "Could not append RTA_METRICS attribute: %m"); @@ -1069,3 +1081,49 @@ int config_parse_route_type(const char *unit, return 0; } + +int config_parse_tcp_window(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) { + Network *network = userdata; + _cleanup_route_free_ Route *n = NULL; + 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 < 0) + return r; + + r = safe_atou32(rvalue, &k); + if (r < 0) { + log_syntax(unit, LOG_ERR, filename, line, r, + "Could not parse TCP %s \"%s\", ignoring assignment: %m", rvalue, lvalue); + return 0; + } + + if (streq(lvalue, "InitialCongestionWindow")) + n->initcwnd = k; + else if (streq(lvalue, "InitialAdvertisedReceiveWindow")) + n->initrwnd = k; + else { + log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse TCP %s: %s", lvalue, rvalue); + return 0; + } + + n = NULL; + + return 0; +} diff --git a/src/network/networkd-route.h b/src/network/networkd-route.h index cde31c96633..f856b62406f 100644 --- a/src/network/networkd-route.h +++ b/src/network/networkd-route.h @@ -42,6 +42,8 @@ struct Route { uint32_t priority; /* note that ip(8) calls this 'metric' */ uint32_t table; uint32_t mtu; + uint32_t initcwnd; + uint32_t initrwnd; unsigned char pref; unsigned flags; @@ -82,3 +84,4 @@ int config_parse_gateway_onlink(const char *unit, const char *filename, unsigned int config_parse_ipv6_route_preference(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); int config_parse_route_protocol(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); int config_parse_route_type(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); +int config_parse_tcp_window(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);