diff --git a/net/mwan3/files/lib/mwan3/mwan3.sh b/net/mwan3/files/lib/mwan3/mwan3.sh index f08f89914..596d3e759 100644 --- a/net/mwan3/files/lib/mwan3/mwan3.sh +++ b/net/mwan3/files/lib/mwan3/mwan3.sh @@ -8,6 +8,8 @@ IPT6="ip6tables -t mangle -w" LOG="logger -t mwan3[$$] -p" CONNTRACK_FILE="/proc/net/nf_conntrack" +MWAN3_STATUS_DIR="/var/run/mwan3track" + # mwan3's MARKing mask (at least 3 bits should be set) MMX_MASK=0xff00 @@ -65,6 +67,10 @@ mwan3_unlock() { lock -u /var/run/mwan3.lock } +mwan3_lock_clean() { + rm -rf /var/run/mwan3.lock +} + mwan3_get_iface_id() { local _tmp _iface _iface_count @@ -919,3 +925,13 @@ mwan3_flush_conntrack() $LOG warning "connection tracking not enabled" fi } + +mwan3_track_clean() +{ + rm -rf "$MWAN3_STATUS_DIR/${1}" &> /dev/null + [ -d "$MWAN3_STATUS_DIR" ] && { + if [ -z "$(ls -A "$MWAN3_STATUS_DIR")" ]; then + rm -rf "$MWAN3_STATUS_DIR" + fi + } +} diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index 043f8ec48..41d78a3f2 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -37,6 +37,7 @@ ifdown() ACTION=ifdown INTERFACE=$1 /sbin/hotplug-call iface kill $(pgrep -f "mwan3track $1 $2") &> /dev/null + mwan3_track_clean $1 } ifup() @@ -121,6 +122,9 @@ stop() killall mwan3track &> /dev/null + config_load mwan3 + config_foreach mwan3_track_clean interface + for IP in "$IP4" "$IP6"; do for route in $($IP route list table all | sed 's/.*table \([^ ]*\) .*/\1/' | awk '{print $1}' | awk '{for(i=1;i<=NF;i++) if($i+0>0) if($i+0<255) {print;break}}'); do @@ -153,6 +157,8 @@ stop() for ipset in $($IPS -n list | grep mwan3 | grep -E '_v4|_v6'); do $IPS -q destroy $ipset done + + mwan3_lock_clean } restart() { diff --git a/net/mwan3/files/usr/sbin/mwan3track b/net/mwan3/files/usr/sbin/mwan3track index 7e695ed77..1495afa63 100755 --- a/net/mwan3/files/usr/sbin/mwan3track +++ b/net/mwan3/files/usr/sbin/mwan3track @@ -10,12 +10,6 @@ IFDOWN_EVENT=0 clean_up() { $LOG notice "Stopping mwan3track for interface \"${INTERFACE}\"" - if [ "$(pgrep -f "mwan3track ${INTERFACE} ${DEVICE}")" = "" ]; then - rm -rf "/var/run/mwan3track/${INTERFACE}" &> /dev/null - fi - if [ -z "$(ls -A "/var/run/mwan3track")" ]; then - rm -rf "/var/run/mwan3track" - fi exit 0 } @@ -144,7 +138,6 @@ main() { if [ $score -eq $up ]; then $LOG notice "Interface $1 ($2) is online" env -i ACTION=ifup INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface - rm -rf "/var/run/mwan3track/${1}" &> /dev/null exit 0 fi fi