[Dnsmasq-discuss] [PATCH] ubus: add lease management methods
Bergamote
pierre.gaufillet at bergamote.eu
Sun Mar 15 16:42:42 UTC 2026
Hi!
The attached patch adds three ubus methods to dnsmasq: add_lease, delete_lease and get_leases. These are the ubus equivalent of the existing dbus AddDhcpLease/DeleteDhcpLease, plus get_leases which has no dbus counterpart.
The use case is HA DHCP on OpenWrt: when a dnsmasq instance creates or removes a lease, an external daemon replicates it to peer nodes via the new ubus methods, so that all instances share a consistent lease database.
The implementation follows the same internal APIs as the dbus path (lease4_allocate, lease_set_hwaddr, lease_set_expires, etc.) with a few improvements: hostname validation via legal_hostname(), IPv6 domain lookup with get_domain6(), and script-triggering flag suppression for injected leases (preventing dhcp-script ping-pong).
No extra per-lease storage is required. get_leases iterates the existing lease linked list on demand.
I am aware of the 2021 discussion around Eduardo Aguilar's lease method proposal. This takes a different approach: it hooks directly into the ubus method table (not log_packet()), stores no extra data, and mirrors the existing dbus design rather than introducing a new one.
The patch is tested on an OpenWrt HA cluster. If there is interest, I also have a self-contained contrib daemon (contrib/lease-sync/) that uses these methods, which I could submit separately.
Browsable code: https://github.com/pgaufillet/dnsmasq/tree/submission/lease-sync-patches, and for information https://github.com/pgaufillet/openwrt-ha-feed
N.B. This work has been performed using Claude Code, among other tools.
Pierre Gaufillet

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20260315/8f628df9/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-ubus-methods-for-DHCP-lease-management.patch
Type: application/octet-stream
Size: 13610 bytes
Desc: not available
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20260315/8f628df9/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20260315/8f628df9/attachment-0003.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4725 bytes
Desc: not available
URL: <http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/attachments/20260315/8f628df9/attachment-0001.bin>
More information about the Dnsmasq-discuss
mailing list