]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-client: simply enter renewing/rebinding state send DHCPREQUEST on T1/T2
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 Mar 2026 16:26:45 +0000 (01:26 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Apr 2026 22:40:07 +0000 (07:40 +0900)
It is not necessary to enable another timer event source to send
DHCPREQUEST from the T1/T2 timer event source. Just call the callback
function for sending message.

Also, T1 hits only we have a bound lease. Drop spurious conditions.

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

index f301018d4f7a261d781e676d7f9a7649e861a3a2..7a08861eb819003b919cb427d8efbc45df2a6bd1 100644 (file)
@@ -1353,38 +1353,28 @@ static int client_timeout_expire(sd_event_source *s, uint64_t usec, void *userda
 static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata) {
         sd_dhcp_client *client = ASSERT_PTR(userdata);
         DHCP_CLIENT_DONT_DESTROY(client);
-        int r;
 
+        /* Explicitly close the unicast socket opened during renewing. On success path, the socket will be
+         * closed anyway on sending broadcast DHCPREQUEST, but let's explicitly close it here for failure
+         * path to ignore all unicast replies from now on. */
         client->receive_message = sd_event_source_disable_unref(client->receive_message);
 
         client_set_state(client, DHCP_STATE_REBINDING);
         client->discover_attempt = 0;
         client->request_attempt = 0;
 
-        r = client_initialize_time_events(client);
-        if (r < 0)
-                client_stop(client, r);
-
-        return 0;
+        return client_timeout_resend(s, usec, userdata);
 }
 
 static int client_timeout_t1(sd_event_source *s, uint64_t usec, void *userdata) {
         sd_dhcp_client *client = ASSERT_PTR(userdata);
         DHCP_CLIENT_DONT_DESTROY(client);
-        int r;
 
-        if (client->lease)
-                client_set_state(client, DHCP_STATE_RENEWING);
-        else if (client->state != DHCP_STATE_INIT)
-                client_set_state(client, DHCP_STATE_INIT_REBOOT);
+        client_set_state(client, DHCP_STATE_RENEWING);
         client->discover_attempt = 0;
         client->request_attempt = 0;
 
-        r = client_initialize_time_events(client);
-        if (r < 0)
-                client_stop(client, r);
-
-        return 0;
+        return client_timeout_resend(s, usec, userdata);
 }
 
 static int dhcp_option_parse_and_verify(