Browse Source

Merge pull request #4235 from TDT-GmbH/mwan3track-refactoring

Mwan3track refactoring
lilik-openwrt-22.03
Hannu Nyman 8 years ago
committed by GitHub
parent
commit
6aa43264ea
4 changed files with 92 additions and 89 deletions
  1. +1
    -1
      net/mwan3/Makefile
  2. +2
    -14
      net/mwan3/files/lib/mwan3/mwan3.sh
  3. +0
    -2
      net/mwan3/files/usr/sbin/mwan3
  4. +89
    -72
      net/mwan3/files/usr/sbin/mwan3track

+ 1
- 1
net/mwan3/Makefile View File

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=mwan3
PKG_VERSION:=2.4
PKG_VERSION:=2.4.1
PKG_RELEASE:=5
PKG_MAINTAINER:=Florian Eckert <fe@dev.tdt.de>
PKG_LICENSE:=GPLv2


+ 2
- 14
net/mwan3/files/lib/mwan3/mwan3.sh View File

@ -382,8 +382,7 @@ mwan3_delete_iface_ipset_entries()
mwan3_track()
{
local track_ip track_ips reliability count timeout interval down up size
local failure_interval recovery_interval
local track_ip track_ips
mwan3_list_track_ips()
{
@ -393,21 +392,10 @@ mwan3_track()
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 [ -n "$track_ips" ]; then
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 failure_interval $1 failure_interval $interval
config_get recovery_interval $1 recovery_interval $interval
config_get down $1 down 5
config_get up $1 up 5
config_get size $1 size 56
[ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track $1 $2 $reliability $count $timeout $interval $down $up $size $failure_interval $recovery_interval $track_ips &
[ -x /usr/sbin/mwan3track ] && /usr/sbin/mwan3track $1 $2 $track_ips &
fi
}


+ 0
- 2
net/mwan3/files/usr/sbin/mwan3 View File

@ -44,7 +44,6 @@ ifdown()
if [ -e /var/run/mwan3track-$1.pid ] ; then
kill $(cat /var/run/mwan3track-$1.pid)
rm /var/run/mwan3track-$1.pid
fi
}
@ -129,7 +128,6 @@ stop()
local ipset route rule table IP IPT
killall mwan3track &> /dev/null
rm /var/run/mwan3track-* &> /dev/null
for IP in "$IP4" "$IP6"; do


+ 89
- 72
net/mwan3/files/usr/sbin/mwan3track View File

@ -1,78 +1,95 @@
#!/bin/sh
[ -z "$12" ] && echo "Error: should not be started manually" && exit 0
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
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 [ $score -lt $8 ]; then
score=0
. /lib/functions.sh
LOG="/usr/bin/logger -t $(basename "$0")[$$] -p"
INTERFACE=""
clean_up() {
$LOG notice "Stopping mwan3track for interface \"${INTERFACE}\""
rm "/var/run/mwan3track-${INTERFACE}.pid" &> /dev/null
exit 0
}
main() {
local reliability count timeout interval failure_interval
local recovery_interval down up size
[ -z "$3" ] && echo "Error: should not be started manually" && exit 0
INTERFACE=$1
echo "$$" > /var/run/mwan3track-$1.pid
trap clean_up SIGINT SIGTERM
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 lost=0
local sleep_time=0
while true; do
sleep_time=$interval
for track_ip in $track_ips; do
ping -I $2 -c $count -W $timeout -s $size -q $track_ip &> /dev/null
if [ $? -eq 0 ]; then
let host_up_count++
else
let lost++
fi
done
if [ $host_up_count -lt $reliability ]; then
let score--
if [ $score -lt $up ]; then
score=0
else
sleep_time=$failure_interval
fi
if [ $score -eq $up ]; then
$LOG 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
if [ $score -lt $(($down+$up)) ] && [ $lost -gt 0 ]; then
$LOG info "Lost $(($lost*$count)) ping(s) on interface $1 ($2)"
fi
let score++
lost=0
if [ $score -gt $up ]; then
score=$(($down+$up))
elif [ $score -le $up ]; then
sleep_time=$recovery_interval
fi
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 /var/run/mwan3track-$1.pid
exit 0
fi
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
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