|
@ -1,5 +1,7 @@ |
|
|
#!/bin/sh |
|
|
#!/bin/sh |
|
|
|
|
|
|
|
|
|
|
|
. /lib/functions.sh |
|
|
|
|
|
|
|
|
LOG="/usr/bin/logger -t $(basename "$0")[$$] -p" |
|
|
LOG="/usr/bin/logger -t $(basename "$0")[$$] -p" |
|
|
INTERFACE="" |
|
|
INTERFACE="" |
|
|
|
|
|
|
|
@ -10,25 +12,38 @@ clean_up() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
main() { |
|
|
main() { |
|
|
|
|
|
local reliability count timeout interval failure_interval |
|
|
|
|
|
local recovery_interval down up size |
|
|
|
|
|
|
|
|
[ -z "$12" ] && echo "Error: should not be started manually" && exit 0 |
|
|
|
|
|
|
|
|
[ -z "$3" ] && echo "Error: should not be started manually" && exit 0 |
|
|
|
|
|
|
|
|
INTERFACE=$1 |
|
|
INTERFACE=$1 |
|
|
echo "$$" > /var/run/mwan3track-$1.pid |
|
|
echo "$$" > /var/run/mwan3track-$1.pid |
|
|
trap clean_up SIGINT SIGTERM |
|
|
trap clean_up SIGINT SIGTERM |
|
|
|
|
|
|
|
|
local score=$(($7+$8)) |
|
|
|
|
|
local track_ips=$(echo $* | cut -d ' ' -f 12-99) |
|
|
|
|
|
|
|
|
config_load mwan3 |
|
|
|
|
|
config_get reliability $1 reliability 1 |
|
|
|
|
|
config_get count $1 count 1 |
|
|
|
|
|
config_get timeout $1 timeout 4 |
|
|
|
|
|
config_get interval $1 interval 10 |
|
|
|
|
|
config_get down $1 down 5 |
|
|
|
|
|
config_get up $1 up 5 |
|
|
|
|
|
config_get size $1 size 56 |
|
|
|
|
|
config_get failure_interval $1 failure_interval $interval |
|
|
|
|
|
config_get recovery_interval $1 recovery_interval $interval |
|
|
|
|
|
|
|
|
|
|
|
local score=$(($down+$up)) |
|
|
|
|
|
local track_ips=$(echo $* | cut -d ' ' -f 3-99) |
|
|
local host_up_count=0 |
|
|
local host_up_count=0 |
|
|
local lost=0 |
|
|
local lost=0 |
|
|
local sleep_time=0 |
|
|
local sleep_time=0 |
|
|
|
|
|
|
|
|
while true; do |
|
|
while true; do |
|
|
|
|
|
|
|
|
sleep_time=$6 |
|
|
|
|
|
|
|
|
sleep_time=$interval |
|
|
|
|
|
|
|
|
for track_ip in $track_ips; do |
|
|
for track_ip in $track_ips; do |
|
|
ping -I $2 -c $4 -W $5 -s $9 -q $track_ip &> /dev/null |
|
|
|
|
|
|
|
|
ping -I $2 -c $count -W $timeout -s $size -q $track_ip &> /dev/null |
|
|
if [ $? -eq 0 ]; then |
|
|
if [ $? -eq 0 ]; then |
|
|
let host_up_count++ |
|
|
let host_up_count++ |
|
|
else |
|
|
else |
|
@ -36,35 +51,35 @@ main() { |
|
|
fi |
|
|
fi |
|
|
done |
|
|
done |
|
|
|
|
|
|
|
|
if [ $host_up_count -lt $3 ]; then |
|
|
|
|
|
|
|
|
if [ $host_up_count -lt $reliability ]; then |
|
|
let score-- |
|
|
let score-- |
|
|
|
|
|
|
|
|
if [ $score -lt $8 ]; then |
|
|
|
|
|
|
|
|
if [ $score -lt $up ]; then |
|
|
score=0 |
|
|
score=0 |
|
|
else |
|
|
else |
|
|
sleep_time=$10 |
|
|
|
|
|
|
|
|
sleep_time=$failure_interval |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ $score -eq $8 ]; then |
|
|
|
|
|
|
|
|
if [ $score -eq $up ]; then |
|
|
$LOG notice "Interface $1 ($2) is offline" |
|
|
$LOG notice "Interface $1 ($2) is offline" |
|
|
env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface |
|
|
env -i ACTION=ifdown INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface |
|
|
score=0 |
|
|
score=0 |
|
|
fi |
|
|
fi |
|
|
else |
|
|
else |
|
|
if [ $score -lt $(($7+$8)) ] && [ $lost -gt 0 ]; then |
|
|
|
|
|
$LOG info "Lost $(($lost*$4)) ping(s) on interface $1 ($2)" |
|
|
|
|
|
|
|
|
if [ $score -lt $(($down+$up)) ] && [ $lost -gt 0 ]; then |
|
|
|
|
|
$LOG info "Lost $(($lost*$count)) ping(s) on interface $1 ($2)" |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
let score++ |
|
|
let score++ |
|
|
lost=0 |
|
|
lost=0 |
|
|
|
|
|
|
|
|
if [ $score -gt $8 ]; then |
|
|
|
|
|
score=$(($7+$8)) |
|
|
|
|
|
elif [ $score -le $8 ]; then |
|
|
|
|
|
sleep_time=$11 |
|
|
|
|
|
|
|
|
if [ $score -gt $up ]; then |
|
|
|
|
|
score=$(($down+$up)) |
|
|
|
|
|
elif [ $score -le $up ]; then |
|
|
|
|
|
sleep_time=$recovery_interval |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ $score -eq $8 ]; then |
|
|
|
|
|
|
|
|
if [ $score -eq $up ]; then |
|
|
$LOG notice "Interface $1 ($2) is online" |
|
|
$LOG notice "Interface $1 ($2) is online" |
|
|
env -i ACTION=ifup INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface |
|
|
env -i ACTION=ifup INTERFACE=$1 DEVICE=$2 /sbin/hotplug-call iface |
|
|
rm /var/run/mwan3track-$1.pid |
|
|
rm /var/run/mwan3track-$1.pid |
|
|