[Dnsmasq-discuss] SIGHUP and external script
simon at thekelleys.org.uk
Mon Jul 9 09:29:35 BST 2007
richardvoigt at gmail.com wrote:
> Would it be possible to add some logic to resync with the external database
> when SIGHUP is received?
> I propose the following set of rules:
> rerun external-script "init"
> any lease in the external database, which does not match any mac address in
> the internal list, is added to the internal list (unless it has expired,
> then use external-script "del")
> any lease in the external database, which matches the MAC address in the
> internal list but a different IP address, is removed with external-script
> any lease in the external database, which matches both MAC address and IP
> address in the internal list, is updated with external-script "old"
> any lease in the internal list not found in the external database is added
> in the external database with external-script "add"
> Would this be possible? Any complications or undesired behavior you can
A couple of things spring to mind. First, you are assuming that the
primary key for the lease database is the MAC address. That's not true,
it's the IP address. Any of the client-id, MAC address, hostname and
expiry time can change on an existing lease and at least some of them
can be repeated over different leases, only the IP address is unique and
Second, the big implementation problem I can see with your suggestion is
the old problem of user privs. By the time we want to re-run the
externel script with "init" dnsmasq has thrown away root so that it can
no longer run the script as root. This problem is solved for the add,
old and del actions by keeping a helper process around which is still
running as root. At the moment information flows one way, from the main
process to the helper. If the helper was used to re-run "init" then
information would need to flow from the helper back to the main
process. That's not impossible, but it's a lot of code.
> Right now, spanning tree protocol and its "learning" states are playing
> havoc with my external-script "init", because the postgresql server isn't
> reachable when dnsmasq starts. I'll work on a solution to that
> independently, but it would be really nice to be able to resync the
> database any time connectivity is lost and then restored.
If the need is simply to re-sync the external database, then how about
this: a signal which marks all leases as "changed" so that "old" events
are created for each one. that won't handle deleted leases, but a
separate reaper which looks at expiry times could do that.
This function would be useful for other things too: I have
port-forwarding controlled by a script which runs on the DHCP
lease-change hook. At the moment, when I change the port-forward
configuration, I have to restart dnsmasq to effect the change.
Signalling it instead would be a win.
> Ben Voigt
Ah sorry, I called you Richard in my previous email, I was looking at
your email address, not you signature....
> Dnsmasq-discuss mailing list
> Dnsmasq-discuss at lists.thekelleys.org.uk
More information about the Dnsmasq-discuss