dhcpcd-discuss

RE: Terminating 'dhcpcd' From a Hook Script

David Hauck

Thu Jun 15 15:45:55 2017

Hi Roy,
 
On Thursday, June 15, 2017 1:30 AM, Roy Marples wrote:
> 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

Hmmm, OK, thx. I'll have to investigate what "master mode" is exactly. We have a very specific usage/invocation of 'dhcpcd' in order to properly interface with our application. This involves interface-specific and protocol-specific invocations - typically the following 'dhcpcd -4|-6 <interface>'. As a result it isn't uncommon to have active invocations like the following:

dhcpcd -4 eth0
dhcpcd -6 etho
 
In my case I would only want to stop the former instance.

Where would I find more information regarding the various behaviours/effects of master mode?

Regards,
-David

PS: It seems like your new site doesn't have up to date links for the various man pages (there are indications that these are being "worked on"). Should I be using the versions in the v6.11.5 archive for the most up to date versions?

> 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 ScriptRoy Marples
References:
Terminating 'dhcpcd' From a Hook ScriptDavid Hauck
Re: Terminating 'dhcpcd' From a Hook ScriptRoy Marples
Archive administrator: postmaster@marples.name