main/wpa_supplicant: refactor wpa_cli.sh

udhcpc doesn't have link beat detection and the purposes of this script
is making udhcpc acquire a new lease when connecting to an access point.

The previous version of this script achieved that goal by running
ifdown/ifup which is pretty ugly and never worked properly (at least
with my setup). A better solution for acquiring a DHCP lease when
connecting to a new AP is sending a SIGUSR1 signal to the udhcpc running
on the affected interfaces, this solution is implemented in this commit.

Together with the wpa_cli OpenRC service added in the previous commit
this makes using udhcpc on laptops very convenient.

See also: cc8f61f633
This commit is contained in:
Sören Tempel 2018-02-28 20:57:47 +01:00
parent ea4db75da4
commit 56826afa03
2 changed files with 23 additions and 16 deletions

View File

@ -2,7 +2,7 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=wpa_supplicant
pkgver=2.6
pkgrel=10
pkgrel=11
pkgdesc="A utility providing key negotiation for WPA wireless networks"
url="https://w1.fi/wpa_supplicant/"
arch="all"
@ -113,4 +113,4 @@ a0ac905ef23af18f1899a797e18157a54fa509c7cc3c59583de768a493d750876bbc0a89237373b6
e98edc1ecec91335d515c50cac8816e3f6eef139aba574bcf0c6c20c131ef0de40aa657a33d07af09ab28245471a09cb6b3e29b306e48f46d335a0c47a0a56c4 libressl.patch
2be055dd1f7da5a3d8e79c2f2c0220ddd31df309452da18f290144d2112d6dbde0fc633bb2ad02c386a39d7785323acaf5f70e5969995a1e8303a094eb5fe232 eloop.patch
6707991f9a071f2fcb09d164d31d12b1f52b91fbb5574b70b8d6f9727f72bbe42b03dd66d10fcc2126f5b7e49ac785657dec90e88b4bf54a9aa5638582f6e505 config
44d33cfe419cdb65cc14f2ac05aa9f8a1b9f2f432181e498071e41ef835662db1e4c5142adf4cfab2475e7b606696169936bd159d1d711f803322db93f242361 wpa_cli.sh"
212c4265afce2e72b95a32cd785612d6c3e821b47101ead154136d184ac4add01434ada6c87edbb9a98496552e76e1a4d79c6b5840e3a5cfe5e6d602fceae576 wpa_cli.sh"

View File

@ -1,33 +1,40 @@
#!/bin/sh
# Distributed under the terms of the BSD License.
# Copyright (c) 2015 Sören Tempel <soeren+alpine@soeren-tempel.net>
# Script for using udhcpc (started by ifup) with wpa_supplicant.
#
# Distributed under the same license as wpa_supplicant itself.
# Copyright (c) 2015,2018 Sören Tempel <soeren+alpine@soeren-tempel.net>
IFUP="/sbin/ifup"
IFDOWN="/sbin/ifdown"
if [ -z "${1}" -o -z "${2}" ]; then
if [ $# -ne 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 "${IFUP} or ${IFDOWN} doesn't exist"
exit 1
fi
IFNAME="${1}"
ACTION="${2}"
SIGNAL=""
DHCPID=""
EXEC=""
# PID file created by the busybox ifup applet for udhcpc.
DHCPIDFILE="/var/run/udhcpc.${IFNAME}.pid"
if [ ! -e "${DHCPIDFILE}" ]; then
logger -t wpa_cli "udhcpc isn't running for interface '${IFNAME}'"
exit 1
fi
logger -t wpa_cli "interface ${IFNAME} ${ACTION}"
case "${ACTION}" in
CONNECTED)
EXEC="${IFUP}"
SIGNAL="USR1"
;;
DISCONNECTED)
EXEC="${IFDOWN}"
SIGNAL="USR2"
;;
*)
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"
read -r DHCPID < "${DHCPIDFILE}"
kill -${SIGNAL} "${DHCPID}" || logger -t wpa_cli \
"Couldn't send '${SIGNAL}' to '${DHCPID}'"