Adaptive lease time patch

Christof Chen christof at chen.de
Fri Sep 9 22:28:43 UTC 2005


Hello *,

searching the archives i found no simple solution to the following problem:
Think of small offices with normally about 5 clients and a pool of 20 leases. 
Those clients should get rather long leases - about 3 to 6 days. Sometimes 
people from another offices meet at one location and connect their laptops  
shortly to the network (Checking mail etc...).

So this visitors should get rather short leases - about 1 hour.

The following patch (without fancy configuration options yet) modifies dhcp.c 
so, that once a pool reaches 50% active leases, the server hands out only 
short min_lease_time leases - until the allocation drop down under 50%, when 
it reverts back to default_lease_time.

My question: Is this OK to do or plain silly?

Best regards,
	Christof Chen

diff -c dhcp-3.0.3/server/dhcp.c dhcp-3.0.3-cc/server/dhcp.c
*** dhcp-3.0.3/server/dhcp.c    Sat Apr 30 01:10:57 2005
--- dhcp-3.0.3-cc/server/dhcp.c Fri Sep  9 23:56:17 2005
***************
*** 2001,2006 ****
--- 2001,2025 ----
                        }
                }

+               /* log_info ("ack_lease Total: %d, Free: %d",
+                         lease -> pool -> lease_count,
+                           lease -> pool -> free_leases); */
+
+               /* If there are less than 50% free leases,
+                    hand out only short term leases */
+               if (lease -> pool -> lease_count -
+                     lease -> pool -> free_leases >=
+                     lease -> pool -> free_leases) {
+                       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