Browse Source

Dont duplicate routes

Rafal Kupiec 7 months ago
parent
commit
0014a033fe
1 changed files with 10 additions and 4 deletions
  1. 10
    4
      files/usr/sbin/wanmonitor

+ 10
- 4
files/usr/sbin/wanmonitor View File

@@ -123,8 +123,8 @@ WAN=0
123 123
 while true; do
124 124
 	WAN_PRIMARY_STATUS=$(ifstatus ${WAN_PRIMARY} | grep \"up\" | awk '{gsub(/[",]/, ""); print $2}')
125 125
 	if [ "x${WAN_PRIMARY_STATUS}" = "xtrue" ]; then
126
-		CHECK_ROUTE=$(route | grep ${CHECK_HOST} | grep ${IFNAME_WAN_PRIMARY} | wc -l)
127
-		if [ "x${CHECK_ROUTE}" = "x0" ]; then
126
+		CHECK_HOST_ROUTE=$(route | grep ${CHECK_HOST} | grep ${IFNAME_WAN_PRIMARY} | wc -l)
127
+		if [ "x${CHECK_HOST_ROUTE}" = "x0" ]; then
128 128
 			/sbin/route add -host ${CHECK_HOST} gateway ${GATEWAY_WAN_PRIMARY} metric 0 ${IFNAME_WAN_PRIMARY} &>/dev/null
129 129
 		fi
130 130
 		WAN_PRIMARY_PING=$(ping -I ${IFNAME_WAN_PRIMARY} -w 3 -c 3 ${CHECK_HOST} 2>/dev/null | awk '/packets received/ {print $4}')
@@ -133,14 +133,20 @@ while true; do
133 133
 		if [ "${WAN}" = "0" ] || [ "${WAN}" = "1" ]; then
134 134
 			/usr/bin/logger -t $0 -p ${LOGGER_ALERT} "Primary WAN Interface is DOWN! Switching traffic to ${WAN_SECONDARY}."
135 135
 			/sbin/route del default gw ${GATEWAY_WAN_PRIMARY} metric ${WAN_PRIMARY_METRIC:-0} ${IFNAME_WAN_PRIMARY} &>/dev/null
136
-			/sbin/route add default gw ${GATEWAY_WAN_SECONDARY} metric ${WAN_SECONDARY_METRIC:-0} ${IFNAME_WAN_SECONDARY} &>/dev/null
136
+			CHECK_SECONDARY_ROUTE=$(route | grep default | grep ${IFNAME_WAN_SECONDARY} | wc -l)
137
+			if [ "x${CHECK_SECONDARY_ROUTE}" = "x0" ]; then
138
+				/sbin/route add default gw ${GATEWAY_WAN_SECONDARY} metric ${WAN_SECONDARY_METRIC:-0} ${IFNAME_WAN_SECONDARY} &>/dev/null
139
+			fi
137 140
 			WAN=2
138 141
 		fi
139 142
 	else
140 143
 		if [ "${WAN}" = "0" ] || [ "${WAN}" = "2" ]; then
141 144
 			/usr/bin/logger -t $0 -p ${LOGGER_ALERT} "Primary WAN Interface is UP! Switching traffic to ${WAN_PRIMARY}."
142 145
 			/sbin/route del default gw ${GATEWAY_WAN_SECONDARY} metric ${WAN_SECONDARY_METRIC:-0} ${IFNAME_WAN_SECONDARY} &>/dev/null
143
-			/sbin/route add default gw ${GATEWAY_WAN_PRIMARY} metric ${WAN_PRIMARY_METRIC:-0} ${IFNAME_WAN_PRIMARY} &>/dev/null
146
+			CHECK_PRIMARY_ROUTE=$(route | grep default | grep ${IFNAME_WAN_PRIMARY} | wc -l)
147
+			if [ "x${CHECK_PRIMARY_ROUTE}" = "x0" ]; then
148
+				/sbin/route add default gw ${GATEWAY_WAN_PRIMARY} metric ${WAN_PRIMARY_METRIC:-0} ${IFNAME_WAN_PRIMARY} &>/dev/null
149
+			fi
144 150
 			WAN=1
145 151
 		fi
146 152
 	fi

Loading…
Cancel
Save