From f9a787e8dfc89c7804463ea2cb78ad3a93a423e1 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 5 Feb 2018 10:15:03 +0100 Subject: [PATCH 1/4] net/mwan3: add init script to enable/disable mwan3 globally Adding a init script to "/etc/init.d/" introduce the possibility to enable/disable mwan3 globally. Signed-off-by: Florian Eckert --- net/mwan3/files/etc/hotplug.d/iface/14-mwan3 | 3 ++ net/mwan3/files/etc/hotplug.d/iface/15-mwan3 | 11 ++++--- .../files/etc/hotplug.d/iface/16-mwan3-user | 3 ++ net/mwan3/files/etc/init.d/mwan3 | 32 +++++++++++++++++++ net/mwan3/files/usr/sbin/mwan3 | 14 ++++++++ 5 files changed, 59 insertions(+), 4 deletions(-) create mode 100755 net/mwan3/files/etc/init.d/mwan3 diff --git a/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 index f977b3d84..4f8e0be16 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 @@ -12,6 +12,9 @@ if [ "$ACTION" = "ifup" ]; then fi config_load mwan3 +config_get_bool enabled globals 'enabled' '0' +[ ${enabled} -gt 0 ] || exit 0 + config_get local_source globals local_source 'none' [ "${local_source}" = "none" ] && { exit 0 diff --git a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 index 71d6393b4..bea7baad9 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 @@ -12,15 +12,18 @@ if [ "$ACTION" == "ifup" ]; then [ -n "$DEVICE" ] || exit 3 fi -mwan3_lock -mwan3_set_connected_iptables -mwan3_unlock - config_load mwan3 +config_get_bool enabled globals 'enabled' '0' +[ ${enabled} -gt 0 ] || exit 0 + config_get enabled $INTERFACE enabled 0 config_get initial_state $INTERFACE initial_state "online" [ "$enabled" == "1" ] || exit 0 +mwan3_lock +mwan3_set_connected_iptables +mwan3_unlock + if [ "$ACTION" == "ifup" ]; then config_get family $INTERFACE family ipv4 if [ "$family" = "ipv4" ]; then diff --git a/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user b/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user index 485f8de4e..9372c736e 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user +++ b/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user @@ -4,6 +4,9 @@ . /lib/functions.sh config_load mwan3 + config_get_bool enabled globals 'enabled' '0' + [ ${enabled} -gt 0 ] || exit 0 + config_get enabled "$INTERFACE" enabled 0 [ "${enabled}" = "1" ] || exit 0 env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \ diff --git a/net/mwan3/files/etc/init.d/mwan3 b/net/mwan3/files/etc/init.d/mwan3 new file mode 100755 index 000000000..dac1fb89a --- /dev/null +++ b/net/mwan3/files/etc/init.d/mwan3 @@ -0,0 +1,32 @@ +#!/bin/sh /etc/rc.common + +START=19 + +reload() { + local enabled + + config_load mwan3 + config_get_bool enabled globals 'enabled' 0 + [ ${enabled} -gt 0 ] || { + echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start" + exit 0 + } + mwan3 restart +} + +boot() { + . /lib/config/uci.sh + uci_toggle_state mwan3 globals enabled "1" +} + +start() { + . /lib/config/uci.sh + uci_toggle_state mwan3 globals enabled "1" + mwan3 start +} + +stop() { + . /lib/config/uci.sh + uci_toggle_state mwan3 globals enabled "0" + mwan3 stop +} diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index 38e80a083..3e1b64456 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -54,6 +54,12 @@ ifup() echo "Too many arguments. Usage: mwan3 ifup " && exit 0 fi + config_get_bool enabled globals 'enabled' 0 + [ ${enabled} -gt 0 ] || { + echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start" + exit 0 + } + config_get enabled "$1" enabled 0 device=$(uci -p /var/state get network.$1.ifname) &> /dev/null @@ -112,7 +118,15 @@ status() start() { + local enabled + config_load mwan3 + config_get_bool enabled globals 'enabled' 0 + [ ${enabled} -gt 0 ] || { + echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start" + exit 0 + } + config_foreach ifup interface } From 7cf9d9ec201444f2d03d28873bf91b02c6a47a77 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Wed, 31 Jan 2018 11:58:38 +0100 Subject: [PATCH 2/4] net/mwan3: send SIGKILL to mwan3track In some situation it is not enough to send a SIGTERM to mwan3track to ask service to stop accurate. If this does not work send him a SIGKILL to prevent mwan3track running more then once per interface. Signed-off-by: Florian Eckert --- net/mwan3/files/lib/mwan3/mwan3.sh | 8 ++++++-- net/mwan3/files/usr/sbin/mwan3 | 8 ++++++-- net/mwan3/files/usr/sbin/mwan3track | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 05ee9eedf..3d64ec44b 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -446,7 +446,7 @@ mwan3_delete_iface_ipset_entries() mwan3_track() { - local track_ip track_ips + local track_ip track_ips pid mwan3_list_track_ips() { @@ -454,7 +454,11 @@ mwan3_track() } config_list_foreach $1 track_ip mwan3_list_track_ips - kill $(pgrep -f "mwan3track $1 $2") &> /dev/null + for pid in $(pgrep -f "mwan3track $1 $2"); do + kill -TERM "$pid" > /dev/null 2>&1 + sleep 1 + kill -KILL "$pid" > /dev/null 2>&1 + done if [ -n "$track_ips" ]; then [ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track "$1" "$2" "$3" "$4" $track_ips & fi diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index 3e1b64456..5c4259c7d 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -132,9 +132,13 @@ start() stop() { - local ipset route rule table IP IPT + local ipset route rule table IP IPT pid - killall mwan3track &> /dev/null + for pid in $(pgrep -f "mwan3track"); do + kill -TERM "$pid" > /dev/null 2>&1 + sleep 1 + kill -KILL "$pid" > /dev/null 2>&1 + done config_load mwan3 config_foreach mwan3_track_clean interface diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 588eb9bf4..2e6f0ffdd 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -62,8 +62,8 @@ main() { STATUS=$3 SRC_IP=$4 mkdir -p /var/run/mwan3track/$1 - trap clean_up SIGINT SIGTERM - trap if_down SIGUSR1 + trap clean_up TERM + trap if_down USR1 config_load mwan3 config_get track_method $1 track_method ping From 8fa2101ea3b2d787029cdd5a89526a5ef041748f Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 2 Feb 2018 14:56:18 +0100 Subject: [PATCH 3/4] net/mwan3: add mwan3_init function Move all shell commands which are executed during /lib/mwan3/mwan3.sh sourceing into a seperate init function which must be called at first. Signed-off-by: Florian Eckert --- net/mwan3/files/etc/hotplug.d/iface/15-mwan3 | 1 + net/mwan3/files/lib/mwan3/mwan3.sh | 53 +++++++++++++------- net/mwan3/files/usr/sbin/mwan3 | 1 + 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 index bea7baad9..f94b40093 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 @@ -21,6 +21,7 @@ config_get initial_state $INTERFACE initial_state "online" [ "$enabled" == "1" ] || exit 0 mwan3_lock +mwan3_init mwan3_set_connected_iptables mwan3_unlock diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index 3d64ec44b..7a4f1f2c8 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -11,17 +11,14 @@ CONNTRACK_FILE="/proc/net/nf_conntrack" MWAN3_STATUS_DIR="/var/run/mwan3" MWAN3TRACK_STATUS_DIR="/var/run/mwan3track" DEFAULT_LOWEST_METRIC=256 +MMX_MASK="" +MMX_DEFAULT="" +MMX_BLACKHOLE="" +MM_BLACKHOLE="" + +MMX_UNREACHABLE="" +MM_UNREACHABLE="" -[ -d $MWAN3_STATUS_DIR ] || mkdir -p $MWAN3_STATUS_DIR/iface_state -# mwan3's MARKing mask (at least 3 bits should be set) -if [ -e "${MWAN3_STATUS_DIR}/mmx_mask" ]; then - MMX_MASK=$(cat "${MWAN3_STATUS_DIR}/mmx_mask") -else - config_load mwan3 - config_get MMX_MASK globals mmx_mask '0xff00' - echo "$MMX_MASK" > "${MWAN3_STATUS_DIR}/mmx_mask" - $LOG notice "Using firewall mask ${MMX_MASK}" -fi # counts how many bits are set to 1 # n&(n-1) clears the lowest bit set to 1 @@ -58,16 +55,34 @@ mwan3_id2mask() printf "0x%x" $result } -# mark mask constants -MM_BIT_CNT=$(mwan3_count_one_bits MMX_MASK) -MM_DEFAULT=$(((1< "${MWAN3_STATUS_DIR}/mmx_mask" + $LOG notice "Using firewall mask ${MMX_MASK}" + fi -# MMX_DEFAULT should equal MMX_MASK -MMX_DEFAULT=$(mwan3_id2mask MM_DEFAULT MMX_MASK) -MMX_BLACKHOLE=$(mwan3_id2mask MM_BLACKHOLE MMX_MASK) -MMX_UNREACHABLE=$(mwan3_id2mask MM_UNREACHABLE MMX_MASK) + # mark mask constants + bitcnt=$(mwan3_count_one_bits MMX_MASK) + mmdefault=$(((1< Date: Mon, 5 Feb 2018 10:16:10 +0100 Subject: [PATCH 4/4] net/mwan3: update to version 2.6.10 Signed-off-by: Florian Eckert --- net/mwan3/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mwan3/Makefile b/net/mwan3/Makefile index 4cdaed9ee..07d6827f7 100644 --- a/net/mwan3/Makefile +++ b/net/mwan3/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mwan3 -PKG_VERSION:=2.6.9 +PKG_VERSION:=2.6.10 PKG_RELEASE:=1 PKG_MAINTAINER:=Florian Eckert PKG_LICENSE:=GPLv2