[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 include $(TOPDIR)/rules.mk
PKG_NAME:=multiwan PKG_NAME:=multiwan
PKG_VERSION:=1.0.2 PKG_VERSION:=1.0.3
PKG_RELEASE:=1 PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk 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() { add() {
wan_fail_map=$(echo $wan_fail_map | sed -e "s/${1}\[${failchk}\]//g") 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") wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/${1}\[${recvrychk}\]//g")
update_cache
if [ "$existing_failover" == "2" ]; then if [ "$existing_failover" == "2" ]; then
if [ "$failover_to" != "balancer" -a "$failover_to" != "disable" -a "$failover_to_wanid" != "$wanid" ]; 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
fi fi
mwnote "$1 has failed and is currently offline." mwnote "$1 has failed and is currently offline."
query_config update
} }
del() { del() {
wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/${1}\[${recvrychk}\]//g") 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") wan_fail_map=$(echo $wan_fail_map | sed -e "s/${1}\[${failchk}\]//g")
update_cache
if [ "$existing_failover" == "3" ]; then if [ "$existing_failover" == "3" ]; then
iptables -D FW${wanid}MARK 2 -t mangle iptables -D FW${wanid}MARK 2 -t mangle
fi fi
mwnote "$1 has recovered and is back online!" mwnote "$1 has recovered and is back online!"
query_config update
} }
case $1 in 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") wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/${1}\[${recvrychk}\]//g")
if [ -z "$failchk" ]; then 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 if [ "$health_fail_retries" == "1" ]; then
fail_wan $1 fail_wan $1
fi fi
@ -92,6 +91,7 @@ else
new_fail_count=$(expr $failchk + 1) new_fail_count=$(expr $failchk + 1)
if [ "$new_fail_count" -lt "$health_fail_retries" ]; then 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") wan_fail_map=$(echo $wan_fail_map | sed -e "s/${1}\[${failchk}\]/$1\[${new_fail_count}\]/g")
update_cache
else else
failover add $1 failover add $1
refresh_dns refresh_dns
@ -99,10 +99,10 @@ else
refresh_loadbalancer refresh_loadbalancer
fi fi
fi fi
fi fi
fi fi
query_config update
} }
@ -121,9 +121,15 @@ failchk=$(query_config failchk $1)
recvrychk=$(query_config recvrychk $1) recvrychk=$(query_config recvrychk $1)
wanid=$(query_config wanid $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 [ "$failchk" == "x" ]; then
if [ -z "$recvrychk" ]; 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 if [ "$health_recovery_retries" == "1" ]; then
recover_wan $1 recover_wan $1
fi fi
@ -131,6 +137,7 @@ if [ "$failchk" == "x" ]; then
new_recovery_count=$(expr $recvrychk + 1) new_recovery_count=$(expr $recvrychk + 1)
if [ "$new_recovery_count" -lt "$health_recovery_retries" ]; then 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") wan_recovery_map=$(echo $wan_recovery_map | sed -e "s/${1}\[${recvrychk}\]/$1\[${new_recovery_count}\]/g")
update_cache
else else
failover del $1 failover del $1
refresh_dns refresh_dns
@ -140,8 +147,6 @@ if [ "$failchk" == "x" ]; then
fi fi
fi fi
fi fi
query_config update
} }
acquire_wan_data() { 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 if [ -z $check_old_map ]; then
wancount=`expr $wancount + 1` wancount=`expr $wancount + 1`
wan_if_map="$wan_if_map $1[${ifname}]" wan_if_map="$wan_if_map${1}[${ifname}]"
wan_id_map="$wan_id_map $1[${wancount}]" wan_id_map="$wan_id_map${1}[${wancount}]"
wan_gw_map="$wan_gw_map $1[${gateway}]" wan_gw_map="$wan_gw_map${1}[${gateway}]"
wan_ip_map="$wan_ip_map $1[${ipaddr}]" wan_ip_map="$wan_ip_map${1}[${ipaddr}]"
else else
old_ipaddr=$(query_config ipaddr $1) old_ipaddr=$(query_config ipaddr $1)
old_gateway=$(query_config gateway $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 if [ "$ifname" != "x" -a "$ipaddr" != "x" -a "$gateway" != "x" ]; then
failover del $1 failover del $1
iprules_config $get_wanid iprules_config $get_wanid
qos_init $1 $get_wanid
else else
failover add $1 failover add $1
fi fi
@ -206,30 +210,33 @@ check_old_map=`echo $wan_id_map 2>&1 | grep -o "$1\["`
refresh_routes refresh_routes
refresh_loadbalancer refresh_loadbalancer
refresh_dns refresh_dns
update_cache
fi fi
else else
wancount=9 wancount=9
fi 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() { 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 case $1 in
update) update_cache_data;; update) update_cache_data;;
ifname) echo $wan_if_map | grep -o "$2\[\w*.*\]" | awk -F "[" '{print $2}' | awk -F "]" '{print $1}';; 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. ##" echo "## Unloaded, updating syslog and exiting. ##"
mwnote "Succesfully Unloaded on $(exec date -R)." mwnote "Succesfully Unloaded on $(exec date -R)."
ip route flush cache
rm -r /tmp/.mwan > /dev/null 2>&1
else else
echo "## Restarting Multi-WAN. ##" echo "## Restarting Multi-WAN. ##"
mwnote "Reinitializing Multi-WAN Configuration." 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 /etc/init.d/multiwan start & > /dev/null 2>&1
fi 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 exit
} }
@ -348,19 +353,12 @@ local ifname
local queue_count local queue_count
local get_wan_tc local get_wan_tc
local get_wan_iptables local get_wan_iptables
local qos_done_chk
local add_qos_iptables local add_qos_iptables
local add_qos_tc local add_qos_tc
local execute local execute
local i local i
local p local p
qos_done_chk=`echo $qos_done | grep -o "$1\."`
if [ ! -z "$qos_done_chk" ]; then
return
fi
ifname=$(query_config ifname $1) ifname=$(query_config ifname $1)
if [ "$ifname" == "x" ]; then 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_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") 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 i=0
while [ $i -lt $queue_count ]; do 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` i=`expr $i + 1`
done 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 echo "$add_qos_iptables" | while read execute; do ${execute}; done
rm /tmp/.mwan.$1.sedfilter rm /tmp/.mwan/qos.$1.sedfilter
i=1 i=1
while [ $i -lt $queue_count ]; do 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` i=`expr $i + 1`
done 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 echo "$add_qos_tc" | while read execute; do ${execute}; done
rm /tmp/.mwan.$1.sedfilter rm /tmp/.mwan/qos.$1.sedfilter
i=0 i=0
while [ $i -lt $queue_count ]; do while [ $i -lt $queue_count ]; do
@ -411,9 +408,6 @@ fi
iptables -t mangle -A MultiWanQoS -m mark --mark 0x$p -j MultiWanQoS_${1} iptables -t mangle -A MultiWanQoS -m mark --mark 0x$p -j MultiWanQoS_${1}
i=`expr $i + 1` i=`expr $i + 1`
done done
qos_done="$qos_done $1."
} }
mwanrule() { mwanrule() {
@ -774,6 +768,8 @@ local i
echo "## Main Initialization ##" echo "## Main Initialization ##"
mkdir /tmp/.mwan > /dev/null 2>&1
mwan_kill mwan_kill
flush flush
@ -921,7 +917,7 @@ bg_counter=0
while [ 1 ]; do while [ 1 ]; do
. /tmp/.mwan.cache . /tmp/.mwan/cache
if [ "$bg_counter" -eq 5 ]; then if [ "$bg_counter" -eq 5 ]; then
@ -1001,9 +997,11 @@ config_get debug config debug
config_foreach acquire_wan_data interface config_foreach acquire_wan_data interface
update_cache
CHKFORQOS=`iptables -n -L Default -t mangle 2>&1 | grep "Chain Default"` CHKFORQOS=`iptables -n -L Default -t mangle 2>&1 | grep "Chain Default"`
jobfile="/tmp/.mwan.jobqueue" jobfile="/tmp/.mwan/jobqueue"
case $1 in case $1 in
agent) silencer main_init;; agent) silencer main_init;;