udhcpc: code shrink, rename functions, no logic changes
function old new delta
d4_run_script - 739 +739
d4_recv_raw_packet - 484 +484
d4_run_script_deconfig - 12 +12
perform_release 207 200 -7
udhcpc_main 2598 2556 -42
udhcp_recv_raw_packet 484 - -484
udhcp_run_script 739 - -739
------------------------------------------------------------------------------
(add/remove: 3/2 grow/shrink: 0/2 up/down: 1235/-1272) Total: -37 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index e0bddcd..e55b606 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -566,8 +566,8 @@
}
}
-/* Call a script with a par file and env vars */
-static void udhcp_run_script(struct dhcp_packet *packet, const char *name)
+/* Call a script with env vars */
+static void d4_run_script(struct dhcp_packet *packet, const char *name)
{
char *argv[3];
@@ -585,6 +585,10 @@
client_data.envp = NULL;
}
+static void d4_run_script_deconfig(void)
+{
+ d4_run_script(NULL, "deconfig");
+}
/*** Sending/receiving packets ***/
@@ -882,7 +886,7 @@
/* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */
/* NOINLINE: limit stack usage in caller */
-static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
+static NOINLINE int d4_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
{
int bytes;
struct ip_udp_dhcp_packet packet;
@@ -1143,7 +1147,7 @@
* Users requested to be notified in all cases, even if not in one
* of the states above.
*/
- udhcp_run_script(NULL, "deconfig");
+ d4_run_script_deconfig();
client_data.state = RELEASED;
}
@@ -1374,7 +1378,7 @@
srand(monotonic_us());
client_data.state = INIT_SELECTING;
- udhcp_run_script(NULL, "deconfig");
+ d4_run_script_deconfig();
packet_num = 0;
timeout = 0;
lease_remaining = 0;
@@ -1460,7 +1464,7 @@
}
leasefail:
change_listen_mode(LISTEN_NONE);
- udhcp_run_script(NULL, "leasefail");
+ d4_run_script(NULL, "leasefail");
#if BB_MMU /* -b is not supported on NOMMU */
if (opt & OPT_b) { /* background if no lease */
bb_simple_info_msg("no lease, forking to background");
@@ -1555,7 +1559,7 @@
/* Timed out, enter init state */
change_listen_mode(LISTEN_NONE);
bb_simple_info_msg("lease lost, entering init state");
- udhcp_run_script(NULL, "deconfig");
+ d4_run_script_deconfig();
client_data.state = INIT_SELECTING;
client_data.first_secs = 0; /* make secs field count from 0 */
timeout = 0;
@@ -1595,7 +1599,7 @@
/* Two SIGUSR1 received, start things over */
case RENEW_REQUESTED:
change_listen_mode(LISTEN_NONE);
- udhcp_run_script(NULL, "deconfig");
+ d4_run_script_deconfig();
/* Wake from SIGUSR2-induced deconfigured state */
default:
@@ -1627,7 +1631,7 @@
if (client_data.listen_mode == LISTEN_KERNEL)
len = udhcp_recv_kernel_packet(&packet, client_data.sockfd);
else
- len = udhcp_recv_raw_packet(&packet, client_data.sockfd);
+ len = d4_recv_raw_packet(&packet, client_data.sockfd);
if (len == -1) {
/* Error is severe, reopen socket */
bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO);
@@ -1772,7 +1776,7 @@
send_decline(/*xid,*/ server_addr, packet.yiaddr);
if (client_data.state != REQUESTING)
- udhcp_run_script(NULL, "deconfig");
+ d4_run_script_deconfig();
client_data.state = INIT_SELECTING;
client_data.first_secs = 0; /* make secs field count from 0 */
requested_ip = 0;
@@ -1784,7 +1788,7 @@
#endif
/* enter bound state */
start = monotonic_sec();
- udhcp_run_script(&packet, client_data.state == REQUESTING ? "bound" : "renew");
+ d4_run_script(&packet, client_data.state == REQUESTING ? "bound" : "renew");
lease_remaining -= (unsigned)monotonic_sec() - start;
if (lease_remaining < 0)
lease_remaining = 0;
@@ -1831,9 +1835,9 @@
/* return to init state */
change_listen_mode(LISTEN_NONE);
bb_info_msg("received %s", "DHCP NAK");
- udhcp_run_script(&packet, "nak");
+ d4_run_script(&packet, "nak");
if (client_data.state != REQUESTING)
- udhcp_run_script(NULL, "deconfig");
+ 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 */