]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp-client: replace max_request_attempts with constant macro
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 13 Mar 2026 21:34:19 +0000 (06:34 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 23 Apr 2026 22:40:07 +0000 (07:40 +0900)
src/libsystemd-network/dhcp-client-internal.h
src/libsystemd-network/sd-dhcp-client.c

index b59f0e632ddb6f23ce17928fb5b514d67337e6f7..e08ea3deda0ff819207402d0c801c9b3215bc2cf 100644 (file)
@@ -65,7 +65,6 @@ struct sd_dhcp_client {
         uint64_t discover_attempt;
         uint64_t request_attempt;
         uint64_t max_discover_attempts;
-        uint64_t max_request_attempts;
         OrderedHashmap *extra_options;
         OrderedHashmap *vendor_options;
         sd_event_source *timeout_t1;
index 720f23cba8ce960ad82707d8822af11fdf8ca135..7cfebcb5963d3dd79fa0a09dc3a45e5dfbf68f4c 100644 (file)
@@ -35,6 +35,7 @@
 #define RESTART_AFTER_NAK_MIN_USEC (1 * USEC_PER_SEC)
 #define RESTART_AFTER_NAK_MAX_USEC (30 * USEC_PER_MINUTE)
 
+#define MAX_REQUEST_ATTEMPTS 5
 #define TRANSIENT_FAILURE_ATTEMPTS 3 /* Arbitrary limit: how many attempts are considered enough to report
                                       * transient failure. */
 
@@ -1222,7 +1223,7 @@ static int client_timeout_resend(
                 break;
         case DHCP_STATE_REQUESTING:
         case DHCP_STATE_BOUND:
-                if (client->request_attempt >= client->max_request_attempts)
+                if (client->request_attempt >= MAX_REQUEST_ATTEMPTS)
                         goto error;
 
                 client->request_attempt++;
@@ -1266,7 +1267,7 @@ static int client_timeout_resend(
         case DHCP_STATE_RENEWING:
         case DHCP_STATE_REBINDING:
                 r = client_send_request(client);
-                if (r < 0 && client->request_attempt >= client->max_request_attempts)
+                if (r < 0 && client->request_attempt >= MAX_REQUEST_ATTEMPTS)
                          goto error;
 
                 if (client->state == DHCP_STATE_INIT_REBOOT)
@@ -1292,7 +1293,7 @@ error:
         /* Avoid REQUEST infinite loop. Per RFC 2131 section 3.1.5: if the client receives
            neither a DHCPACK or a DHCPNAK message after employing the retransmission algorithm,
            the client reverts to INIT state and restarts the initialization process */
-        if (client->request_attempt >= client->max_request_attempts) {
+        if (client->request_attempt >= MAX_REQUEST_ATTEMPTS) {
                 log_dhcp_client(client, "Max REQUEST attempts reached. Restarting...");
                 r = client_restart(client);
                 if (r >= 0)
@@ -2394,7 +2395,6 @@ int sd_dhcp_client_new(sd_dhcp_client **ret, int anonymize) {
                 .server_port = DHCP_PORT_SERVER,
                 .anonymize = !!anonymize,
                 .max_discover_attempts = UINT64_MAX,
-                .max_request_attempts = 5,
                 .ip_service_type = -1,
         };
         /* NOTE: this could be moved to a function. */