[packages] multiwan:

- updated revision
- overhauled probability matrix for netfilter route selection
- added configuration options for specifying method of traffic distribution per default route/rule/failover (iproute/netfilter)


git-svn-id: svn://svn.openwrt.org/openwrt/packages@21448 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
craigc 2010-05-14 12:41:50 +00:00
parent 9ecb712861
commit f09ff069e5
3 changed files with 32 additions and 39 deletions

View File

@ -8,8 +8,8 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=multiwan PKG_NAME:=multiwan
PKG_VERSION:=1.0.11 PKG_VERSION:=1.0.12
PKG_RELEASE:=2 PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk

View File

@ -32,10 +32,10 @@ config 'mwanfw'
config 'mwanfw' config 'mwanfw'
option 'src' '192.168.0.3' option 'src' '192.168.0.3'
option 'proto' 'icmp' option 'proto' 'icmp'
option 'wanrule' 'wan' option 'wanrule' 'balancer'
config 'mwanfw' config 'mwanfw'
option 'dst' 'www.whatismyip.com' option 'dst' 'www.whatismyip.com'
option 'wanrule' 'balancer' option 'wanrule' 'fastbalancer'

View File

@ -39,10 +39,12 @@ add() {
update_cache 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" != "fastbalancer" -a "$failover_to" != "disable" -a "$failover_to_wanid" != "$wanid" ]; then
iptables -I FW${wanid}MARK 2 -t mangle -j FW${failover_to_wanid}MARK iptables -I FW${wanid}MARK 2 -t mangle -j FW${failover_to_wanid}MARK
elif [ "$failover_to" == "balancer" ]; then elif [ "$failover_to" == "balancer" ]; then
iptables -I FW${wanid}MARK 2 -t mangle -j LoadBalancer iptables -I FW${wanid}MARK 2 -t mangle -j LoadBalancer
elif [ "$failover_to" == "fastbalancer" ]; then
iptables -I FW${wanid}MARK 2 -t mangle -j FastBalancer
fi fi
fi fi
mwnote "$1 has failed and is currently offline." mwnote "$1 has failed and is currently offline."
@ -317,6 +319,8 @@ iptables -t mangle -F MultiWanPostHandler
iptables -t mangle -X MultiWanPostHandler iptables -t mangle -X MultiWanPostHandler
iptables -t mangle -F LoadBalancer iptables -t mangle -F LoadBalancer
iptables -t mangle -X LoadBalancer iptables -t mangle -X LoadBalancer
iptables -t mangle -F FastBalancer
iptables -t mangle -X FastBalancer
i=0 i=0
while [ $i -lt $wancount ]; do while [ $i -lt $wancount ]; do
@ -429,11 +433,13 @@ mwanrule() {
return return
fi fi
if [ "$wanrule" != "balancer" ]; then if [ "$wanrule" != "balancer" -a "$wanrule" != "fastbalancer" ]; then
wanrule=$(query_config wanid ${wanrule}) wanrule=$(query_config wanid ${wanrule})
wanrule="FW${wanrule}MARK" wanrule="FW${wanrule}MARK"
elif [ "$wanrule" == "balancer" ]; then elif [ "$wanrule" == "balancer" ]; then
wanrule="LoadBalancer" wanrule="LoadBalancer"
elif [ "$wanrule" == "fastbalancer" ]; then
wanrule="FastBalancer"
fi fi
if [ "$dst" == "all" ]; then if [ "$dst" == "all" ]; then
dst=$NULL dst=$NULL
@ -559,11 +565,12 @@ fi
iptables -t mangle -N MultiWan iptables -t mangle -N MultiWan
iptables -t mangle -N LoadBalancer iptables -t mangle -N LoadBalancer
iptables -t mangle -N FastBalancer
iptables -t mangle -N MultiWanRules iptables -t mangle -N MultiWanRules
iptables -t mangle -N MultiWanDNS iptables -t mangle -N MultiWanDNS
iptables -t mangle -N MultiWanPreHandler iptables -t mangle -N MultiWanPreHandler
iptables -t mangle -N MultiWanPostHandler iptables -t mangle -N MultiWanPostHandler
iptables -t mangle -N MultiWanLoadBalancer iptables -t mangle -N MultiWanFastBalancer
echo "## Creating FW Rules ##" echo "## Creating FW Rules ##"
i=0 i=0
@ -578,18 +585,27 @@ done
iptables -t mangle -A LoadBalancer -j MARK --set-mark 0x123 iptables -t mangle -A LoadBalancer -j MARK --set-mark 0x123
iptables -t mangle -A LoadBalancer -j CONNMARK --save-mark iptables -t mangle -A LoadBalancer -j CONNMARK --save-mark
if [ -z "$CHKFORMODULE" ]; then
iptables -t mangle -A FastBalancer -j MARK --set-mark 0x124
iptables -t mangle -A FastBalancer -j CONNMARK --save-mark
else
mwnote "Fast Balancer is unavailable due to missing netfilter statistics module, resorting to standard route based load balancer."
iptables -t mangle -A FastBalancer -j MARK --set-mark 0x123
iptables -t mangle -A FastBalancer -j CONNMARK --save-mark
fi
iptables -t mangle -I PREROUTING -j MultiWan iptables -t mangle -I PREROUTING -j MultiWan
iptables -t mangle -I PREROUTING 2 -j MultiWanPreHandler iptables -t mangle -I PREROUTING 2 -j MultiWanPreHandler
iptables -t mangle -I PREROUTING 3 -j MultiWanDNS iptables -t mangle -I PREROUTING 3 -j MultiWanDNS
iptables -t mangle -I PREROUTING 4 -j MultiWanRules iptables -t mangle -I PREROUTING 4 -j MultiWanRules
iptables -t mangle -I PREROUTING 5 -j MultiWanLoadBalancer iptables -t mangle -I PREROUTING 5 -j MultiWanFastBalancer
iptables -t mangle -I FORWARD -j MultiWan iptables -t mangle -I FORWARD -j MultiWan
iptables -t mangle -I OUTPUT -j MultiWan iptables -t mangle -I OUTPUT -j MultiWan
iptables -t mangle -I OUTPUT 2 -j MultiWanDNS iptables -t mangle -I OUTPUT 2 -j MultiWanDNS
iptables -t mangle -I OUTPUT 3 -j MultiWanRules iptables -t mangle -I OUTPUT 3 -j MultiWanRules
iptables -t mangle -I OUTPUT 4 -j MultiWanLoadBalancer iptables -t mangle -I OUTPUT 4 -j MultiWanFastBalancer
iptables -t mangle -I OUTPUT 5 -j MultiWanPostHandler iptables -t mangle -I OUTPUT 5 -j MultiWanPostHandler
@ -603,9 +619,11 @@ refresh_dns
config_load "multiwan" config_load "multiwan"
config_foreach mwanrule mwanfw config_foreach mwanrule mwanfw
if [ "$default_route" != "balancer" ]; then if [ "$default_route" != "balancer" -a "$default_route" != "fastbalancer" ]; then
default_route_id=$(query_config wanid $default_route) default_route_id=$(query_config wanid $default_route)
iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j FW${default_route_id}MARK iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j FW${default_route_id}MARK
elif [ "$default_route" == "fastbalancer" ]; then
iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j FastBalancer
else else
iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j LoadBalancer iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j LoadBalancer
fi fi
@ -636,14 +654,8 @@ local weight
local nexthop local nexthop
local pre_nexthop_chk local pre_nexthop_chk
local rand_probability local rand_probability
local last_probability
local total_weight local total_weight
local total_wans
local roundme
local roundlen
local i local i
local x
local n
echo "## Refreshing Load Balancer ##" echo "## Refreshing Load Balancer ##"
@ -662,10 +674,9 @@ ip route flush table 123 > /dev/null 2>&1
done done
done done
iptables -F MultiWanLoadBalancer -t mangle iptables -F MultiWanFastBalancer -t mangle
total_weight=0 total_weight=0
total_wans=0
i=0 i=0
while [ $i -lt $wancount ]; do while [ $i -lt $wancount ]; do
@ -677,16 +688,9 @@ ifname=$(query_config ifname $group)
weight=`uci -q -P /var/state get multiwan.${group}.weight` weight=`uci -q -P /var/state get multiwan.${group}.weight`
if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then
total_weight=$(expr $total_weight + $weight) total_weight=$(expr $total_weight + $weight)
total_wans=$i
fi fi
done done
last_probability=0
roundme=0
roundlen=0
x=0
n=0
i=0 i=0
while [ $i -lt $wancount ]; do while [ $i -lt $wancount ]; do
i=`expr $i + 1` i=`expr $i + 1`
@ -700,19 +704,8 @@ weight=`uci -q -P /var/state get multiwan.${group}.weight`
if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then
nexthop="$nexthop nexthop via $gateway dev $ifname weight $weight" nexthop="$nexthop nexthop via $gateway dev $ifname weight $weight"
n=$(expr $n + $last_probability) rand_probability=$(expr $(expr $weight \* 100) / $total_weight)
last_probability=$(expr $x / $(expr $total_wans - $i + 1)) total_weight=$(expr $total_weight - $weight)
rand_probability=$(expr $(expr $weight \* 1000) / $total_weight)
roundlen=`expr length $rand_probability - 1`
roundme=${rand_probability:$roundlen}
rand_probability=$(echo $rand_probability | sed 's/\(..\)\(.\)/\1/g')
if [ $roundme -ge 5 ]; then
rand_probability=$(expr $rand_probability + 1)
fi
rand_probability=$(expr $rand_probability + $n + $last_probability)
x=$rand_probability
if [ $rand_probability -lt 10 ]; then if [ $rand_probability -lt 10 ]; then
rand_probability="0.0${rand_probability}" rand_probability="0.0${rand_probability}"
@ -723,7 +716,7 @@ x=$rand_probability
fi fi
if [ -z "$CHKFORMODULE" ]; then if [ -z "$CHKFORMODULE" ]; then
iptables -A MultiWanLoadBalancer -t mangle -m mark --mark 0x123 -m statistic --mode random --probability $rand_probability -j FW${i}MARK iptables -A MultiWanFastBalancer -t mangle -m mark --mark 0x124 -m statistic --mode random --probability $rand_probability -j FW${i}MARK
fi fi
fi fi