netutils/dhcpc:receiving unexpected packet not leading to dhcp retry.
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
This commit is contained in:
parent
3837091582
commit
21e1ef11da
@ -680,6 +680,7 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
|||||||
uint8_t msgtype;
|
uint8_t msgtype;
|
||||||
int retries;
|
int retries;
|
||||||
int state;
|
int state;
|
||||||
|
clock_t start;
|
||||||
|
|
||||||
/* RFC2131: For example, a client may choose a different,
|
/* RFC2131: For example, a client may choose a different,
|
||||||
* random initial 'xid' each time the client is rebooted, and
|
* random initial 'xid' each time the client is rebooted, and
|
||||||
@ -730,6 +731,9 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
|||||||
|
|
||||||
/* Get the DHCPOFFER response */
|
/* Get the DHCPOFFER response */
|
||||||
|
|
||||||
|
start = clock();
|
||||||
|
do
|
||||||
|
{
|
||||||
result = recv(pdhcpc->sockfd, &pdhcpc->packet,
|
result = recv(pdhcpc->sockfd, &pdhcpc->packet,
|
||||||
sizeof(struct dhcp_msg), 0);
|
sizeof(struct dhcp_msg), 0);
|
||||||
if (result >= 0)
|
if (result >= 0)
|
||||||
@ -768,6 +772,9 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (state == STATE_INITIAL && TICK2MSEC(clock() - start) <
|
||||||
|
CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT_MS);
|
||||||
|
}
|
||||||
while (state == STATE_INITIAL &&
|
while (state == STATE_INITIAL &&
|
||||||
retries < CONFIG_NETUTILS_DHCPC_RETRIES);
|
retries < CONFIG_NETUTILS_DHCPC_RETRIES);
|
||||||
|
|
||||||
@ -804,6 +811,9 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
|||||||
|
|
||||||
/* Get the ACK/NAK response to the REQUEST (or timeout) */
|
/* Get the ACK/NAK response to the REQUEST (or timeout) */
|
||||||
|
|
||||||
|
start = clock();
|
||||||
|
do
|
||||||
|
{
|
||||||
result = recv(pdhcpc->sockfd, &pdhcpc->packet,
|
result = recv(pdhcpc->sockfd, &pdhcpc->packet,
|
||||||
sizeof(struct dhcp_msg), 0);
|
sizeof(struct dhcp_msg), 0);
|
||||||
if (result >= 0)
|
if (result >= 0)
|
||||||
@ -822,15 +832,12 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
|||||||
state = STATE_HAVE_LEASE;
|
state = STATE_HAVE_LEASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* NAK means the server has refused our request. Break out of
|
/* NAK means the server has refused our request */
|
||||||
* this loop with state == STATE_HAVE_OFFER and send DISCOVER
|
|
||||||
* again
|
|
||||||
*/
|
|
||||||
|
|
||||||
else if (msgtype == DHCPNAK)
|
else if (msgtype == DHCPNAK)
|
||||||
{
|
{
|
||||||
ninfo("Received NAK\n");
|
ninfo("Received NAK\n");
|
||||||
break;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we get any OFFERs from other servers, then decline
|
/* If we get any OFFERs from other servers, then decline
|
||||||
@ -866,6 +873,9 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (state == STATE_HAVE_OFFER && TICK2MSEC(clock() - start) <
|
||||||
|
CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT_MS);
|
||||||
|
}
|
||||||
while (state == STATE_HAVE_OFFER &&
|
while (state == STATE_HAVE_OFFER &&
|
||||||
retries < CONFIG_NETUTILS_DHCPC_RETRIES);
|
retries < CONFIG_NETUTILS_DHCPC_RETRIES);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user