6 if [ -z "$debug" -o "$debug" == "0" ]; then
14 logger
"[Multi-WAN Notice]: $1"
19 local failover_to_wanid
22 local existing_failover
24 wanid
=$
(query_config wanid
$2)
25 failover_to
=`uci -q -P /var/state get multiwan.${2}.failover_to`
26 failover_to_wanid
=$
(query_config wanid
$failover_to)
28 existing_failover
=$
(iptables
-n -L FW
${wanid}MARK
-t mangle |
echo $
(expr $
(wc -l) - 2))
31 if [ "$existing_failover" == "2" ]; then
32 if [ "$failover_to" != "balancer" -a "$failover_to" != "disable" -a "$failover_to_wanid" != "$wanid" ]; then
33 iptables
-I FW
${wanid}MARK
2 -t mangle
-j FW
${failover_to_wanid}MARK
34 elif [ "$failover_to" == "balancer" ]; then
35 iptables
-I FW
${wanid}MARK
2 -t mangle
-j LoadBalancer
38 mwnote
"$1 has failed and is currently offline."
42 if [ "$existing_failover" == "3" ]; then
43 if [ "$failover_to" != "balancer" -a "failover_to" != "disable" -a "$failover_to_wanid" != "$wanid" ]; then
44 iptables
-D FW
${wanid}MARK
-t mangle
-j FW
${failover_to_wanid}MARK
45 elif [ "$failover_to" == "balancer" ]; then
46 iptables
-D FW
${wanid}MARK
-t mangle
-j LoadBalancer
49 mwnote
"$1 has recovered and is back online!"
62 local health_fail_retries
65 health_fail_retries
=`uci -q -P /var/state get multiwan.${1}.health_fail_retries`
66 weight
=`uci -q -P /var/state get multiwan.${1}.weight`
68 failchk
=$
(query_config failchk
$1)
69 recvrychk
=$
(query_config recvrychk
$1)
70 wan_recovery_map
=$
(echo $wan_recovery_map |
sed -e "s/${1}\[${recvrychk}\]//g")
72 if [ -z "$failchk" ]; then
73 wan_fail_map
="$wan_fail_map $1[1]"
74 if [ "$health_fail_retries" == "1" ]; then
78 if [ "$failchk" != "x" ]; then
79 new_fail_count
=$
(expr $failchk + 1)
80 if [ "$new_fail_count" -lt "$health_fail_retries" ]; then
81 wan_fail_map
=$
(echo $wan_fail_map |
sed -e "s/${1}\[${failchk}\]/$1\[${new_fail_count}\]/g")
83 wan_fail_map
=$
(echo $wan_fail_map |
sed -e "s/${1}\[${failchk}\]/$1\[x\]/g")
84 if [ "$weight" != "disable" ]; then
99 local health_recovery_retires
102 health_recovery_retries
=`uci -q -P /var/state get multiwan.${1}.health_recovery_retries`
103 weight
=`uci -q -P /var/state get multiwan.${1}.weight`
105 failchk
=$
(query_config failchk
$1)
106 recvrychk
=$
(query_config recvrychk
$1)
107 wanid
=$
(query_config wanid
$1)
109 if [ "$failchk" == "x" ]; then
110 if [ -z "$recvrychk" ]; then
111 wan_recovery_map
="$wan_recovery_map $1[1]"
112 if [ "$health_recovery_retries" == "1" ]; then
116 new_recovery_count
=$
(expr $recvrychk + 1)
117 if [ "$new_recovery_count" -lt "$health_recovery_retries" ]; then
118 wan_recovery_map
=$
(echo $wan_recovery_map |
sed -e "s/${1}\[${recvrychk}\]/$1\[${new_recovery_count}\]/g")
120 wan_recovery_map
=$
(echo $wan_recovery_map |
sed -e "s/${1}\[${recvrychk}\]//g")
121 wan_fail_map
=$
(echo $wan_fail_map |
sed -e "s/${1}\[${failchk}\]//g")
122 if [ "$weight" != "disable" ]; then
133 if [ $wancount -lt 9 ]; then
144 ifname
=`uci -q -P /var/state get network.${1}.ifname`
145 ipaddr
=`uci -q -P /var/state get network.${1}.ipaddr`
146 gateway
=`uci -q -P /var/state get network.${1}.gateway`
148 if [ -z "$ifname" ]; then
151 if [ -z "$ipaddr" ]; then
154 if [ -z "$gateway" ]; then
158 check_old_map
=`echo $wan_id_map 2>&1 | grep -o "$1\["`
160 if [ -z $check_old_map ]; then
161 wancount
=`expr $wancount + 1`
162 wan_if_map
="$wan_if_map $1[${ifname}] "
163 wan_id_map
="$wan_id_map $1[${wancount}] "
164 wan_gw_map
="$wan_gw_map $1[${gateway}] "
165 wan_ip_map
="$wan_ip_map $1[${ipaddr}] "
167 old_ipaddr
=$
(query_config ipaddr
$1)
168 old_gateway
=$
(query_config gateway
$1)
169 old_ifname
=$
(query_config ifname
$1)
170 get_wanid
=$
(query_config wanid
$1)
172 wan_if_map
=$
(echo $wan_if_map |
sed -e "s/${1}\[${old_ifname}\]/$1\[${ifname}\]/g")
173 wan_ip_map
=$
(echo $wan_ip_map |
sed -e "s/${1}\[${old_ipaddr}\]/$1\[${ipaddr}\]/g")
174 wan_gw_map
=$
(echo $wan_gw_map |
sed -e "s/${1}\[${old_gateway}\]/$1\[${gateway}\]/g")
176 if [ "$old_ifname" != "$ifname" ]; then
177 iptables
-D MultiWanPreHandler
-t mangle
-i $old_$ifname -m state
--state NEW
-j FW
${get_wanid}MARK
178 iptables
-A MultiWanPreHandler
-t mangle
-i $ifname -m state
--state NEW
-j FW
${get_wanid}MARK
179 iptables
-D MultiWanPostHandler
-t mangle
-o $old_$ifname -m mark
--mark 0x123 -j FW
${get_wanid}MARK
180 iptables
-A MultiWanPostHandler
-t mangle
-o $ifname -m mark
--mark 0x123 -j FW
${get_wanid}MARK
187 if [ "$ifname" != "x" -a "$ipaddr" != "x" -a "$gateway" != "x" ]; then
188 iprules_config
$get_wanid
189 qos_init
$1 $get_wanid
202 ifname
) echo $wan_if_map |
grep -o "$2\[\w*.*\]" |
awk -F "[" '{print $2}' |
awk -F "]" '{print $1}';;
203 ipaddr
) echo $wan_ip_map |
grep -o "$2\[\w*.*\]" |
awk -F "[" '{print $2}' |
awk -F "]" '{print $1}';;
204 gateway
) echo $wan_gw_map |
grep -o "$2\[\w*.*\]" |
awk -F "[" '{print $2}' |
awk -F "]" '{print $1}';;
205 wanid
) echo $wan_id_map |
grep -o "$2\[\w*.*\]" |
awk -F "[" '{print $2}' |
awk -F "]" '{print $1}';;
206 failchk
) echo $wan_fail_map |
grep -o "$2\[\w*.*\]" |
awk -F "[" '{print $2}' |
awk -F "]" '{print $1}';;
207 recvrychk
) echo $wan_recovery_map |
grep -o "$2\[\w*.*\]" |
awk -F "[" '{print $2}' |
awk -F "]" '{print $1}';;
208 group
) echo $wan_id_map |
grep -o "\w*\[$2\]" |
awk -F "[" '{print $1}';;
215 otherpids
=$
(ps
-a 2>&1 |
grep 'multiwan agent' |
grep -v $$ |
awk -F " " '{print $1}')
216 echo "$otherpids" |
while read execute
218 kill -9 ${execute} > /dev
/null
2>&1
229 if [ "$1" != "restart" ]; then
230 echo "## Refreshing Interfaces ##"
232 while [ $i -lt $wancount ]; do
234 group
=$
(query_config group
$i)
235 fdown
$group > /dev
/null
2>&1
236 ifup
$group > /dev
/null
2>&1 &
239 if [ ! -z "$CHKFORQOS" ]; then
240 /etc
/init.d
/qos restart
& > /dev
/null
2>&1
243 echo "## Unloaded, updating syslog and exiting. ##"
244 mwnote
"Succesfully Unloaded on $(exec date -R)."
248 echo "## Restarting Multi-WAN. ##"
249 mwnote
"Reinitializing Multi-WAN Configuration."
250 /etc
/init.d
/multiwan start
& > /dev
/null
2>&1
263 iptables
-t mangle
-F PREROUTING
264 iptables
-t mangle
-F FORWARD
265 iptables
-t mangle
-F POSTROUTING
266 iptables
-t mangle
-F OUTPUT
267 iptables
-t mangle
-F MultiWan
268 iptables
-t mangle
-X MultiWan
269 iptables
-t mangle
-F MultiWanRules
270 iptables
-t mangle
-X MultiWanRules
271 iptables
-t mangle
-F MultiWanDNS
272 iptables
-t mangle
-X MultiWanDNS
273 iptables
-t mangle
-F MultiWanPreHandler
274 iptables
-t mangle
-X MultiWanPreHandler
275 iptables
-t mangle
-F MultiWanPostHandler
276 iptables
-t mangle
-X MultiWanPostHandler
277 iptables
-t mangle
-F LoadBalancer
278 iptables
-t mangle
-X LoadBalancer
281 while [ $i -lt $wancount ]; do
283 iptables
-t mangle
-F FW
${i}MARK
287 while [ $i -lt $wancount ]; do
289 iptables
-t mangle
-X FW
${i}MARK
292 if [ ! -z "$CHKFORQOS" ]; then
294 iptables
-t mangle
-F MultiWanQoS
295 iptables
-t mangle
-X MultiWanQoS
298 while [ $i -lt $wancount ]; do
300 group
=$
(query_config group
$i)
301 iptables
-t mangle
-F MultiWanQoS_
${group}
302 iptables
-t mangle
-F MultiWanQoS_
${group}_ct
303 iptables
-t mangle
-X MultiWanQoS_
${group}
304 iptables
-t mangle
-X MultiWanQoS_
${group}_ct
314 local get_wan_iptables
316 local add_qos_iptables
322 qos_done_chk
=`echo $qos_done | grep -o "$1\."`
324 if [ ! -z "$qos_done_chk" ]; then
328 ifname
=$
(query_config ifname
$1)
330 if [ "$ifname" == "x" ]; then
334 queue_count
=$
(tc filter list dev
$ifname |
tail -n 1 |
awk -F " " '{print $10}' |
sed "s/0x//g")
336 if [ -z "$queue_count" ]; then
340 queue_count
=`expr $queue_count + 1`
342 iptables
-t mangle
-N MultiWanQoS_
${1}
343 iptables
-t mangle
-N MultiWanQoS_
${1}_ct
345 get_wan_tc
=$
(tc filter list dev
$ifname |
grep "0x" |
sed -e "s/filter /tc filter add dev $ifname /g" -e "s/pref/prio/g" -e "s/fw//g")
346 get_wan_iptables
=$
(iptables-save |
egrep '(-A Default )|(-A Default_ct )' |
grep -v "MultiWanQoS" |
sed -e "s/Default /MultiWanQoS_${1} /g" -e "s/Default_ct /MultiWanQoS_${1}_ct /g" -e "s/-A/iptables -t mangle -A/g")
348 rm /tmp
/.mwan.
$1.sedfilter
> /dev
/null
2>&1
350 while [ $i -lt $queue_count ]; do
351 echo "s/\(0x$i \|0x$i\/0xffffffff\)/0x${2}${i} /g" >> /tmp
/.mwan.
$1.sedfilter
355 add_qos_iptables
=$
(echo "$get_wan_iptables" |
sed -f /tmp
/.mwan.
$1.sedfilter
)
356 echo "$add_qos_iptables" |
while read execute
; do ${execute}; done
358 rm /tmp
/.mwan.
$1.sedfilter
360 while [ $i -lt $queue_count ]; do
361 echo "s/0x$i /0x${2}${i} fw /g" >> /tmp
/.mwan.
$1.sedfilter
365 add_qos_tc
=$
(echo "$get_wan_tc" |
sed -f /tmp
/.mwan.
$1.sedfilter
)
366 echo "$add_qos_tc" |
while read execute
; do ${execute}; done
367 rm /tmp
/.mwan.
$1.sedfilter
370 while [ $i -lt $queue_count ]; do
371 p
=`expr $i + $2 \* 10`
372 if [ $i -lt $
(expr $queue_count - 1) ]; then
373 ip rule add fwmark
0x$
(expr $p + 1) table $
(expr $2 \
* 10) prio $
(expr $p + 2)
375 iptables
-t mangle
-A MultiWanQoS
-m mark
--mark 0x
$p -j MultiWanQoS_
${1}
379 qos_done
="$qos_done $1."
390 config_get src
$1 src
391 config_get dst
$1 dst
392 config_get ports
$1 ports
393 config_get proto
$1 proto
394 config_get wanrule
$1 wanrule
395 ports_first
=${ports%-*}
396 ports_last
=${ports#*-}
398 if [ -z "$wanrule" ]; then
402 if [ "$wanrule" != "balancer" ]; then
403 wanrule
=$
(query_config wanid
${wanrule})
404 wanrule
="FW${wanrule}MARK"
405 elif [ "$wanrule" == "balancer" ]; then
406 wanrule
="LoadBalancer"
408 if [ "$dst" == "all" ]; then
411 if [ "$proto" == "all" ]; then
414 if [ "$ports" == "all" ]; then
417 if [ "$ports_first" -ne "$ports_last" ]; then
418 ports
="$ports_first:$ports_last"
421 if [ "$proto" == "icmp" ]; then
424 if [ "$src" == "all" ]; then
427 iptables
-t mangle
-A MultiWanRules
-m mark
--mark 0x0\
428 ${proto:+-p $proto} \
431 ${ports:+--dport $ports} \
434 if [ -z "$proto" -a ! -z "$ports" ]; then
456 iptables
-F MultiWanDNS
-t mangle
461 echo "## Refreshing DNS Resolution and Tables ##"
464 while [ $i -lt $wancount ]; do
466 group
=$
(query_config group
$i)
467 gateway
=$
(query_config gateway
$group)
468 ipaddr
=$
(query_config ipaddr
$group)
469 ifname
=$
(query_config ifname
$group)
470 failchk
=$
(query_config failchk
$group)
472 dns
=`uci -q -P /var/state get network.${group}.dns`
473 dns
=$
(echo $dns |
sed -e "s/ /\n/g")
475 if [ ! -z "$dns" -a "$failchk" != "x" -a "$ipaddr" != "x" -a "$gateway" != "x" -a "$ifname" != "x" ]; then
476 echo "$dns" |
while read dns_server
478 iptables
-t mangle
-A MultiWanDNS
-d $dns_server -j FW
${i}MARK
480 compile_dns
="nameserver $dns_server"
481 echo "$compile_dns" >> $resolv_conf
488 echo "## IPTables Rule Initialization ##"
494 local default_route_id
497 if [ ! -z "$CHKFORQOS" ]; then
498 echo "## QoS Initialization ##"
500 /etc
/init.d
/qos restart
> /dev
/null
2>&1
502 IMQ_NFO
=`iptables -n -L PREROUTING -t mangle -v | grep IMQ | awk -F " " '{print $6,$12}'`
504 iptables
-t mangle
-F PREROUTING
505 iptables
-t mangle
-F FORWARD
506 iptables
-t mangle
-F POSTROUTING
507 iptables
-t mangle
-F OUTPUT
509 echo "$IMQ_NFO" |
while read execute
511 iptables
-t mangle
-A PREROUTING
-i $
(echo $execute |
awk -F " " '{print $1}') -j IMQ
--todev $
(echo $execute |
awk -F " " '{print $2}')
514 iptables
-t mangle
-N MultiWanQoS
517 while [ $i -lt $wancount ]; do
519 qos_init $
(query_config group
$i) $i
524 iptables
-t mangle
-N MultiWan
525 iptables
-t mangle
-N LoadBalancer
526 iptables
-t mangle
-N MultiWanRules
527 iptables
-t mangle
-N MultiWanDNS
528 iptables
-t mangle
-N MultiWanPreHandler
529 iptables
-t mangle
-N MultiWanPostHandler
531 echo "## Creating FW Rules ##"
533 while [ $i -lt $wancount ]; do
535 iprule
=$
(expr $i \
* 10)
536 iptables
-t mangle
-N FW
${i}MARK
537 iptables
-t mangle
-A FW
${i}MARK
-j MARK
--set-mark 0x
${iprule}
538 iptables
-t mangle
-A FW
${i}MARK
-j CONNMARK
--save-mark
541 iptables
-t mangle
-A LoadBalancer
-j MARK
--set-mark 0x123
542 iptables
-t mangle
-A LoadBalancer
-j CONNMARK
--save-mark
544 iptables
-t mangle
-I PREROUTING
-j MultiWan
545 iptables
-t mangle
-I FORWARD
-j MultiWan
546 iptables
-t mangle
-I OUTPUT
-j MultiWan
547 iptables
-t mangle
-I POSTROUTING
-j MultiWan
549 iptables
-t mangle
-A MultiWan
-j CONNMARK
--restore-mark
550 iptables
-t mangle
-A MultiWan
-j MultiWanPreHandler
554 config_load
"multiwan"
555 config_foreach mwanrule mwanfw
557 if [ "$default_route" != "balancer" ]; then
558 default_route_id
=$
(query_config wanid
$default_route)
559 iptables
-t mangle
-A MultiWanRules
-m mark
--mark 0x0 -j FW
${default_route_id}MARK
561 iptables
-t mangle
-A MultiWanRules
-m mark
--mark 0x0 -j LoadBalancer
564 iptables
-t mangle
-A MultiWan
-j MultiWanRules
565 iptables
-t mangle
-A MultiWan
-j MultiWanDNS
566 iptables
-t mangle
-A MultiWan
-j MultiWanPostHandler
569 while [ $i -lt $wancount ]; do
571 group
=$
(query_config group
$i)
572 ifname
=$
(query_config ifname
$group)
573 iptables
-t mangle
-A MultiWanPreHandler
-i $ifname -m state
--state NEW
-j FW
${i}MARK
574 iptables
-t mangle
-A MultiWanPostHandler
-o $ifname -m mark
--mark 0x123 -j FW
${i}MARK
577 if [ ! -z "$CHKFORQOS" ]; then
578 iptables
-t mangle
-A MultiWan
-j MultiWanQoS
582 refresh_loadbalancer
() {
589 local pre_nexthop_chk
593 echo "## Refreshing Load Balancer ##"
595 CHKIPROUTE
=`cat /etc/iproute2/rt_tables | grep LoadBalancer`
596 if [ -z "$CHKIPROUTE" ]; then
597 echo "123 LoadBalancer" >> /etc
/iproute
2/rt_tables
599 ip rule del prio
123 > /dev
/null
2>&1
600 ip route flush table
123 > /dev
/null
2>&1
604 ip route |
grep link |
grep -Ev ^default |
while read ROUTE
606 ip route add table
$TABLE to
$ROUTE
611 while [ $i -lt $wancount ]; do
613 group
=$
(query_config group
$i)
614 failchk
=$
(query_config failchk
$group)
615 gateway
=$
(query_config gateway
$group)
616 ifname
=$
(query_config ifname
$group)
618 weight
=`uci -q -P /var/state get multiwan.${group}.weight`
620 if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then
621 nexthop
="$nexthop nexthop via $gateway dev $ifname weight $weight"
625 pre_nexthop_chk
=`echo $nexthop | awk -F "nexthop" '{print NF-1}'`
626 if [ "$pre_nexthop_chk" == "1" ]; then
627 ip route add default via $
(echo $nexthop |
awk -F " " '{print $3}') dev $
(echo $nexthop |
awk -F " " '{print $5}') proto static table
123
628 elif [ "$pre_nexthop_chk" -gt "1" ]; then
629 ip route add proto static table
123 default scope global
$nexthop
632 ip rule add fwmark
0x123 table
123 prio
123
644 echo "## Refreshing Routing Tables ##"
647 while [ $i -lt $wancount ]
650 group
=$
(query_config group
$i)
651 gateway
=$
(query_config gateway
$group)
652 ifname
=$
(query_config ifname
$group)
653 ipaddr
=$
(query_config ipaddr
$group)
655 iprule
=$
(expr $i \
* 10)
656 ip route flush table
$iprule > /dev
/null
2>&1
660 ip route |
grep link |
grep -Ev ^default |
while read ROUTE
662 ip route add table
$TABLE to
$ROUTE
666 if [ "$gateway" != "x" -a "$ipaddr" != "x" -a "$ifname" != "x" ]; then
667 ip route add default via
$gateway table
$iprule src
$ipaddr proto static
668 route add default gw
$gateway dev
$ifname
682 iprule
=$
(expr $1 \
* 10)
683 group
=$
(query_config group
$1)
684 gateway
=$
(query_config gateway
$group)
685 ipaddr
=$
(query_config ipaddr
$group)
687 CHKIPROUTE
=`cat /etc/iproute2/rt_tables | grep MWAN${1}`
688 if [ -z "$CHKIPROUTE" ]; then
689 echo "$iprule MWAN${1}" >> /etc
/iproute
2/rt_tables
692 ip rule del prio
$iprule > /dev
/null
2>&1
693 ip rule del prio $
(expr $iprule + 1) > /dev
/null
2>&1
695 if [ "$gateway" != "x" -a "$ipaddr" != "x" ]; then
696 ip rule add from
$ipaddr table
$iprule prio
$iprule
697 ip rule add fwmark
0x
${iprule} table
$iprule prio $
(expr $iprule + 1)
705 echo "## Flushing IP Rules & Routes ##"
707 ip rule flush
> /dev
/null
2>&1
708 ip rule add lookup main prio
32766 > /dev
/null
2>&1
709 ip rule add lookup default prio
32767 > /dev
/null
2>&1
711 ip route flush table
123 > /dev
/null
714 while [ $i -lt $wancount ]; do
716 iprule
=$
(expr $i \
* 10)
717 ip route del default
> /dev
/null
2>&1
718 ip route flush table
$iprule > /dev
/null
2>&1
721 echo "## Clearing Rules ##"
722 clear_rules
> /dev
/null
2>&1
724 rm $jobfile > /dev
/null
2>&1
730 local health_interval
733 echo "## Main Initialization ##"
740 echo "## IP Rules Initialization ##"
742 while [ $i -lt $wancount ]; do
750 RP_PATH
=/proc
/sys
/net
/ipv
4/conf
751 for IFACE
in `ls $RP_PATH`; do
752 echo 0 > $RP_PATH/$IFACE/rp_filter
754 echo "## Initialization Complete, switching to background mode. ##"
755 mwnote
"Succesfully Initialized on $(exec date -R)."
758 stagger_health_monitors
() {
760 while [ $i -lt $wancount ]; do
762 group
=$
(query_config group
$i)
763 health_interval
=`uci -q -P /var/state get multiwan.${group}.health_interval`
764 if [ ! -z "$health_interval" -a "$health_interval" != "disable" -a "$health_interval" -gt 0 ]; then
765 health_monitor
$group &
771 stagger_health_monitors
&
786 local icmp_hosts_acquire
787 local default_routes_check
791 local health_interval
794 timeout
=`uci -q -P /var/state get multiwan.${1}.timeout`
795 icmp_hosts
=`uci -q -P /var/state get multiwan.${1}.icmp_hosts`
796 health_interval
=`uci -q -P /var/state get multiwan.${1}.health_interval`
797 ifname_cur
=$
(query_config ifname
$1)
798 ipaddr_cur
=$
(query_config ipaddr
$1)
799 gateway_cur
=$
(query_config gateway
$1)
803 ifname
=`uci -q -P /var/state get network.${1}.ifname`
804 ipaddr
=`uci -q -P /var/state get network.${1}.ipaddr`
805 gateway
=`uci -q -P /var/state get network.${1}.gateway`
807 if [ -z "$ifname" ]; then
811 if [ -z "$ipaddr" ]; then
815 if [ -z "$gateway" ]; then
819 if [ "$ifname_cur" != "$ifname" -o "$ipaddr_cur" != "$ipaddr" -o "$gateway_cur" != "$gateway" ]; then
820 echo $1.acquire
>> $jobfile
823 if [ "$gateway" != "x" ]; then
824 default_routes_check
=`ip route | grep -o $gateway`
825 if [ -z "$default_routes_check" ]; then
826 check_for_job
=`cat $jobfile 2>&1 | grep -o "route.refresh"`
827 if [ -z "$check_for_job" ]; then
828 echo route.refresh
>> $jobfile
834 if [ "$icmp_hosts" != "disable" -a "$ifname" != "x" -a "$ipaddr" != "x" -a "$gateway" != "x" ]; then
836 if [ "$icmp_hosts" == "gateway" -o -z "$icmp_hosts" ]; then
837 icmp_hosts_acquire
=$gateway
838 elif [ "$icmp_hosts" == "dns" ]; then
839 icmp_hosts_acquire
=`uci -q -P /var/state get network.$1.dns`
841 icmp_hosts_acquire
=$icmp_hosts
844 icmp_hosts
=$
(echo $icmp_hosts_acquire |
sed -e "s/\,/ /g" |
sed -e "s/ /\n/g")
847 echo "$icmp_hosts" |
while read icmp_test_host
849 ping -c 1 -W $timeout -I $ifname $icmp_test_host 2>&1 |
grep -o "round-trip"
853 check_test
=$
(ping_test
)
855 if [ -z "$check_test" ]; then
856 echo "$1.fail" >> $jobfile
858 echo "$1.pass" >> $jobfile
861 elif [ "$icmp_hosts" == "disable" ]; then
862 echo "$1.pass" >> $jobfile
865 sleep $health_interval
878 if [ "$bg_counter" -eq 5 ]; then
880 check_iptables
=$
(iptables
-n -L MultiWan
-t mangle |
grep "references" |
awk -F "(" '{print $2}' | cut
-d " " -f 1)
882 if [ -z "$check_iptables" -o "$check_iptables" -lt 4 ]; then
883 mwnote
"Netfilter rules appear to of been altered."
884 /etc
/init.d
/multiwan restart
&
892 if [ -f $jobfile ]; then
894 mv $jobfile $jobfile.work
902 pass
) recover_wan
$1;;
903 acquire
) acquire_wan_data
$1 && health_monitor
$1 &;;
904 refresh
) refresh_routes
;;
908 queued_task
=`echo $LINE | awk -F "." '{print $1,$2}'`
909 execute_task
$queued_task
915 bg_counter
=$
(expr $bg_counter + 1)
928 while [ $i -lt $wancount ]; do
930 group
=$
(query_config group
$i)
931 ifname
=$
(query_config ifname
$group)
932 ipaddr
=$
(query_config ipaddr
$group)
933 gateway
=$
(query_config gateway
$group)
935 if [ "$ifname" == "x" -o "$ipaddr" == "x" -o "$gateway" == "x" ]; then
937 wan_fail_map
="echo $wan_fail_map $group[x]"
945 config_load
"multiwan"
946 config_get default_route config default_route
947 config_get resolv_conf config resolv_conf
948 config_get debug config debug
950 config_foreach acquire_wan_data interface
952 CHKFORQOS
=`iptables -n -L Default -t mangle 2>&1 | grep "Chain Default"`
954 jobfile
="/tmp/.mwan.jobqueue"
957 agent
) silencer main_init
;;
958 restart
) silencer stop restart
;;
959 stop
) silencer stop
;;