Subject: [alpine-aports] [PATCH] main/wpa_supplicant: add wpa_cli(8) action script

From: Sören Tempel <[email-masked]>
Date: Sat, 5 Sep 2015 16:05:02 +0200

This action script manages the associated network interfaces. It start
them when wpa_supplicant successfully established a connection and it
stops them when wpa_supplicant disconnected from an access point.

When traveling between different location / networks / access points
with my laptop I noticed that udhcpc didn't automatically require a new
lease and had to be restarted each time I was associated with a new
access point. I had to manually invoke `ifdown <interface> && ifup
<interface>` each time I associated with a new access point.

Searching for solutions I looked at gentoo's netifrc[1] and noticed that
they are using a wpa_cli(8) action script[2] to solve this. I read the
gentoo action script[3] and decided to write a new action script for
alpine loosely based on gentoo's version. This is the result.

Maybe there is a better way to solve this problem if so I would to hear
about it. Otherwise I believe that this is the best approach to solve
it. It should also make it unnecessary to add the wpa_supplicant service
to the boot level since it doesn't need to be started before the
networking service anymore.

The action script has to be started manually using `wpa_cli -a
/etc/wpa_supplicant/wpa_cli.sh` currently. I couldn't decide how to
start it automatically. Gentoo starts it as a part of netifrc using
start-stop-daemon[4]. Maybe we should start it with the same options
from the wpa_supplicant OpenRC service?

[1]: https://gitweb.gentoo.org/proj/netifrc.git
[2]: https://gitweb.gentoo.org/proj/netifrc.git/tree/net/wpa_supplicant.sh#n54
[3]: https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/net-wireless/wpa_supplicant/files/wpa_cli.sh
[4]: https://gitweb.gentoo.org/proj/netifrc.git/tree/net/wpa_supplicant.sh#n164
---
 main/wpa_supplicant/APKBUILD   | 19 ++++++++++++++-----
 main/wpa_supplicant/wpa_cli.sh | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 5 deletions(-)
 create mode 100644 main/wpa_supplicant/wpa_cli.sh

diff --git a/main/wpa_supplicant/APKBUILD b/main/wpa_supplicant/APKBUILD
index d9d04b1..2e62b70 100644
--- a/main/wpa_supplicant/APKBUILD
+++ b/main/wpa_supplicant/APKBUILD
@@ -1,7 +1,8 @@
+# Contributor: Sören Tempel <[email-masked]>
 # Maintainer: Natanael Copa <[email-masked]>
 pkgname=wpa_supplicant
 pkgver=2.4
-pkgrel=2
+pkgrel=3
 pkgdesc="A utility providing key negotiation for WPA wireless networks"
 url="http://hostap.epitest.fi/wpa_supplicant"
 arch="all"
@@ -21,6 +22,8 @@ source="http://hostap.epitest.fi/releases/$pkgname-$pkgver.tar.gz
 
 	wpa_supplicant.initd
 	wpa_supplicant.confd
+
+	wpa_cli.sh
 	"
 
 _builddir="$srcdir"/$pkgname-$pkgver
@@ -125,7 +128,10 @@ package() {
 	cd "$_builddir"/wpa_supplicant
 	make DESTDIR="$pkgdir" LIBDIR=/lib BINDIR=/sbin install || return 1
 	install -Dm644 wpa_supplicant.conf \
-		"$pkgdir"/etc/wpa_supplicant/wpa_supplicant.conf
+		"$pkgdir"/etc/wpa_supplicant/wpa_supplicant.conf || return 1
+	install -Dm755 "$srcdir"/wpa_cli.sh \
+		"$pkgdir"/etc/wpa_supplicant/wpa_cli.sh || return 1
+
 	install -Dm644 doc/docbook/wpa_supplicant.conf.5 \
 		"$pkgdir"/usr/share/man/man5/wpa_supplicant.conf.5 || return 1
 	for i in wpa_background wpa_cli wpa_passphrase wpa_supplicant; do
@@ -170,7 +176,8 @@ fa2aed3cf49f7e6c7b17bf9db9a001f5  0003-EAP-pwd-peer-Fix-Total-Length-parsing-for
 de0fca4d74a1883d15ef5754f13a5226  0004-EAP-pwd-server-Fix-Total-Length-parsing-for-fragment.patch
 9d854969af23b207f9f3dff38ef78770  0005-EAP-pwd-peer-Fix-asymmetric-fragmentation-behavior.patch
 a8da41f58b8b4779d666ab7bd8233c18  wpa_supplicant.initd
-bc117427f2c538439f3f1481a028ee06  wpa_supplicant.confd"
+bc117427f2c538439f3f1481a028ee06  wpa_supplicant.confd
+cbdff360cf3f0f31d33027deb868e5f2  wpa_cli.sh"
 sha256sums="058dc832c096139a059e6df814080f50251a8d313c21b13364c54a1e70109122  wpa_supplicant-2.4.tar.gz
 a3abf75801f02199ff48c316a7b6598860e6ca20ce2fe79b0bec873905e5c8a4  CVE-2015-1863.patch
 eb63d845fdc38b6310c527ad1705b6fe3b74f90e263188da2aca97468cc55142  CVE-2015-4141.patch
@@ -181,7 +188,8 @@ a204bc37f52e5346780a306c01706689eb46263dedcdcb1eb2f4c0b291a0db93  0001-EAP-pwd-p
 c28ca6303a562809dfd1812f9b918808b3b0f0c52cc43070fd1777e1cfc88f18  0004-EAP-pwd-server-Fix-Total-Length-parsing-for-fragment.patch
 04ef66fbd5b2167274cd7123d7f7252963b9a9c1ec2f5edf6558a6ad92d47689  0005-EAP-pwd-peer-Fix-asymmetric-fragmentation-behavior.patch
 5d6ee43b7752d15013fb31298087e9d82caa2568064e59e6ed6230d7de403867  wpa_supplicant.initd
-61ec59007f66ac5bacc0aa095d1f2ccbc977a687038e161a463d1727223d5a90  wpa_supplicant.confd"
+61ec59007f66ac5bacc0aa095d1f2ccbc977a687038e161a463d1727223d5a90  wpa_supplicant.confd
+34c06cabfb9c7cf73fda64836971898424b4fcf2569bf21af628239093e8417e  wpa_cli.sh"
 sha512sums="03d8199325b3910f77013ddb7edd803ab4444542230484e1cb465dc3df9372b39ee3307d823ce88730e8f5a5231ef3183954c54cf07297b70432f526e45aac2b  wpa_supplicant-2.4.tar.gz
 61f90d06bd42fb7ea17ba147db861303f5b1fdce2cda35492cec578214da5ea5d654a1df99dee4d4a0c07ef3e8b3bfb65ab4b98eff21c2013adf536766136ce1  CVE-2015-1863.patch
 4633a96a91e151407e4c62b74b4e78d37e4fba586278c6ae4340ce149bee0c644a4d62675256839c3130374a4dc7531beaeed8282946e7dcd3faf1ed74bf99be  CVE-2015-4141.patch
@@ -192,4 +200,5 @@ dc561d90f3f329ebb201abbb53eea161603fb2abba6b2fc5c79298d97c84f2d65d401608cd7bb2fb
 b752f91c3d6dcf0784d9cb20a0c7f8de6c837c38ff62cf77b136d9b818890b13f55eeed1d6097f244181b480be953e1bdfb5651116dc5d62a2d02c018e19042a  0004-EAP-pwd-server-Fix-Total-Length-parsing-for-fragment.patch
 07a21f0cc7d00e17bed8ef5ced36159020a410a4606aa0ca24e47223835ab0cc5fbeed3075c4f17d2ce1aee437eedf9fea8f4b95252b2fa255d54a195637cb6f  0005-EAP-pwd-peer-Fix-asymmetric-fragmentation-behavior.patch
 cfe9de2813d5ec778c7f5cb404c23aad371dee9922dea172358a8ea95ab4e5dd01a3b9fc1a452dd3c3c9a2f02e8b12ffe162b69767f95faa18480fb79499301b  wpa_supplicant.initd
-29103161ec2b9631fca9e8d9a97fafd60ffac3fe78cf613b834395ddcaf8be1e253c22e060d7d9f9b974b2d7ce794caa932a2125e29f6494b75bce475f7b30e1  wpa_supplicant.confd"
+29103161ec2b9631fca9e8d9a97fafd60ffac3fe78cf613b834395ddcaf8be1e253c22e060d7d9f9b974b2d7ce794caa932a2125e29f6494b75bce475f7b30e1  wpa_supplicant.confd
+fa2688288c8f7882745e131f90f5ed6692c38c4fd9d0cd4082f3661bbf6fc09627c3d5005a9f4d00ac900753a8a28931079e5e17e2238bff33e1beff48774cfd  wpa_cli.sh"
diff --git a/main/wpa_supplicant/wpa_cli.sh b/main/wpa_supplicant/wpa_cli.sh
new file mode 100644
index 0000000..3c7325c
--- /dev/null
+++ b/main/wpa_supplicant/wpa_cli.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Distributed under the terms of the BSD License.
+# Copyright (c) 2015 Sören Tempel <[email-masked]>
+
+IFUP="/sbin/ifup"
+IFDOWN="/sbin/ifdown"
+
+if [ -z "${1}" -o -z "${2}" ]; then
+	logger -t wpa_cli "this script should be called from wpa_cli(8)"
+	exit 1
+elif ! [ -x "${IFUP}" -a -x "${IFDOWN}" ]; then
+	logger -t wpa_cli "/sbin/ifup or /sbin/ifdown doesn't exist"
+	exit 1
+fi
+
+IFNAME="${1}"
+ACTION="${2}"
+
+EXEC=""
+case "${ACTION}" in
+	CONNECTED)
+		EXEC="${IFUP}"
+		;;
+	DISCONNECTED)
+		EXEC="${IFDOWN}"
+		;;
+	*)
+		logger -t wpa_cli "unknown action '${ACTION}'"
+		exit 1
+esac
+
+logger -t wpa_cli "interface ${IFNAME} ${ACTION}"
+${EXEC} "${IFNAME}" || logger -t wpa_cli "executing '${EXEC}' failed"
-- 
2.5.1

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---