netutils/dhcpc: configurable timeout and retry count.
Change-Id: I92e77bd24ddd7ffff39de9215f4b7c05a7b55bee Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
d7df165c45
commit
70bb13ce3b
@ -16,4 +16,17 @@ config NETUTILS_DHCPC_HOST_NAME
|
||||
string "DHCP client host name"
|
||||
default "nuttx"
|
||||
|
||||
config NETUTILS_DHCPC_RECV_TIMEOUT
|
||||
int "Number of receive timeout in second"
|
||||
default 3
|
||||
---help---
|
||||
This is the timeout value when dhcp client receives response
|
||||
|
||||
config NETUTILS_DHCPC_RETRIES
|
||||
int "Number of retries for dhcp client request"
|
||||
default 3
|
||||
---help---
|
||||
This setting determines how many times resolver retries request
|
||||
until failing.
|
||||
|
||||
endif
|
||||
|
@ -433,7 +433,7 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
|
||||
|
||||
/* Configure for read timeouts */
|
||||
|
||||
tv.tv_sec = 10;
|
||||
tv.tv_sec = CONFIG_NETUTILS_DHCPC_RECV_TIMEOUT;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
ret = setsockopt(pdhcpc->sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv,
|
||||
@ -516,6 +516,10 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
||||
newaddr.s_addr = INADDR_ANY;
|
||||
netlib_set_ipv4addr(pdhcpc->interface, &newaddr);
|
||||
|
||||
/* Loop sending the DISCOVER up to CONFIG_NETUTILS_DHCPC_RETRIES times */
|
||||
|
||||
retries = 0;
|
||||
|
||||
/* Loop sending DISCOVER until we receive an OFFER from a DHCP
|
||||
* server. We will lock on to the first OFFER and decline any
|
||||
* subsequent offers (which will happen if there are more than one
|
||||
@ -533,6 +537,8 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
retries++;
|
||||
|
||||
/* Get the DHCPOFFER response */
|
||||
|
||||
result = recv(pdhcpc->sockfd, &pdhcpc->packet,
|
||||
@ -573,10 +579,18 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
while (state == STATE_INITIAL);
|
||||
while (state == STATE_INITIAL && retries < CONFIG_NETUTILS_DHCPC_RETRIES);
|
||||
|
||||
/* If no DHCPOFFER recveived here, error out */
|
||||
|
||||
/* Loop sending the REQUEST up to three times (if there is no response) */
|
||||
if (state == STATE_INITIAL)
|
||||
{
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Loop sending the REQUEST up to CONFIG_NETUTILS_DHCPC_RETRIES times
|
||||
* (if there is no response)
|
||||
*/
|
||||
|
||||
retries = 0;
|
||||
do
|
||||
@ -657,7 +671,7 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
while (state == STATE_HAVE_OFFER && retries < 3);
|
||||
while (state == STATE_HAVE_OFFER && retries < CONFIG_NETUTILS_DHCPC_RETRIES);
|
||||
}
|
||||
while (state != STATE_HAVE_LEASE);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user