You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/04/04 00:11:34 UTC
[incubator-nuttx-apps] 01/02: netutils/dhcpc: configurable timeout
and retry count.
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 70bb13ce3b3866189f004c7e169116331654babc
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Mar 30 18:50:47 2020 +0800
netutils/dhcpc: configurable timeout and retry count.
Change-Id: I92e77bd24ddd7ffff39de9215f4b7c05a7b55bee
Signed-off-by: chao.an <an...@xiaomi.com>
---
netutils/dhcpc/Kconfig | 13 +++++++++++++
netutils/dhcpc/dhcpc.c | 22 ++++++++++++++++++----
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/netutils/dhcpc/Kconfig b/netutils/dhcpc/Kconfig
index 304cfc3..1a2839e 100644
--- a/netutils/dhcpc/Kconfig
+++ b/netutils/dhcpc/Kconfig
@@ -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
diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c
index 8ca64b3..d39c51f 100644
--- a/netutils/dhcpc/dhcpc.c
+++ b/netutils/dhcpc/dhcpc.c
@@ -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);