Skip to content

Commit

Permalink
dhcp: add option for lowering discover interval
Browse files Browse the repository at this point in the history
  • Loading branch information
someburner committed Sep 6, 2019
1 parent f4918f9 commit 1372a35
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions glue-lwip/arduino/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,13 @@
#if !defined LWIP_DHCP_MAX_DNS_SERVERS || defined __DOXYGEN__
#define LWIP_DHCP_MAX_DNS_SERVERS DNS_MAX_SERVERS
#endif

/**
* DHCP discover retransmission interval (milliseconds)
*/
#if !defined LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL || defined __DOXYGEN__
#define LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL 250 // 250 - 1000
#endif
/**
* @}
*/
Expand Down
7 changes: 7 additions & 0 deletions glue-lwip/open/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,13 @@
#if !defined LWIP_DHCP_MAX_DNS_SERVERS || defined __DOXYGEN__
#define LWIP_DHCP_MAX_DNS_SERVERS DNS_MAX_SERVERS
#endif

/**
* DHCP discover retransmission interval (milliseconds)
*/
#if !defined LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL || defined __DOXYGEN__
#define LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL 250 // 250 - 1000
#endif
/**
* @}
*/
Expand Down
20 changes: 20 additions & 0 deletions patches/dhcp-lower-retry-backoff.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c
index 534574fe..88c7669f 100644
--- a/src/core/ipv4/dhcp.c
+++ b/src/core/ipv4/dhcp.c
@@ -1024,7 +1024,15 @@ dhcp_discover(struct netif *netif)
autoip_start(netif);
}
#endif /* LWIP_DHCP_AUTOIP_COOP */
+#ifdef LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL
+/**
+ * Since for embedded devices it's not that hard to miss a discover packet, so lower
+ * the discover retry backoff time from (2,4,8,16,32,60,60)s to (500m,1,2,4,8,15,15)s.
+ */
+ msecs = (u16_t)((dhcp->tries < 6 ? 1 << dhcp->tries : 60) * LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL);
+#else
msecs = (u16_t)((dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000);
+#endif /* LWIP_DHCP_DISCOVER_RETRANSMISSION_INTERVAL */
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_discover(): set request timeout %"U16_F" msecs\n", msecs));
return result;

0 comments on commit 1372a35

Please sign in to comment.