[PATCH] udhcpd: discard saved leases if conflicting with static_lease config

Michael McTernan Michael.McTernan.2001 at cs.bris.ac.uk
Wed Nov 5 20:33:08 UTC 2014


Hi All,

There's a FIXME in udhcpd which describes a small corner case when saved leases are read and honoured even if the IP or MAC of that lease overlaps a static_lease from the config file.  I found that because of this, after updating config and restarting udhcpd, a client which already had a lease can continue to renew that lease instead of either getting the IP specified in a new 'static_lease' config item, or being nak'd and assigned a new free IP.

Following is a small patch which removes the FIXME and adds a check to discard saved lease records if they would conflict with a static_lease from the config file.  

In my configuration, this added 48 bytes to the stripped executable.  I tested it by defining a /24 subnet and adding static_lease records for all but 1 on the available IP addresses, and then moving that 1 available IP around while reconnecting a single client.  After the patch, verbose logging and Wireshark show NAK and then offering of the single free address, with the client having it's IP updated each time ipconfig /renew is issued.

Please consider for inclusion to busybox.

Kind Regards,

Mike

Signed-off-by: Michael McTernan <Michael.McTernan.2001 at cs.bris.ac.uk>


diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 6840f3c..7da0522 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -189,12 +189,20 @@ 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 slnip;
+
 			if (expires <= 0)
 				continue;
+
+			// Check if there is a different static lease for this IP or MAC
+			slnip = get_static_nip_by_mac(server_config.static_leases, lease.lease_mac);
+			if ((slnip != 0 && slnip != lease.lease_nip)
+			 || (slnip == 0 && 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 mailing list