How to run a helper script on state changes?

Denys Vlasenko vda.linux at googlemail.com
Fri Feb 7 09:55:12 EST 2014


Hi,

I want to run a script every time wpa_supplicant detects
a change in association state.
In particular, I want to restart DHCP client,
since my home wifi is not using the same IP as my work wifi.
Currently, wpa_supplicant happily drops old association and
acquires new one... but DHCP client is blissfully unaware
that it needs to restart, and I am stuck with wrong IP
until I manually restart DHCP client.

Many other network daemon have such functionality:
pppd, openvpn, udhcpc.

I read "man wpa_supplicant" and "man wpa_supplicant.conf"
and I don't see such functionality mentioned anywhere.
Did I miss it?


As an example, udhcpc executes a specified script
with the following $1 and some environment variables:

deconfig: udhcpc starts, or lease is lost.
Environment example: interface=eth0

bound: lease is obtained. Environment example:
dhcptype=5
serverid=172.16.42.102
lease=97200
interface=eth0
ip=172.16.42.177
subnet=255.255.255.0
mask=24
broadcast=172.16.22.255
router=172.16.42.98
dns=10.34.32.125 10.32.63.5 10.34.255.7 10.11.255.27
domain=lab.example.com example.com
ntpsrv=10.34.32.125 10.34.255.7

renew: lease is renewed. Environment is similar to "bound".
The IP address does not not change, however, the other DHCP paramaters,
such as the default gateway, subnet mask, and dns server may change.

nak: udhcpc received a NAK message.
Environment example: interface=eth0

leasefail: udhcpc cannot obtain a lease (DHCP server not responding, etc).
Environment example: interface=eth0


More information about the HostAP mailing list