]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: dhcp6: introduce UseDelegatedPrefix= setting and enable by default
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Oct 2021 07:26:09 +0000 (16:26 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 26 Oct 2021 11:29:08 +0000 (20:29 +0900)
Previously, the prefix delegation is enabled when at least one
downstream interfaces request it. But, when the DHCPv6 client on the
upstream interface is configured, some downstream interfaces may not
exist yet, nor have .network file assigned.

Also, if a system has thousands of interfaces, then the previous logic
introduce O(n^2) search.

This makes the prefix delegation is always enabled, except when it is
explicitly disabled. Hopefully, that should not break anything, as the
DHCPv6 server should ignore the prefix delegation request if the server
do not have any prefix to delegate.

man/systemd.network.xml
src/network/networkd-dhcp6.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h
test/fuzz/fuzz-network-parser/directives.network

index 01297c397f3081179ade362cc098f547bc5154d9..cdb6f4eb87b45d3ccdd740db1ffd4e3e100d8ede 100644 (file)
@@ -2063,6 +2063,19 @@ Table=1234</programlisting></para>
           </listitem>
         </varlistentry>
 
+        <varlistentry>
+          <term><varname>UseDelegatedPrefix=</varname></term>
+          <listitem>
+            <para>When true (the default), the client will request the DHCPv6 server to delegate
+            prefixes. If the server provides prefixes to be delegated, then subnets of the prefixes are
+            assigned to the interfaces which enables <varname>DHCPv6PrefixDelegation=</varname>.
+            See also <varname>DHCPv6PrefixDelegation=</varname> in [Network] section,
+            [DHCPv6PrefixDelegation] section, and
+            <ulink url="https://www.rfc-editor.org/rfc/rfc8415.html#section-6.3">RFC 8415</ulink>.
+            </para>
+          </listitem>
+        </varlistentry>
+
         <varlistentry>
           <term><varname>RouteMetric=</varname></term>
           <term><varname>UseDNS=</varname></term>
index 76f4833b4cc49d85e2c41aa4ea3ec3e439edde2b..1deaed13477dccd6e7d459348f3980f27ade5480 100644 (file)
@@ -1423,25 +1423,6 @@ static int dhcp6_set_hostname(sd_dhcp6_client *client, Link *link) {
         return 0;
 }
 
-static bool dhcp6_enable_prefix_delegation(Link *dhcp6_link) {
-        Link *link;
-
-        assert(dhcp6_link);
-        assert(dhcp6_link->manager);
-
-        HASHMAP_FOREACH(link, dhcp6_link->manager->links_by_index) {
-                if (link == dhcp6_link)
-                        continue;
-
-                if (!link_dhcp6_pd_is_enabled(link))
-                        continue;
-
-                return true;
-        }
-
-        return false;
-}
-
 static int dhcp6_set_identifier(Link *link, sd_dhcp6_client *client) {
         const DUID *duid;
         int r;
@@ -1559,11 +1540,10 @@ static int dhcp6_configure(Link *link) {
         if (r < 0)
                 return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set callback: %m");
 
-        if (dhcp6_enable_prefix_delegation(link)) {
-                r = sd_dhcp6_client_set_prefix_delegation(client, true);
-                if (r < 0)
-                        return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set prefix delegation: %m");
-        }
+        r = sd_dhcp6_client_set_prefix_delegation(client, link->network->dhcp6_use_pd_prefix);
+        if (r < 0)
+                return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to %s prefix delegation: %m",
+                                            enable_disable(link->network->dhcp6_use_pd_prefix));
 
         if (link->network->dhcp6_pd_prefix_length > 0) {
                 r = sd_dhcp6_client_set_prefix_delegation_hint(client,
index a6415c231100673fa49dd5f2c4b1351e9e23f47c..758aa8ee19e7304a5c9b892f96854549db8f510e 100644 (file)
@@ -238,6 +238,7 @@ DHCPv4.SendVendorOption,                     config_parse_dhcp_send_option,
 DHCPv4.RouteMTUBytes,                        config_parse_mtu,                                         AF_INET,                       offsetof(Network, dhcp_route_mtu)
 DHCPv4.FallbackLeaseLifetimeSec,             config_parse_dhcp_fallback_lease_lifetime,                0,                             0
 DHCPv6.UseAddress,                           config_parse_bool,                                        0,                             offsetof(Network, dhcp6_use_address)
+DHCPv6.UseDelegatedPrefix,                   config_parse_bool,                                        0,                             offsetof(Network, dhcp6_use_pd_prefix)
 DHCPv6.UseDNS,                               config_parse_dhcp_use_dns,                                AF_INET6,                      0
 DHCPv6.UseHostname,                          config_parse_bool,                                        0,                             offsetof(Network, dhcp6_use_hostname)
 DHCPv6.UseDomains,                           config_parse_dhcp_use_domains,                            AF_INET6,                      0
index 3b8e508ee8ba8b6c7c88846ef30ee56fd37d98ff..be3c087c8a7abdccc2dc17a876b809a9ce3dc9a4 100644 (file)
@@ -400,6 +400,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
                 .dhcp_broadcast = -1,
 
                 .dhcp6_use_address = true,
+                .dhcp6_use_pd_prefix = true,
                 .dhcp6_use_dns = true,
                 .dhcp6_use_hostname = true,
                 .dhcp6_use_ntp = true,
index b23f70b356e6e419dbbf4ca7c5463af9a9d3085e..dd9804ea2dbcc5b45f42dda40853efabef62dd2f 100644 (file)
@@ -169,6 +169,7 @@ struct Network {
 
         /* DHCPv6 Client support */
         bool dhcp6_use_address;
+        bool dhcp6_use_pd_prefix;
         bool dhcp6_use_dns;
         bool dhcp6_use_dns_set;
         bool dhcp6_use_hostname;
index ea02d4c640fba2466a20ec4573fffc9e01e72dfe..dae13a243cd9623238c9e67eb03f3f7525434486 100644 (file)
@@ -130,6 +130,7 @@ RouteMTUBytes=
 FallbackLeaseLifetimeSec=
 [DHCPv6]
 UseAddress=
+UseDelegatedPrefix=
 UseNTP=
 UseDNS=
 UseHostname=