aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpc.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-02-27 18:15:50 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-02-27 18:15:50 +0100
commite2318bbad786d6f9ebff704490246bfe52e588c0 (patch)
tree0f46ed673345e8dfe1febf9a36f90a1b2f38a012 /networking/udhcp/dhcpc.c
parentfca0ee5959f212e46b9a5bb324a1482899172750 (diff)
downloadbusybox-w32-e2318bbad786d6f9ebff704490246bfe52e588c0.tar.gz
busybox-w32-e2318bbad786d6f9ebff704490246bfe52e588c0.tar.bz2
busybox-w32-e2318bbad786d6f9ebff704490246bfe52e588c0.zip
udhcpc: ignore NAKs from "wrong" servers. Closes 4267
function old new delta udhcpc_main 2716 2814 +98 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpc.c')
-rw-r--r--networking/udhcp/dhcpc.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 25f18b35d..7dfc160e2 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1232,7 +1232,7 @@ static void client_background(void)
1232int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 1232int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1233int udhcpc_main(int argc UNUSED_PARAM, char **argv) 1233int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1234{ 1234{
1235 uint8_t *temp, *message; 1235 uint8_t *message;
1236 const char *str_V, *str_h, *str_F, *str_r; 1236 const char *str_V, *str_h, *str_F, *str_r;
1237 IF_FEATURE_UDHCP_PORT(char *str_P;) 1237 IF_FEATURE_UDHCP_PORT(char *str_P;)
1238 void *clientid_mac_ptr; 1238 void *clientid_mac_ptr;
@@ -1640,6 +1640,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1640 case INIT_SELECTING: 1640 case INIT_SELECTING:
1641 /* Must be a DHCPOFFER */ 1641 /* Must be a DHCPOFFER */
1642 if (*message == DHCPOFFER) { 1642 if (*message == DHCPOFFER) {
1643 uint8_t *temp;
1644
1643/* What exactly is server's IP? There are several values. 1645/* What exactly is server's IP? There are several values.
1644 * Example DHCP offer captured with tchdump: 1646 * Example DHCP offer captured with tchdump:
1645 * 1647 *
@@ -1689,6 +1691,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1689 if (*message == DHCPACK) { 1691 if (*message == DHCPACK) {
1690 uint32_t lease_seconds; 1692 uint32_t lease_seconds;
1691 struct in_addr temp_addr; 1693 struct in_addr temp_addr;
1694 uint8_t *temp;
1692 1695
1693 temp = udhcp_get_option(&packet, DHCP_LEASE_TIME); 1696 temp = udhcp_get_option(&packet, DHCP_LEASE_TIME);
1694 if (!temp) { 1697 if (!temp) {
@@ -1766,6 +1769,26 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1766 continue; /* back to main loop */ 1769 continue; /* back to main loop */
1767 } 1770 }
1768 if (*message == DHCPNAK) { 1771 if (*message == DHCPNAK) {
1772 /* If network has more than one DHCP server,
1773 * "wrong" server can reply first, with a NAK.
1774 * Do not interpret it as a NAK from "our" server.
1775 */
1776 if (server_addr != 0) {
1777 uint32_t svid;
1778 uint8_t *temp;
1779
1780 temp = udhcp_get_option(&packet, DHCP_SERVER_ID);
1781 if (!temp) {
1782 non_matching_svid:
1783 log1("%s with wrong server ID, ignoring packet",
1784 "Received DHCP NAK"
1785 );
1786 continue;
1787 }
1788 move_from_unaligned32(svid, temp);
1789 if (svid != server_addr)
1790 goto non_matching_svid;
1791 }
1769 /* return to init state */ 1792 /* return to init state */
1770 bb_info_msg("Received DHCP NAK"); 1793 bb_info_msg("Received DHCP NAK");
1771 udhcp_run_script(&packet, "nak"); 1794 udhcp_run_script(&packet, "nak");