dhcpd will not use corresponding address if network interface activated after dhcpd started
I spent several days on figuring out how to make dhcpd respond on network interfaces that became available/configured after dhcpd is started. The reason for this is that if dhcpd serves more than one iface and dhcpd service is in strong dependency of both interfaces, dhcpd will fail if any interface fail to start. In my case dhcpd is serving lan and wlan. Both can fail randomly on a long run/ Known reasons: lightning can take lan out, wlan can fail to start because of hotsapd problems, any driver/kernel update/configuration mistake will bring iface down taking dhcpd out if it "need" any of network interfaces.
Originally, I had both lan0 and wlan0 specified as options to dhcpd service, but this resulted in:
No subnet declaration for lan0 (no IPv4 addresses).
** Ignoring requests on lan0. If this is not what
you want, please write a subnet declaration
in your dhcpd.conf file for the network segment
to which interface lan0 is attached. **
error message in logs if corresponding interface is activated (get IPv4 address) after dhcpd was started.
So, I removed interfaces from service command arguments and introduced interface
option to my subnet:
subnet 10.0.0.0 netmask 255.255.255.0 {
interface lan0;
range 10.0.0.8 10.0.0.16;
default-lease-time 14400;
max-lease-time 86400;
option domain-name-servers 10.0.0.1;
option routers 10.0.0.1;
option ntp-servers 10.0.0.1;
option broadcast-address 10.0.0.255;
}
wlan0 configuration is omitted.
When dhcpd is started after lan0, I can see the fallowing (client side):
22:05:30.454105 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:05:31.585355 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:05:33.796111 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:05:33.797024 IP 10.0.0.1.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
22:05:33.797306 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 298
22:05:33.798182 IP 10.0.0.1.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
Notice the dhcpd replaying from 10.0.0.1.
Then I simulate interface failure by 1) brinning lan0 down (the link will go down as well, test client will notice this and will start sending discovers) 2) restarting dhcpd, it will report receive_packet failed on lan0: Network is down
3) staring lan0.
Finally, dhcpd will receive a discover from a client:
22:06:02.453552 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:06:02.454528 IP 0.0.0.0.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
22:06:04.057172 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:06:04.058009 IP 0.0.0.0.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
22:06:06.076225 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:06:06.077561 IP 0.0.0.0.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
22:06:07.647378 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:06:07.648335 IP 0.0.0.0.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
22:06:11.751204 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:06:11.752284 IP 0.0.0.0.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
22:06:18.830728 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:06:18.831779 IP 0.0.0.0.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
22:06:35.453960 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
But dhcpd will respond from 0.0.0.0 and the client seems to ignore (tested on two different clients) this DHCPOFFER never sending DHCPREQUEST until dhcpd is restarted with lan0 up/configured. If I restart dhcpd, it will use corresponding IP address and client will accept offers responding with request:
22:06:35.454256 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 292
22:06:35.454550 IP 10.0.0.1.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
22:06:35.456998 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:xx:xx:xx:xx:xx, length 298
22:06:35.457165 IP 10.0.0.1.67 > 10.0.0.4.68: BOOTP/DHCP, Reply, length 300
This seem to be invalid because even if interface is not ready when dhcpd starts up, dhcpd is aware of the correct address because of interface
option in subnet and therefore can use correct src address for offers and acks. It maybe needed to accomplish some percedure to use new address after pointed iface becames ready. For example, bind starts before any network interface become ready, and then reports something like:
named[2060]: listening on IPv4 interface lan0, 10.0.0.1#53
So there is no need to watch for interfaces and start orders. BIND will take care of this by itself. And it will be nice to be able to configure dhcpd is such way it will be able to serve DHCP on interfaces that became ready after dhcpd is started in case dhcpd is able to match interface and subnet.