]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
- A new dhcp server option 'adaptive-lease-time-threshold' has been added
authorDavid Hankins <dhankins@isc.org>
Mon, 31 Jul 2006 23:17:24 +0000 (23:17 +0000)
committerDavid Hankins <dhankins@isc.org>
Mon, 31 Jul 2006 23:17:24 +0000 (23:17 +0000)
  which causes the server to substantially reduce lease-times if there are
  few (configured percentage) remaining leases.  Thanks to a patch submitted
  from Christof Chen. [ISC-Bugs #15409]

RELNOTES
includes/dhcpd.h
server/dhcp.c
server/dhcpd.conf.5
server/stables.c

index eedf94096a9bc400015ab0b6fd0165f89ab880ba..8acc2193096d51985038d8ea01839870f64261d7 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -162,6 +162,11 @@ and for prodding me into improving it.
   language.  Thanks to a patch written by Mattias Ronnblom, gotten to us
   via Robin Breathe.
 
+- A new dhcp server option 'adaptive-lease-time-threshold' has been added
+  which causes the server to substantially reduce lease-times if there are
+  few (configured percentage) remaining leases.  Thanks to a patch submitted
+  from Christof Chen.
+
                        Changes since 3.0.4
 
 - A warning that host statements declared within subnet or shared-network
index f63cd924c04e73a0e984c8222b9b62a99f79492a..5d1bdabefbecb3db936b55d3bceed392b8616c6c 100644 (file)
@@ -512,6 +512,7 @@ struct lease_state {
 #define SV_RESERVE_INFINITE            47
 #define SV_DDNS_CONFLICT_DETECT                48
 #define SV_LEASEQUERY                  49
+#define SV_ADAPTIVE_LEASE_TIME_THRESHOLD       50
 
 #if !defined (DEFAULT_PING_TIMEOUT)
 # define DEFAULT_PING_TIMEOUT 1
index 5d068909750aed698958ea163ca94e05b289e2e7..ddec7a53739a7751c29864ebb1cbc3998a43b475 100644 (file)
@@ -34,7 +34,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: dhcp.c,v 1.209 2006/07/25 13:26:00 shane Exp $ Copyright (c) 2004-2006 Internet Systems Consortium.  All rights reserved.\n";
+"$Id: dhcp.c,v 1.210 2006/07/31 23:17:24 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -2021,6 +2021,62 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp, hp)
                        }
                }
 
+               /* CC: If there are less than
+                  adaptive-lease-time-threshold % free leases,
+                    hand out only short term leases */
+
+               memset(&d1, 0, sizeof(d1));
+               if (lease->pool &&
+                   (oc = lookup_option(&server_universe, state->options,
+                                       SV_ADAPTIVE_LEASE_TIME_THRESHOLD)) &&
+                   evaluate_option_cache(&d1, packet, lease, NULL,
+                                         packet->options, state->options,
+                                         &lease->scope, oc, MDL)) {
+                       if (d1.len == 1 && d1.data[0] > 0 &&
+                           d1.data[0] < 100) {
+                               TIME adaptive_time;
+                               int poolfilled, total, count;
+
+                               if (min_lease_time)
+                                       adaptive_time = min_lease_time;
+                               else
+                                       adaptive_time = DEFAULT_MIN_LEASE_TIME;
+
+                               /* Allow the client to keep its lease. */
+                               if (lease->ends - cur_time > adaptive_time)
+                                       adaptive_time = lease->ends - cur_time;
+
+                               count = lease->pool->lease_count;
+                               total = count - (lease->pool->free_leases +
+                                                lease->pool->backup_leases);
+
+                               poolfilled = (total > (INT_MAX / 100)) ?
+                                            total / (count / 100) :
+                                            (total * 100) / count;
+
+                               log_debug("Adap-lease: Total: %d, Free: %d, "
+                                         "Ends: %d, Adaptive: %d, Fill: %d, "
+                                         "Threshold: %d",
+                                         lease->pool->lease_count,
+                                         lease->pool->free_leases,
+                                         (int)(lease->ends - cur_time),
+                                         (int)adaptive_time, poolfilled,
+                                         d1.data[0]);
+
+                               if (poolfilled >= d1.data[0] &&
+                                   lease_time > adaptive_time) {
+                                       log_info("Pool over threshold, time "
+                                                "for %s reduced from %d to "
+                                                "%d.", piaddr(lease->ip_addr),
+                                                (int)lease_time,
+                                                (int)adaptive_time);
+
+                                       lease_time = adaptive_time;
+                               }
+                       }
+                       data_string_forget(&d1, MDL);
+               }
+
                if (lease_time < min_lease_time) {
                        if (min_lease_time)
                                lease_time = min_lease_time;
index 66629da6e6be35524a115b63ab409afa50e834b3..2a8126783c81fecc4cd2a54c3cb40e9ace11f9be 100644 (file)
@@ -28,7 +28,7 @@
 .\" see ``http://www.vix.com''.   To learn more about Nominum, Inc., see
 .\" ``http://www.nominum.com''.
 .\"
-.\" $Id: dhcpd.conf.5,v 1.78 2006/07/25 13:26:00 shane Exp $
+.\" $Id: dhcpd.conf.5,v 1.79 2006/07/31 23:17:24 dhankins Exp $
 .\"
 .TH dhcpd.conf 5
 .SH NAME
@@ -617,7 +617,7 @@ The
 statement
 .RS 0.25i
 .PP
-.B max-lease-misbalance \fIinteger\fR\fB;\fR
+.B max-lease-misbalance \fIpercentage\fR\fB;\fR
 .PP
 The \fBmax-lease-misbalance\fR statement tells the DHCP server what
 percentage of total free leases (as defined as the total number of
@@ -636,7 +636,7 @@ The
 statement
 .RS 0.25i
 .PP
-.B max-lease-ownership \fIinteger\fR\fB;\fR
+.B max-lease-ownership \fIpercentage\fR\fB;\fR
 .PP
 The \fBmax-lease-ownership\fR statement tells the DHCP server what
 percentage of total free leases either it or its peer are normally allowed to
@@ -1737,6 +1737,24 @@ force all clients that have been allocated addresses from this pool to
 obtain new addresses immediately when they next renew.
 .SH REFERENCE: PARAMETERS
 The
+.I adaptive-lease-time-threshold
+statement
+.RS 0.25i
+.PP
+.B adaptive-lease-time-threshold \fIpercentage\fR\fB;\fR
+.PP
+When the number of allocated leases within a pool rises above
+the \fIpercentage\fR given in this statement, the DHCP server decreases
+the lease length for new clients within this pool to \fImin-lease-time\fR
+seconds. Clients renewing an already valid (long) leases get at least the
+remaining time from the current lease. Since the leases expire faster,
+the server may either recover more quickly or avoid pool exhaustion
+entirely.  Once the number of allocated leases drop below the threshold,
+the server reverts back to normal lease times.  Valid percentages are
+between 1 and 99.
+.RE
+.PP
+The
 .I always-broadcast
 statement
 .RS 0.25i
index 4bfbaf255de553cd30ec5045475e04183713d82a..849f16b9bfa927576d5d2540021104f15aed5ffa 100644 (file)
@@ -34,7 +34,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: stables.c,v 1.32 2006/07/19 17:14:55 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium.  All rights reserved.\n";
+"$Id: stables.c,v 1.33 2006/07/31 23:17:24 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -234,6 +234,7 @@ static struct option server_options[] = {
        { "ping-timeout", "T",                  &server_universe,  46, 1 },
        { "infinite-is-reserved", "f",          &server_universe,  47, 1 },
        { "update-conflict-detection", "f",     &server_universe,  48, 1 },
+       { "adaptive-lease-time-threshold", "B", &server_universe,  50, 1 },
        { NULL, NULL, NULL, 0, 0 }
 };