Re: Triggering action on connection change using hooks
Roy Marples
Sun May 05 13:44:27 2019
Hi Reto
On 05/05/2019 13:28, Reto Schneider wrote:
I would like to get my embedded device to check for updates whenever its
connectivity got changed (and the interface is up). For example, after
the user has plugged in the Ethernet cable or the WLAN came up and an IP
address and default gateway got assigned.
Looking at $reason in dhcpcd-run-hook it seems to me that BOUND and
BOUND6 is what I want to use for DHCP/DHCPv6 networks. However, only for
IPv4 networks I can be (quite) sure that DHCP gets used. Not for IPv6 ones.
It seems to me that I also have to trigger on ROUTERADVERT. However, my
hook gets called every time my device receives a router advertisement
and I do not know how to figure out if actually anything of relevance
has changed regarding the networking topology.
CARRIER together with a big-ish delay before starting the update would
likely work, but is quite hackish.
Is it possible to do achieve my obviously non-DHCP related goal using
dhcpcd? If so, how?
Most simple test
cat /etc/dhcpcd.exit-hook
if $if_up || [ "$reason" = ROUTERADVERT ]; then
do_your_update()
fi
Now that will fire whenever dhcpcd gets as valid lease or a router
advertisement.
That might be far too frequent for your needs.
Antyhing *of relevance* that has changed could mean many things - for
example has the hardware address of the default router changed? Are we
running on wireless or wired?
I think the easiest solution would be to pull for an update via a cron job.
Roy
Archive administrator: postmaster@marples.name