Why are DHCP leases reconfirmed when disabling and enabling blocking?

I track DHCP leases for device presence detection. It usually works nicely. But every time when I disable and enable blocking the DHCP server sends out 'old' messages (lease confirmations, if I am not mistaken) without having been queried and also for devices that weren't on the network before I disabled blocking (and where the lease already should have expired).

This messes with device presence detection. Is there a way to fix this?

DHCP leases cannot reliably reflect current connection status of a client device.

Once a DHCP server has handed a lease to a client, it doesn't track whether that client still has an active conection.
It just keeps record of that lease so it wouldn't hand out the same IP to another device before the lease would have expired.

It is a client that may or may not try to send a DHCPRELEASE before disconnecting, but it may also fail to do so, e.g. if the physical connection was severed. dnsmasq's respective DHCP lease record would remain as is in that case.

Disabling or enabling Pi-hole's blocking triggers a restart of pihole-FTL (a tailored dnsmasq optimised for Pi-hole) via pihole restartdns reload.

Since you mention receiving "old" messages, it seems you are using dnsmasq's dhcp-script option to get informed of DHCP lease information.

Note that

"old" is a notification of an existing lease when dnsmasq starts or a change to MAC address or hostname of an existing lease (also, lease length or expiry and client-id, if leasefile-ro is set).

(quoting dnsmasq documentation)

If I'd correctly assume you are using dhcp-script, then what you observe would be expected for a restart: dnsmasq is informing you of its known leases.

Thank you for the elaborate explanation. I am indeed using the dhcp-script option. I thought I encountered OLD messages for clients that left the network beyond the lease duration but I cannot reproduce it.

At any rate, understanding the potential pitfalls, I'll only look out for ADD messages to detect presence (and use other means to detect absence). I know that should a client leave and return during the lease interval I may not detect that.

For what do you need presence detection and how accurate (in term of delay) does it have to be? Consider active probing (ping) if you really need to check for if a device is still within reach. I don't think anything else will work reliably.

We're internally changing from reloading the entire system on en-/disable (see here) so you should not see any "old" messages in the currently running beta resp. the next released version of Pi-hole.

This is very possible. For efficiency reasons, there is no dedicated loop periodically checking if there are expired leases (because expired leases do not hurt anyone). Instead, expired leases are only pruned when a new lease is to be added - just in case we need to make room for storing the new lease.

Thanks for your comments. DHCP leases are just an additional layer for my (family members/devices) presence detection. Some home automation scripts take household members' presence into consideration. There's geofencing apps with webhooks on the devices that are also working most of the time. iDevices have the tendency to go into stealth mode and a ping may get no response.

Your explanation about OLD messages is very informative. Thank you also for the info about the list-reload change, it sounds like a good improvement to an already perfect solution.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.