diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-05-01 13:48:50 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-05-01 13:48:50 +0200 |
commit | e6007c4911c3ea26925f9473b9f156a692585f30 (patch) | |
tree | 427feda4336d414a9b862f015447b01b62556e63 | |
parent | a1a77ad5eae7384dd6b1ccaa436a1df48c3c9cd7 (diff) | |
download | busybox-w32-e6007c4911c3ea26925f9473b9f156a692585f30.tar.gz busybox-w32-e6007c4911c3ea26925f9473b9f156a692585f30.tar.bz2 busybox-w32-e6007c4911c3ea26925f9473b9f156a692585f30.zip |
udhcpc[6]: fold perform_renew() into its only caller
function old new delta
udhcpc_main 2550 2541 -9
udhcpc6_main 2576 2567 -9
change_listen_mode 321 299 -22
.rodata 103294 103225 -69
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-109) Total: -109 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 44 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 47 |
2 files changed, 37 insertions, 54 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 592f5b127..0a5cae310 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -1040,7 +1040,6 @@ static int d6_raw_socket(int ifindex) | |||
1040 | log2("opening raw socket on ifindex %d", ifindex); | 1040 | log2("opening raw socket on ifindex %d", ifindex); |
1041 | 1041 | ||
1042 | fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6)); | 1042 | fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6)); |
1043 | log3("got raw socket fd %d", fd); | ||
1044 | 1043 | ||
1045 | memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ | 1044 | memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ |
1046 | sock.sll_family = AF_PACKET; | 1045 | sock.sll_family = AF_PACKET; |
@@ -1087,29 +1086,6 @@ static void change_listen_mode(int new_mode) | |||
1087 | /* else LISTEN_NONE: client_data.sockfd stays closed */ | 1086 | /* else LISTEN_NONE: client_data.sockfd stays closed */ |
1088 | } | 1087 | } |
1089 | 1088 | ||
1090 | /* Called only on SIGUSR1 */ | ||
1091 | static void perform_renew(void) | ||
1092 | { | ||
1093 | bb_simple_info_msg("performing DHCP renew"); | ||
1094 | switch (client_data.state) { | ||
1095 | case BOUND: | ||
1096 | change_listen_mode(LISTEN_KERNEL); | ||
1097 | case RENEWING: | ||
1098 | case REBINDING: | ||
1099 | client_data.state = RENEW_REQUESTED; | ||
1100 | break; | ||
1101 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ | ||
1102 | d6_run_script_no_option("deconfig"); | ||
1103 | case REQUESTING: | ||
1104 | case RELEASED: | ||
1105 | change_listen_mode(LISTEN_RAW); | ||
1106 | client_data.state = INIT_SELECTING; | ||
1107 | break; | ||
1108 | case INIT_SELECTING: | ||
1109 | break; | ||
1110 | } | ||
1111 | } | ||
1112 | |||
1113 | static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6) | 1089 | static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6) |
1114 | { | 1090 | { |
1115 | /* send release packet */ | 1091 | /* send release packet */ |
@@ -1535,10 +1511,26 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1535 | switch (udhcp_sp_read()) { | 1511 | switch (udhcp_sp_read()) { |
1536 | case SIGUSR1: | 1512 | case SIGUSR1: |
1537 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1513 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1538 | perform_renew(); | 1514 | bb_simple_info_msg("performing DHCP renew"); |
1539 | if (client_data.state == RENEW_REQUESTED) | 1515 | |
1516 | switch (client_data.state) { | ||
1517 | /* Try to renew/rebind */ | ||
1518 | case BOUND: | ||
1519 | case RENEWING: | ||
1520 | case REBINDING: | ||
1521 | change_listen_mode(LISTEN_KERNEL); | ||
1522 | client_data.state = RENEW_REQUESTED; | ||
1540 | goto case_RENEW_REQUESTED; | 1523 | goto case_RENEW_REQUESTED; |
1524 | |||
1541 | /* Start things over */ | 1525 | /* Start things over */ |
1526 | case RENEW_REQUESTED: /* two or more SIGUSR1 received */ | ||
1527 | d6_run_script_no_option("deconfig"); | ||
1528 | /* case REQUESTING: break; */ | ||
1529 | /* case RELEASED: break; */ | ||
1530 | /* case INIT_SELECTING: break; */ | ||
1531 | } | ||
1532 | change_listen_mode(LISTEN_RAW); | ||
1533 | client_data.state = INIT_SELECTING; | ||
1542 | packet_num = 0; | 1534 | packet_num = 0; |
1543 | /* Kill any timeouts, user wants this to hurry along */ | 1535 | /* Kill any timeouts, user wants this to hurry along */ |
1544 | timeout = 0; | 1536 | timeout = 0; |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index a818c1875..6666cbce6 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -1027,7 +1027,6 @@ static int udhcp_raw_socket(int ifindex) | |||
1027 | * SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them) | 1027 | * SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them) |
1028 | * ETH_P_IP: want to receive only packets with IPv4 eth type | 1028 | * ETH_P_IP: want to receive only packets with IPv4 eth type |
1029 | */ | 1029 | */ |
1030 | log3("got raw socket fd %d", fd); | ||
1031 | 1030 | ||
1032 | memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ | 1031 | memset(&sock, 0, sizeof(sock)); /* let's be deterministic */ |
1033 | sock.sll_family = AF_PACKET; | 1032 | sock.sll_family = AF_PACKET; |
@@ -1122,29 +1121,6 @@ static void change_listen_mode(int new_mode) | |||
1122 | /* else LISTEN_NONE: client_data.sockfd stays closed */ | 1121 | /* else LISTEN_NONE: client_data.sockfd stays closed */ |
1123 | } | 1122 | } |
1124 | 1123 | ||
1125 | /* Called only on SIGUSR1 */ | ||
1126 | static void perform_renew(void) | ||
1127 | { | ||
1128 | bb_simple_info_msg("performing DHCP renew"); | ||
1129 | switch (client_data.state) { | ||
1130 | case BOUND: | ||
1131 | change_listen_mode(LISTEN_KERNEL); | ||
1132 | case RENEWING: | ||
1133 | case REBINDING: | ||
1134 | client_data.state = RENEW_REQUESTED; | ||
1135 | break; | ||
1136 | case RENEW_REQUESTED: /* impatient are we? fine, square 1 */ | ||
1137 | udhcp_run_script(NULL, "deconfig"); | ||
1138 | case REQUESTING: | ||
1139 | case RELEASED: | ||
1140 | change_listen_mode(LISTEN_RAW); | ||
1141 | client_data.state = INIT_SELECTING; | ||
1142 | break; | ||
1143 | case INIT_SELECTING: | ||
1144 | break; | ||
1145 | } | ||
1146 | } | ||
1147 | |||
1148 | static void perform_release(uint32_t server_addr, uint32_t requested_ip) | 1124 | static void perform_release(uint32_t server_addr, uint32_t requested_ip) |
1149 | { | 1125 | { |
1150 | char buffer[sizeof("255.255.255.255")]; | 1126 | char buffer[sizeof("255.255.255.255")]; |
@@ -1247,7 +1223,6 @@ static void client_background(void) | |||
1247 | //usage: "\n USR1 Renew lease" | 1223 | //usage: "\n USR1 Renew lease" |
1248 | //usage: "\n USR2 Release lease" | 1224 | //usage: "\n USR2 Release lease" |
1249 | 1225 | ||
1250 | |||
1251 | int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1226 | int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1252 | int udhcpc_main(int argc UNUSED_PARAM, char **argv) | 1227 | int udhcpc_main(int argc UNUSED_PARAM, char **argv) |
1253 | { | 1228 | { |
@@ -1597,10 +1572,26 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1597 | switch (udhcp_sp_read()) { | 1572 | switch (udhcp_sp_read()) { |
1598 | case SIGUSR1: | 1573 | case SIGUSR1: |
1599 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1574 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1600 | perform_renew(); | 1575 | bb_simple_info_msg("performing DHCP renew"); |
1601 | if (client_data.state == RENEW_REQUESTED) | 1576 | |
1577 | switch (client_data.state) { | ||
1578 | /* Try to renew/rebind */ | ||
1579 | case BOUND: | ||
1580 | case RENEWING: | ||
1581 | case REBINDING: | ||
1582 | change_listen_mode(LISTEN_KERNEL); | ||
1583 | client_data.state = RENEW_REQUESTED; | ||
1602 | goto case_RENEW_REQUESTED; | 1584 | goto case_RENEW_REQUESTED; |
1585 | |||
1603 | /* Start things over */ | 1586 | /* Start things over */ |
1587 | case RENEW_REQUESTED: /* two or more SIGUSR1 received */ | ||
1588 | udhcp_run_script(NULL, "deconfig"); | ||
1589 | /* case REQUESTING: break; */ | ||
1590 | /* case RELEASED: break; */ | ||
1591 | /* case INIT_SELECTING: break; */ | ||
1592 | } | ||
1593 | change_listen_mode(LISTEN_RAW); | ||
1594 | client_data.state = INIT_SELECTING; | ||
1604 | packet_num = 0; | 1595 | packet_num = 0; |
1605 | /* Kill any timeouts, user wants this to hurry along */ | 1596 | /* Kill any timeouts, user wants this to hurry along */ |
1606 | timeout = 0; | 1597 | timeout = 0; |
@@ -1737,7 +1728,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1737 | /* paranoia: must not be too small and not prone to overflows */ | 1728 | /* paranoia: must not be too small and not prone to overflows */ |
1738 | /* NB: 60s leases _are_ used in real world | 1729 | /* NB: 60s leases _are_ used in real world |
1739 | * (temporary IPs while ISP modem initializes) | 1730 | * (temporary IPs while ISP modem initializes) |
1740 | * do not break this case by bumplit it up. | 1731 | * do not break this case by bumping it up. |
1741 | */ | 1732 | */ |
1742 | if (lease_remaining < 0) /* signed overflow? */ | 1733 | if (lease_remaining < 0) /* signed overflow? */ |
1743 | lease_remaining = INT_MAX; | 1734 | lease_remaining = INT_MAX; |