udhcpd initial lease
Grahame Jordan
gbj at theforce.com.au
Fri Nov 26 20:48:44 UTC 2010
Hi,
When using dhcpd on an embedded system after booting on some clients for
example Windows7 it takes a long time
to negotiate an ip address. In the case of Win7 it is insistent on using
the previous IP address that it had at its previous
connection to the device.
The problem is that on most embedded systems the leases file is empty
after every boot. Making the negotiation
difficult as there is no previous record in the leases file to negotiate
with. The lease request needs to time out before
a new lease can be requested resulting in long delays on getting an IP
Address.
Additionally some embedded systems generate a random MAC address every
time they connect say over USB making the
negotiation just as difficult as with an empty leases file.
I have created a patch that allows a request to go through if the leases
file is empty. This results in very quick dhcp
negotiating. To alleviate the random MAC address issue I empty the
leases file which results in quick dhcp negotiation also.
In this case only one client ever connects to these types of device. The
requested IP address is then parsed later in the code to ensure that it
is in the correct range etc.
--- busybox-1.13.2/networking/udhcp/dhcpd.c 2010-11-17
09:08:17.870655217 +1100
+++ busybox-1.13.2-new/networking/udhcp/dhcpd.c 2010-11-17
09:22:22.600650751 +1100
@@ -229,12 +229,14 @@
/* make some contention for this address */
} else
send_NAK(&packet);
- } else {
- uint32_t r = ntohl(requested_align);
- if (r < server_config.start_ip
- || r > server_config.end_ip
- ) {
- send_NAK(&packet);
+ } else { /* Lets see if the leases file is empty. If so
why not add 'requested' address */
+ if (is_initial_lease() && send_offer(&packet) < 0) {
+ uint32_t r = ntohl(requested_align);
+ if (r < server_config.start_ip
+ || r > server_config.end_ip
+ ) {
+ send_NAK(&packet);
+ }
}
/* else remain silent */
}
--- busybox-1.13.2/networking/udhcp/dhcpd.h 2010-11-17
09:08:17.870655217 +1100
+++ busybox-1.13.2-new/networking/udhcp/dhcpd.h 2010-11-17
09:08:17.870655217 +1100
@@ -84,6 +84,7 @@
struct dhcpOfferedAddr *add_lease(const uint8_t *chaddr, uint32_t
yiaddr, unsigned long lease) FAST_FUNC;
int lease_expired(struct dhcpOfferedAddr *lease) FAST_FUNC;
+int is_initial_lease(void) FAST_FUNC;
struct dhcpOfferedAddr *find_lease_by_chaddr(const uint8_t *chaddr)
FAST_FUNC;
struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr) FAST_FUNC;
uint32_t find_address(int check_expired) FAST_FUNC;
--- busybox-1.13.2/networking/udhcp/leases.c 2010-11-17
09:08:17.882035995 +1100
+++ busybox-1.13.2-new/networking/udhcp/leases.c 2010-11-17
09:08:17.870655217 +1100
@@ -69,6 +69,15 @@
}
+/* Is this the initial lease. ie. Is the leases file empty? */
+int FAST_FUNC is_initial_lease(void)
+{
+ if(leases[0].yiaddr == 0)
+ return 1;
+ return 0;
+}
+
+
/* Find the first lease that matches chaddr, NULL if no match */
struct dhcpOfferedAddr* FAST_FUNC find_lease_by_chaddr(const uint8_t
*chaddr)
{
Thanks
Grahame Jordan
More information about the busybox
mailing list