]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: add UseFQDN option for DHCPv6
authorVinnie Magro <v@vinn.ie>
Fri, 29 Jan 2021 00:24:34 +0000 (16:24 -0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 11 Feb 2021 04:30:04 +0000 (13:30 +0900)
Similar to DHCPv4's UseHostname option, add a UseFQDN config option in
[DHCPv6] to set the system's transient hostname if the FQDN option is
set in the DHCPv6 response from the server.

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 606a2dd5dbbf637f9b3a7af9e13616c25fffdfda..7cf1da6ce5e3b3ca187034778648fbbbd5a26597 100644 (file)
@@ -1926,6 +1926,13 @@ IPv6Token=prefixstable:2002:da8:1::</programlisting></para>
           </listitem>
         </varlistentry>
 
+        <varlistentry>
+          <term><varname>UseFQDN=</varname></term>
+          <listitem>
+            <para>Equivalent of <varname>UseHostname=</varname> in the [DHCPv4] section.</para>
+          </listitem>
+        </varlistentry>
+
         <varlistentry>
           <term><varname>RouteMetric=</varname></term>
           <listitem>
index 85a533b32fc94994d75f491d1d062376ec1dae8e..e643a92247dc561e9baedc041bf1f9a7ad0d8bf5 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "escape.h"
 #include "hashmap.h"
+#include "hostname-setup.h"
 #include "hostname-util.h"
 #include "missing_network.h"
 #include "networkd-address.h"
@@ -1073,6 +1074,25 @@ static int dhcp6_address_acquired(Link *link) {
                         return r;
         }
 
+        if (link->network->dhcp6_use_fqdn) {
+                const char *dhcpname = NULL;
+                _cleanup_free_ char *hostname = NULL;
+                (void) sd_dhcp6_lease_get_fqdn(link->dhcp6_lease, &dhcpname);
+
+                if (dhcpname) {
+                        r = shorten_overlong(dhcpname, &hostname);
+                        if (r < 0)
+                                log_link_warning_errno(link, r, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhcpname);
+                        if (r == 1)
+                                log_link_notice(link, "Overlong DHCP hostname received, shortened from '%s' to '%s'", dhcpname, hostname);
+                }
+                if (hostname) {
+                        r = manager_set_hostname(link->manager, hostname);
+                        if (r < 0)
+                                log_link_error_errno(link, r, "Failed to set transient hostname to '%s': %m", hostname);
+                }
+        }
+
         return 0;
 }
 
index 7f0de7660c31a040dd54dff2c240f02fe35bde84..ad261406f0a765b39847e18879de21c2305b06ed 100644 (file)
@@ -223,6 +223,7 @@ DHCPv4.RouteMTUBytes,                        config_parse_mtu,
 DHCPv4.FallbackLeaseLifetimeSec,             config_parse_dhcp_fallback_lease_lifetime,                0,                             0
 DHCPv6.UseAddress,                           config_parse_bool,                                        0,                             offsetof(Network, dhcp6_use_address)
 DHCPv6.UseDNS,                               config_parse_dhcp_use_dns,                                0,                             0
+DHCPv6.UseFQDN,                              config_parse_bool,                                        0,                             offsetof(Network, dhcp6_use_fqdn)
 DHCPv6.UseNTP,                               config_parse_dhcp_use_ntp,                                0,                             0
 DHCPv6.RapidCommit,                          config_parse_bool,                                        0,                             offsetof(Network, dhcp6_rapid_commit)
 DHCPv6.MUDURL,                               config_parse_dhcp6_mud_url,                               0,                             0
index 84ab1d5e18d673981ddcef3c7b7fc150ad293874..69cf95fedee7275ee6636027c9d0b1f0d5622c32 100644 (file)
@@ -374,6 +374,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
 
                 .dhcp6_use_address = true,
                 .dhcp6_use_dns = true,
+                .dhcp6_use_fqdn = true,
                 .dhcp6_use_ntp = true,
                 .dhcp6_rapid_commit = true,
                 .dhcp6_route_metric = DHCP_ROUTE_METRIC,
index 288248dfa686987c910b0eab6c3b25f779025f9a..899b86eec91e077b94a99e9f5a8daad144b39c52 100644 (file)
@@ -159,6 +159,7 @@ struct Network {
         bool dhcp6_use_address;
         bool dhcp6_use_dns;
         bool dhcp6_use_dns_set;
+        bool dhcp6_use_fqdn;
         bool dhcp6_use_ntp;
         bool dhcp6_use_ntp_set;
         bool dhcp6_rapid_commit;
index 1c4f338ad0954a51a602ef3b3ca8b0391380090a..51dd56ade92d7dcefbaf5d3bb997da08d86774c2 100644 (file)
@@ -127,6 +127,7 @@ FallbackLeaseLifetimeSec=
 UseAddress=
 UseNTP=
 UseDNS=
+UseFQDN=
 RapidCommit=
 ForceDHCPv6PDOtherInformation=
 PrefixDelegationHint=