5 LOG
="logger -t $(basename "$0")[$$] -p"
12 $LOG notice
"Stopping mwan3track for interface \"${INTERFACE}\""
17 $LOG info
"Detect ifdown event on interface ${INTERFACE} (${DEVICE})"
21 validate_track_method
() {
24 # Assume that ping is installed
27 which arping
1>/dev
/null
2>&1 ||
{
28 $LOG warn
"Missing arping. Please install iputils-arping package."
33 which httping
1>/dev
/null
2>&1 ||
{
34 $LOG warn
"Missing httping. Please install httping package."
39 $LOG warn
"Unsupported tracking method: $track_method"
46 local reliability count timeout interval failure_interval
47 local recovery_interval down up size
48 local keep_failure_interval
50 [ -z "$5" ] && echo "Error: should not be started manually" && exit 0
55 mkdir
-p /var
/run
/mwan3track
/$1
56 trap clean_up SIGINT SIGTERM
60 config_get track_method
$1 track_method
ping
61 validate_track_method
$track_method ||
{
62 $LOG warn
"Using ping to track interface $INTERFACE avaliability"
65 config_get reliability
$1 reliability
1
66 config_get count
$1 count
1
67 config_get timeout
$1 timeout
4
68 config_get interval
$1 interval
10
69 config_get down
$1 down
5
71 config_get size
$1 size
56
72 config_get failure_interval
$1 failure_interval
$interval
73 config_get_bool keep_failure_interval
$1 keep_failure_interval
0
74 config_get recovery_interval
$1 recovery_interval
$interval
76 local score
=$
(($down+$up))
77 local track_ips
=$
(echo $
* | cut
-d ' ' -f 5-99)
83 if [ "$STATUS" = "offline" ]; then
84 echo "offline" > /var
/run
/mwan3track
/$1/STATUS
87 echo "online" > /var
/run
/mwan3track
/$1/STATUS
93 for track_ip
in $track_ips; do
94 case "$track_method" in
96 ping -I $2 -c $count -W $timeout -s $size -q $track_ip &> /dev
/null
;;
98 arping
-I $2 -c $count -w $timeout -q $track_ip &> /dev
/null
;;
100 httping
-y $3 -c $count -t $timeout -q $track_ip &> /dev
/null
;;
102 if [ $?
-eq 0 ]; then
104 echo "up" > /var
/run
/mwan3track
/$1/TRACK_
${track_ip}
107 echo "down" > /var
/run
/mwan3track
/$1/TRACK_
${track_ip}
111 if [ $host_up_count -lt $reliability ]; then
114 if [ $score -lt $up ]; then
116 [ ${keep_failure_interval} -eq 1 ] && {
117 sleep_time
=$failure_interval
120 sleep_time
=$failure_interval
123 if [ $score -eq $up ]; then
124 echo "offline" > /var
/run
/mwan3track
/$1/STATUS
125 $LOG notice
"Interface $1 ($2) is offline"
126 env
-i ACTION
=ifdown INTERFACE
=$1 DEVICE
=$2 /sbin
/hotplug-call iface
130 if [ $score -lt $
(($down+$up)) ] && [ $lost -gt 0 ]; then
131 $LOG info
"Lost $(($lost*$count)) ping(s) on interface $1 ($2)"
137 if [ $score -gt $up ]; then
138 echo "online" > /var
/run
/mwan3track
/$1/STATUS
140 elif [ $score -le $up ]; then
141 sleep_time
=$recovery_interval
144 if [ $score -eq $up ]; then
145 $LOG notice
"Interface $1 ($2) is online"
146 echo "online" > /var
/run
/mwan3track
/$1/STATUS
147 env
-i ACTION
=ifup INTERFACE
=$1 DEVICE
=$2 /sbin
/hotplug-call iface
153 mkdir
-p "/var/run/mwan3track/${1}"
154 echo "${lost}" > /var
/run
/mwan3track
/$1/LOST
155 echo "${score}" > /var
/run
/mwan3track
/$1/SCORE
156 echo "${turn}" > /var
/run
/mwan3track
/$1/TURN
159 sleep "${sleep_time}" &
162 if [ "${IFDOWN_EVENT}" -eq 1 ]; then
164 echo "offline" > /var
/run
/mwan3track
/$1/STATUS