]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-client: use event_reset_time_relative()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Mar 2025 01:59:53 +0000 (10:59 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Mar 2025 02:41:25 +0000 (11:41 +0900)
Fixes CID#1548073.

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

index 566da47638e2d7120361b970a0642c03c5ab5b37..9df4a3dd3fdfe7a7085e9a4661d4adbcf800f9eb 100644 (file)
@@ -740,10 +740,9 @@ static void client_stop(sd_dhcp_client *client, int error) {
  * for retransmission delays, timeout should start at 4s then double
  * each attempt with max of 64s, with -1 to +1 sec of random 'fuzz' added.
  * This assumes the first call will be using attempt 1. */
-static usec_t client_compute_request_timeout(usec_t now, uint64_t attempt) {
+static usec_t client_compute_request_timeout(uint64_t attempt) {
         usec_t timeout = (UINT64_C(1) << MIN(attempt + 1, UINT64_C(6))) * USEC_PER_SEC;
-
-        return usec_sub_signed(usec_add(now, timeout), RFC2131_RANDOM_FUZZ);
+        return usec_sub_signed(timeout, RFC2131_RANDOM_FUZZ);
 }
 
 /* RFC2131 section 4.4.5:
@@ -758,8 +757,8 @@ static usec_t client_compute_request_timeout(usec_t now, uint64_t attempt) {
  * of 60 seconds.
  * Note that while the default T1/T2 initial times do have random 'fuzz' applied,
  * the RFC sec 4.4.5 does not mention adding any fuzz to retries. */
-static usec_t client_compute_reacquisition_timeout(usec_t now, usec_t expire) {
-        return now + MAX(usec_sub_unsigned(expire, now) / 2, 60 * USEC_PER_SEC);
+static usec_t client_compute_reacquisition_timeout(usec_t now_usec, usec_t expire) {
+        return MAX(usec_sub_unsigned(expire, now_usec) / 2, 60 * USEC_PER_SEC);
 }
 
 static int cmp_uint8(const uint8_t *a, const uint8_t *b) {
@@ -1242,7 +1241,7 @@ static int client_timeout_resend(
                         goto error;
 
                 client->discover_attempt++;
-                next_timeout = client_compute_request_timeout(time_now, client->discover_attempt);
+                next_timeout = client_compute_request_timeout(client->discover_attempt);
                 break;
         case DHCP_STATE_REQUESTING:
         case DHCP_STATE_BOUND:
@@ -1250,7 +1249,7 @@ static int client_timeout_resend(
                         goto error;
 
                 client->request_attempt++;
-                next_timeout = client_compute_request_timeout(time_now, client->request_attempt);
+                next_timeout = client_compute_request_timeout(client->request_attempt);
                 break;
 
         case DHCP_STATE_STOPPED:
@@ -1261,11 +1260,11 @@ static int client_timeout_resend(
                 assert_not_reached();
         }
 
-        r = event_reset_time(client->event, &client->timeout_resend,
-                             CLOCK_BOOTTIME,
-                             next_timeout, 10 * USEC_PER_MSEC,
-                             client_timeout_resend, client,
-                             client->event_priority, "dhcp4-resend-timer", true);
+        r = event_reset_time_relative(
+                        client->event, &client->timeout_resend,
+                        CLOCK_BOOTTIME, next_timeout, 10 * USEC_PER_MSEC,
+                        client_timeout_resend, client,
+                        client->event_priority, "dhcp4-resend-timer", true);
         if (r < 0)
                 goto error;