[git commit] udhcpc: code shrink by reusing "deconfig" code path
Denys Vlasenko
vda.linux at googlemail.com
Sun Oct 11 13:52:33 UTC 2026
commit: https://git.busybox.net/busybox/commit/?id=8d4ac0d17bbb09db91746b73ca6229b9edb531bf
branch: https://git.busybox.net/busybox/log/?h=master
function old new delta
udhcpc_main 2544 2501 -43
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
networking/udhcp/dhcpc.c | 34 +++++++++++++---------------------
1 file changed, 13 insertions(+), 21 deletions(-)
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 936687e13..2112edca8 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1363,11 +1363,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
/* We want random_xid to be random... */
srand(monotonic_us());
- client_data.state = INIT_SELECTING;
+ deconfig_and_set_INIT_SELECTING:
d4_run_script_deconfig();
+ set_INIT_SELECTING:
+ client_data.state = INIT_SELECTING;
packet_num = 0;
timeout = 0;
lease_remaining = 0;
+ client_data.first_secs = 0;
/* Main event loop. select() waits on signal pipe and possibly
* on sockfd.
@@ -1545,12 +1548,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
/* Timed out, enter init state */
change_listen_mode(LISTEN_NONE);
bb_simple_info_msg("lease lost, entering init state");
- d4_run_script_deconfig();
- client_data.state = INIT_SELECTING;
- client_data.first_secs = 0; /* make secs field count from 0 */
- timeout = 0;
- packet_num = 0;
- continue;
+ /* sets packet_num = timeout = lease_remaining = 0 */
+ /* also makes secs count from 0: client_data.first_secs = 0 */
+ goto deconfig_and_set_INIT_SELECTING;
/* case RELEASED: */
}
/* RELEASED state (when we got SIGUSR2) ends up here.
@@ -1763,15 +1763,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
"(got ARP reply), declining");
client_data.xid = random_xid(); //TODO: can omit?
send_decline(server_id, packet.yiaddr);
-
+ bad_ip_back_to_INIT_SELECTING:
if (client_data.state != REQUESTING)
d4_run_script_deconfig();
- client_data.state = INIT_SELECTING;
- client_data.first_secs = 0; /* make secs field count from 0 */
+ sleep(3); /* avoid excessive network traffic */
requested_ip = 0;
- timeout = tryagain_timeout;
- packet_num = 0;
- continue; /* back to main loop */
+ /* sets packet_num = timeout = lease_remaining = 0 */
+ /* also makes secs count from 0: client_data.first_secs = 0 */
+ goto set_INIT_SELECTING;
}
}
#endif
@@ -1819,14 +1818,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
change_listen_mode(LISTEN_NONE);
bb_info_msg("received %s", "DHCP NAK");
d4_run_script(&packet, "nak");
- if (client_data.state != REQUESTING)
- d4_run_script_deconfig();
- sleep(3); /* avoid excessive network traffic */
- client_data.state = INIT_SELECTING;
- client_data.first_secs = 0; /* make secs field count from 0 */
- requested_ip = 0;
- timeout = 0;
- packet_num = 0;
+ goto bad_ip_back_to_INIT_SELECTING;
}
continue;
/* case BOUND: - ignore all packets */
More information about the busybox-cvs
mailing list