daandemeyer / rpms / systemd

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