diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-15 01:15:44 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-15 01:15:44 +0200 |
| commit | 9e27fed6b9a21454149873cfc4e034c8226f8ffb (patch) | |
| tree | 65b2833c8e33b7beb2465a0334b52ada7b103a9a | |
| parent | 827b690fa7b9dd006f305449c342fb1b9bff6fb7 (diff) | |
| download | busybox-w32-9e27fed6b9a21454149873cfc4e034c8226f8ffb.tar.gz busybox-w32-9e27fed6b9a21454149873cfc4e034c8226f8ffb.tar.bz2 busybox-w32-9e27fed6b9a21454149873cfc4e034c8226f8ffb.zip | |
udhcpc: rename server_addr to server_id, fix id comparison if it's not specified
Even though it is _meant to be_ an IP address, in the wild servers sometimes
give bogus server ids, like 1.1.1.1
function old new delta
udhcpc_main 2551 2542 -9
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | networking/udhcp/dhcpc.c | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 1c3c478ac..d67f60c00 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
| @@ -1113,7 +1113,7 @@ static void change_listen_mode(int new_mode) | |||
| 1113 | /* else LISTEN_NONE: client_data.sockfd stays closed */ | 1113 | /* else LISTEN_NONE: client_data.sockfd stays closed */ |
| 1114 | } | 1114 | } |
| 1115 | 1115 | ||
| 1116 | static void perform_release(uint32_t server_addr, uint32_t requested_ip) | 1116 | static void perform_release(uint32_t server_id, uint32_t requested_ip) |
| 1117 | { | 1117 | { |
| 1118 | char buffer[sizeof("255.255.255.255")]; | 1118 | char buffer[sizeof("255.255.255.255")]; |
| 1119 | struct in_addr temp_addr; | 1119 | struct in_addr temp_addr; |
| @@ -1126,13 +1126,13 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip) | |||
| 1126 | || client_data.state == REBINDING | 1126 | || client_data.state == REBINDING |
| 1127 | || client_data.state == RENEW_REQUESTED | 1127 | || client_data.state == RENEW_REQUESTED |
| 1128 | ) { | 1128 | ) { |
| 1129 | temp_addr.s_addr = server_addr; | 1129 | temp_addr.s_addr = server_id; |
| 1130 | strcpy(buffer, inet_ntoa(temp_addr)); | 1130 | strcpy(buffer, inet_ntoa(temp_addr)); |
| 1131 | temp_addr.s_addr = requested_ip; | 1131 | temp_addr.s_addr = requested_ip; |
| 1132 | bb_info_msg("unicasting a release of %s to %s", | 1132 | bb_info_msg("unicasting a release of %s to %s", |
| 1133 | inet_ntoa(temp_addr), buffer); | 1133 | inet_ntoa(temp_addr), buffer); |
| 1134 | client_data.xid = random_xid(); //TODO: can omit? | 1134 | client_data.xid = random_xid(); //TODO: can omit? |
| 1135 | send_release(server_addr, requested_ip); /* unicast */ | 1135 | send_release(server_id, requested_ip); /* unicast */ |
| 1136 | } | 1136 | } |
| 1137 | bb_simple_info_msg("entering released state"); | 1137 | bb_simple_info_msg("entering released state"); |
| 1138 | /* | 1138 | /* |
| @@ -1218,7 +1218,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 1218 | int tryagain_timeout = 20; | 1218 | int tryagain_timeout = 20; |
| 1219 | int discover_timeout = 3; | 1219 | int discover_timeout = 3; |
| 1220 | int discover_retries = 3; | 1220 | int discover_retries = 3; |
| 1221 | uint32_t server_addr = server_addr; /* for compiler */ | 1221 | uint32_t server_id = server_id; /* for compiler */ |
| 1222 | uint32_t requested_ip = 0; | 1222 | uint32_t requested_ip = 0; |
| 1223 | int packet_num; | 1223 | int packet_num; |
| 1224 | int timeout; /* must be signed */ | 1224 | int timeout; /* must be signed */ |
| @@ -1481,7 +1481,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 1481 | case REQUESTING: | 1481 | case REQUESTING: |
| 1482 | if (packet_num < 3) { | 1482 | if (packet_num < 3) { |
| 1483 | /* send broadcast select packet */ | 1483 | /* send broadcast select packet */ |
| 1484 | send_select(server_addr, requested_ip); | 1484 | send_select(server_id, requested_ip); |
| 1485 | timeout = discover_timeout; | 1485 | timeout = discover_timeout; |
| 1486 | packet_num++; | 1486 | packet_num++; |
| 1487 | continue; | 1487 | continue; |
| @@ -1512,7 +1512,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 1512 | * Anyway, it does recover by eventually failing through | 1512 | * Anyway, it does recover by eventually failing through |
| 1513 | * into INIT_SELECTING state. | 1513 | * into INIT_SELECTING state. |
| 1514 | */ | 1514 | */ |
| 1515 | if (send_renew(server_addr, requested_ip) >= 0) { | 1515 | if (send_renew(server_id, requested_ip) >= 0) { |
| 1516 | timeout = discover_timeout; | 1516 | timeout = discover_timeout; |
| 1517 | packet_num++; | 1517 | packet_num++; |
| 1518 | continue; | 1518 | continue; |
| @@ -1603,7 +1603,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 1603 | timeout = 0; | 1603 | timeout = 0; |
| 1604 | continue; | 1604 | continue; |
| 1605 | case SIGUSR2: | 1605 | case SIGUSR2: |
| 1606 | perform_release(server_addr, requested_ip); | 1606 | perform_release(server_id, requested_ip); |
| 1607 | /* ^^^ switches to LISTEN_NONE */ | 1607 | /* ^^^ switches to LISTEN_NONE */ |
| 1608 | timeout = INT_MAX; | 1608 | timeout = INT_MAX; |
| 1609 | continue; | 1609 | continue; |
| @@ -1688,13 +1688,13 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 1688 | * They either supply DHCP_SERVER_ID of 0.0.0.0 or don't supply it at all. | 1688 | * They either supply DHCP_SERVER_ID of 0.0.0.0 or don't supply it at all. |
| 1689 | * They say ISC DHCP client supports this case. | 1689 | * They say ISC DHCP client supports this case. |
| 1690 | */ | 1690 | */ |
| 1691 | server_addr = 0; | 1691 | server_id = 0; |
| 1692 | temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); | 1692 | temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); |
| 1693 | if (!temp) { | 1693 | if (!temp) { |
| 1694 | bb_simple_info_msg("no server ID, using 0.0.0.0"); | 1694 | bb_simple_info_msg("no server ID, using 0.0.0.0"); |
| 1695 | } else { | 1695 | } else { |
| 1696 | /* it IS unaligned sometimes, don't "optimize" */ | 1696 | /* it IS unaligned sometimes, don't "optimize" */ |
| 1697 | move_from_unaligned32(server_addr, temp); | 1697 | move_from_unaligned32(server_id, temp); |
| 1698 | } | 1698 | } |
| 1699 | /*xid = packet.xid; - already is */ | 1699 | /*xid = packet.xid; - already is */ |
| 1700 | temp_addr.s_addr = requested_ip = packet.yiaddr; | 1700 | temp_addr.s_addr = requested_ip = packet.yiaddr; |
| @@ -1718,7 +1718,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 1718 | 1718 | ||
| 1719 | change_listen_mode(LISTEN_NONE); | 1719 | change_listen_mode(LISTEN_NONE); |
| 1720 | 1720 | ||
| 1721 | temp_addr.s_addr = server_addr; | 1721 | temp_addr.s_addr = server_id; |
| 1722 | strcpy(server_str, inet_ntoa(temp_addr)); | 1722 | strcpy(server_str, inet_ntoa(temp_addr)); |
| 1723 | temp_addr.s_addr = packet.yiaddr; | 1723 | temp_addr.s_addr = packet.yiaddr; |
| 1724 | 1724 | ||
| @@ -1766,7 +1766,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 1766 | bb_simple_info_msg("offered address is in use " | 1766 | bb_simple_info_msg("offered address is in use " |
| 1767 | "(got ARP reply), declining"); | 1767 | "(got ARP reply), declining"); |
| 1768 | client_data.xid = random_xid(); //TODO: can omit? | 1768 | client_data.xid = random_xid(); //TODO: can omit? |
| 1769 | send_decline(server_addr, packet.yiaddr); | 1769 | send_decline(server_id, packet.yiaddr); |
| 1770 | 1770 | ||
| 1771 | if (client_data.state != REQUESTING) | 1771 | if (client_data.state != REQUESTING) |
| 1772 | d4_run_script_deconfig(); | 1772 | d4_run_script_deconfig(); |
| @@ -1810,20 +1810,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 1810 | * "wrong" server can reply first, with a NAK. | 1810 | * "wrong" server can reply first, with a NAK. |
| 1811 | * Do not interpret it as a NAK from "our" server. | 1811 | * Do not interpret it as a NAK from "our" server. |
| 1812 | */ | 1812 | */ |
| 1813 | if (server_addr != 0) { | 1813 | uint32_t svid = 0; /* we treat no server id as 0.0.0.0 */ |
| 1814 | uint32_t svid; | 1814 | uint8_t *temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); |
| 1815 | uint8_t *temp; | 1815 | if (temp) |
| 1816 | |||
| 1817 | temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); | ||
| 1818 | if (!temp) { | ||
| 1819 | non_matching_svid: | ||
| 1820 | log1("received DHCP NAK with wrong" | ||
| 1821 | " server ID%s", ", ignoring packet"); | ||
| 1822 | continue; | ||
| 1823 | } | ||
| 1824 | move_from_unaligned32(svid, temp); | 1816 | move_from_unaligned32(svid, temp); |
| 1825 | if (svid != server_addr) | 1817 | if (svid != server_id) { |
| 1826 | goto non_matching_svid; | 1818 | log1("received DHCP NAK with wrong" |
| 1819 | " server ID%s", ", ignoring packet"); | ||
| 1820 | continue; | ||
| 1827 | } | 1821 | } |
| 1828 | /* return to init state */ | 1822 | /* return to init state */ |
| 1829 | change_listen_mode(LISTEN_NONE); | 1823 | change_listen_mode(LISTEN_NONE); |
| @@ -1847,7 +1841,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
| 1847 | 1841 | ||
| 1848 | ret0: | 1842 | ret0: |
| 1849 | if (opt & OPT_R) /* release on quit */ | 1843 | if (opt & OPT_R) /* release on quit */ |
| 1850 | perform_release(server_addr, requested_ip); | 1844 | perform_release(server_id, requested_ip); |
| 1851 | retval = 0; | 1845 | retval = 0; |
| 1852 | ret: | 1846 | ret: |
| 1853 | /*if (client_data.pidfile) - remove_pidfile has its own check */ | 1847 | /*if (client_data.pidfile) - remove_pidfile has its own check */ |
