Hello Jon,
I like this idea. This might not be the most performant approach, but maybe that isn’t the biggest problem here. Correctness comes before performance at least.
On 30 Nov 2023, at 16:01, jon jon.murphy@ipfire.org wrote:
Michael & All,
I am offering a Proof Of Concept (POC) for a DHCP to DNS bridge. The POC below is written in bash and may not be fast enough for thousands of devices.
It uses the On Commit/Release/Expiry (CRE) already included into ISC DHCP. I believe these are known as EVENTS.
=== NOTE === REFERENCE: EVENTS - There are three kinds of events that can happen regarding a lease, and it is possible to declare statements that occur when any of these events happen. These events are the commit event, when the server has made a commitment of a certain lease to a client, the release event, when the client has released the server from its commitment, and the expiry event, when the commitment expires.
To declare a set of statements to execute when an event happens, you must use the on statement, followed by the name of the event, followed by a series of statements to execute when the event happens, enclosed in braces.
If I did this correctly is should simplify the bridge by eliminating some of the parsing though `/var/ipfire/dhcp/fixleases` and searching for new or expired leases.
If I understand CRE correctly, it should also simplify the separated Dynamic Leases and Fixed Leases. CRE seems to handle both FIXED and DYNAMIC. The downside (or upside depending on your point of view) is the elimination of the DHCP configuration "Remarks" appearing to unbound as client domain names. See DHCP configuration - Current fixed leases (at menu Network > DHCP Server)
This is not complete and it currently does not include the Hostname (static) items at `/etc/unbound/hosts.conf`
There are many extra lines included to help me test & debug (i.e., "logger"). Most to be removed.
If this helps, please offer ideas or corrections. If not, then I will be :-(
This is only one half the solution I would say - but probably fixes the problem of the past…
I think that we can easily use this script to dynamically load/remove entries from Unbound with removing it. Since we already have to fork unbound-control, I do not consider this too bad.
But: A new problem would be that we have a bootstrap problem: How do we load an initial set of leases into Unbound - either on boot or when Unbound gets restarted?
* Parsing the leases file in shell is painful and veeeery slow. Not really a problem since we only do this once, but it has to work. * Keeping the existing Python code feels like the wrong choice. * I played around with awk and I think that could be an option, but it is not fun to write - not the biggest problem again. * Another option could be that we don’t bother with the leases file at all. We could simply create yet another file that we write any events to and hope that we will never miss one.
I am really not sure which ones of these options I would disfavour the least. What do you think?
-Michael
File = `/var/ipfire/dhcp/dhcpd.conf.local`
<dhcpd.conf.local.txt>
File = `dhcpEvent_v6.sh`
<dhcpEvent_v6.sh.txt>
The bash script currently writes to `/etc/unbound/dhcp-leases2.conf` so I can compare it to `dhcp-leases.conf`. It does NOT provide any data to unbound (yet!)
Is this script helpful?
Jon
Inspiration link: https://jpmens.net/2011/07/06/execute-a-script-when-isc-dhcp-hands-out-a-new...
Reference Link: Still looking!! https://stackoverflow.com/questions/51550326/is-there-any-hook-for-finishing...