NetworkConfiguration / dhcpcd

DHCP / IPv4LL / IPv6RA / DHCPv6 client.
https://roy.marples.name/projects/dhcpcd
BSD 2-Clause "Simplified" License
347 stars 111 forks source link

Exposing advertisments/offers via dhcpcd-run-hooks #304

Open rmarioe opened 8 months ago

rmarioe commented 8 months ago

I would like to have visibility of all the DHCP servers that offered/advertised a lease in the network to the client through my user defined hook script. It could be handled by adding a reason to run the hooks script (i.e. OFFER/ADVERTISE). Before sending out a PR I would like to know if something like this could be an acceptable enhancement to dhcpcd?

rsmarples commented 8 months ago

dhcpcd currently works on a one to one basis and reacts to the first OFFER/ADVERTISE it gets and then discards the others it receives while it's in the next phase.

What is your use case for this?

rmarioe commented 8 months ago

I want to get configuration data/vendor options of all servers into the hooks environment.

RFC2131 does not mandate this kind of behavior but does allow it:

  1. The client receives one or more DHCPOFFER messages from one or more servers. The client may choose to wait for multiple responses. The client chooses one server from which to request configuration parameters, based on the configuration parameters offered in the DHCPOFFER messages.

RFC8415:

Having all the info in the environment is enough for me.

If we would go the way of choosing the server in might be trickier.

We could restart the server until the client chooses the correct one in the existing algorithm? It is first come - first serve currently?

Another way could be for the client to wait for user input on what to choose if the client registered for this hook.

ColinMcInnes commented 3 weeks ago

I added some extra "run script" calls that trigger hooks whenever we receive or send a message such as DISCOVER, OFFER, etc. I use it to trigger some external state monitoring that is not part of the DHCP standard.

I don't currently have it wrapped up in any cli or conf optioning, but if I clean it up I could post a pull request.

rsmarples commented 3 weeks ago

fdeb8c7945211d424c3a30912004eeb56e009865 changes the behavior to be more RFC conformant. We now discard ADVERTs of a lower priority than what we have received until IRT has elapsed. If we get a priority of 255 then we use that right away. If we get a REPLY with rapid commit and we want a rapid commit we use that right away.

rsmarples commented 3 weeks ago

d4d3b115c1ec4755edb284eef5d31d28ae2c1846 exposes the preference option for hooks.