]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: DHCP6 client- Allow to send manual DUID
authorSusant Sahani <ssahani@gmail.com>
Tue, 15 Aug 2023 13:26:19 +0000 (18:56 +0530)
committerSusant Sahani <ssahani@gmail.com>
Thu, 17 Aug 2023 18:22:22 +0000 (23:52 +0530)
```
[DHCPv6]
DUIDType=custom
DUIDRawData=00:00:ab:11:f9:2a:c2:77:29:f9:5c:00
```

```
Client Identifier
    Option: Client Identifier (1)
    Length: 12
    DUID: 0000ab11f92ac27729f95c00
    DUID Type: Unknown (0)
```

man/networkd.conf.xml
src/libsystemd-network/dhcp-identifier.c
src/libsystemd-network/dhcp-identifier.h
src/libsystemd-network/sd-dhcp6-client.c
src/network/networkd-dhcp-common.c
src/network/networkd-dhcp6.c

index bf597cac2ecb0e70ccb5d792e95d07e5fd77bd9a..9fa925e85c87d7ff96260fcbabd918205f46b2ee 100644 (file)
             </para></listitem>
           </varlistentry>
 
+          <varlistentry>
+            <term><option>custom</option></term>
+            <listitem><para>If <literal>DUIDType=custom</literal>, then the <literal>DUIDRawData=</literal> value will
+            used be as custom identifier. If <literal>DUIDType=custom</literal> is specified then the
+            <literal>DUIDRawData=</literal> key is mandatory. Note it applies only on DHCPv6 clients.</para></listitem>
+          </varlistentry>
+
           <varlistentry>
             <term><option>uuid</option></term>
             <listitem><para>If <literal>DUIDType=uuid</literal>, and <varname>DUIDRawData=</varname> is not set,
index a27d67a315dfe685e8f45a7015d2adc234b19949..83fb6ce3408d4d79eeae58764f79cbf8302f1f17 100644 (file)
 #define USEC_2000       ((usec_t) 946684800000000) /* 2000-01-01 00:00:00 UTC */
 
 static const char * const duid_type_table[_DUID_TYPE_MAX] = {
-        [DUID_TYPE_LLT]  = "DUID-LLT",
-        [DUID_TYPE_EN]   = "DUID-EN/Vendor",
-        [DUID_TYPE_LL]   = "DUID-LL",
-        [DUID_TYPE_UUID] = "UUID",
+        [DUID_TYPE_LLT]    = "DUID-LLT",
+        [DUID_TYPE_EN]     = "DUID-EN/Vendor",
+        [DUID_TYPE_LL]     = "DUID-LL",
+        [DUID_TYPE_UUID]   = "UUID",
+        [DUID_TYPE_CUSTOM] = "Custom",
 };
 
 DEFINE_STRING_TABLE_LOOKUP_TO_STRING(duid_type, DUIDType);
index 523dfc4a71ba18df6f4cc7f0dbeaf932b3a35c07..1ac34761573ccdf8d6efd53a53fba588608cbda0 100644 (file)
@@ -17,6 +17,7 @@ typedef enum DUIDType {
         DUID_TYPE_EN        = 2,
         DUID_TYPE_LL        = 3,
         DUID_TYPE_UUID      = 4,
+        DUID_TYPE_CUSTOM    = 5,
         _DUID_TYPE_MAX,
         _DUID_TYPE_INVALID  = -EINVAL,
 } DUIDType;
index 2f4053caad01ed630478c367498ac706e28dbd03..e8d99718b301583eef66062be2bbccb35aa6b571 100644 (file)
@@ -212,10 +212,14 @@ static int dhcp6_client_set_duid_internal(
                         log_dhcp6_client(client, "Using DUID of type %i of incorrect length, proceeding.", duid_type);
                 }
 
-                client->duid.type = htobe16(duid_type);
-                memcpy(&client->duid.raw.data, duid, duid_len);
-                client->duid_len = sizeof(client->duid.type) + duid_len;
-
+                if (duid_type == DUID_TYPE_CUSTOM) {
+                        memcpy(&client->duid, duid, duid_len);
+                        client->duid_len = duid_len;
+                } else {
+                        client->duid.type = htobe16(duid_type);
+                        memcpy(&client->duid.raw.data, duid, duid_len);
+                        client->duid_len = sizeof(client->duid.type) + duid_len;
+                }
         } else {
                 r = dhcp_identifier_set_duid(duid_type, &client->hw_addr, client->arp_type, llt_time,
                                              client->test_mode, &client->duid, &client->duid_len);
index 5f9ef80e3e5b681ff9a2e7faa0dcbfcf1d8b4cef..baf80cb6442b19ce132077a0ae261333ce84bf62 100644 (file)
@@ -1106,10 +1106,11 @@ static const char * const dhcp_option_data_type_table[_DHCP_OPTION_DATA_MAX] = {
 DEFINE_STRING_TABLE_LOOKUP(dhcp_option_data_type, DHCPOptionDataType);
 
 static const char* const duid_type_table[_DUID_TYPE_MAX] = {
-        [DUID_TYPE_LLT]  = "link-layer-time",
-        [DUID_TYPE_EN]   = "vendor",
-        [DUID_TYPE_LL]   = "link-layer",
-        [DUID_TYPE_UUID] = "uuid",
+        [DUID_TYPE_LLT]    = "link-layer-time",
+        [DUID_TYPE_EN]     = "vendor",
+        [DUID_TYPE_LL]     = "link-layer",
+        [DUID_TYPE_UUID]   = "uuid",
+        [DUID_TYPE_CUSTOM] = "custom",
 };
 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(duid_type, DUIDType);
 
index 00c767e1fb8f8411a5bafbb62da16d6990d5d04a..e0f0850898872b239051c3e1c0c79e434ab6065d 100644 (file)
@@ -555,6 +555,11 @@ static int dhcp6_set_identifier(Link *link, sd_dhcp6_client *client) {
         }
 
         duid = link_get_dhcp6_duid(link);
+
+        if (duid->type == DUID_TYPE_CUSTOM && duid->raw_data_len == 0)
+                return log_link_debug_errno(link, SYNTHETIC_ERRNO(EINVAL),
+                                            "DHCPv6 CLIENT: Missing DUID Raw Data as duid type set to 'custom': %m");
+
         if (duid->type == DUID_TYPE_LLT && duid->raw_data_len == 0)
                 r = sd_dhcp6_client_set_duid_llt(client, duid->llt_time);
         else