Skip to contentSkip to conversation

dhcp: Decrease re-try delay after initial discovery message

PATCH Applied Tim Kourt 2 participants 2 messages Jul 31, 2019 – Aug 1, 2019

lore
Share & tools
lore

Tim Kourt

author
#0 lore raw

PATCH 1/1 dhcp: Decrease re-try delay after initial discovery message

Some of the routers require ‘setup’ time between the moment when connection is established and before they are ready to respond to the DHCP discovery messages. This used to cause the DHCP clients to wait a full delay of +-4 seconds for the next attempt to rediscover DHCP servers. To address this issue, the time delay between the initial discovery message and its retransmission is shorten to milliseconds to give enough time to the routers to get ready and minimize the delay for the clients.

---
 ell/dhcp.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
ell/dhcp.c +18 -1
index 57d5ae2..ca81311 100644
@@ -485,6 +485,23 @@ static uint64_t dhcp_fuzz_secs(uint32_t secs)
 	return ms;
 }
 
+/*
+ * Takes a time in milliseconds and produces a fuzzed value that can be directly
+ * used by l_timeout_modify_ms. The fluctuation of the random noise added is
+ * from -63 to 63 milliseconds.
+ */
+static uint64_t dhcp_fuzz_msecs(uint64_t ms)
+{
+	uint32_t r = l_getrandom_uint32();
+
+	if (r & 0x80000000)
+		ms += r & 0x3f;
+	else
+		ms -= r & 0x3f;
+
+	return ms;
+}
+
 static uint32_t dhcp_rebind_renew_retry_time(uint64_t start_t, uint32_t expiry)
 {
 	uint64_t now = l_time_now();
@@ -1191,7 +1208,7 @@ LIB_EXPORT bool l_dhcp_client_start(struct l_dhcp_client *client)
 	if (err < 0)
 		return false;
 
-	client->timeout_resend = l_timeout_create_ms(dhcp_fuzz_secs(4),
+	client->timeout_resend = l_timeout_create_ms(dhcp_fuzz_msecs(600),
 						dhcp_client_timeout_resend,
 						client, NULL);
 	CLIENT_ENTER_STATE(DHCP_STATE_SELECTING);
Signature · 1 line
2.13.6
#1 lore raw

Hi Tim,

Quoted 8 lines · Tim Kourt

Some of the routers require ‘setup’ time between the moment when connection is established and before they are ready to respond to the DHCP discovery messages. This used to cause the DHCP clients to wait a full delay of +-4 seconds for the next attempt to rediscover DHCP servers. To address this issue, the time delay between the initial discovery message and its retransmission is shorten to milliseconds to give enough time to the routers to get ready and minimize the delay for the clients.

Quoted 4 lines
---
  ell/dhcp.c | 19 ++++++++++++++++++-
  1 file changed, 18 insertions(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis