]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: clean up DUID code a bit
authorLennart Poettering <lennart@poettering.net>
Tue, 26 Apr 2016 14:19:28 +0000 (16:19 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 29 Apr 2016 10:23:34 +0000 (12:23 +0200)
Let's move DUID configuration into the [DHCP] section, since it only makes
sense in a DHCP context, and should be close to the configuration of
ClientIdentifier= and suchlike.

This really shouldn't be a section of its own, we don't have any for any of our
other per-protocol specific identifiers...

Follow-up for #2890 #2943

man/systemd.network.xml
src/network/networkd-conf.c
src/network/networkd-gperf.gperf
src/network/networkd-network-gperf.gperf
src/network/networkd-network.c

index 9bf1b198ad7db18e5fb11b8a5283e0f0b8672065..2a2074837608d15349f5f870436323e8ef4ddd24 100644 (file)
         <varlistentry>
           <term><varname>ClientIdentifier=</varname></term>
           <listitem>
-            <para>DHCP client identifier to use. Either <literal>mac</literal>
-            to use the MAC address of the link or <literal>duid</literal>
-            (the default) to use a RFC4361-compliant Client ID.</para>
+            <para>The DHCPv4 client identifier to use. Either <literal>mac</literal> to use the MAC address of the link
+            or <literal>duid</literal> (the default, see below) to use a RFC4361-compliant Client ID.</para>
           </listitem>
         </varlistentry>
         <varlistentry>
             type and configuration.</para>
           </listitem>
         </varlistentry>
+        <varlistentry>
+          <term><varname>DUIDRawData=</varname></term>
+          <listitem><para>Specifies the DHCP DUID bytes as a single newline-terminated, hexadecimal string, with each
+          byte separated by a ':'.  A DHCPv6 client sends the DHCP Unique Identifier (DUID) and the interface Identity
+          Association Identifier (IAID) to a DHCP server when acquiring a dynamic IPv6 address. Similar, DHCPv4 clients
+          send the IAID and DUID to the DHCP server when acquiring a dynamic IPv4 address if
+          <option>ClientIdentifier=duid</option>. IAID and DUID allows a DHCP server to uniquely identify the machine
+          and the interface requesting a DHCP IP address.</para>
+
+          <para>The DUID value specified here takes precedence over the DUID that systemd-networkd generates
+          using the machine-id from the <filename>/etc/machine-id</filename> file, as well as the
+          global DUID that may be specified in <citerefentry><refentrytitle>networkd.conf
+          </refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
+
+          <para>The configured DHCP DUID should conform to the specification in
+          <ulink url="http://tools.ietf.org/html/rfc3315#section-9">RFC 3315</ulink>,
+          <ulink url="http://tools.ietf.org/html/rfc6355">RFC 6355</ulink>.</para>
+          </listitem>
+        </varlistentry>
         <varlistentry>
           <term><varname>RequestBroadcast=</varname></term>
           <listitem>
           </listitem>
         </varlistentry>
       </variablelist>
-
-  </refsect1>
-
-  <refsect1>
-    <title>[DUID] Section Options</title>
-
-    <para>This section configures the DHCP Unique Identifier (DUID) value used by DHCP
-    protocol. DHCPv6 client protocol sends the DHCP Unique Identifier and the interface
-    Identity Association Identifier (IAID) to a DHCP server when acquiring a dynamic IPv6
-    address. DHCPv4 client protocol sends IAID and DUID to the DHCP server when acquiring
-    a dynamic IPv4 address if <option>ClientIdentifier=duid</option>. IAID and DUID allows a
-    DHCP server to uniquely identify the machine and the interface requesting a DHCP IP.</para>
-
-    <para>The DUID value specified here overrides the DUID that systemd-networkd generates
-    using the machine-id from the <filename>/etc/machine-id</filename> file, as well as the
-    global DUID that may be specified in <citerefentry><refentrytitle>networkd.conf
-    </refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
-
-    <para>The configured DHCP DUID should conform to the specification in
-    <ulink url="http://tools.ietf.org/html/rfc3315#section-9">RFC 3315</ulink>,
-    <ulink url="http://tools.ietf.org/html/rfc6355">RFC 6355</ulink>.</para>
-
-    <para>The following options are available in <literal>[DUID]</literal> section:</para>
-
-    <variablelist class='network-directives'>
-
-      <varlistentry>
-        <term><varname>RawData=</varname></term>
-        <listitem><para>Specifies the DUID bytes as a single newline-terminated, hexadecimal
-        string, with each byte separated by a ':'.</para></listitem>
-      </varlistentry>
-
-    </variablelist>
-  </refsect1>
+    </refsect1>
 
   <refsect1>
     <title>[DHCPServer] Section Options</title>
index 73a8d16b580933426e828314486f6508f950daa6..70f0121d6db1d0fb3b2c2473c704916c1ef6ad35 100644 (file)
@@ -31,7 +31,7 @@ int manager_parse_config_file(Manager *m) {
 
         return config_parse_many(PKGSYSCONFDIR "/networkd.conf",
                                  CONF_PATHS_NULSTR("systemd/networkd.conf.d"),
-                                 "DUID\0",
+                                 "DHCP\0",
                                  config_item_perf_lookup, networkd_gperf_lookup,
                                  false, m);
 }
@@ -57,7 +57,8 @@ int config_parse_duid_rawdata(
                 const char *rvalue,
                 void *data,
                 void *userdata) {
-        int r, n1, n2, byte;
+
+        int r;
         char *cbyte;
         const char *pduid = rvalue;
         Manager *m = userdata;
@@ -72,71 +73,78 @@ int config_parse_duid_rawdata(
         assert(rvalue);
         assert(userdata);
 
-        duidtype = (ltype == DUID_CONFIG_SOURCE_GLOBAL) ? m->duid_type
-                                                        : n->duid_type;
+        duidtype = (ltype == DUID_CONFIG_SOURCE_GLOBAL) ? m->duid_type : n->duid_type;
 
         if (duidtype == _DUID_TYPE_INVALID)
                 duidtype = DUID_TYPE_RAW;
 
         switch (duidtype) {
+
         case DUID_TYPE_LLT:
                 /* RawData contains DUID-LLT link-layer address (offset 6) */
                 duid_start_offset = 6;
                 break;
+
         case DUID_TYPE_EN:
                 /* RawData contains DUID-EN identifier (offset 4) */
                 duid_start_offset = 4;
                 break;
+
         case DUID_TYPE_LL:
                 /* RawData contains DUID-LL link-layer address (offset 2) */
                 duid_start_offset = 2;
                 break;
+
         case DUID_TYPE_UUID:
                 /* RawData specifies UUID (offset 0) - fall thru */
+
         case DUID_TYPE_RAW:
                 /* First two bytes of RawData is DUID Type - fall thru */
+
         default:
                 break;
         }
 
         if (duidtype != DUID_TYPE_RAW)
-                dhcp_duid_type = (uint16_t)duidtype;
+                dhcp_duid_type = (uint16_t) duidtype;
 
         /* RawData contains DUID in format " NN:NN:NN... " */
         for (;;) {
+                int n1, n2;
+                uint32_t byte;
+
                 r = extract_first_word(&pduid, &cbyte, ":", 0);
                 if (r < 0) {
-                        log_syntax(unit, LOG_ERR, filename, line, r,
-                                   "Failed to read DUID, ignoring assignment: %s.", rvalue);
-                        goto exit;
+                        log_syntax(unit, LOG_ERR, filename, line, r, "Failed to read DUID, ignoring assignment: %s.", rvalue);
+                        return 0;
                 }
                 if (r == 0)
                         break;
-                if ((duid_start_offset + dhcp_duid_len) >= MAX_DUID_LEN) {
-                        log_syntax(unit, LOG_ERR, filename, line, 0,
-                                   "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
-                        goto exit;
+                if (duid_start_offset + dhcp_duid_len >= MAX_DUID_LEN) {
+                        log_syntax(unit, LOG_ERR, filename, line, 0, "Max DUID length exceeded, ignoring assignment: %s.", rvalue);
+                        return 0;
                 }
 
                 len = strlen(cbyte);
-                if ((len == 0) || (len > 2)) {
-                        log_syntax(unit, LOG_ERR, filename, line, 0,
-                                   "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
-                        goto exit;
+                if (len != 1 && len != 2) {
+                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid length - DUID byte: %s, ignoring assignment: %s.", cbyte, rvalue);
+                        return 0;
                 }
-                n2 = 0;
                 n1 = unhexchar(cbyte[0]);
                 if (len == 2)
                         n2 = unhexchar(cbyte[1]);
-                if ((n1 < 0) || (n2 < 0)) {
-                        log_syntax(unit, LOG_ERR, filename, line, 0,
-                                   "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue);
-                        goto exit;
+                else
+                        n2 = 0;
+
+                if (n1 < 0 || n2 < 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid DUID byte: %s. Ignoring assignment: %s.", cbyte, rvalue);
+                        return 0;
                 }
-                byte = (n1 << (4 * (len-1))) | n2;
+
+                byte = ((uint8_t) n1 << (4 * (len-1))) | (uint8_t) n2;
 
                 /* If DUID_TYPE_RAW, first two bytes hold DHCP DUID type code */
-                if ((duidtype == DUID_TYPE_RAW) && (count < 2)) {
+                if (duidtype == DUID_TYPE_RAW && count < 2) {
                         dhcp_duid_type |= (byte << (8 * (1 - count)));
                         count++;
                         continue;
@@ -159,6 +167,5 @@ int config_parse_duid_rawdata(
                 memcpy(&n->dhcp_duid[duid_start_offset], dhcp_duid, dhcp_duid_len);
         }
 
-exit:
         return 0;
 }
index 0625fb335b8097e6751e70e8626b3d29538101b9..afc71b4cb8c8d2788619a9d93ff96c63fa9a5d8a 100644 (file)
@@ -14,5 +14,5 @@ struct ConfigPerfItem;
 %struct-type
 %includes
 %%
-DUID.Type,              config_parse_duid_type,                 0,                                  offsetof(Manager, duid_type)
-DUID.RawData,           config_parse_duid_rawdata,              DUID_CONFIG_SOURCE_GLOBAL,          offsetof(Manager, dhcp_duid)
+DHCP.DUIDType,              config_parse_duid_type,                 0,                                  offsetof(Manager, duid_type)
+DHCP.DUIDRawData,           config_parse_duid_rawdata,              DUID_CONFIG_SOURCE_GLOBAL,          offsetof(Manager, dhcp_duid)
index 1da99cd5bc84c33ccbcf7e1ba8029d586752fc9d..654d6a0316b4346f9d1f36a55562fc737d59b95a 100644 (file)
@@ -28,8 +28,6 @@ Match.Architecture,                     config_parse_net_condition,
 Link.MACAddress,                        config_parse_hwaddr,                            0,                             offsetof(Network, mac)
 Link.MTUBytes,                          config_parse_iec_size,                          0,                             offsetof(Network, mtu)
 Link.IAID,                              config_parse_iaid,                              0,                             offsetof(Network, iaid)
-DUID.Type,                              config_parse_duid_type,                         0,                             offsetof(Network, duid_type)
-DUID.RawData,                           config_parse_duid_rawdata,                      DUID_CONFIG_SOURCE_NETWORK,    offsetof(Network, dhcp_duid)
 Network.Description,                    config_parse_string,                            0,                             offsetof(Network, description)
 Network.Bridge,                         config_parse_netdev,                            0,                             offsetof(Network, bridge)
 Network.Bond,                           config_parse_netdev,                            0,                             offsetof(Network, bond)
@@ -85,6 +83,8 @@ DHCP.Hostname,                          config_parse_hostname,
 DHCP.RequestBroadcast,                  config_parse_bool,                              0,                             offsetof(Network, dhcp_broadcast)
 DHCP.CriticalConnection,                config_parse_bool,                              0,                             offsetof(Network, dhcp_critical)
 DHCP.VendorClassIdentifier,             config_parse_string,                            0,                             offsetof(Network, dhcp_vendor_class_identifier)
+DHCP.DUIDType,                          config_parse_duid_type,                         0,                             offsetof(Network, duid_type)
+DHCP.DUIDRawData,                       config_parse_duid_rawdata,                      DUID_CONFIG_SOURCE_NETWORK,    offsetof(Network, dhcp_duid)
 DHCP.RouteMetric,                       config_parse_unsigned,                          0,                             offsetof(Network, dhcp_route_metric)
 DHCP.UseTimezone,                       config_parse_bool,                              0,                             offsetof(Network, dhcp_use_timezone)
 DHCPServer.MaxLeaseTimeSec,             config_parse_sec,                               0,                             offsetof(Network, dhcp_server_max_lease_time_usec)
index 07f8fb028f1fb8df2021c38dd9e240146c4a0f7c..2ebcdfa744b4aef3591486b913c8738031af8d5e 100644 (file)
@@ -137,7 +137,6 @@ static int network_load_one(Manager *manager, const char *filename) {
         r = config_parse(NULL, filename, file,
                          "Match\0"
                          "Link\0"
-                         "DUID\0"
                          "Network\0"
                          "Address\0"
                          "Route\0"