Browse Source

net/mwan3: move global mwan3track into main function

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
lilik-openwrt-22.03
Florian Eckert 8 years ago
parent
commit
23339d7ae1
1 changed files with 65 additions and 69 deletions
  1. +65
    -69
      net/mwan3/files/usr/sbin/mwan3track

+ 65
- 69
net/mwan3/files/usr/sbin/mwan3track View File

@ -1,78 +1,74 @@
#!/bin/sh
[ -z "$12" ] && echo "Error: should not be started manually" && exit 0
main() {
if [ -e /var/run/mwan3track-$1.pid ] ; then
kill $(cat /var/run/mwan3track-$1.pid) &> /dev/null
rm /var/run/mwan3track-$1.pid &> /dev/null
fi
[ -z "$12" ] && echo "Error: should not be started manually" && exit 0
echo "$$" > /var/run/mwan3track-$1.pid
score=$(($7+$8))
track_ips=$(echo $* | cut -d ' ' -f 12-99)
host_up_count=0
lost=0
sleep_time=0
while true; do
sleep_time=$6
for track_ip in $track_ips; do
ping -I $2 -c $4 -W $5 -s $9 -q $track_ip &> /dev/null
if [ $? -eq 0 ]; then
let host_up_count++
else
let lost++
fi
done
if [ $host_up_count -lt $3 ]; then
let score--
if [ -e /var/run/mwan3track-$1.pid ] ; then
kill $(cat /var/run/mwan3track-$1.pid) &> /dev/null
rm /var/run/mwan3track-$1.pid &> /dev/null
fi
if [ $score -lt $8 ]; then
score=0
echo "$$" > /var/run/mwan3track-$1.pid
local score=$(($7+$8))
local track_ips=$(echo $* | cut -d ' ' -f 12-99)
local host_up_count=0
local lost=0
local sleep_time=0
while true; do
sleep_time=$6
for track_ip in $track_ips; do
ping -I $2 -c $4 -W $5 -s $9 -q $track_ip &> /dev/null
if [ $? -eq 0 ]; then
let host_up_count++
else
let lost++
fi
done
if [ $host_up_count -lt $3 ]; then
let score--
if [ $score -lt $8 ]; then
score=0
else
sleep_time=$10
fi
if [ $score -eq $8 ]; then
logger -t mwan3track -p notice "Interface $1 ($2) is offline"
env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
score=0
fi
else
sleep_time=$10
fi
if [ $score -eq $8 ]; then
logger -t mwan3track -p notice "Interface $1 ($2) is offline"
env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
score=0
if [ $score -lt $(($7+$8)) ] && [ $lost -gt 0 ]; then
logger -t mwan3track -p info "Lost $(($lost*$4)) ping(s) on interface $1 ($2)"
fi
let score++
lost=0
if [ $score -gt $8 ]; then
score=$(($7+$8))
elif [ $score -le $8 ]; then
sleep_time=$11
fi
if [ $score -eq $8 ]; then
logger -t mwan3track -p notice "Interface $1 ($2) is online"
env -i ACTION=ifup INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
rm /var/run/mwan3track-$1.pid
exit 0
fi
fi
else
if [ $score -lt $(($7+$8)) ] && [ $lost -gt 0 ]; then
logger -t mwan3track -p info "Lost $(($lost*$4)) ping(s) on interface $1 ($2)"
fi
let score++
lost=0
if [ $score -gt $8 ]; then
score=$(($7+$8))
elif [ $score -le $8 ]; then
sleep_time=$11
fi
if [ $score -eq $8 ]; then
logger -t mwan3track -p notice "Interface $1 ($2) is online"
env -i ACTION=ifup INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface
rm /var/run/mwan3track-$1.pid
exit 0
fi
fi
host_up_count=0
sleep $sleep_time
done
host_up_count=0
sleep $sleep_time
done
}
exit 1
main "$@"

Loading…
Cancel
Save