|
|
|
@ -8,7 +8,7 @@ PACKETS=1 |
|
|
|
|
#how often (in seconds) to re-check primary wan while on secondary wan and primary had failed |
|
|
|
|
RECOVERY_CHECK=300 |
|
|
|
|
#reliable hosts for checking are cloudflare, quad9, hgoogle |
|
|
|
|
HOSTS=("1.1.1.1" "9.9.9.9" "8.8.8.8") |
|
|
|
|
HOSTS=("1.1.1.1" "9.9.9.9" "8.8.8.8" "208.67.220.220") |
|
|
|
|
PING_RESULTS=() |
|
|
|
|
#interface and luci names of primary and secondary wan |
|
|
|
|
WAN1_IFACE_NAME="eth0" |
|
|
|
@ -51,9 +51,10 @@ function change_wan_metric() { |
|
|
|
|
while [ $ROUTE -le 100 ] |
|
|
|
|
do |
|
|
|
|
ROUTE_IFACE=`uci get network.@route[$ROUTE].interface` |
|
|
|
|
ROUTE_TARGET=`uci get network.@route[$ROUTE].target` |
|
|
|
|
if [ "$ROUTE_IFACE" == "uci: Entry not found" ]; then |
|
|
|
|
break |
|
|
|
|
elif [ "$ROUTE_IFACE" == "$WAN1_LUCI_NAME" ]; then |
|
|
|
|
elif [ "$ROUTE_IFACE" == "$WAN1_LUCI_NAME" ] && [ "$ROUTE_TARGET" == "$VPN_GATEWAY" ]; then |
|
|
|
|
uci set network.@route[$ROUTE].metric="$1" |
|
|
|
|
uci commit |
|
|
|
|
reload_config |
|
|
|
@ -103,9 +104,9 @@ do |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
#debug if any pings fail |
|
|
|
|
if [ $PINGS -lt ${#HOSTS[@]} ]; then |
|
|
|
|
debug |
|
|
|
|
fi |
|
|
|
|
# if [ $PINGS -lt ${#HOSTS[@]} ]; then |
|
|
|
|
# debug |
|
|
|
|
# fi |
|
|
|
|
|
|
|
|
|
# if all pings failed increase counter |
|
|
|
|
if [ $PINGS -eq 0 ]; then |
|
|
|
@ -116,7 +117,7 @@ do |
|
|
|
|
|
|
|
|
|
# counter failed pings to all hosts multiple times, switch WAN |
|
|
|
|
# NOTE: if both wan fail somultaneously, it will just switch back and forth. but not like it matters, neither would work anyway... lol |
|
|
|
|
if [ $COUNTER -gt 3 ]; then |
|
|
|
|
if [ $COUNTER -gt 2 ]; then |
|
|
|
|
debug |
|
|
|
|
if [ "$USINGWAN" == "$WAN1_IFACE_NAME" ]; then |
|
|
|
|
#if failed and currently on wan, switch to wanb |
|
|
|
|