From 679ae2bb8fbaca8f398af5639a39bc7b9cc0f263 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 17 Aug 2020 21:52:06 +0200 Subject: network: add basic support for wpa_supplicant This adds wpa_ssid and wpa_psk on each interface to load wpa_supplicant and enable clear or WPA communications on the interface. Only wireless interfaces are supported. --- sbin/init.d/network | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/sbin/init.d/network b/sbin/init.d/network index bd72f0f..57f2adf 100755 --- a/sbin/init.d/network +++ b/sbin/init.d/network @@ -19,6 +19,8 @@ # ip route <-|gw> [ip args...] # ip6 route <-|gwv6> [ip args...] # vrrp ... (ignored by this script) +# wpa_ssid +# wpa_psk # we want ALL instances to stop and restart at once if [ "$1" = "restart" ]; then @@ -65,6 +67,8 @@ option shutdown boolean_option option vrrp multiple_option option load multiple_option option unload multiple_option +option wpa_ssid standard_option +option wpa_psk standard_option option autoconf_script standard_option /usr/libexec/ipautoconfig SVC_VARS="addr_list addr6_list route_list route6_list arp_list addr_idx addr6_idx route_idx route6_idx arp_idx ipautoconf" @@ -88,6 +92,7 @@ function do_help { echo " - lladdr ; replace " echo " - mtu ; arp {on|off} ; multicast {on|off} ; shutdown" echo " - vrrp " + echo " - wpa_ssid ; wpa_psk " echo exit 1 } @@ -597,6 +602,25 @@ function do_start { done fi + if [ -e "/sys/class/net/$instname/wireless" -a -n "${opt_wpa_ssid}" ] ; then + echo " Configuring WPA supplicant." + rm -f "/var/run/wpa_supplicant-$instname.conf" + ( + echo "network={" + echo " ssid=\"${opt_wpa_ssid}\"" + echo " scan_ssid=1" + if [ -n "${opt_wpa_psk}" ]; then + echo " key_mgmt=WPA-PSK" + echo " proto=WPA" + echo " psk=\"${opt_wpa_psk}\"" + else + echo " key_mgmt=NONE" + fi + echo "}" + ) > "/var/run/wpa_supplicant-${instname}.conf" + /usr/sbin/wpa_supplicant -B -i"${instname}" -c"/var/run/wpa_supplicant-${instname}.conf" -P"/var/run/wpa_supplicant-${instname}.pid" + fi + if [ -n "$ipautoconf" ] ; then echo " Autoconfiguring using DHCP request." if [ -z "${opt_autoconf_script}" -o ! -e "${opt_autoconf_script}" ] ; then @@ -764,6 +788,12 @@ function do_stop { arg=$[$arg+1] done + if [ -e "/var/run/wpa_supplicant-${instname}.pid" ]; then + kill $(cat "/var/run/wpa_supplicant-${instname}.pid") + rm -f "/var/run/wpa_supplicant-${instname}.pid" + fi + rm -f "/var/run/wpa_supplicant-${instname}.conf" + ip link set $instname down >/dev/null 2>&1 ip addr flush dev $instname >/dev/null 2>&1 -- 2.28.0