aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/udhcp/d6_dhcpc.c4
-rw-r--r--networking/udhcp/dhcpc.c30
2 files changed, 19 insertions, 15 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 276ceca3c..1a58f5f44 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -441,7 +441,7 @@ static char **fill_envp(const uint8_t *option, const uint8_t *option_end)
441 return envp; 441 return envp;
442} 442}
443 443
444/* Call a script with a par file and env vars */ 444/* Call a script with env vars */
445static void d6_run_script(const uint8_t *option, const uint8_t *option_end, 445static void d6_run_script(const uint8_t *option, const uint8_t *option_end,
446 const char *name) 446 const char *name)
447{ 447{
@@ -464,7 +464,7 @@ static void d6_run_script(const uint8_t *option, const uint8_t *option_end,
464 free(envp); 464 free(envp);
465} 465}
466 466
467/* Call a script with a par file and no env var */ 467/* Call a script with no env var */
468static void d6_run_script_no_option(const char *name) 468static void d6_run_script_no_option(const char *name)
469{ 469{
470 d6_run_script(NULL, NULL, name); 470 d6_run_script(NULL, NULL, name);
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index e0bddcdc9..e55b606cd 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -566,8 +566,8 @@ static void fill_envp(struct dhcp_packet *packet)
566 } 566 }
567} 567}
568 568
569/* Call a script with a par file and env vars */ 569/* Call a script with env vars */
570static void udhcp_run_script(struct dhcp_packet *packet, const char *name) 570static void d4_run_script(struct dhcp_packet *packet, const char *name)
571{ 571{
572 char *argv[3]; 572 char *argv[3];
573 573
@@ -585,6 +585,10 @@ static void udhcp_run_script(struct dhcp_packet *packet, const char *name)
585 client_data.envp = NULL; 585 client_data.envp = NULL;
586} 586}
587 587
588static void d4_run_script_deconfig(void)
589{
590 d4_run_script(NULL, "deconfig");
591}
588 592
589/*** Sending/receiving packets ***/ 593/*** Sending/receiving packets ***/
590 594
@@ -882,7 +886,7 @@ int send_release(uint32_t server, uint32_t ciaddr)
882 886
883/* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */ 887/* Returns -1 on errors that are fatal for the socket, -2 for those that aren't */
884/* NOINLINE: limit stack usage in caller */ 888/* NOINLINE: limit stack usage in caller */
885static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd) 889static NOINLINE int d4_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
886{ 890{
887 int bytes; 891 int bytes;
888 struct ip_udp_dhcp_packet packet; 892 struct ip_udp_dhcp_packet packet;
@@ -1143,7 +1147,7 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip)
1143 * Users requested to be notified in all cases, even if not in one 1147 * Users requested to be notified in all cases, even if not in one
1144 * of the states above. 1148 * of the states above.
1145 */ 1149 */
1146 udhcp_run_script(NULL, "deconfig"); 1150 d4_run_script_deconfig();
1147 client_data.state = RELEASED; 1151 client_data.state = RELEASED;
1148} 1152}
1149 1153
@@ -1374,7 +1378,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1374 srand(monotonic_us()); 1378 srand(monotonic_us());
1375 1379
1376 client_data.state = INIT_SELECTING; 1380 client_data.state = INIT_SELECTING;
1377 udhcp_run_script(NULL, "deconfig"); 1381 d4_run_script_deconfig();
1378 packet_num = 0; 1382 packet_num = 0;
1379 timeout = 0; 1383 timeout = 0;
1380 lease_remaining = 0; 1384 lease_remaining = 0;
@@ -1460,7 +1464,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1460 } 1464 }
1461 leasefail: 1465 leasefail:
1462 change_listen_mode(LISTEN_NONE); 1466 change_listen_mode(LISTEN_NONE);
1463 udhcp_run_script(NULL, "leasefail"); 1467 d4_run_script(NULL, "leasefail");
1464#if BB_MMU /* -b is not supported on NOMMU */ 1468#if BB_MMU /* -b is not supported on NOMMU */
1465 if (opt & OPT_b) { /* background if no lease */ 1469 if (opt & OPT_b) { /* background if no lease */
1466 bb_simple_info_msg("no lease, forking to background"); 1470 bb_simple_info_msg("no lease, forking to background");
@@ -1555,7 +1559,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1555 /* Timed out, enter init state */ 1559 /* Timed out, enter init state */
1556 change_listen_mode(LISTEN_NONE); 1560 change_listen_mode(LISTEN_NONE);
1557 bb_simple_info_msg("lease lost, entering init state"); 1561 bb_simple_info_msg("lease lost, entering init state");
1558 udhcp_run_script(NULL, "deconfig"); 1562 d4_run_script_deconfig();
1559 client_data.state = INIT_SELECTING; 1563 client_data.state = INIT_SELECTING;
1560 client_data.first_secs = 0; /* make secs field count from 0 */ 1564 client_data.first_secs = 0; /* make secs field count from 0 */
1561 timeout = 0; 1565 timeout = 0;
@@ -1595,7 +1599,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1595 /* Two SIGUSR1 received, start things over */ 1599 /* Two SIGUSR1 received, start things over */
1596 case RENEW_REQUESTED: 1600 case RENEW_REQUESTED:
1597 change_listen_mode(LISTEN_NONE); 1601 change_listen_mode(LISTEN_NONE);
1598 udhcp_run_script(NULL, "deconfig"); 1602 d4_run_script_deconfig();
1599 1603
1600 /* Wake from SIGUSR2-induced deconfigured state */ 1604 /* Wake from SIGUSR2-induced deconfigured state */
1601 default: 1605 default:
@@ -1627,7 +1631,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1627 if (client_data.listen_mode == LISTEN_KERNEL) 1631 if (client_data.listen_mode == LISTEN_KERNEL)
1628 len = udhcp_recv_kernel_packet(&packet, client_data.sockfd); 1632 len = udhcp_recv_kernel_packet(&packet, client_data.sockfd);
1629 else 1633 else
1630 len = udhcp_recv_raw_packet(&packet, client_data.sockfd); 1634 len = d4_recv_raw_packet(&packet, client_data.sockfd);
1631 if (len == -1) { 1635 if (len == -1) {
1632 /* Error is severe, reopen socket */ 1636 /* Error is severe, reopen socket */
1633 bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO); 1637 bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO);
@@ -1772,7 +1776,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1772 send_decline(/*xid,*/ server_addr, packet.yiaddr); 1776 send_decline(/*xid,*/ server_addr, packet.yiaddr);
1773 1777
1774 if (client_data.state != REQUESTING) 1778 if (client_data.state != REQUESTING)
1775 udhcp_run_script(NULL, "deconfig"); 1779 d4_run_script_deconfig();
1776 client_data.state = INIT_SELECTING; 1780 client_data.state = INIT_SELECTING;
1777 client_data.first_secs = 0; /* make secs field count from 0 */ 1781 client_data.first_secs = 0; /* make secs field count from 0 */
1778 requested_ip = 0; 1782 requested_ip = 0;
@@ -1784,7 +1788,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1784#endif 1788#endif
1785 /* enter bound state */ 1789 /* enter bound state */
1786 start = monotonic_sec(); 1790 start = monotonic_sec();
1787 udhcp_run_script(&packet, client_data.state == REQUESTING ? "bound" : "renew"); 1791 d4_run_script(&packet, client_data.state == REQUESTING ? "bound" : "renew");
1788 lease_remaining -= (unsigned)monotonic_sec() - start; 1792 lease_remaining -= (unsigned)monotonic_sec() - start;
1789 if (lease_remaining < 0) 1793 if (lease_remaining < 0)
1790 lease_remaining = 0; 1794 lease_remaining = 0;
@@ -1831,9 +1835,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1831 /* return to init state */ 1835 /* return to init state */
1832 change_listen_mode(LISTEN_NONE); 1836 change_listen_mode(LISTEN_NONE);
1833 bb_info_msg("received %s", "DHCP NAK"); 1837 bb_info_msg("received %s", "DHCP NAK");
1834 udhcp_run_script(&packet, "nak"); 1838 d4_run_script(&packet, "nak");
1835 if (client_data.state != REQUESTING) 1839 if (client_data.state != REQUESTING)
1836 udhcp_run_script(NULL, "deconfig"); 1840 d4_run_script_deconfig();
1837 sleep(3); /* avoid excessive network traffic */ 1841 sleep(3); /* avoid excessive network traffic */
1838 client_data.state = INIT_SELECTING; 1842 client_data.state = INIT_SELECTING;
1839 client_data.first_secs = 0; /* make secs field count from 0 */ 1843 client_data.first_secs = 0; /* make secs field count from 0 */