From: Roy Marples Date: Fri, 7 Jun 2013 20:03:28 +0000 (+0000) Subject: Add a wpa_supplicant hook script. X-Git-Tag: v6.0.0~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f127375eee85b4091ce0e6ae4b6797e709b7130d;p=thirdparty%2Fdhcpcd.git Add a wpa_supplicant hook script. This script starts wpa_supplicant on a wireless interface if not already running and /etc/wpa_supplicant.conf exists, stops it when the interface departs and sends wpa_supplicant a reconfigure command. If dhcpcd is running in master mode, you can use `dhcpcd -n eth0' it instruct wpa_supplicant to reload its configuration file. --- diff --git a/README b/README index 2ef4c9b3..467107cf 100644 --- a/README +++ b/README @@ -54,8 +54,8 @@ the binary has to run on older versions which lack support, such as getline. Hooks ----- Not all the hooks in dhcpcd-hooks are installed by default. -By default we install 01-test, 10-mtu, 20-resolv.conf, -29-lookup-hostname and 30-hostname. +By default we install 01-test, 02-dump, 10-mtu, 10-wpa_supplicant, +15-timezone, 20-resolv.conf, 29-lookup-hostname and 30-hostname. The default dhcpcd.conf disables the lookup-hostname hook by default. The configure program attempts to find hooks for systems you have installed. To add more simply diff --git a/dhcpcd-hooks/10-wpa_supplicant b/dhcpcd-hooks/10-wpa_supplicant new file mode 100644 index 00000000..18c889f2 --- /dev/null +++ b/dhcpcd-hooks/10-wpa_supplicant @@ -0,0 +1,63 @@ +# Start and stop wpa_supplicant per wireless interface. +# This is needed because wpa_supplicant lacks hotplugging of any kind +# and the user should not be expected to have to wire it into their system +# if the base system doesn't do this itself. + +: ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf} + +wpa_supplicant_start() +{ + local err errn + + wpa_cli -i "$interface" status >/dev/null 2>&1 && return 0 + syslog info "starting wpa_supplicant" + err=$(wpa_supplicant -B -c"$wpa_supplicant_conf" -i"$interface" 2>&1) + errn=$? + if [ $errn != 0 ]; then + syslog err "failed to start wpa_supplicant" + syslog err "$err" + fi + return $errn +} + +wpa_supplicant_reconfigure() +{ + local err errn + + wpa_cli -i "$interface" status >/dev/null 2>&1 || return 0 + syslog info "reconfiguring wpa_supplicant" + err=$(wpa_cli -i"$interface" reconfigure 2>&1) + errn=$? + if [ $errn != 0 ]; then + syslog err "failed to reconfigure wpa_supplicant" + syslog err "$err" + fi + return $errn +} + +wpa_supplicant_stop() +{ + local err errn + + wpa_cli -i "$interface" status >/dev/null 2>&1 || return 0 + syslog info "stopping wpa_supplicant" + err=$(wpa_cli -i"$interface" terminate 2>&1) + errn=$? + if [ $errn != 0 ]; then + syslog err "failed to start wpa_supplicant" + syslog err "$err" + fi + return $errn +} + + +if [ "$ifwireless" = "1" -a -s "$wpa_supplicant_conf" ] && \ + type wpa_supplicant >/dev/null 2>&1 && \ + type wpa_cli >/dev/null 2>&1 +then + case "$reason" in + PREINIT) wpa_supplicant_start;; + RECONFIGURE) wpa_supplicant_reconfigure;; + DEPARTED) wpa_supplicant_stop;; + esac +fi diff --git a/dhcpcd-hooks/Makefile b/dhcpcd-hooks/Makefile index acd1c182..cf215c8a 100644 --- a/dhcpcd-hooks/Makefile +++ b/dhcpcd-hooks/Makefile @@ -4,7 +4,7 @@ include ${TOP}/config.mk SCRIPTSDIR= ${LIBEXECDIR}/dhcpcd-hooks SCRIPTS= 01-test 02-dump -SCRIPTS+= 10-mtu 15-timezone 20-resolv.conf +SCRIPTS+= 10-mtu 10-wpa_supplicant 15-timezone 20-resolv.conf SCRIPTS+= 29-lookup-hostname 30-hostname SCRIPTS+= ${HOOKSCRIPTS} diff --git a/dhcpcd-run-hooks.8.in b/dhcpcd-run-hooks.8.in index c8aca105..8d1b7464 100644 --- a/dhcpcd-run-hooks.8.in +++ b/dhcpcd-run-hooks.8.in @@ -75,8 +75,6 @@ dhcpcd is starting up and any pre-initialisation should be done. .It Dv CARRIER dhcpcd has detected the carrier is up. This is generally just a notification and no action need be taken. -.It Dv DEPARTED -The interface has been removed. .It Dv INFORM | Dv INFORM6 dhcpcd informed a DHCP server about it's address and obtained other configuration details. @@ -102,6 +100,8 @@ dhcpcd's lease or state expired and it failed to obtain a new one. .It Dv NAK dhcpcd received a NAK from the DHCP server. This should be treated as EXPIRE. +.It Dv RECONFIGURE +dhcpcd has been instructed to reconfigure an interface. .It Dv NOCARRIER dhcpcd lost the carrier. The cable may have been unplugged or association to the wireless point lost. @@ -112,6 +112,8 @@ means it cannot work as a DHCP or ZeroConf client. Static configuration and DHCP INFORM is still allowed. .It Dv STOP | Dv STOP6 dhcpcd stopped running on the interface. +.It Dv DEPARTED +The interface has been removed. .It Dv DUMP dhcpcd has been asked to dump the last lease for the interface. .It Dv TEST diff --git a/dhcpcd.8.in b/dhcpcd.8.in index 3bfec7a7..355277d1 100644 --- a/dhcpcd.8.in +++ b/dhcpcd.8.in @@ -171,7 +171,7 @@ changes the routes to use the interface with the same route and the lowest metric. See options below for controlling which interfaces we allow and deny through the use of patterns. -.Ss Hooking into DHCP events +.Ss Hooking into events .Nm runs .Pa @SCRIPT@ , @@ -184,6 +184,8 @@ in a lexical order. The default installation supplies the scripts .Pa 01-test , .Pa 10-mtu , +.Pa 10-wpa_supplicant , +.Pa 15-timezone , .Pa 20-resolv.conf and .Pa 30-hostname . diff --git a/dhcpcd.c b/dhcpcd.c index 25e98072..f9d53a7f 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -617,6 +617,7 @@ if_reboot(struct interface *ifp, int argc, char **argv) int oldopts; oldopts = ifp->options->options; + script_runreason(ifp, "RECONFIGURE"); configure_interface(ifp, argc, argv); dhcp_reboot_newopts(ifp, oldopts); dhcp6_reboot(ifp);