]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: introduce SendHostname/Hostname DHCPv6 options
authorRonan Pigott <ronan@rjp.ie>
Tue, 24 Oct 2023 20:56:22 +0000 (13:56 -0700)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 30 Oct 2023 11:04:10 +0000 (11:04 +0000)
These options were previously reused by the DHCPv6 client from the
DHCPv4 client settings. Let's separate them for consistency.

NEWS
man/systemd.network.xml
src/network/networkd-dhcp-common.c
src/network/networkd-dhcp-common.h
src/network/networkd-dhcp6.c
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c
src/network/networkd-network.h

diff --git a/NEWS b/NEWS
index 62cc4698dc7770a5560fe2ae952391bec5039bd5..1d1f08deda7bd38f18d3ef623e67b488a0802fdb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -78,6 +78,10 @@ CHANGES WITH 255 in spe:
           simplified 2-message exchange instead of the typical 4-message
           exchange if also supported by the DHCP server.
 
+        * The SendHostname and Hostname options are now available for the
+          DHCPv6 client, independent of the DHCPv4 option, so that these
+          configuration values can be set independently for each client.
+
         Changes in systemd-analyze:
 
         * "systemd-analyze plot" has gained tooltips on each unit name with
index 684a54e08bb7681bea43baed2371b447c195bf12..4e360d7a8e81c3143957b90113d6165418180429 100644 (file)
@@ -2829,6 +2829,30 @@ NFTSet=prefix:netdev:filter:eth_ipv4_prefix</programlisting>
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><varname>SendHostname=</varname></term>
+        <listitem>
+          <para>When true (the default), the machine's hostname (or the value specified with
+          <varname>Hostname=</varname>, described below) will be sent to the DHCPv6 server. Note that the
+          hostname must consist only of 7-bit ASCII lower-case characters and no spaces or dots, and be
+          formatted as a valid DNS domain name. Otherwise, the hostname is not sent even if this option
+          is true.</para>
+
+          <xi:include href="version-info.xml" xpointer="v255"/>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term><varname>Hostname=</varname></term>
+        <listitem>
+          <para>Use this value for the hostname which is sent to the DHCPv6 server, instead of machine's
+          hostname. Note that the specified hostname must consist only of 7-bit ASCII lower-case
+          characters and no spaces or dots, and be formatted as a valid DNS domain name.</para>
+
+          <xi:include href="version-info.xml" xpointer="v255"/>
+        </listitem>
+      </varlistentry>
+
       <!-- How to use the DHCP lease -->
 
       <varlistentry>
index cfc7a388e8fdf07165d243f6ae62fb715d763f6a..195ce2d71fa126e4643472933ac2720c7fea0002 100644 (file)
@@ -481,6 +481,56 @@ int config_parse_ipv6_accept_ra_route_metric(
         return 0;
 }
 
+int config_parse_dhcp_send_hostname(
+                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;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6));
+        assert(rvalue);
+        assert(data);
+
+        r = parse_boolean(rvalue);
+        if (r < 0) {
+                log_syntax(unit, LOG_WARNING, filename, line, r,
+                           "Failed to parse SendHostname=%s, ignoring assignment: %m", rvalue);
+                return 0;
+        }
+
+        switch (ltype) {
+        case AF_INET:
+                network->dhcp_send_hostname = r;
+                network->dhcp_send_hostname_set = true;
+                break;
+        case AF_INET6:
+                network->dhcp6_send_hostname = r;
+                network->dhcp6_send_hostname_set = true;
+                break;
+        case AF_UNSPEC:
+                /* For backward compatibility. */
+                if (!network->dhcp_send_hostname_set)
+                        network->dhcp_send_hostname = r;
+                if (!network->dhcp6_send_hostname_set)
+                        network->dhcp6_send_hostname = r;
+                break;
+        default:
+                assert_not_reached();
+        }
+
+        return 0;
+}
 int config_parse_dhcp_use_dns(
                 const char* unit,
                 const char *filename,
index ea942af721d5b9f40eb7d511aeaf34cb5a9ebdfe..6e3f3b2a1ef25eed4b7d839c3d9f64b8f31fb6a3 100644 (file)
@@ -96,6 +96,7 @@ DHCPOptionDataType dhcp_option_data_type_from_string(const char *d) _pure_;
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_route_metric);
 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_accept_ra_route_metric);
+CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_send_hostname);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_dns);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_domains);
 CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_use_ntp);
index 0aa56bffbc7c6726ab6b8a9baaa1ace3db3fba93..cc2c466cdd0658f015e42bdeaaba2906ddb4c95d 100644 (file)
@@ -522,10 +522,10 @@ static int dhcp6_set_hostname(sd_dhcp6_client *client, Link *link) {
 
         assert(link);
 
-        if (!link->network->dhcp_send_hostname)
+        if (!link->network->dhcp6_send_hostname)
                 hn = NULL;
-        else if (link->network->dhcp_hostname)
-                hn = link->network->dhcp_hostname;
+        else if (link->network->dhcp6_hostname)
+                hn = link->network->dhcp6_hostname;
         else {
                 r = gethostname_strict(&hostname);
                 if (r < 0 && r != -ENXIO) /* ENXIO: no hostname set or hostname is "localhost" */
index b87ae006f135a94a28f6e27b0de6a602225d35a1..6323f6b212809e0d64d43c5f561489786bc7fc43 100644 (file)
@@ -230,7 +230,7 @@ DHCPv4.UseGateway,                           config_parse_tristate,
 DHCPv4.QuickAck,                             config_parse_bool,                                        0,                             offsetof(Network, dhcp_quickack)
 DHCPv4.RequestOptions,                       config_parse_dhcp_request_options,                        AF_INET,                       0
 DHCPv4.Anonymize,                            config_parse_bool,                                        0,                             offsetof(Network, dhcp_anonymize)
-DHCPv4.SendHostname,                         config_parse_bool,                                        0,                             offsetof(Network, dhcp_send_hostname)
+DHCPv4.SendHostname,                         config_parse_dhcp_send_hostname,                          AF_INET,                       0
 DHCPv4.Hostname,                             config_parse_hostname,                                    0,                             offsetof(Network, dhcp_hostname)
 DHCPv4.Label,                                config_parse_dhcp_label,                                  0,                             offsetof(Network, dhcp_label)
 DHCPv4.RequestBroadcast,                     config_parse_tristate,                                    0,                             offsetof(Network, dhcp_broadcast)
@@ -270,6 +270,8 @@ DHCPv6.UseDomains,                           config_parse_dhcp_use_domains,
 DHCPv6.UseNTP,                               config_parse_dhcp_use_ntp,                                AF_INET6,                      0
 DHCPv6.UseCaptivePortal,                     config_parse_bool,                                        0,                             offsetof(Network, dhcp6_use_captive_portal)
 DHCPv6.MUDURL,                               config_parse_mud_url,                                     0,                             offsetof(Network, dhcp6_mudurl)
+DHCPv6.SendHostname,                         config_parse_dhcp_send_hostname,                          AF_INET6,                      0
+DHCPv6.Hostname,                             config_parse_hostname,                                    0,                             offsetof(Network, dhcp6_hostname)
 DHCPv6.RequestOptions,                       config_parse_dhcp_request_options,                        AF_INET6,                      0
 DHCPv6.UserClass,                            config_parse_dhcp_user_or_vendor_class,                   AF_INET6,                      offsetof(Network, dhcp6_user_class)
 DHCPv6.VendorClass,                          config_parse_dhcp_user_or_vendor_class,                   AF_INET6,                      offsetof(Network, dhcp6_vendor_class)
@@ -583,7 +585,7 @@ DHCP.UseDomains,                             config_parse_dhcp_use_domains,
 DHCP.UseDomainName,                          config_parse_dhcp_use_domains,                            AF_UNSPEC,                     0
 DHCP.UseRoutes,                              config_parse_bool,                                        0,                             offsetof(Network, dhcp_use_routes)
 DHCP.Anonymize,                              config_parse_bool,                                        0,                             offsetof(Network, dhcp_anonymize)
-DHCP.SendHostname,                           config_parse_bool,                                        0,                             offsetof(Network, dhcp_send_hostname)
+DHCP.SendHostname,                           config_parse_dhcp_send_hostname,                          AF_UNSPEC,                     0
 DHCP.Hostname,                               config_parse_hostname,                                    0,                             offsetof(Network, dhcp_hostname)
 DHCP.RequestBroadcast,                       config_parse_tristate,                                    0,                             offsetof(Network, dhcp_broadcast)
 DHCP.CriticalConnection,                     config_parse_tristate,                                    0,                             offsetof(Network, dhcp_critical)
index 4a38bc88ae1896ac0f77eabfa5123708d5f70e44..b9119d9d18c8f95ebd5cfbe583066bbf037bdb56 100644 (file)
@@ -410,6 +410,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
                 .dhcp6_use_ntp = true,
                 .dhcp6_use_captive_portal = true,
                 .dhcp6_use_rapid_commit = true,
+                .dhcp6_send_hostname = true,
                 .dhcp6_duid.type = _DUID_TYPE_INVALID,
                 .dhcp6_client_start_mode = _DHCP6_CLIENT_START_MODE_INVALID,
                 .dhcp6_send_release = true,
index e0891f9c186cec95012cb09137db84a14df7c2a9..00a6b50310f018f5e8585ca41de35ce40fd6561c 100644 (file)
@@ -138,6 +138,7 @@ struct Network {
         bool dhcp_socket_priority_set;
         bool dhcp_anonymize;
         bool dhcp_send_hostname;
+        bool dhcp_send_hostname_set;
         int dhcp_broadcast;
         int dhcp_ipv6_only_mode;
         bool dhcp_use_rapid_commit;
@@ -173,6 +174,8 @@ struct Network {
         /* DHCPv6 Client support */
         bool dhcp6_use_address;
         bool dhcp6_use_pd_prefix;
+        bool dhcp6_send_hostname;
+        bool dhcp6_send_hostname_set;
         bool dhcp6_use_dns;
         bool dhcp6_use_dns_set;
         bool dhcp6_use_hostname;
@@ -188,6 +191,7 @@ struct Network {
         DUID dhcp6_duid;
         uint8_t dhcp6_pd_prefix_length;
         struct in6_addr dhcp6_pd_prefix_hint;
+        char *dhcp6_hostname;
         char *dhcp6_mudurl;
         char **dhcp6_user_class;
         char **dhcp6_vendor_class;