From 8fa2101ea3b2d787029cdd5a89526a5ef041748f Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Fri, 2 Feb 2018 14:56:18 +0100 Subject: [PATCH] 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 bea7baad95..f94b400934 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 3d64ec44bf..7a4f1f2c80 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<