[git commit] udhcpd: if a lease from lease file coincides with a static one, ignore it

Denys Vlasenko vda.linux at googlemail.com
Tue Nov 25 17:49:14 UTC 2014


commit: http://git.busybox.net/busybox/commit/?id=298fabaefcdb79037d0dd33ba331369586690202
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
read_leases                                          269     328     +59

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/udhcp/files.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 6840f3c..1c8808c 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -189,12 +189,24 @@ void FAST_FUNC read_leases(const char *file)
 		goto ret;
 
 	while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
-//FIXME: what if it matches some static lease?
 		uint32_t y = ntohl(lease.lease_nip);
 		if (y >= server_config.start_ip && y <= server_config.end_ip) {
 			signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed;
+			uint32_t static_nip;
+
 			if (expires <= 0)
 				continue;
+
+			/* 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);
+			if (static_nip) {
+				/* NB: we do not add lease even if static_nip == lease.lease_nip.
+				 */
+				continue;
+			}
+			if (is_nip_reserved(server_config.static_leases, lease.lease_nip))
+				continue;
+
 			/* NB: add_lease takes "relative time", IOW,
 			 * lease duration, not lease deadline. */
 			if (add_lease(lease.lease_mac, lease.lease_nip,


More information about the busybox-cvs mailing list