dhcp-client and IPv4 lease times

Mike the.lists at mgm51.com
Fri Dec 10 16:57:28 UTC 2021


On 12/8/2021 4:33 PM, Simon wrote:

> Mike <the.lists at mgm51.com> wrote:
> 
>> From the environment passed to the script specified in dhclient4.conf, I
>> see, among others, the following variables:
>>
>> new_dhcp_lease_time=45605
>> new_dhcp_rebinding_time=34805
>> new_dhcp_renewal_time=2405
>>
>>
>> In the log for the dhclient daemon I see the following entry (sanitized):
>>
>> dhclient: ... -- renewal in 2121 seconds.
>>
>>
>> I have two questions:
>>
>> 1) Why is the renewal time specified in the log different than any of
>> the renewal times passed in the environment?
>>
>> 2) Why is not the renewal time taken to be half the lease time?
> 
> What lease time do you get ?

Thanks for the reply.

At the time, the lease length from the server was 86400 seconds.

A couple days ago, the lease length was 7200 seconds (the ISP was doing
some maintenance, and it is routine for the lease lengths to drop when
that occurs).

While the lease length from the server was 7200 seconds, I was seeing
lease renewal times in the order of 250 to 350 seconds.


> The lease you get is probably nothing like any of the values you’ve set at the client end.

I've noticed. :)   I know that the time I set in the dhclient4.conf is
merely a hint to the server.


> You might need to do some packet capture on the interface to see what the server is sending to you.

I started looking through the source code at the lease renewal time
processing.  I found some interesting things.


At one point, some randomness is introduced into the lease renewal time.
 I wrote a patch [see below] to remove that, and now the lease renewal
times shown in the environment variable and the lease renewal time shown
in the log record match up.

The lease renewal time is still short, i.e., it is still less than half
the lease length.  So I'm still wandering through the source code trying
to understand what is going on.


Thanks again for your reply.


Here's the patch... (also attached, because of word wrapping)


+++ ./client/dhclient.c	Tue Dec  7 20:36:50 2021
@@ -1450,9 +1450,9 @@
 		client -> new -> renewal = TIME_MAX;

 	/* Now introduce some randomness to the renewal time: */
-	if (client->new->renewal <= ((TIME_MAX / 3) - 3))
-		client->new->renewal = (((client->new->renewal * 3) + 3) / 4) +
-				(((random() % client->new->renewal) + 3) / 4);
+// mgm	if (client->new->renewal <= ((TIME_MAX / 3) - 3))
+//		client->new->renewal = (((client->new->renewal * 3) + 3) / 4) +
+//				(((random() % client->new->renewal) + 3) / 4);

 	/* Same deal with the rebind time. */
 	oc = lookup_option (&dhcp_universe, client -> new -> options,
@@ -1480,14 +1480,14 @@

 	/* Make sure our randomness didn't run the renewal time past the
 	   rebind time. */
-	if (client -> new -> renewal > client -> new -> rebind) {
-		if (client -> new -> rebind <= TIME_MAX / 3)
-			client -> new -> renewal =
-					client -> new -> rebind * 3 / 4;
-		else
-			client -> new -> renewal =
-					client -> new -> rebind / 4 * 3;
-	}
+//mgm	if (client -> new -> renewal > client -> new -> rebind) {
+//		if (client -> new -> rebind <= TIME_MAX / 3)
+//			client -> new -> renewal =
+//					client -> new -> rebind * 3 / 4;
+//		else
+//			client -> new -> renewal =
+//					client -> new -> rebind / 4 * 3;
+//	}

 	client -> new -> expiry += cur_time;
 	/* Lease lengths can never be negative. */


-------------- next part --------------

+++ ./client/dhclient.c	Tue Dec  7 20:36:50 2021
@@ -1450,9 +1450,9 @@
 		client -> new -> renewal = TIME_MAX;
 
 	/* Now introduce some randomness to the renewal time: */
-	if (client->new->renewal <= ((TIME_MAX / 3) - 3))
-		client->new->renewal = (((client->new->renewal * 3) + 3) / 4) +
-				(((random() % client->new->renewal) + 3) / 4);
+// mgm	if (client->new->renewal <= ((TIME_MAX / 3) - 3))
+//		client->new->renewal = (((client->new->renewal * 3) + 3) / 4) +
+//				(((random() % client->new->renewal) + 3) / 4);
 
 	/* Same deal with the rebind time. */
 	oc = lookup_option (&dhcp_universe, client -> new -> options,
@@ -1480,14 +1480,14 @@
 
 	/* Make sure our randomness didn't run the renewal time past the
 	   rebind time. */
-	if (client -> new -> renewal > client -> new -> rebind) {
-		if (client -> new -> rebind <= TIME_MAX / 3)
-			client -> new -> renewal =
-					client -> new -> rebind * 3 / 4;
-		else
-			client -> new -> renewal =
-					client -> new -> rebind / 4 * 3;
-	}
+//mgm	if (client -> new -> renewal > client -> new -> rebind) {
+//		if (client -> new -> rebind <= TIME_MAX / 3)
+//			client -> new -> renewal =
+//					client -> new -> rebind * 3 / 4;
+//		else
+//			client -> new -> renewal =
+//					client -> new -> rebind / 4 * 3;
+//	}
 
 	client -> new -> expiry += cur_time;
 	/* Lease lengths can never be negative. */


More information about the dhcp-users mailing list