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-e2318bbad786d6f9ebff704490246bfe52e588c0.tar.gz
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)
int udhcpc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int udhcpc_main(int argc UNUSED_PARAM, char **argv)
{
- uint8_t *temp, *message;
+ uint8_t *message;
const char *str_V, *str_h, *str_F, *str_r;
IF_FEATURE_UDHCP_PORT(char *str_P;)
void *clientid_mac_ptr;
@@ -1640,6 +1640,8 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
case INIT_SELECTING:
/* Must be a DHCPOFFER */
if (*message == DHCPOFFER) {
+ uint8_t *temp;
+
/* What exactly is server's IP? There are several values.
* Example DHCP offer captured with tchdump:
*
@@ -1689,6 +1691,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
if (*message == DHCPACK) {
uint32_t lease_seconds;
struct in_addr temp_addr;
+ uint8_t *temp;
temp = udhcp_get_option(&packet, DHCP_LEASE_TIME);
if (!temp) {
@@ -1766,6 +1769,26 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
continue; /* back to main loop */
}
if (*message == DHCPNAK) {
+ /* If network has more than one DHCP server,
+ * "wrong" server can reply first, with a NAK.
+ * Do not interpret it as a NAK from "our" server.
+ */
+ if (server_addr != 0) {
+ uint32_t svid;
+ uint8_t *temp;
+
+ temp = udhcp_get_option(&packet, DHCP_SERVER_ID);
+ if (!temp) {
+ non_matching_svid:
+ log1("%s with wrong server ID, ignoring packet",
+ "Received DHCP NAK"
+ );
+ continue;
+ }
+ move_from_unaligned32(svid, temp);
+ if (svid != server_addr)
+ goto non_matching_svid;
+ }
/* return to init state */
bb_info_msg("Received DHCP NAK");
udhcp_run_script(&packet, "nak");