diff options
author | PÁLI Gábor János <pali.gabor@gmail.com> | 2022-05-28 12:44:37 +0200 |
---|---|---|
committer | PÁLI Gábor János <pali.gabor@gmail.com> | 2022-05-31 22:02:42 +0200 |
commit | 97c67abab07a57840f95d04fadbd13b3c0f5b328 (patch) | |
tree | cdd484a2af71b89ff7a75c5eb808e6e18f00801d /aports/uds_passthru | |
parent | a6085330a18c8a257d2e185aab016c483335f86a (diff) | |
download | freebsd-wifibox-alpine-97c67abab07a57840f95d04fadbd13b3c0f5b328.zip |
Incorporate `hostapd`.
The inclusion of `hostapd` [1] brings a lot of related changes
because the build process have to extended to take the challenge.
- Convert `wpa_passthru` to a more a generic services, called
`uds_passthru` to deal with the control socket forwarding.
It can also log the `socat` errors properly.
- Make the `Makefile` more parametric therefore the virtual disk
image can be customized better.
- Default configurations are now moved fully to the guest's side.
- Tweak the packages to be more flexible.
- Document everything.
[1] https://w1.fi/hostapd/
Diffstat (limited to 'aports/uds_passthru')
-rw-r--r-- | aports/uds_passthru/APKBUILD | 26 | ||||
-rw-r--r-- | aports/uds_passthru/uds_passthru | 114 | ||||
-rw-r--r-- | aports/uds_passthru/uds_passthru.initd | 13 |
3 files changed, 153 insertions, 0 deletions
diff --git a/aports/uds_passthru/APKBUILD b/aports/uds_passthru/APKBUILD new file mode 100644 index 0000000..41cfa4d --- /dev/null +++ b/aports/uds_passthru/APKBUILD @@ -0,0 +1,26 @@ +# Maintainer: Gabor Pali <pali.gabor@gmail.com> + +pkgname=uds_passthru +pkgver=0.1.0 +pkgrel=0 +pkgdesc="Unix Domain Socket pass-through for Wifibox" +url="https://github.com/pgj/freebsd-wifibox-alpine" +arch="all" +license="BSD2" +depends="socat" +install="" +subpackages= +options="!check" +arch="noarch" +source="uds_passthru.initd + uds_passthru +" + +package() { + install -D -m755 "$srcdir"/uds_passthru.initd "$pkgdir"/etc/init.d/uds_passthru + install -D -m755 "$srcdir"/uds_passthru "$pkgdir"/sbin/uds_passthru +} +sha512sums=" +efb66ffbfde79321b534c8427bbb77bbb298175fb30be8c79f21e091ed3b942d8260020996e15d62ada60de778d38d5352f4f323bd7023672b4b778e4ef1318f uds_passthru.initd +bc83be88e395dd73d1ba5e65d23dde045918b763b1562b3ebd17beb35e3599ca44f78dd6a732815fd6aecb0e6f8ae97ea70ef359620bf14c9ffbe88c5005ad00 uds_passthru +" diff --git a/aports/uds_passthru/uds_passthru b/aports/uds_passthru/uds_passthru new file mode 100644 index 0000000..95e0931 --- /dev/null +++ b/aports/uds_passthru/uds_passthru @@ -0,0 +1,114 @@ +#!/bin/sh +# shellcheck disable=SC2034,SC3043,SC3060 + +log() { + local _level="$1" + local _message="$2" + + /usr/bin/logger -p "daemon.${_level}" -t "uds_passthru[$$]" "${_message}" +} + +capture_output() { + local _type="$1" + local _id="$2" + + while read -r message; do + log "${_type}" "[${_id}] ${message}" + done +} + +_block= +sockets= +network= + +# shellcheck disable=SC1091 +. /media/etc/uds_passthru.conf + +log debug "Configuration: network=${network}, sockets=[${sockets}]" + +if_lan=eth0 + +terminate() { + local _sleep + + if [ -n "${_block}" ]; then + log info "Received signal for termination, stopping PID ${_block}." + /bin/kill -KILL "${_block}" + log debug "Killed: $?" + _sleep=$(/bin/ps -o ppid,comm,pid \ + | /bin/grep -F "1 sleep" \ + | /usr/bin/head -1 \ + | /bin/sed "s@[ ]*1[ ]*sleep[ ]*@@") + log info "Stopping the orphaned sleep as PID ${_sleep}." + /bin/kill -KILL "${_sleep}" + log debug "Killed: $?" + else + log warn "Nothing is blocked, nothing to do." + fi +} + +trap terminate 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!' +} + +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 + +_socket_directory=$(/bin/mktemp -d) + +for s in ${sockets}; do + _path="${s##*path=}" + _path="${_path%%,*}" + + if [ ! -S "${_path}" ]; then + log warn "${_path} is not available, skipping." + continue + fi + + _socket=$(/bin/mktemp -up "${_socket_directory}") + _port="${s##*port=}" + _port="${_port%%,*}" + + if [ -z "${_port}" ]; then + log warn "No port defined for ${_path}, skipping." + continue + fi + + log info "Associating ${_ip}:${_port} (${network}) with ${_path} (${_socket})" + /usr/bin/socat \ + TCP4-LISTEN:"${_port}",reuseaddr,bind="${_ip}",range="${network}",fork \ + UNIX-SENDTO:"${_path}",bind="${_socket}",unlink-early 2>&1 \ + | capture_output debug socat & +done + +(while /bin/true; do /bin/sleep 365d; done) & +_block=$! + +log info "Waiting for PID ${_block} to stop." +wait "${_block}" + +_socats=$(/usr/bin/pgrep socat) +log info "Stopping, socat processes: [${_socats}]" + +# shellcheck disable=SC2086 +[ -n "${_socats}" ] && /bin/kill -TERM ${_socats} +[ -n "${_socket_directory}" ] && /bin/rm -rf "${_socket_directory}" + +log info "Finished." diff --git a/aports/uds_passthru/uds_passthru.initd b/aports/uds_passthru/uds_passthru.initd new file mode 100644 index 0000000..67f7698 --- /dev/null +++ b/aports/uds_passthru/uds_passthru.initd @@ -0,0 +1,13 @@ +#!/sbin/openrc-run + +supervisor=supervise-daemon +name="Unix Domain Socket pass-through" +description="Unix Domain Socket pass-through support" + +command=/sbin/uds_passthru +command_background=true + +depend() { + need net + after firewall +} |