diff options
author | PÁLI Gábor János <pali.gabor@gmail.com> | 2022-02-28 23:27:06 +0100 |
---|---|---|
committer | PÁLI Gábor János <pali.gabor@gmail.com> | 2022-03-01 03:42:22 +0100 |
commit | 10753b412aa24bc476db7bc0179fdf05d48d1a51 (patch) | |
tree | 3d4cb3850c64cd03c2f6e9bbfd1205dc928c4959 /guest | |
parent | 4cda29a5b8f695a039d91d6e9d4c1fe7aa9cd55f (diff) | |
download | freebsd-wifibox-alpine-10753b412aa24bc476db7bc0179fdf05d48d1a51.zip |
Add support for WPA Supplicant pass-through.
Diffstat (limited to 'guest')
-rw-r--r-- | guest/etc/conf.d/wpa_supplicant | 3 | ||||
-rw-r--r-- | guest/etc/fstab | 9 | ||||
-rwxr-xr-x | guest/etc/init.d/wpa_passthru | 12 | ||||
l--------- | guest/etc/wpa_supplicant/wpa_supplicant.conf | 1 | ||||
-rwxr-xr-x | guest/sbin/wpa_passthru | 101 | ||||
-rw-r--r-- | guest/setup.sh | 2 |
6 files changed, 123 insertions, 5 deletions
diff --git a/guest/etc/conf.d/wpa_supplicant b/guest/etc/conf.d/wpa_supplicant new file mode 100644 index 0000000..d93fcef --- /dev/null +++ b/guest/etc/conf.d/wpa_supplicant @@ -0,0 +1,3 @@ +wpa_supplicant_args="" +wpa_supplicant_dbus=no +wpa_supplicant_conf=/media/wpa/wpa_supplicant.conf diff --git a/guest/etc/fstab b/guest/etc/fstab index c36a899..6fbca3c 100644 --- a/guest/etc/fstab +++ b/guest/etc/fstab @@ -1,4 +1,5 @@ -root / 9p trans=virtio,ro,noatime,nodiratime,norelatime 0 0 -tmpfs /tmp tmpfs size=1M 0 0 -config /media/etc 9p trans=virtio,ro,noatime,nodiratime,norelatime 0 0 -var /var 9p trans=virtio,rw 0 0 +root / 9p trans=virtio,ro,noatime,nodiratime,norelatime 0 0 +tmpfs /tmp tmpfs size=1M 0 0 +config /media/etc 9p trans=virtio,ro,noatime,nodiratime,norelatime 0 0 +wpa_config /media/wpa 9p trans=virtio,rw 0 0 +var /var 9p trans=virtio,rw 0 0 diff --git a/guest/etc/init.d/wpa_passthru b/guest/etc/init.d/wpa_passthru new file mode 100755 index 0000000..d7c5c07 --- /dev/null +++ b/guest/etc/init.d/wpa_passthru @@ -0,0 +1,12 @@ +#!/sbin/openrc-run + +supervisor=supervise-daemon +name="WPA Supplicant pass-through" +description="Control socket pass-through support for WPA Supplicant" + +command=/sbin/wpa_passthru +command_background=true + +depend() { + need wpa_supplicant +} diff --git a/guest/etc/wpa_supplicant/wpa_supplicant.conf b/guest/etc/wpa_supplicant/wpa_supplicant.conf deleted file mode 120000 index b5c7213..0000000 --- a/guest/etc/wpa_supplicant/wpa_supplicant.conf +++ /dev/null @@ -1 +0,0 @@ -/media/etc/wpa_supplicant.conf
\ No newline at end of file diff --git a/guest/sbin/wpa_passthru b/guest/sbin/wpa_passthru new file mode 100755 index 0000000..4e95d2f --- /dev/null +++ b/guest/sbin/wpa_passthru @@ -0,0 +1,101 @@ +#!/bin/sh +# shellcheck disable=SC2034,SC3043,SC3060 + +log() { + local _level="$1" + local _message="$2" + + /usr/bin/logger -p "daemon.${_level}" -t "wpa_passthru[$$]" "${_message}" +} + +enabled=no + +# shellcheck disable=SC1091 +. /media/etc/wpa_ctrl.conf + +_wlan_devs=$(set | /bin/grep -F "_port=" | /bin/sed 's!_port=.*!!') +log debug "Configuration: enabled=${enabled}, network=${network}, wlan devs=[${_wlan_devs}]" + +if [ "${enabled}" = "no" ]; then + log info "Not enabled, exiting." + exit 0 +fi + +if_lan=eth0 +wpa_conf="/media/wpa/wpa_supplicant.conf" + +cleanup() { + local _socats + + _socats=$(/usr/bin/pgrep socat) + log info "Stopping, socat processes: [${_socats}]" + [ -n "${_socats}" ] \ + && /usr/bin/kill -TERM ${_socats} + [ -n "${_socket_directory}" ] \ + && /bin/rm -rf "${_socket_directory}" +} + +trap cleanup EXIT TERM + +find_network() { + /sbin/ifconfig ${if_lan} \ + | /bin/grep -F "inet addr:" \ + | /bin/sed -E 's!.*inet addr:([0-9\.]+).*Mask:([0-9\.]+)!\1:\2!' +} + +get_ctrl_interface() { + /bin/grep "^ctrl_interface=" "${wpa_conf}" \ + | /bin/sed 's!^ctrl_interface=!!' +} + +if [ -z "${network}" ]; then + if ! /sbin/ifconfig ${if_lan}; then + log error "Interface ${if_lan} not found, exiting." + exit 1 + fi + + network=$(find_network) +fi + +_ip=${network%%:*} + +if [ -z "${_ip}" ]; then + log error "No IP address for ${if_lan} could found, exiting." + exit 1 +fi + +_ctrl_interface=$(get_ctrl_interface) + +if [ -z "${_ctrl_interface}" ]; then + log warn "No control interface found, exiting." + exit 0 +fi + +_socket_directory=$(/bin/mktemp -d) + +for _wlan_dev in ${_wlan_devs}; do + _wlan=${_wlan_dev//_/-} + _ctrl_socket="${_ctrl_interface}/${_wlan}" + + if [ ! -S "${_ctrl_socket}" ]; then + log warn "${_ctrl_socket} is not available, skipping." + continue + fi + + _socket="${_socket_directory}/${_wlan}" + _port=$(eval "echo \${${_wlan_dev}_port}") + + if [ -z "${_port}" ]; then + log warn "No port defined for ${_wlan}, skipping." + continue + fi + + log info "Associating ${_ip}:${_port} (${network}) with ${_ctrl_socket} (${_socket})" + /usr/bin/socat \ + TCP4-LISTEN:"${_port}",reuseaddr,bind="${_ip}",range="${network}",fork \ + UNIX-SENDTO:"${_ctrl_socket}",bind="${_socket}",unlink-early & +done + +while /bin/true; do + /bin/sleep 60 +done diff --git a/guest/setup.sh b/guest/setup.sh index 51784b6..28ee0a1 100644 --- a/guest/setup.sh +++ b/guest/setup.sh @@ -24,4 +24,6 @@ rc-update add sysctl boot rc-update add syslog boot rc-update add udhcpd default rc-update add wpa_supplicant boot +rc-update add wpa_passthru boot mkdir -p /media/etc +mkdir -p /media/wpa |