dhcpcd-discuss

Re: Terminating 'dhcpcd' From a Hook Script

Roy Marples

Thu Jun 15 08:29:51 2017

Hi David

On 14/06/2017 23:55, David Hauck wrote:
> I've been trying to determine whether there's a way to terminate the running dhcpcd process from a hook script :). Yes, scary, I know. However I'm running into a bit of a predicament. When our targets (running 'dhcpcd') recognize a specific vendor option in the response to the initial DISCOVER sequence it performs some network related configuration. Specifically, it changes the OS network configuration file (/etc/network/interfaces) to include the static addressing information received along with the vendor option. It thereby effectively switches out of DHCP mode and into a static configuration. This is done in the hook script as part of the BOUND reason. The idea here is that DHCP with this vendor option can be use as a one-shot network configuration sequence (negotiate with DHCP once and transition to a static OSL configuration with the negotiated DHCP addressing information).
> 
> The problem currently is that 'dhcpcd' continues to run in this case [ and now even though the OS's configuration indicates a static configuration]. This can cause problems since 'dhcpcd' is still running at this point and it may get triggered for any number of reasons (CARRIER lost, lease timed out, etc.). Each of these events becomes insignificant once the hook script has transitioned the OS configuration (from DHCP) to the static addressing configuration. So I'd like to prevent 'dhcpcd' from running.
> 
> I happen to know that the BOUND event is a terminating event in the 'dhcpcd' state machine. In this case, once the hook scripts complete, 'dhcpcd' is daemonized. Is there any way to signal back from the hook scripts (via exit codes) in order to prevent this daemonization and to also not stop the interface the 'dhcpcd' instance is currently operating on? I mention this last part because I thought I could send a signal to the process to stop it, and I can, however, these signals seem to always result in a call to "stop_all_interfaces", which ends up de-configuring the interface (I'd like to prevent this).

I have an open ticket for this kind of special configuration here:
https://dev.marples.name/T116

However, this still possible by taking advantage of Master Mode!
In Master Mode, dhcpcd will control all interfaces and allow remote
control for stopping/starting each interface. Just add the word master
on a line by itself in the global section of dhcpcd.conf

Then, in the hook script you can do this to stop dhcpcd running on an
interface:

dhcpcd -x "$interface"

Restart dhcpcd

dhcpcd -n "$interface"

> PS: I'm currently using v6.11.5.

It should still work .....

Roy

Follow-Ups:
RE: Terminating 'dhcpcd' From a Hook ScriptDavid Hauck
References:
Terminating 'dhcpcd' From a Hook ScriptDavid Hauck
Archive administrator: postmaster@marples.name