From 0a377494bcfcf4e145e260478071be124d56dc6d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 20 Aug 2021 09:41:34 +0900 Subject: [PATCH] network: add UseMTU= in [IPv6AcceptRA] Note that kernel has similar knob in sysctl: accept_ra_mtu. Closes #18868. --- man/systemd.network.xml | 8 ++++++++ src/network/networkd-ndisc.c | 14 +++++++------- src/network/networkd-network-gperf.gperf | 1 + src/network/networkd-network.c | 3 ++- src/network/networkd-network.h | 1 + test/fuzz/fuzz-network-parser/directives.network | 1 + 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 03100c035b84..573ba959eb4d 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -2265,6 +2265,14 @@ IPv6Token=prefixstable:2002:da8:1:: + + UseMTU= + + Takes a boolean. When true, the MTU received in the Router Advertisement will be + used. Defaults to true. + + + UseAutonomousPrefix= diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index f58edb8f3cae..fe1f1e0333cf 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -536,9 +536,9 @@ static int ndisc_request_address(Address *in, Link *link, sd_ndisc_router *rt) { static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) { _cleanup_(route_freep) Route *route = NULL; struct in6_addr gateway; - uint16_t lifetime; + uint32_t table, mtu = 0; unsigned preference; - uint32_t table, mtu; + uint16_t lifetime; usec_t time_now; int r; @@ -575,11 +575,11 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) { if (r < 0) return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); - r = sd_ndisc_router_get_mtu(rt, &mtu); - if (r == -ENODATA) - mtu = 0; - else if (r < 0) - return log_link_error_errno(link, r, "Failed to get default router MTU from RA: %m"); + if (link->network->ipv6_accept_ra_use_mtu) { + r = sd_ndisc_router_get_mtu(rt, &mtu); + if (r < 0 && r != -ENODATA) + return log_link_error_errno(link, r, "Failed to get default router MTU from RA: %m"); + } table = link_get_ipv6_accept_ra_route_table(link); diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index aa4dc00e55bc..846e54aed759 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -256,6 +256,7 @@ IPv6AcceptRA.UseAutonomousPrefix, config_parse_bool, IPv6AcceptRA.UseOnLinkPrefix, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_onlink_prefix) IPv6AcceptRA.UseDNS, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_dns) IPv6AcceptRA.UseDomains, config_parse_ipv6_accept_ra_use_domains, 0, offsetof(Network, ipv6_accept_ra_use_domains) +IPv6AcceptRA.UseMTU, config_parse_bool, 0, offsetof(Network, ipv6_accept_ra_use_mtu) IPv6AcceptRA.DHCPv6Client, config_parse_ipv6_accept_ra_start_dhcp6_client, 0, offsetof(Network, ipv6_accept_ra_start_dhcp6_client) IPv6AcceptRA.RouteTable, config_parse_section_route_table, 0, 0 IPv6AcceptRA.RouteMetric, config_parse_dhcp_route_metric, 0, 0 diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index bb09ba9e8933..1928db537e0c 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -400,15 +400,16 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi .ipv4_accept_local = -1, .ipv4_route_localnet = -1, .ipv6_privacy_extensions = IPV6_PRIVACY_EXTENSIONS_NO, - .ipv6_accept_ra = -1, .ipv6_dad_transmits = -1, .ipv6_hop_limit = -1, .ipv6_proxy_ndp = -1, .proxy_arp = -1, + .ipv6_accept_ra = -1, .ipv6_accept_ra_use_dns = true, .ipv6_accept_ra_use_autonomous_prefix = true, .ipv6_accept_ra_use_onlink_prefix = true, + .ipv6_accept_ra_use_mtu = true, .ipv6_accept_ra_route_table = RT_TABLE_MAIN, .ipv6_accept_ra_route_metric = DHCP_ROUTE_METRIC, .ipv6_accept_ra_start_dhcp6_client = IPV6_ACCEPT_RA_START_DHCP6_CLIENT_YES, diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 815bcf5023fc..95c86e723040 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -301,6 +301,7 @@ struct Network { bool ipv6_accept_ra_use_dns; bool ipv6_accept_ra_use_autonomous_prefix; bool ipv6_accept_ra_use_onlink_prefix; + bool ipv6_accept_ra_use_mtu; bool active_slave; bool primary_slave; DHCPUseDomains ipv6_accept_ra_use_domains; diff --git a/test/fuzz/fuzz-network-parser/directives.network b/test/fuzz/fuzz-network-parser/directives.network index 8fe4ced35154..a3711cb77d9c 100644 --- a/test/fuzz/fuzz-network-parser/directives.network +++ b/test/fuzz/fuzz-network-parser/directives.network @@ -342,6 +342,7 @@ Label= Prefix= [IPv6AcceptRA] UseDomains= +UseMTU= RouteTable= RouteMetric= UseDNS=