Adaptive lease time patch

Christof Chen christof at chen.de
Mon Sep 12 20:46:27 UTC 2005


On Monday 12 September 2005 18:55, David W. Hankins wrote:
> How many admins would be saved being called if the server had started
> giving short leases out before the pool was exhausted?
>
Thats encouraging! Indeed this could be helpful to others.
> So one further optimization might be to see how long the lease is
> already set to expire, if this is a renewal.  In the 'lease shortfall'
> case, the server might choose to give a lease->ends optimal lease-time,
> or the min-time, whichever is greater.

Ok, here is the new patch with your idea and the correction from Ted. Would 
there be any chance for inclusion of this patch into the mainline? 
,,,patches to dhcpd.conf.5 would be supplied too :)

*** dhcp-3.0.3/server/dhcp.c    Sat Apr 30 01:10:57 2005
--- dhcp-3.0.3-cc/server/dhcp.c Mon Sep 12 22:35:31 2005
***************
*** 2001,2006 ****
--- 2001,2041 ----
                        }
                }

+               /* CC: If there are less than 50% free leases,
+                    hand out only short term leases */
+
+               if (lease -> pool &&
+                   (oc = lookup_option (&server_universe, state -> options,
+                               SV_ADAPTIVE_LEASE_TIME)) &&
+                   evaluate_boolean_option_cache (&ignorep, packet, lease,
+                                          (struct client_state *)0,
+                                          packet -> options,
+                                          state -> options,
+                                          &lease -> scope, oc, MDL)) {
+                   log_info ("Adap-lease: Total: %d, Free: %d, Ends: %d",
+                               lease -> pool -> lease_count,
+                               lease -> pool -> free_leases,
+                               (int) (lease -> ends - cur_time));
+
+                   if (lease -> pool -> lease_count -
+                       lease -> pool -> free_leases >=
+                       lease -> pool -> free_leases) {
+                          /* CC: if the client has a long lease already,
+                             do not cut the running lease beyond what we
+                               already committed. */
+                          if (lease -> ends - cur_time > min_lease_time)
+                               min_lease_time = lease -> ends - cur_time;
+                          if (lease_time > min_lease_time) {
+                             log_info ("Pool over %s %s from %d to %d",
+                             "threshold, reduce lease time for",
+                                       piaddr (lease -> ip_addr),
+                                               (int) lease_time,
+                                               (int) min_lease_time);
+                               lease_time = min_lease_time;
+                          }
+                   }
+               }
+
                if (lease_time < min_lease_time) {
                        if (min_lease_time)
                                lease_time = min_lease_time;


More information about the dhcp-hackers mailing list