|
From: | Bill Auerbach |
Subject: | [lwip-devel] Using DHCP & AutoIP as connections change |
Date: | Tue, 1 Jun 2010 14:28:51 -0400 |
With DHCP how can I reuse IP addresses on link disconnects but not reuse addresses on physical connection changes?
If I call dhcp_stop when the cable is disconnected and dhcp_start when it’s connected, I get a different IP address each time this happens. This is not good if the connection glitches. The reason I’m doing this is that I also want to handle removing the cable from a DHCP-enabled connection to one which doesn’t have DHCP – in this case I want the device to get an AutoIP address. If I don’t make these calls, the device will continue to work while using the DHCP-offered address which won’t be valid if the device has power cycled.
Is there a way to handle this case cleanly? Too many customers change cabling without cycling power because they are spoiled by not having to do so with PCs.
Also, which I don’t think is right, calling dhcp_start and dhcp_stop also calls autoip_start and autoip_stop and doing so causes the netif to get the next IP address. I believe the
autoip->tried_llipaddr++;
in autoip_start should be removed or be used conditionally only when there are multiple netif’s.
I noticed that a DHCP server should try to give a device an IP address it already used prior. It can do so using DHCP_OPTION_REQUESTED_IP with DHCP_DISCOVER but lwIP doesn’t use this option.
In dhcp_discover(), we could have:
if(!ip_addr_isany(&netif->ip_addr)) {
dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
dhcp_option_long(dhcp, ntohl(netif->ip_addr.addr));
}
to inform DHCP of a previous address. This would fill in DHCP_OPTION_REQUESTED_IP if the lwIP device had a previous IP address. Interestingly on a 5-year old Linksys router this option is ignored and I still get a new IP address with each dhcp stop and start call.
Thanks,
Bill
[Prev in Thread] | Current Thread | [Next in Thread] |