[packages] multiwan: updated cache location, write times, adjusted failover and qos initilization

git-svn-id: svn://svn.openwrt.org/openwrt/packages@21279 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
craigc 2010-05-01 05:59:13 +00:00
parent 6f9e646ff2
commit 74f5ee2c0f
2 changed files with 54 additions and 56 deletions

View File

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=multiwan
PKG_VERSION:=1.0.2
PKG_VERSION:=1.0.3
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk

View File

@ -34,8 +34,9 @@ existing_failover=$(iptables -n -L FW${wanid}MARK -t mangle | echo $(expr $(wc -
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
@ -45,21 +46,18 @@ if [ "$existing_failover" == "2" ]; 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
@ -83,7 +81,8 @@ recvrychk=$(query_config recvrychk $1)
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
@ -92,6 +91,7 @@ else
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
@ -99,10 +99,10 @@ else
refresh_loadbalancer
fi
fi
fi
fi
query_config update
}
@ -121,9 +121,15 @@ failchk=$(query_config failchk $1)
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
@ -131,6 +137,7 @@ if [ "$failchk" == "x" ]; then
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
@ -140,8 +147,6 @@ if [ "$failchk" == "x" ]; then
fi
fi
fi
query_config update
}
acquire_wan_data() {
@ -174,10 +179,10 @@ check_old_map=`echo $wan_id_map 2>&1 | grep -o "$1\["`
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)
@ -198,7 +203,6 @@ check_old_map=`echo $wan_id_map 2>&1 | grep -o "$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
@ -206,30 +210,33 @@ check_old_map=`echo $wan_id_map 2>&1 | grep -o "$1\["`
refresh_routes
refresh_loadbalancer
refresh_dns
update_cache
fi
else
wancount=9
fi
}
query_config update
update_cache() {
if [ ! -d /tmp/.mwan ]; then
mkdir /tmp/.mwan > /dev/null 2>&1
fi
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() {
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
}
case $1 in
update) update_cache_data;;
ifname) echo $wan_if_map | grep -o "$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';;
@ -275,20 +282,18 @@ fi
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
}
@ -348,19 +353,12 @@ local ifname
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
@ -381,26 +379,25 @@ iptables -t mangle -N MultiWanQoS_${1}_ct
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
@ -411,9 +408,6 @@ fi
iptables -t mangle -A MultiWanQoS -m mark --mark 0x$p -j MultiWanQoS_${1}
i=`expr $i + 1`
done
qos_done="$qos_done $1."
}
mwanrule() {
@ -774,6 +768,8 @@ local i
echo "## Main Initialization ##"
mkdir /tmp/.mwan > /dev/null 2>&1
mwan_kill
flush
@ -921,7 +917,7 @@ bg_counter=0
while [ 1 ]; do
. /tmp/.mwan.cache
. /tmp/.mwan/cache
if [ "$bg_counter" -eq 5 ]; then
@ -1001,9 +997,11 @@ config_get debug config debug
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;;