[Networkmanager] Check if a DHCP server is responsive
Thomas Haller
thaller at redhat.com
Thu May 4 12:06:15 UTC 2023
Hi,
On Thu, 2023-05-04 at 11:47 +0200, Frédéric Martinsons wrote:
> Hello list,
>
> I would like to add some monitoring of the dhcp servers via the
> machines which request ip addresses from it (no access to the server
> itself)
> For the moment, we are only aware of the outage of this server when
> the lease expired.
>
> I first check if NM has a dbus api for that and didn't find one, the
> I use a Nagios plug-in as a standalone program
> (https://github.com/nagios-plugins/nagios-plugins/blob/master/plugins
> -root/check_dhcp.c) but it seems to not work on all cases I have
> (strong firewalling among other).
>
> I don't want to use nmap or other external tools that I didn't
> already have on the machines (I have strong constraint on the size
> available)
>
> Since our machines used NM to manage ethernet , I decided to look at
> the code to know how the things are handled and if a can have the
> possibility to "ping" (just emit a DISCOVER and listen for OFFER
> without accepting the lease). I first came up with a solution that
> involves instantiating a NMDhcpClient to use an internal dhcp
> mechanism. It worked but I had to patch NM code to avoid messing with
> the system (I don't want to read the already accepted lease or modify
> the current lease). Moreover my binary had to link with almost all NM
> code which makes it very big.
>
> I finally came up with a minimal solution by mimicking what is done
> in nm-dhcp-nettools.c and talking directly to the n-dhcp4 library.
>
> Long story short, I'm wondering if this "ping dhcp" capability is a
> feature fitted to enter as a standalone binary (or a dedicated DBus
> endpoint) in NM code ?
I don't see how such functionality would fit into NetworkManager. But
maybe it does, if you have a specific suggestion please make it.
Instead, I would use/build a separate tool for that. If it's a specific
tool for that purpose, then the API would be simple. If it's a more
general tool (e.g. integrate it into ISC dhclient) then it is already
more complicated to make the functionality general purpose and fit it
into a more general tool.
There are several DHCP client libraries and implementations. For
example there is https://github.com/nispor/mozim
I would actually use nettools' n-dhcp4 library (which you already
investigated) and build a specialized one-purpose tool on top of that.
That should be relatively straight forward, and if API is missing for
making it happen, it probably can be accepted upstream.
https://github.com/nettools/n-dhcp4
Thomas
More information about the Networkmanager
mailing list