From 0d5b50c4bf16cbb6acbb680b8a72a2b0ae2b917d Mon Sep 17 00:00:00 2001 From: Carey Sonsino Date: Wed, 13 Nov 2019 13:05:47 -0500 Subject: [PATCH] dcwapd: Update init script to use procd consolidate shell scripts into init script remove "litter" from uci file update default UCI values Signed-off-by: Carey Sonsino Signed-off-by: Carey Sonsino --- net/dcwapd/Makefile | 11 +- net/dcwapd/files/{dcwapd.inc => dcwapd.init} | 150 ++++++++++++++----- net/dcwapd/files/dcwapd.init.d | 31 ---- net/dcwapd/files/dcwapd.uci | 88 +---------- net/dcwapd/files/start_dcwapd.sh | 39 ----- net/dcwapd/files/stop_dcwapd.sh | 45 ------ 6 files changed, 114 insertions(+), 250 deletions(-) rename net/dcwapd/files/{dcwapd.inc => dcwapd.init} (63%) delete mode 100755 net/dcwapd/files/dcwapd.init.d delete mode 100755 net/dcwapd/files/start_dcwapd.sh delete mode 100755 net/dcwapd/files/stop_dcwapd.sh diff --git a/net/dcwapd/Makefile b/net/dcwapd/Makefile index 0fe3362981..3566f50feb 100644 --- a/net/dcwapd/Makefile +++ b/net/dcwapd/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=dcwapd PKG_VERSION:=1.1.0 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://codeload.github.com/ewsi/$(PKG_NAME)/tar.gz/v$(PKG_VERSION)? @@ -58,19 +58,12 @@ define Package/dcwapd/install # Note: $(INSTALL_BIN) does not keep symlinks, so use $(CP) $(CP) $(PKG_INSTALL_DIR)/usr/lib/*.so* $(1)/usr/lib/ -# Utility files - $(INSTALL_DIR) $(1)/etc/$(PKG_NAME) - $(INSTALL_DATA) ./files/*.inc $(1)/etc/$(PKG_NAME)/ - $(INSTALL_BIN) ./files/*.sh $(1)/etc/$(PKG_NAME)/ -# UCI config file copy - this is here for convenience and reference only - $(INSTALL_DATA) ./files/dcwapd.uci $(1)/etc/$(PKG_NAME)/ - # UCI config file $(INSTALL_DIR) $(1)/etc/config $(INSTALL_DATA) ./files/dcwapd.uci $(1)/etc/config/dcwapd # Init script $(INSTALL_DIR) $(1)/etc/init.d - $(INSTALL_BIN) ./files/dcwapd.init.d $(1)/etc/init.d/dcwapd + $(INSTALL_BIN) ./files/dcwapd.init $(1)/etc/init.d/dcwapd endef $(eval $(call BuildPackage,dcwapd)) diff --git a/net/dcwapd/files/dcwapd.inc b/net/dcwapd/files/dcwapd.init similarity index 63% rename from net/dcwapd/files/dcwapd.inc rename to net/dcwapd/files/dcwapd.init index c4b44f1b18..ad28a0b0d4 100644 --- a/net/dcwapd/files/dcwapd.inc +++ b/net/dcwapd/files/dcwapd.init @@ -1,30 +1,25 @@ -#!/bin/sh +#!/bin/sh /etc/rc.common -# -# Dual Channel Wi-Fi Startup Script -# -# This script creates the proper network bridge configuration -# necessary for Dual Channel Wi-Fi, and starts the dcwapd daemon -# +USE_PROCD=1 -verbose=1 - -uciconfig=dcwapd - -result= +START=99 +STOP=01 +CONFIGURATION=dcwapd +VERBOSE=1 # NOTE: all functions write the result to the $result variable +result= get_channelsets() { # default to empty result= - channelsets=$(uci show $uciconfig | grep "=channel-set$") + channelsets=$(uci show $CONFIGURATION | grep "=channel-set$") for channelset in $channelsets; do - channelset=$(echo "$channelset" | sed -rn "s/$uciconfig\.(.*)=.*/\1/p") + channelset=$(echo "$channelset" | sed -rn "s/$CONFIGURATION\.(.*)=.*/\1/p") result="$result $channelset" done - if [ $verbose -eq 1 ]; then + if [ $VERBOSE -eq 1 ]; then echo "Channel Sets: $result" 2>&1 | logger fi } @@ -35,9 +30,9 @@ get_channelset_enabled() # default to disabled result=0 if [ -n "$1" ]; then - result=$(uci get $uciconfig."$1".enabled) + result=$(uci get $CONFIGURATION."$1".enabled) fi - if [ $verbose -eq 1 ]; then + if [ $VERBOSE -eq 1 ]; then echo "Channel Set \"$1\" Enabled: $result" 2>&1 | logger fi } @@ -47,9 +42,9 @@ get_primary_bridge() { result= if [ -n "$1" ]; then - result=$(uci get $uciconfig."$1".bridge) + result=$(uci get $CONFIGURATION."$1".bridge) fi - if [ $verbose -eq 1 ]; then + if [ $VERBOSE -eq 1 ]; then echo "Channel Set \"$1\" Primary Bridge: $result" 2>&1 | logger fi } @@ -60,9 +55,9 @@ get_datachannels() # default to empty result= if [ -n "$1" ]; then - result=$(uci get $uciconfig."$1".data_channels) + result=$(uci get $CONFIGURATION."$1".data_channels) fi - if [ $verbose -eq 1 ]; then + if [ $VERBOSE -eq 1 ]; then echo "Channel Set \"$1\" Data Channels: $result" 2>&1 | logger fi } @@ -118,10 +113,10 @@ set_iface_init_state() fi # save the initial network - if [ $verbose -eq 1 ]; then + if [ $VERBOSE -eq 1 ]; then echo "Saving '$iface' initial network '$init_net'" 2>&1 | logger fi - uci set $uciconfig.init_net."$iface"="$init_net" + uci set $CONFIGURATION.init_net."$iface"="$init_net" uci commit # save the initial network in the result variable @@ -135,7 +130,7 @@ get_iface_init_state() { result= if [ -n "$1" ];then - init_net=$(uci get $uciconfig.init_net."$iface") + init_net=$(uci get $CONFIGURATION.init_net."$iface") # if the response starts with "uci: ", it was an error not the real result err=$(echo "$init_net" | grep "^uci: ") @@ -143,7 +138,7 @@ get_iface_init_state() # no error, set the result result=$init_net - if [ $verbose -eq 1 ]; then + if [ $VERBOSE -eq 1 ]; then echo "Got '$iface' initial network '$init_net'" 2>&1 | logger fi fi @@ -154,19 +149,19 @@ get_iface_init_state() datachannel_up() { if [ -n "$1" ]; then - bridge=$(uci get $uciconfig."$1".bridge) - interfaces=$(uci get $uciconfig."$1".interfaces) - if [ $verbose -eq 1 ]; then + bridge=$(uci get $CONFIGURATION."$1".bridge) + interfaces=$(uci get $CONFIGURATION."$1".interfaces) + if [ $VERBOSE -eq 1 ]; then echo "Creating Data Channel Bridge: $bridge" 2>&1 | logger fi get_bridge_network_name "$bridge" netname=$result if [ -n "$netname" ]; then - uci set network."$netname"=interface - uci set network."$netname".type=bridge - uci set network."$netname".proto=static - uci set network."$netname".bridge_empty='1' + uci set network."$netname"=interface + uci set network."$netname".type=bridge + uci set network."$netname".proto=static + uci set network."$netname".bridge_empty='1' fi # create the bridge @@ -182,7 +177,7 @@ datachannel_up() get_wifi_iface_num "$iface" iface_num=$result if [ -n "$iface_num" ]; then - uci set wireless.@wifi-iface[$iface_num].network="$netname" + uci set wireless.@wifi-iface[$iface_num].network="$netname" fi # manually put the interface into the data bridge @@ -211,10 +206,10 @@ datachannel_up() datachannel_down() { if [ -n "$1" ]; then - bridge=$(uci get $uciconfig."$1".bridge) - interfaces=$(uci get $uciconfig."$1".interfaces) + bridge=$(uci get $CONFIGURATION."$1".bridge) + interfaces=$(uci get $CONFIGURATION."$1".interfaces) for iface in $interfaces; do - if [ $verbose -eq 1 ]; then + if [ $VERBOSE -eq 1 ]; then echo "Deconfiguring Data Channel Interface: $iface" 2>&1 | logger fi @@ -228,16 +223,16 @@ datachannel_down() brctl addif "$init_bridge" "$iface" 2>&1 | logger # update uci with the new bridge and interface configuration - get_wifi_iface_num "$iface" + get_wifi_iface_num "$iface" iface_num=$result get_bridge_network_name "$init_bridge" netname=$result if [ -n "$iface_num" ] && [ -n "$netname" ]; then - uci set wireless.@wifi-iface[$iface_num].network="$netname" + uci set wireless.@wifi-iface[$iface_num].network="$netname" fi fi done - if [ $verbose -eq 1 ]; then + if [ $VERBOSE -eq 1 ]; then echo "Deconfiguring Data Channel Bridge: $bridge" 2>&1 | logger fi @@ -245,7 +240,7 @@ datachannel_down() get_bridge_network_name "$bridge" netname=$result if [ -n "$netname" ]; then - uci delete network."$netname" + uci delete network."$netname" fi # commit uci changes and reload the network @@ -254,3 +249,78 @@ datachannel_down() #`/etc/init.d/network restart` fi } + +start_service() { + config_load "$CONFIGURATION" + local enabled + + config_get enabled general enabled + if [ "$enabled" != "1" ]; then + echo "dcwapd is disabled in UCI" + return 1 + fi + + get_channelsets + # get the list of channel sets + channelsets=$result + + for channelset in $channelsets; do + if [ -n "$channelset" ]; then + get_channelset_enabled "$channelset" + enabled=$result + if [ "$enabled" = "1" ]; then + # the channel set is enabled + + # get the list of data channels used by the channel set + get_datachannels "$channelset" + datachannels=$result + for datachannel in $datachannels; do + datachannel_up "$datachannel" + done + fi + fi + done + + procd_open_instance + procd_set_param file /etc/config/dcwapd + procd_set_param command dcwapd + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_close_instance +} + +stop_service() { + get_channelsets + # get the list of channel sets + channelsets=$result + + for channelset in $channelsets; do + if [ -n "$channelset" ]; then +# we don't care if it is enabled, tear it down +# get_channelset_enabled $channelset +# enabled=$result +# if [ $enabled = "1" ]; then +# # the channel set is enabled + + # get the list of data channels used by the channel set + get_datachannels "$channelset" + datachannels=$result + for datachannel in $datachannels; do + datachannel_down "$datachannel" + done +# fi + fi + done + + sleep 1 +} + +service_triggers() +{ + procd_add_reload_trigger dcwapd +} + +reload_service() { + stop + start +} diff --git a/net/dcwapd/files/dcwapd.init.d b/net/dcwapd/files/dcwapd.init.d deleted file mode 100755 index 6f6a48fb23..0000000000 --- a/net/dcwapd/files/dcwapd.init.d +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh /etc/rc.common - -START=99 -# Setting the stop value makes the restart script unreliable when invoked by LuCI -#STOP=0 - -scriptdir=/etc/dcwapd - -#validate_section_dcwapd() { -# uci_validate_section dcwapd general "${1}" \ -# 'enabled:bool:1' -#} - -start() { -# validate_section_dcwapd dcwapd - - # only run the start script if the enabled uci option is set properly - enabled=$(uci get dcwapd.general.enabled) - if [ "${enabled}" = "1" ]; then - ${scriptdir}/start_dcwapd.sh - else - echo "dcwapd is disabled in UCI" - return 1 - fi -} - -stop() { - ${scriptdir}/stop_dcwapd.sh - # Add a sleep after stopping because an immediate restat will fail otherwise - sleep 1 -} diff --git a/net/dcwapd/files/dcwapd.uci b/net/dcwapd/files/dcwapd.uci index b24ec6f0d0..b3b62ad290 100644 --- a/net/dcwapd/files/dcwapd.uci +++ b/net/dcwapd/files/dcwapd.uci @@ -1,99 +1,22 @@ -###################################################### -# Copyright 2018 EWSI -# -# Licensed to the public under the Apache License 2.0. -###################################################### -# Dual Channel Wi-Fi AP Daemon configuration - -################### -# General Options # -################### -# The "enabled" option controls the run state of the Dual Channel Wi-Fi AP Daemon -# 0 - disabled, 1 - enabled -# The "tmpdir" option MUST be specified -# option tmpdir '' - config general 'general' option enabled 0 option tmpdir '/tmp/dcwapd' -################ -# Channel Sets # -################ -# Sections of type "channel-set" define a Dual Channel Wi-Fi primary channel, -# along with it's associated data channels -# -# The "data_channels" option is a space-delimited list of "datachannel"-typed instance names - config channel-set 'channelset0' option enabled 0 -# option enabled 1 option ssid 'OpenWrt' option bridge 'br-lan' option data_channels 'datachannel0' -#config channel-set 'channelset1' -# option enabled 0 -# option ssid 'OpenWrt2' -# option bridge 'br-lan' -# option data_channels 'datachannel1' - -################# -# Data Channels # -################# -# Sections of type "datachannel" define a Dual Channel Wi-Fi data channel, -# along with it's associated bridge and wireless interfaces -# -# The "interfaces" option is a space-delimited list of wireless interface names - config datachannel 'datachannel0' - option ssid 'DCW0' + option ssid 'OpenWrt-DCW' option bridge 'br-dc0' - option interfaces 'wlan2 wlan5' - -#config datachannel 'datachannel1' -# option ssid 'DCW1' -# option bridge 'br-dc1' -# option interfaces 'wlan4' - -#################### -# Init Net Options # -#################### -# The "init_net" section MUST be specified -# This section will be used to save and restore the state of the data interfaces -config init_net 'init_net' - -############### -# Filter Sets # -############### -# Sections of type "filter-set" define a Dual Channel Wi-Fi group of filters, -# along with it's associated MAC address and filter rules -# -# The "TFP_Default" filter set MUST be defined, although it is not required -# to have any associated filter rules -# The "TFP_Default" filter mac option can have the value of '*', meaning match -# all MAC addresses -# -# The "filters" option is a space-delimited list of "filter"-typed instance names + option interfaces '' config filter-set 'TFP_Default' option mac '*' option filters 'filter0 filter1' -#config filter-set 'filterset0' -# option mac '00:00:BE:EF:F0:0D' -# option filters 'filter2' - - -################ -# Filter Rules # -################ -# Sections of type "filter" define a Dual Channel Wi-Fi filter, -# along with it's associated filter parameters -# -# Any or all of the filter options may be set to '*' to match -# all values - config filter 'filter0' option packet_size '*' option source_ip '*' @@ -107,10 +30,3 @@ config filter 'filter1' option source_port '443' option protocol 'tcp' option dest_port '*' - -#config filter 'filter2' -# option packet_size '*' -# option source_ip '*' -# option source_port '22' -# option protocol 'tcp' -# option dest_port '*' diff --git a/net/dcwapd/files/start_dcwapd.sh b/net/dcwapd/files/start_dcwapd.sh deleted file mode 100755 index 8a8c11bc6b..0000000000 --- a/net/dcwapd/files/start_dcwapd.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh - -# -# Dual Channel Wi-Fi Startup Script -# -# This script creates the proper network bridge configuration -# necessary for Dual Channel Wi-Fi, and starts the dcwapd daemon -# - -# Note - shellcheck cannot deal with the dynamic sourcing -# shellcheck disable=SC1090 -# which also messes with variables defined in the sourced file -# shellcheck disable=SC2154 -scriptdir=$(dirname -- "$(readlink -f -- "$0")") -. "$scriptdir"/dcwapd.inc - -get_channelsets -# get the list of channel sets -channelsets=$result - -for channelset in $channelsets; do - if [ -n "$channelset" ]; then - get_channelset_enabled "$channelset" - enabled=$result - if [ "$enabled" = "1" ]; then - # the channel set is enabled - - # get the list of data channels used by the channel set - get_datachannels "$channelset" - datachannels=$result - for datachannel in $datachannels; do - datachannel_up "$datachannel" - done - fi - fi -done - -# start dcwapd, sending stdout and stderr to the system log -dcwapd 2>&1 | logger & diff --git a/net/dcwapd/files/stop_dcwapd.sh b/net/dcwapd/files/stop_dcwapd.sh deleted file mode 100755 index a360a8288e..0000000000 --- a/net/dcwapd/files/stop_dcwapd.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - -# -# Dual Channel Wi-Fi Startup Script -# -# This script creates the proper network bridge configuration -# necessary for Dual Channel Wi-Fi, and starts the dcwapd daemon -# - -# Note - shellcheck cannot deal with the dynamic sourcing -# shellcheck disable=SC1090 -# which also messes with variables defined in the sourced file -# shellcheck disable=SC2154 -scriptdir=$(dirname -- "$(readlink -f -- "$0")") -. "$scriptdir"/dcwapd.inc - -pid=$(pidof dcwapd) -if [ -n "$pid" ]; then - if [ "$verbose" -eq "1" ]; then - echo "Stopping dcwapd..." 2>&1 | logger - fi - kill "$pid" -fi - -get_channelsets -# get the list of channel sets -channelsets=$result - -for channelset in $channelsets; do - if [ -n "$channelset" ]; then -# we don't care if it is enabled, tear it down -# get_channelset_enabled $channelset -# enabled=$result -# if [ $enabled = "1" ]; then -# # the channel set is enabled - - # get the list of data channels used by the channel set - get_datachannels "$channelset" - datachannels=$result - for datachannel in $datachannels; do - datachannel_down "$datachannel" - done -# fi - fi -done