add() {
wan_fail_map=$(echo $wan_fail_map | sed -e "s/${1}\[${failchk}\]//g")
- wan_fail_map=$(echo $wan_fail_map $1[x])
+ wan_fail_map=$(echo $wan_fail_map${1}[x])
wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/${1}\[${recvrychk}\]//g")
+ update_cache
if [ "$existing_failover" == "2" ]; then
if [ "$failover_to" != "balancer" -a "$failover_to" != "disable" -a "$failover_to_wanid" != "$wanid" ]; then
fi
fi
mwnote "$1 has failed and is currently offline."
-
-query_config update
}
del() {
wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/${1}\[${recvrychk}\]//g")
wan_fail_map=$(echo $wan_fail_map | sed -e "s/${1}\[${failchk}\]//g")
+ update_cache
if [ "$existing_failover" == "3" ]; then
iptables -D FW${wanid}MARK 2 -t mangle
fi
mwnote "$1 has recovered and is back online!"
-
-query_config update
}
case $1 in
wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/${1}\[${recvrychk}\]//g")
if [ -z "$failchk" ]; then
-wan_fail_map="$wan_fail_map $1[1]"
+wan_fail_map="$wan_fail_map${1}[1]"
+update_cache
if [ "$health_fail_retries" == "1" ]; then
fail_wan $1
fi
new_fail_count=$(expr $failchk + 1)
if [ "$new_fail_count" -lt "$health_fail_retries" ]; then
wan_fail_map=$(echo $wan_fail_map | sed -e "s/${1}\[${failchk}\]/$1\[${new_fail_count}\]/g")
+ update_cache
else
failover add $1
refresh_dns
refresh_loadbalancer
fi
fi
+
fi
fi
-query_config update
}
recvrychk=$(query_config recvrychk $1)
wanid=$(query_config wanid $1)
+if [ ! -z "$failchk" -a "$failchk" != "x" ]; then
+ wan_fail_map=$(echo $wan_fail_map | sed -e "s/${1}\[${failchk}\]//g")
+ update_cache
+fi
+
if [ "$failchk" == "x" ]; then
if [ -z "$recvrychk" ]; then
- wan_recovery_map="$wan_recovery_map $1[1]"
+ wan_recovery_map="$wan_recovery_map${1}[1]"
+ update_cache
if [ "$health_recovery_retries" == "1" ]; then
recover_wan $1
fi
new_recovery_count=$(expr $recvrychk + 1)
if [ "$new_recovery_count" -lt "$health_recovery_retries" ]; then
wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/${1}\[${recvrychk}\]/$1\[${new_recovery_count}\]/g")
+ update_cache
else
failover del $1
refresh_dns
fi
fi
fi
-
-query_config update
}
acquire_wan_data() {
if [ -z $check_old_map ]; then
wancount=`expr $wancount + 1`
- wan_if_map="$wan_if_map $1[${ifname}]"
- wan_id_map="$wan_id_map $1[${wancount}]"
- wan_gw_map="$wan_gw_map $1[${gateway}]"
- wan_ip_map="$wan_ip_map $1[${ipaddr}]"
+ wan_if_map="$wan_if_map${1}[${ifname}]"
+ wan_id_map="$wan_id_map${1}[${wancount}]"
+ wan_gw_map="$wan_gw_map${1}[${gateway}]"
+ wan_ip_map="$wan_ip_map${1}[${ipaddr}]"
else
old_ipaddr=$(query_config ipaddr $1)
old_gateway=$(query_config gateway $1)
if [ "$ifname" != "x" -a "$ipaddr" != "x" -a "$gateway" != "x" ]; then
failover del $1
iprules_config $get_wanid
- qos_init $1 $get_wanid
else
failover add $1
fi
refresh_routes
refresh_loadbalancer
refresh_dns
-
+ update_cache
fi
else
wancount=9
fi
-
-query_config update
}
-query_config() {
+update_cache() {
+
+if [ ! -d /tmp/.mwan ]; then
+mkdir /tmp/.mwan > /dev/null 2>&1
+fi
-update_cache_data() {
-rm /tmp/.mwan.cache > /dev/null 2>&1
-touch /tmp/.mwan.cache
-
-echo "# Automatically Generated by Multi-WAN Agent Script. Do not modify. #" > /tmp/.mwan.cache
-echo "wan_if_map=\"$wan_if_map\"" >> /tmp/.mwan.cache
-echo "wan_ip_map=\"$wan_ip_map\"" >> /tmp/.mwan.cache
-echo "wan_gw_map=\"$wan_gw_map\"" >> /tmp/.mwan.cache
-echo "wan_id_map=\"$wan_id_map\"" >> /tmp/.mwan.cache
-echo "wan_fail_map=\"$wan_fail_map\"" >> /tmp/.mwan.cache
-echo "wan_recovery_map=\"$wan_recovery_map\"" >> /tmp/.mwan.cache
+rm /tmp/.mwan/cache > /dev/null 2>&1
+touch /tmp/.mwan/cache
+
+echo "# Automatically Generated by Multi-WAN Agent Script. Do not modify or remove. #" > /tmp/.mwan/cache
+echo "wan_id_map=\"$wan_id_map\"" >> /tmp/.mwan/cache
+echo "wan_if_map=\"$wan_if_map\"" >> /tmp/.mwan/cache
+echo "wan_ip_map=\"$wan_ip_map\"" >> /tmp/.mwan/cache
+echo "wan_gw_map=\"$wan_gw_map\"" >> /tmp/.mwan/cache
+echo "wan_fail_map=\"$wan_fail_map\"" >> /tmp/.mwan/cache
+echo "wan_recovery_map=\"$wan_recovery_map\"" >> /tmp/.mwan/cache
}
+query_config() {
+
case $1 in
update) update_cache_data;;
ifname) echo $wan_if_map | grep -o "$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';;
echo "## Unloaded, updating syslog and exiting. ##"
mwnote "Succesfully Unloaded on $(exec date -R)."
+ip route flush cache
+rm -r /tmp/.mwan > /dev/null 2>&1
else
echo "## Restarting Multi-WAN. ##"
mwnote "Reinitializing Multi-WAN Configuration."
+ip route flush cache
+rm -r /tmp/.mwan > /dev/null 2>&1
/etc/init.d/multiwan start & > /dev/null 2>&1
-
fi
-ip route flush cache
-
-rm $jobfile > /dev/null 2>&1
-rm $jobfile.work > /dev/null 2>&1
-rm /tmp/.mwan.cache > /dev/null 2>&1
exit
}
local queue_count
local get_wan_tc
local get_wan_iptables
-local qos_done_chk
local add_qos_iptables
local add_qos_tc
local execute
local i
local p
-qos_done_chk=`echo $qos_done | grep -o "$1\."`
-
-if [ ! -z "$qos_done_chk" ]; then
-return
-fi
-
ifname=$(query_config ifname $1)
if [ "$ifname" == "x" ]; then
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")
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")
-rm /tmp/.mwan.$1.sedfilter > /dev/null 2>&1
i=0
while [ $i -lt $queue_count ]; do
-echo "s/\(0x$i \|0x$i\/0xffffffff\)/0x${2}${i} /g" >> /tmp/.mwan.$1.sedfilter
+echo "s/\(0x$i \|0x$i\/0xffffffff\)/0x${2}${i} /g" >> /tmp/.mwan/qos.$1.sedfilter
i=`expr $i + 1`
done
-add_qos_iptables=$(echo "$get_wan_iptables" | sed -f /tmp/.mwan.$1.sedfilter)
+add_qos_iptables=$(echo "$get_wan_iptables" | sed -f /tmp/.mwan/qos.$1.sedfilter)
echo "$add_qos_iptables" | while read execute; do ${execute}; done
-rm /tmp/.mwan.$1.sedfilter
+rm /tmp/.mwan/qos.$1.sedfilter
i=1
while [ $i -lt $queue_count ]; do
-echo "s/0x$i /0x${2}${i} fw /g" >> /tmp/.mwan.$1.sedfilter
+echo "s/0x$i /0x${2}${i} fw /g" >> /tmp/.mwan/qos.$1.sedfilter
i=`expr $i + 1`
done
-add_qos_tc=$(echo "$get_wan_tc" | sed -f /tmp/.mwan.$1.sedfilter)
+add_qos_tc=$(echo "$get_wan_tc" | sed -f /tmp/.mwan/qos.$1.sedfilter)
echo "$add_qos_tc" | while read execute; do ${execute}; done
-rm /tmp/.mwan.$1.sedfilter
+rm /tmp/.mwan/qos.$1.sedfilter
i=0
while [ $i -lt $queue_count ]; do
iptables -t mangle -A MultiWanQoS -m mark --mark 0x$p -j MultiWanQoS_${1}
i=`expr $i + 1`
done
-
-qos_done="$qos_done $1."
-
}
mwanrule() {
echo "## Main Initialization ##"
+mkdir /tmp/.mwan > /dev/null 2>&1
+
mwan_kill
flush
while [ 1 ]; do
-. /tmp/.mwan.cache
+. /tmp/.mwan/cache
if [ "$bg_counter" -eq 5 ]; then
config_foreach acquire_wan_data interface
+update_cache
+
CHKFORQOS=`iptables -n -L Default -t mangle 2>&1 | grep "Chain Default"`
-jobfile="/tmp/.mwan.jobqueue"
+jobfile="/tmp/.mwan/jobqueue"
case $1 in
agent) silencer main_init;;