diff options
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 43 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 55 |
2 files changed, 54 insertions, 44 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index 555446602..276ceca3c 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -1420,7 +1420,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1420 | retval = 1; | 1420 | retval = 1; |
1421 | goto ret; | 1421 | goto ret; |
1422 | } | 1422 | } |
1423 | /* wait before trying again */ | 1423 | /* Wait before trying again */ |
1424 | timeout = tryagain_timeout; | 1424 | timeout = tryagain_timeout; |
1425 | packet_num = 0; | 1425 | packet_num = 0; |
1426 | continue; | 1426 | continue; |
@@ -1442,14 +1442,14 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1442 | /* 1/2 lease passed, enter renewing state */ | 1442 | /* 1/2 lease passed, enter renewing state */ |
1443 | client_data.state = RENEWING; | 1443 | client_data.state = RENEWING; |
1444 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1444 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1445 | change_listen_mode(LISTEN_KERNEL); | 1445 | got_SIGUSR1: |
1446 | log1s("entering renew state"); | 1446 | log1s("entering renew state"); |
1447 | change_listen_mode(LISTEN_KERNEL); | ||
1447 | /* fall right through */ | 1448 | /* fall right through */ |
1448 | case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ | 1449 | case RENEW_REQUESTED: /* in manual (SIGUSR1) renew */ |
1449 | case_RENEW_REQUESTED: | ||
1450 | case RENEWING: | 1450 | case RENEWING: |
1451 | if (packet_num < 3) { | 1451 | if (packet_num == 0) { |
1452 | /* send an unicast renew request */ | 1452 | /* Send an unicast renew request */ |
1453 | /* Sometimes observed to fail (EADDRNOTAVAIL) to bind | 1453 | /* Sometimes observed to fail (EADDRNOTAVAIL) to bind |
1454 | * a new UDP socket for sending inside send_renew. | 1454 | * a new UDP socket for sending inside send_renew. |
1455 | * I hazard to guess existing listening socket | 1455 | * I hazard to guess existing listening socket |
@@ -1463,13 +1463,18 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1463 | else | 1463 | else |
1464 | send_d6_renew(xid, &srv6_buf, requested_ipv6); | 1464 | send_d6_renew(xid, &srv6_buf, requested_ipv6); |
1465 | timeout = discover_timeout; | 1465 | timeout = discover_timeout; |
1466 | /* ^^^ used to be = lease_remaining / 2 - WAY too long */ | ||
1467 | packet_num++; | 1466 | packet_num++; |
1468 | continue; | 1467 | continue; |
1468 | } /* else: we had sent one packet, but got no reply */ | ||
1469 | log1s("no response to renew"); | ||
1470 | if (lease_remaining > 30) { | ||
1471 | /* Some lease time remains, try to renew later */ | ||
1472 | change_listen_mode(LISTEN_NONE); | ||
1473 | goto BOUND_for_half_lease; | ||
1469 | } | 1474 | } |
1470 | /* Timed out, enter rebinding state */ | 1475 | /* Enter rebinding state */ |
1471 | log1s("entering rebinding state"); | ||
1472 | client_data.state = REBINDING; | 1476 | client_data.state = REBINDING; |
1477 | log1s("entering rebinding state"); | ||
1473 | /* Switch to bcast receive */ | 1478 | /* Switch to bcast receive */ |
1474 | change_listen_mode(LISTEN_RAW); | 1479 | change_listen_mode(LISTEN_RAW); |
1475 | packet_num = 0; | 1480 | packet_num = 0; |
@@ -1509,8 +1514,14 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1509 | /* Is it a signal? */ | 1514 | /* Is it a signal? */ |
1510 | switch (udhcp_sp_read()) { | 1515 | switch (udhcp_sp_read()) { |
1511 | case SIGUSR1: | 1516 | case SIGUSR1: |
1517 | if (client_data.state <= REQUESTING) | ||
1518 | /* Initial negotiations in progress, do not disturb */ | ||
1519 | break; | ||
1520 | |||
1521 | if (lease_remaining > 30) /* if renew fails, do not go back to BOUND */ | ||
1522 | lease_remaining = 30; | ||
1512 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1523 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1513 | bb_simple_info_msg("performing DHCP renew"); | 1524 | packet_num = 0; |
1514 | 1525 | ||
1515 | switch (client_data.state) { | 1526 | switch (client_data.state) { |
1516 | /* Try to renew/rebind */ | 1527 | /* Try to renew/rebind */ |
@@ -1519,21 +1530,19 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1519 | case REBINDING: | 1530 | case REBINDING: |
1520 | change_listen_mode(LISTEN_KERNEL); | 1531 | change_listen_mode(LISTEN_KERNEL); |
1521 | client_data.state = RENEW_REQUESTED; | 1532 | client_data.state = RENEW_REQUESTED; |
1522 | goto case_RENEW_REQUESTED; | 1533 | goto got_SIGUSR1; |
1523 | 1534 | ||
1524 | /* Start things over */ | 1535 | /* Two SIGUSR1 received, start things over */ |
1525 | case RENEW_REQUESTED: /* two or more SIGUSR1 received */ | 1536 | case RENEW_REQUESTED: |
1526 | change_listen_mode(LISTEN_NONE); | 1537 | change_listen_mode(LISTEN_NONE); |
1527 | d6_run_script_no_option("deconfig"); | 1538 | d6_run_script_no_option("deconfig"); |
1528 | 1539 | ||
1540 | /* Wake from SIGUSR2-induced deconfigured state */ | ||
1529 | default: | 1541 | default: |
1530 | /* case REQUESTING: */ | ||
1531 | /* case RELEASED: */ | 1542 | /* case RELEASED: */ |
1532 | /* case INIT_SELECTING: */ | ||
1533 | change_listen_mode(LISTEN_NONE); | 1543 | change_listen_mode(LISTEN_NONE); |
1534 | } | 1544 | } |
1535 | client_data.state = INIT_SELECTING; | 1545 | client_data.state = INIT_SELECTING; |
1536 | packet_num = 0; | ||
1537 | /* Kill any timeouts, user wants this to hurry along */ | 1546 | /* Kill any timeouts, user wants this to hurry along */ |
1538 | timeout = 0; | 1547 | timeout = 0; |
1539 | continue; | 1548 | continue; |
@@ -1830,7 +1839,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1830 | } | 1839 | } |
1831 | #endif | 1840 | #endif |
1832 | 1841 | ||
1833 | // BOUND_for_half_lease: | 1842 | BOUND_for_half_lease: |
1834 | timeout = (unsigned)lease_remaining / 2; | 1843 | timeout = (unsigned)lease_remaining / 2; |
1835 | client_data.state = BOUND; | 1844 | client_data.state = BOUND; |
1836 | packet_num = 0; | 1845 | packet_num = 0; |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index f441976dd..e0bddcdc9 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -1480,7 +1480,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1480 | retval = 1; | 1480 | retval = 1; |
1481 | goto ret; | 1481 | goto ret; |
1482 | } | 1482 | } |
1483 | /* wait before trying again */ | 1483 | /* Wait before trying again */ |
1484 | timeout = tryagain_timeout; | 1484 | timeout = tryagain_timeout; |
1485 | packet_num = 0; | 1485 | packet_num = 0; |
1486 | continue; | 1486 | continue; |
@@ -1502,14 +1502,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1502 | /* 1/2 lease passed, enter renewing state */ | 1502 | /* 1/2 lease passed, enter renewing state */ |
1503 | client_data.state = RENEWING; | 1503 | client_data.state = RENEWING; |
1504 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1504 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1505 | change_listen_mode(LISTEN_KERNEL); | 1505 | got_SIGUSR1: |
1506 | log1s("entering renew state"); | 1506 | log1s("entering renew state"); |
1507 | change_listen_mode(LISTEN_KERNEL); | ||
1507 | /* fall right through */ | 1508 | /* fall right through */ |
1508 | case RENEW_REQUESTED: /* manual (SIGUSR1) renew */ | 1509 | case RENEW_REQUESTED: /* in manual (SIGUSR1) renew */ |
1509 | case_RENEW_REQUESTED: | ||
1510 | case RENEWING: | 1510 | case RENEWING: |
1511 | if (packet_num < 3) { | 1511 | if (packet_num == 0) { |
1512 | /* send an unicast renew request */ | 1512 | /* Send an unicast renew request */ |
1513 | /* Sometimes observed to fail (EADDRNOTAVAIL) to bind | 1513 | /* Sometimes observed to fail (EADDRNOTAVAIL) to bind |
1514 | * a new UDP socket for sending inside send_renew. | 1514 | * a new UDP socket for sending inside send_renew. |
1515 | * I hazard to guess existing listening socket | 1515 | * I hazard to guess existing listening socket |
@@ -1520,7 +1520,6 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1520 | */ | 1520 | */ |
1521 | if (send_renew(xid, server_addr, requested_ip) >= 0) { | 1521 | if (send_renew(xid, server_addr, requested_ip) >= 0) { |
1522 | timeout = discover_timeout; | 1522 | timeout = discover_timeout; |
1523 | /* ^^^ used to be = lease_remaining / 2 - WAY too long */ | ||
1524 | packet_num++; | 1523 | packet_num++; |
1525 | continue; | 1524 | continue; |
1526 | } | 1525 | } |
@@ -1529,15 +1528,16 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1529 | * which gave us bogus server ID 1.1.1.1 | 1528 | * which gave us bogus server ID 1.1.1.1 |
1530 | * which wasn't reachable (and probably did not exist). | 1529 | * which wasn't reachable (and probably did not exist). |
1531 | */ | 1530 | */ |
1531 | } /* else: we had sent one packet, but got no reply */ | ||
1532 | log1s("no response to renew"); | ||
1533 | if (lease_remaining > 30) { | ||
1534 | /* Some lease time remains, try to renew later */ | ||
1535 | change_listen_mode(LISTEN_NONE); | ||
1536 | goto BOUND_for_half_lease; | ||
1532 | } | 1537 | } |
1533 | //TODO: if 3 renew's failed (no reply) but remaining lease is large enough, | 1538 | /* Enter rebinding state */ |
1534 | //it might make sense to go back to BOUND and try later? a-la | ||
1535 | // if (lease_remaining > 30) change_listen_mode(LISTEN_NONE) + goto BOUND_for_half_lease; | ||
1536 | //If we do that, "packet_num < 3" test below might be superfluous | ||
1537 | //(lease_remaining will run out anyway) | ||
1538 | /* Timed out or error, enter rebinding state */ | ||
1539 | log1s("entering rebinding state"); | ||
1540 | client_data.state = REBINDING; | 1539 | client_data.state = REBINDING; |
1540 | log1s("entering rebinding state"); | ||
1541 | /* Switch to bcast receive */ | 1541 | /* Switch to bcast receive */ |
1542 | change_listen_mode(LISTEN_RAW); | 1542 | change_listen_mode(LISTEN_RAW); |
1543 | packet_num = 0; | 1543 | packet_num = 0; |
@@ -1575,31 +1575,34 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1575 | /* Is it a signal? */ | 1575 | /* Is it a signal? */ |
1576 | switch (udhcp_sp_read()) { | 1576 | switch (udhcp_sp_read()) { |
1577 | case SIGUSR1: | 1577 | case SIGUSR1: |
1578 | if (client_data.state <= REQUESTING) | ||
1579 | /* Initial negotiations in progress, do not disturb */ | ||
1580 | break; | ||
1581 | |||
1582 | if (lease_remaining > 30) /* if renew fails, do not go back to BOUND */ | ||
1583 | lease_remaining = 30; | ||
1578 | client_data.first_secs = 0; /* make secs field count from 0 */ | 1584 | client_data.first_secs = 0; /* make secs field count from 0 */ |
1579 | bb_simple_info_msg("performing DHCP renew"); | 1585 | packet_num = 0; |
1580 | 1586 | ||
1581 | switch (client_data.state) { | 1587 | switch (client_data.state) { |
1582 | /* Try to renew/rebind */ | 1588 | /* Try to renew/rebind */ |
1583 | case BOUND: | 1589 | case BOUND: |
1584 | case RENEWING: | 1590 | case RENEWING: |
1585 | case REBINDING: | 1591 | case REBINDING: |
1586 | change_listen_mode(LISTEN_KERNEL); | ||
1587 | client_data.state = RENEW_REQUESTED; | 1592 | client_data.state = RENEW_REQUESTED; |
1588 | goto case_RENEW_REQUESTED; | 1593 | goto got_SIGUSR1; |
1589 | 1594 | ||
1590 | /* Start things over */ | 1595 | /* Two SIGUSR1 received, start things over */ |
1591 | case RENEW_REQUESTED: /* two or more SIGUSR1 received */ | 1596 | case RENEW_REQUESTED: |
1592 | change_listen_mode(LISTEN_NONE); | 1597 | change_listen_mode(LISTEN_NONE); |
1593 | udhcp_run_script(NULL, "deconfig"); | 1598 | udhcp_run_script(NULL, "deconfig"); |
1594 | 1599 | ||
1600 | /* Wake from SIGUSR2-induced deconfigured state */ | ||
1595 | default: | 1601 | default: |
1596 | /* case REQUESTING: */ | ||
1597 | /* case RELEASED: */ | 1602 | /* case RELEASED: */ |
1598 | /* case INIT_SELECTING: */ | ||
1599 | change_listen_mode(LISTEN_NONE); | 1603 | change_listen_mode(LISTEN_NONE); |
1600 | } | 1604 | } |
1601 | client_data.state = INIT_SELECTING; | 1605 | client_data.state = INIT_SELECTING; |
1602 | packet_num = 0; | ||
1603 | /* Kill any timeouts, user wants this to hurry along */ | 1606 | /* Kill any timeouts, user wants this to hurry along */ |
1604 | timeout = 0; | 1607 | timeout = 0; |
1605 | continue; | 1608 | continue; |
@@ -1723,10 +1726,9 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1723 | strcpy(server_str, inet_ntoa(temp_addr)); | 1726 | strcpy(server_str, inet_ntoa(temp_addr)); |
1724 | temp_addr.s_addr = packet.yiaddr; | 1727 | temp_addr.s_addr = packet.yiaddr; |
1725 | 1728 | ||
1729 | lease_remaining = 60 * 60; | ||
1726 | temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME); | 1730 | temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME); |
1727 | if (!temp) { | 1731 | if (temp) { |
1728 | lease_remaining = 60 * 60; | ||
1729 | } else { | ||
1730 | uint32_t lease; | 1732 | uint32_t lease; |
1731 | /* it IS unaligned sometimes, don't "optimize" */ | 1733 | /* it IS unaligned sometimes, don't "optimize" */ |
1732 | move_from_unaligned32(lease, temp); | 1734 | move_from_unaligned32(lease, temp); |
@@ -1798,8 +1800,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
1798 | opt = ((opt & ~OPT_b) | OPT_f); | 1800 | opt = ((opt & ~OPT_b) | OPT_f); |
1799 | } | 1801 | } |
1800 | #endif | 1802 | #endif |
1801 | 1803 | BOUND_for_half_lease: | |
1802 | // BOUND_for_half_lease: | ||
1803 | timeout = (unsigned)lease_remaining / 2; | 1804 | timeout = (unsigned)lease_remaining / 2; |
1804 | client_data.state = BOUND; | 1805 | client_data.state = BOUND; |
1805 | /* make future renew packets use different xid */ | 1806 | /* make future renew packets use different xid */ |