Skip to content

Commit 54b9e72

Browse files
AlphixNoltari
authored andcommitted
dhcpv4: bail earlier on release/decline
And make it clearer that the return value from dhcpv4_lease isn't used. Signed-off-by: David Härdeman <david@hardeman.nu> Link: #278 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
1 parent 417f4b1 commit 54b9e72

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/dhcpv4.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -904,16 +904,22 @@ void dhcpv4_handle_msg(void *src_addr, void *data, size_t len,
904904
}
905905
}
906906

907+
info("Received %s from %s on %s", dhcpv4_msg_to_string(req_msg),
908+
odhcpd_print_mac(req->chaddr, req->hlen), iface->name);
909+
907910
switch (req_msg) {
908911
case DHCPV4_MSG_INFORM:
909912
break;
910-
case DHCPV4_MSG_DISCOVER:
911-
_fallthrough;
912-
case DHCPV4_MSG_REQUEST:
913-
_fallthrough;
914913
case DHCPV4_MSG_DECLINE:
915914
_fallthrough;
916915
case DHCPV4_MSG_RELEASE:
916+
dhcpv4_lease(iface, req_msg, req->chaddr, req_addr,
917+
&req_leasetime, req_hostname, req_hostname_len,
918+
req_accept_fr, &incl_fr_opt, &fr_serverid);
919+
return;
920+
case DHCPV4_MSG_DISCOVER:
921+
_fallthrough;
922+
case DHCPV4_MSG_REQUEST:
917923
a = dhcpv4_lease(iface, req_msg, req->chaddr, req_addr,
918924
&req_leasetime, req_hostname, req_hostname_len,
919925
req_accept_fr, &incl_fr_opt, &fr_serverid);
@@ -922,9 +928,7 @@ void dhcpv4_handle_msg(void *src_addr, void *data, size_t len,
922928
return;
923929
}
924930

925-
info("Received %s from %s on %s", dhcpv4_msg_to_string(req_msg),
926-
odhcpd_print_mac(req->chaddr, req->hlen), iface->name);
927-
931+
/* We are at the point where we know the client expects a reply */
928932
switch (req_msg) {
929933
case DHCPV4_MSG_DISCOVER:
930934
if (!a)
@@ -964,11 +968,6 @@ void dhcpv4_handle_msg(void *src_addr, void *data, size_t len,
964968
req->ciaddr.s_addr = INADDR_ANY;
965969
}
966970
break;
967-
968-
case DHCPV4_MSG_RELEASE:
969-
_fallthrough;
970-
case DHCPV4_MSG_DECLINE:
971-
return;
972971
}
973972

974973
/* Note: each option might get called more than once */

0 commit comments

Comments
 (0)