dhcpv4: bail earlier on release/decline
authorDavid Härdeman <[email protected]>
Wed, 8 Oct 2025 14:21:22 +0000 (16:21 +0200)
committerÁlvaro Fernández Rojas <[email protected]>
Tue, 21 Oct 2025 17:05:54 +0000 (19:05 +0200)
And make it clearer that the return value from dhcpv4_lease isn't used.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/278
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/dhcpv4.c

index aa72bdcb89bd6f46c48fb739a90a4ba1582c6588..79c07f8ef5b42350069d2c7d3c6243e509e67937 100644 (file)
@@ -904,16 +904,22 @@ void dhcpv4_handle_msg(void *src_addr, void *data, size_t len,
                }
        }
 
+       info("Received %s from %s on %s", dhcpv4_msg_to_string(req_msg),
+            odhcpd_print_mac(req->chaddr, req->hlen), iface->name);
+
        switch (req_msg) {
        case DHCPV4_MSG_INFORM:
                break;
-       case DHCPV4_MSG_DISCOVER:
-               _fallthrough;
-       case DHCPV4_MSG_REQUEST:
-               _fallthrough;
        case DHCPV4_MSG_DECLINE:
                _fallthrough;
        case DHCPV4_MSG_RELEASE:
+               dhcpv4_lease(iface, req_msg, req->chaddr, req_addr,
+                            &req_leasetime, req_hostname, req_hostname_len,
+                            req_accept_fr, &incl_fr_opt, &fr_serverid);
+               return;
+       case DHCPV4_MSG_DISCOVER:
+               _fallthrough;
+       case DHCPV4_MSG_REQUEST:
                a = dhcpv4_lease(iface, req_msg, req->chaddr, req_addr,
                                 &req_leasetime, req_hostname, req_hostname_len,
                                 req_accept_fr, &incl_fr_opt, &fr_serverid);
@@ -922,9 +928,7 @@ void dhcpv4_handle_msg(void *src_addr, void *data, size_t len,
                return;
        }
 
-       info("Received %s from %s on %s", dhcpv4_msg_to_string(req_msg),
-            odhcpd_print_mac(req->chaddr, req->hlen), iface->name);
-
+       /* We are at the point where we know the client expects a reply */
        switch (req_msg) {
        case DHCPV4_MSG_DISCOVER:
                if (!a)
@@ -964,11 +968,6 @@ void dhcpv4_handle_msg(void *src_addr, void *data, size_t len,
                                req->ciaddr.s_addr = INADDR_ANY;
                }
                break;
-
-       case DHCPV4_MSG_RELEASE:
-               _fallthrough;
-       case DHCPV4_MSG_DECLINE:
-               return;
        }
 
        /* Note: each option might get called more than once */