diff options
author | Christian Lindeberg <christian.lindeberg@axis.com> | 2016-03-01 19:23:22 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-03-01 19:23:22 +0100 |
commit | ea2b71be66b7500cc3ddaa0f617491610ff07dc4 (patch) | |
tree | 14d5c499eda33b727a265f996e5f8c0d78e0295c /networking/udhcp | |
parent | e5aba8871254d411766b9d04d89dcff4ded21e76 (diff) | |
download | busybox-ea2b71be66b7500cc3ddaa0f617491610ff07dc4.tar.gz |
udhcpd: keep expired leases at startup
Let udhcpd retain the information about expired leases when restarting
so that the leases are reserved until they possibly become the oldest
expired lease.
This reduces the frequency of IP address changes for example when the
DHCP server and a group of clients, who do not store and request their
previously offered IP address across restarts, are collectively restarted
and the startup order of the clients are not guaranteed.
Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp')
-rw-r--r-- | networking/udhcp/files.c | 6 | ||||
-rw-r--r-- | networking/udhcp/leases.c | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index 1c8808c0f..5b90e26d2 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c @@ -195,7 +195,11 @@ void FAST_FUNC read_leases(const char *file) uint32_t static_nip; if (expires <= 0) - continue; + /* We keep expired leases: add_lease() will add + * a lease with 0 seconds remaining. + * Fewer IP address changes this way for mass reboot scenario. + */ + expires = 0; /* Check if there is a different static lease for this IP or MAC */ static_nip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac); diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index 844bb60b1..411b74962 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c @@ -17,7 +17,9 @@ static struct dyn_lease *oldest_expired_lease(void) /* Unexpired leases have g_leases[i].expires >= current time * and therefore can't ever match */ for (i = 0; i < server_config.max_leases; i++) { - if (g_leases[i].expires < oldest_time) { + if (g_leases[i].expires == 0 /* empty entry */ + || g_leases[i].expires < oldest_time + ) { oldest_time = g_leases[i].expires; oldest_lease = &g_leases[i]; } |