]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-client: ensure IAID and DUID being set on start
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 30 Aug 2023 08:33:01 +0000 (17:33 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 30 Aug 2023 08:37:03 +0000 (17:37 +0900)
After b2851e8d6287ab9bb3cd6e42395271c45ce0e377, if IAID and DUID are not
set on start, calling sd_dhcp_client_set_iaid_duid_en() in
client_message_init() triggers assertion, as the client is already
running at the stage. Let's set IAID and DUID earlier.

Fixes #28990.

src/libsystemd-network/sd-dhcp-client.c

index 265750d090419b229238d812a1644e3f90268d30..21b6592037405bb0a2195d5e7c8ceb068d1ab9a1 100644 (file)
@@ -870,13 +870,6 @@ static int client_message_init(
         if (client->request_broadcast || client->arp_type != ARPHRD_ETHER)
                 packet->dhcp.flags = htobe16(0x8000);
 
-        /* If no client identifier exists, construct an RFC 4361-compliant one */
-        if (client->client_id_len == 0) {
-                r = sd_dhcp_client_set_iaid_duid_en(client, /* iaid_set = */ false, /* iaid = */ 0);
-                if (r < 0)
-                        return r;
-        }
-
         /* Some DHCP servers will refuse to issue an DHCP lease if the Client
            Identifier option is not set */
         r = dhcp_option_append(&packet->dhcp, optlen, &optoffset, 0,
@@ -2075,6 +2068,13 @@ int sd_dhcp_client_start(sd_dhcp_client *client) {
         if (r < 0)
                 return r;
 
+        /* If no client identifier exists, construct an RFC 4361-compliant one */
+        if (client->client_id_len == 0) {
+                r = sd_dhcp_client_set_iaid_duid_en(client, /* iaid_set = */ false, /* iaid = */ 0);
+                if (r < 0)
+                        return r;
+        }
+
         /* RFC7844 section 3.3:
            SHOULD perform a complete four-way handshake, starting with a
            DHCPDISCOVER, to obtain a new address lease.  If the client can