diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-11-07 00:54:27 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-11-07 00:54:27 +0100 |
commit | 0fd4347cedd1d32341e827c04dd36aaaf2e8040d (patch) | |
tree | cfa6535363f0b28d2cd7f4bcd90688132e4b68cc /networking/udhcp/dhcpc.c | |
parent | 3b46fcb95d1276c538f4c84b63eec33cc27ac760 (diff) | |
download | busybox-w32-0fd4347cedd1d32341e827c04dd36aaaf2e8040d.tar.gz busybox-w32-0fd4347cedd1d32341e827c04dd36aaaf2e8040d.tar.bz2 busybox-w32-0fd4347cedd1d32341e827c04dd36aaaf2e8040d.zip |
udhcpc: code shrink
function old new delta
udhcpc_main 2646 2649 +3
udhcp_run_script 816 802 -14
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r-- | networking/udhcp/dhcpc.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index ea798a3f4..f202ecf74 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -499,9 +499,6 @@ static void udhcp_run_script(struct dhcp_packet *packet, const char *name) | |||
499 | char **envp, **curr; | 499 | char **envp, **curr; |
500 | char *argv[3]; | 500 | char *argv[3]; |
501 | 501 | ||
502 | if (client_config.script == NULL) | ||
503 | return; | ||
504 | |||
505 | envp = fill_envp(packet); | 502 | envp = fill_envp(packet); |
506 | 503 | ||
507 | /* call script */ | 504 | /* call script */ |
@@ -1009,7 +1006,7 @@ static void perform_renew(void) | |||
1009 | } | 1006 | } |
1010 | } | 1007 | } |
1011 | 1008 | ||
1012 | static void perform_release(uint32_t requested_ip, uint32_t server_addr) | 1009 | static void perform_release(uint32_t server_addr, uint32_t requested_ip) |
1013 | { | 1010 | { |
1014 | char buffer[sizeof("255.255.255.255")]; | 1011 | char buffer[sizeof("255.255.255.255")]; |
1015 | struct in_addr temp_addr; | 1012 | struct in_addr temp_addr; |
@@ -1154,15 +1151,12 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1154 | uint32_t server_addr = server_addr; /* for compiler */ | 1151 | uint32_t server_addr = server_addr; /* for compiler */ |
1155 | uint32_t requested_ip = 0; | 1152 | uint32_t requested_ip = 0; |
1156 | uint32_t xid = 0; | 1153 | uint32_t xid = 0; |
1157 | uint32_t lease_seconds = 0; /* can be given as 32-bit quantity */ | ||
1158 | int packet_num; | 1154 | int packet_num; |
1159 | int timeout; /* must be signed */ | 1155 | int timeout; /* must be signed */ |
1160 | unsigned already_waited_sec; | 1156 | unsigned already_waited_sec; |
1161 | unsigned opt; | 1157 | unsigned opt; |
1162 | int max_fd; | 1158 | int max_fd; |
1163 | int retval; | 1159 | int retval; |
1164 | struct timeval tv; | ||
1165 | struct dhcp_packet packet; | ||
1166 | fd_set rfds; | 1160 | fd_set rfds; |
1167 | 1161 | ||
1168 | /* Default options */ | 1162 | /* Default options */ |
@@ -1302,6 +1296,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1302 | * "continue" statements in code below jump to the top of the loop. | 1296 | * "continue" statements in code below jump to the top of the loop. |
1303 | */ | 1297 | */ |
1304 | for (;;) { | 1298 | for (;;) { |
1299 | struct timeval tv; | ||
1300 | struct dhcp_packet packet; | ||
1305 | /* silence "uninitialized!" warning */ | 1301 | /* silence "uninitialized!" warning */ |
1306 | unsigned timestamp_before_wait = timestamp_before_wait; | 1302 | unsigned timestamp_before_wait = timestamp_before_wait; |
1307 | 1303 | ||
@@ -1349,7 +1345,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1349 | NULL, | 1345 | NULL, |
1350 | client_config.client_mac) | 1346 | client_config.client_mac) |
1351 | ) { | 1347 | ) { |
1352 | return 1; /* iface is gone? */ | 1348 | goto ret0; /* iface is gone? */ |
1353 | } | 1349 | } |
1354 | if (clientid_mac_ptr) | 1350 | if (clientid_mac_ptr) |
1355 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); | 1351 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); |
@@ -1486,13 +1482,11 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1486 | timeout = 0; | 1482 | timeout = 0; |
1487 | continue; | 1483 | continue; |
1488 | case SIGUSR2: | 1484 | case SIGUSR2: |
1489 | perform_release(requested_ip, server_addr); | 1485 | perform_release(server_addr, requested_ip); |
1490 | timeout = INT_MAX; | 1486 | timeout = INT_MAX; |
1491 | continue; | 1487 | continue; |
1492 | case SIGTERM: | 1488 | case SIGTERM: |
1493 | bb_info_msg("Received SIGTERM"); | 1489 | bb_info_msg("Received SIGTERM"); |
1494 | if (opt & OPT_R) /* release on quit */ | ||
1495 | perform_release(requested_ip, server_addr); | ||
1496 | goto ret0; | 1490 | goto ret0; |
1497 | } | 1491 | } |
1498 | 1492 | ||
@@ -1589,6 +1583,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1589 | case RENEW_REQUESTED: | 1583 | case RENEW_REQUESTED: |
1590 | case REBINDING: | 1584 | case REBINDING: |
1591 | if (*message == DHCPACK) { | 1585 | if (*message == DHCPACK) { |
1586 | uint32_t lease_seconds; | ||
1587 | struct in_addr temp_addr; | ||
1588 | |||
1592 | temp = udhcp_get_option(&packet, DHCP_LEASE_TIME); | 1589 | temp = udhcp_get_option(&packet, DHCP_LEASE_TIME); |
1593 | if (!temp) { | 1590 | if (!temp) { |
1594 | bb_error_msg("no lease time with ACK, using 1 hour lease"); | 1591 | bb_error_msg("no lease time with ACK, using 1 hour lease"); |
@@ -1597,9 +1594,11 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1597 | /* it IS unaligned sometimes, don't "optimize" */ | 1594 | /* it IS unaligned sometimes, don't "optimize" */ |
1598 | move_from_unaligned32(lease_seconds, temp); | 1595 | move_from_unaligned32(lease_seconds, temp); |
1599 | lease_seconds = ntohl(lease_seconds); | 1596 | lease_seconds = ntohl(lease_seconds); |
1600 | lease_seconds &= 0x0fffffff; /* paranoia: must not be prone to overflows */ | 1597 | /* paranoia: must not be too small and not prone to overflows */ |
1601 | if (lease_seconds < 10) /* and not too small */ | 1598 | if (lease_seconds < 0x10) |
1602 | lease_seconds = 10; | 1599 | lease_seconds = 0x10; |
1600 | if (lease_seconds >= 0x10000000) | ||
1601 | lease_seconds = 0x0fffffff; | ||
1603 | } | 1602 | } |
1604 | #if ENABLE_FEATURE_UDHCPC_ARPING | 1603 | #if ENABLE_FEATURE_UDHCPC_ARPING |
1605 | if (opt & OPT_a) { | 1604 | if (opt & OPT_a) { |
@@ -1637,20 +1636,15 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1637 | #endif | 1636 | #endif |
1638 | /* enter bound state */ | 1637 | /* enter bound state */ |
1639 | timeout = lease_seconds / 2; | 1638 | timeout = lease_seconds / 2; |
1640 | { | 1639 | temp_addr.s_addr = packet.yiaddr; |
1641 | struct in_addr temp_addr; | 1640 | bb_info_msg("Lease of %s obtained, lease time %u", |
1642 | temp_addr.s_addr = packet.yiaddr; | 1641 | inet_ntoa(temp_addr), (unsigned)lease_seconds); |
1643 | bb_info_msg("Lease of %s obtained, lease time %u", | ||
1644 | inet_ntoa(temp_addr), (unsigned)lease_seconds); | ||
1645 | } | ||
1646 | requested_ip = packet.yiaddr; | 1642 | requested_ip = packet.yiaddr; |
1647 | udhcp_run_script(&packet, state == REQUESTING ? "bound" : "renew"); | 1643 | udhcp_run_script(&packet, state == REQUESTING ? "bound" : "renew"); |
1648 | 1644 | ||
1649 | state = BOUND; | 1645 | state = BOUND; |
1650 | change_listen_mode(LISTEN_NONE); | 1646 | change_listen_mode(LISTEN_NONE); |
1651 | if (opt & OPT_q) { /* quit after lease */ | 1647 | if (opt & OPT_q) { /* quit after lease */ |
1652 | if (opt & OPT_R) /* release on quit */ | ||
1653 | perform_release(requested_ip, server_addr); | ||
1654 | goto ret0; | 1648 | goto ret0; |
1655 | } | 1649 | } |
1656 | /* future renew failures should not exit (JM) */ | 1650 | /* future renew failures should not exit (JM) */ |
@@ -1688,6 +1682,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1688 | } /* for (;;) - main loop ends */ | 1682 | } /* for (;;) - main loop ends */ |
1689 | 1683 | ||
1690 | ret0: | 1684 | ret0: |
1685 | if (opt & OPT_R) /* release on quit */ | ||
1686 | perform_release(server_addr, requested_ip); | ||
1691 | retval = 0; | 1687 | retval = 0; |
1692 | ret: | 1688 | ret: |
1693 | /*if (client_config.pidfile) - remove_pidfile has its own check */ | 1689 | /*if (client_config.pidfile) - remove_pidfile has its own check */ |