Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Port to Alpine #332

Merged
merged 5 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ install:
install -Dm755 create_ap $(DESTDIR)$(BINDIR)/create_ap
install -Dm644 create_ap.conf $(DESTDIR)/etc/create_ap.conf
[ ! -d /lib/systemd/system ] || install -Dm644 create_ap.service $(DESTDIR)$(PREFIX)/lib/systemd/system/create_ap.service
[ ! -e /sbin/openrc-run ] || install -Dm755 create_ap.openrc $(DESTDIR)/etc/init.d/create_ap
install -Dm644 bash_completion $(DESTDIR)$(PREFIX)/share/bash-completion/completions/create_ap
install -Dm644 README.md $(DESTDIR)$(PREFIX)/share/doc/create_ap/README.md

uninstall:
rm -f $(DESTDIR)$(BINDIR)/create_ap
rm -f $(DESTDIR)/etc/create_ap.conf
[ ! -f /lib/systemd/system/create_ap.service ] || rm -f $(DESTDIR)$(PREFIX)/lib/systemd/system/create_ap.service
[ ! -e /sbin/openrc-run ] || rm -f $(DESTDIR)/etc/init.d/create_ap
rm -f $(DESTDIR)$(PREFIX)/share/bash-completion/completions/create_ap
rm -f $(DESTDIR)$(PREFIX)/share/doc/create_ap/README.md
51 changes: 43 additions & 8 deletions create_ap
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ usage() {
echo " --mac <MAC> Set MAC address"
echo " --dhcp-dns <IP1[,IP2]> Set DNS returned by DHCP"
echo " --daemon Run create_ap in the background"
echo " --pidfile <pidfile> Save daemon PID to file"
echo " --logfile <logfile> Save daemon messages to file"
echo " --stop <id> Send stop command to an already running create_ap. For an <id>"
echo " you can put the PID of create_ap or the WiFi interface. You can"
echo " get them with --list-running"
Expand Down Expand Up @@ -101,6 +103,17 @@ usage() {
echo " "$PROGNAME" --stop wlan0"
}

# Busybox polyfills
if cp --help 2>&1 | grep -q -- --no-clobber; then
cp_n() {
cp -n "$@"
}
else
cp_n() {
yes n | cp -i "$@"
}
fi

# on success it echos a non-zero unused FD
# on error it echos 0
get_avail_fd() {
Expand Down Expand Up @@ -628,6 +641,8 @@ COUNTRY=
FREQ_BAND=2.4
NEW_MACADDR=
DAEMONIZE=0
DAEMON_PIDFILE=
DAEMON_LOGFILE=/dev/null
NO_HAVEGED=0
USE_PSK=0

Expand All @@ -636,7 +651,7 @@ REDIRECT_TO_LOCALHOST=0

CONFIG_OPTS=(CHANNEL GATEWAY WPA_VERSION ETC_HOSTS DHCP_DNS NO_DNS NO_DNSMASQ HIDDEN MAC_FILTER MAC_FILTER_ACCEPT ISOLATE_CLIENTS
SHARE_METHOD IEEE80211N IEEE80211AC HT_CAPAB VHT_CAPAB DRIVER NO_VIRT COUNTRY FREQ_BAND
NEW_MACADDR DAEMONIZE NO_HAVEGED WIFI_IFACE INTERNET_IFACE
NEW_MACADDR DAEMONIZE DAEMON_PIDFILE DAEMON_LOGFILE NO_HAVEGED WIFI_IFACE INTERNET_IFACE
SSID PASSPHRASE USE_PSK)

FIX_UNMANAGED=0
Expand Down Expand Up @@ -790,6 +805,10 @@ _cleanup() {

mutex_unlock
cleanup_lock

if [[ $RUNNING_AS_DAEMON -eq 1 && -n "$DAEMON_PIDFILE" && -f "$DAEMON_PIDFILE" ]]; then
rm $DAEMON_PIDFILE
fi
}

cleanup() {
Expand Down Expand Up @@ -1028,7 +1047,7 @@ for ((i=0; i<$#; i++)); do
fi
done

GETOPT_ARGS=$(getopt -o hc:w:g:de:nm: -l "help","hidden","hostapd-debug:","redirect-to-localhost","mac-filter","mac-filter-accept:","isolate-clients","ieee80211n","ieee80211ac","ht_capab:","vht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","dhcp-dns:","daemon","stop:","list","list-running","list-clients:","version","psk","no-haveged","no-dns","no-dnsmasq","mkconfig:","config:" -n "$PROGNAME" -- "$@")
GETOPT_ARGS=$(getopt -o hc:w:g:de:nm: -l "help","hidden","hostapd-debug:","redirect-to-localhost","mac-filter","mac-filter-accept:","isolate-clients","ieee80211n","ieee80211ac","ht_capab:","vht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","dhcp-dns:","daemon","pidfile:","logfile:","stop:","list","list-running","list-clients:","version","psk","no-haveged","no-dns","no-dnsmasq","mkconfig:","config:" -n "$PROGNAME" -- "$@")
[[ $? -ne 0 ]] && exit 1
eval set -- "$GETOPT_ARGS"

Expand Down Expand Up @@ -1148,6 +1167,16 @@ while :; do
shift
DAEMONIZE=1
;;
--pidfile)
shift
DAEMON_PIDFILE="$1"
shift
;;
--logfile)
shift
DAEMON_LOGFILE="$1"
shift
;;
--stop)
shift
STOP_ID="$1"
Expand Down Expand Up @@ -1285,10 +1314,16 @@ if [[ $FIX_UNMANAGED -eq 1 ]]; then
fi

if [[ $DAEMONIZE -eq 1 && $RUNNING_AS_DAEMON -eq 0 ]]; then
echo "Running as Daemon..."
# Assume we're running underneath a service manager if PIDFILE is set
# and don't clobber it's output with a useless message
if [ -z "$DAEMON_PIDFILE" ]; then
echo "Running as Daemon..."
fi
# run a detached create_ap
RUNNING_AS_DAEMON=1 setsid "$0" "${ARGS[@]}" &
RUNNING_AS_DAEMON=1 setsid "$0" "${ARGS[@]}" >>$DAEMON_LOGFILE 2>&1 &
exit 0
elif [[ $RUNNING_AS_DAEMON -eq 1 && -n "$DAEMON_PIDFILE" ]]; then
echo $$ >$DAEMON_PIDFILE
fi

if [[ $FREQ_BAND != 2.4 && $FREQ_BAND != 5 ]]; then
Expand Down Expand Up @@ -1494,12 +1529,12 @@ mkdir -p $COMMON_CONFDIR

if [[ "$SHARE_METHOD" == "nat" ]]; then
echo $INTERNET_IFACE > $CONFDIR/nat_internet_iface
cp -n /proc/sys/net/ipv4/conf/$INTERNET_IFACE/forwarding \
cp_n /proc/sys/net/ipv4/conf/$INTERNET_IFACE/forwarding \
$COMMON_CONFDIR/${INTERNET_IFACE}_forwarding
fi
cp -n /proc/sys/net/ipv4/ip_forward $COMMON_CONFDIR
cp_n /proc/sys/net/ipv4/ip_forward $COMMON_CONFDIR
if [[ -e /proc/sys/net/bridge/bridge-nf-call-iptables ]]; then
cp -n /proc/sys/net/bridge/bridge-nf-call-iptables $COMMON_CONFDIR
cp_n /proc/sys/net/bridge/bridge-nf-call-iptables $COMMON_CONFDIR
fi
mutex_unlock

Expand Down Expand Up @@ -1757,7 +1792,7 @@ if [[ "$SHARE_METHOD" != "none" ]]; then
ip link add name $BRIDGE_IFACE type bridge || die
ip link set dev $BRIDGE_IFACE up || die
# set 0ms forward delay
echo 0 > /sys/class/net/$BRIDGE_IFACE/bridge/forward_delay
echo -n 0 > /sys/class/net/$BRIDGE_IFACE/bridge/forward_delay

# attach internet interface to bridge interface
ip link set dev $INTERNET_IFACE promisc on || die
Expand Down
11 changes: 11 additions & 0 deletions create_ap.openrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/sbin/openrc-run

name=$RC_SVCNAME

cfgfile=/etc/$RC_SVCNAME.conf
pidfile=/run/$RC_SVCNAME.pid

command=/usr/bin/create_ap
command_args="--config $cfgfile"
command_args_background="--daemon --pidfile $pidfile"
stopsig=USR1