Changeset 21448


Ignore:
Timestamp:
2010-05-14T14:41:50+02:00 (7 years ago)
Author:
craigc
Message:

[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)
Location:
packages/net/multiwan
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • packages/net/multiwan/Makefile

    r21433 r21448  
    99 
    1010PKG_NAME:=multiwan 
    11 PKG_VERSION:=1.0.11 
    12 PKG_RELEASE:=2 
     11PKG_VERSION:=1.0.12 
     12PKG_RELEASE:=1 
    1313 
    1414include $(INCLUDE_DIR)/package.mk 
  • packages/net/multiwan/files/etc/config/multiwan

    r21273 r21448  
    3333        option 'src' '192.168.0.3' 
    3434        option 'proto' 'icmp' 
    35         option 'wanrule' 'wan' 
     35        option 'wanrule' 'balancer' 
    3636 
    3737config 'mwanfw' 
    3838        option 'dst' 'www.whatismyip.com' 
    39         option 'wanrule' 'balancer' 
     39        option 'wanrule' 'fastbalancer' 
    4040 
    4141 
  • packages/net/multiwan/files/usr/bin/multiwan

    r21433 r21448  
    4040 
    4141if [ "$existing_failover" == "2" ]; then 
    42         if [ "$failover_to" != "balancer" -a "$failover_to" != "disable" -a "$failover_to_wanid" != "$wanid" ]; then 
     42        if [ "$failover_to" != "balancer" -a "$failover_to" != "fastbalancer" -a "$failover_to" != "disable" -a "$failover_to_wanid" != "$wanid" ]; then 
    4343                iptables -I FW${wanid}MARK 2 -t mangle -j FW${failover_to_wanid}MARK 
    4444        elif [ "$failover_to" == "balancer" ]; then 
    4545                iptables -I FW${wanid}MARK 2 -t mangle -j LoadBalancer 
     46        elif [ "$failover_to" == "fastbalancer" ]; then 
     47                iptables -I FW${wanid}MARK 2 -t mangle -j FastBalancer 
    4648        fi 
    4749fi 
     
    318320iptables -t mangle -F LoadBalancer 
    319321iptables -t mangle -X LoadBalancer 
     322iptables -t mangle -F FastBalancer 
     323iptables -t mangle -X FastBalancer 
    320324 
    321325i=0 
     
    430434       fi 
    431435 
    432     if [ "$wanrule" != "balancer" ]; then 
     436    if [ "$wanrule" != "balancer" -a "$wanrule" != "fastbalancer" ]; then 
    433437       wanrule=$(query_config wanid ${wanrule}) 
    434438       wanrule="FW${wanrule}MARK" 
    435439    elif [ "$wanrule" == "balancer" ]; then 
    436440       wanrule="LoadBalancer" 
     441    elif [ "$wanrule" == "fastbalancer" ]; then 
     442       wanrule="FastBalancer" 
    437443    fi 
    438444    if [ "$dst" == "all" ]; then 
     
    560566iptables -t mangle -N MultiWan 
    561567iptables -t mangle -N LoadBalancer 
     568iptables -t mangle -N FastBalancer 
    562569iptables -t mangle -N MultiWanRules 
    563570iptables -t mangle -N MultiWanDNS 
    564571iptables -t mangle -N MultiWanPreHandler 
    565572iptables -t mangle -N MultiWanPostHandler 
    566 iptables -t mangle -N MultiWanLoadBalancer 
     573iptables -t mangle -N MultiWanFastBalancer 
    567574 
    568575echo "## Creating FW Rules ##" 
     
    579586iptables -t mangle -A LoadBalancer -j CONNMARK --save-mark 
    580587 
     588if [ -z "$CHKFORMODULE" ]; then 
     589iptables -t mangle -A FastBalancer -j MARK --set-mark 0x124 
     590iptables -t mangle -A FastBalancer -j CONNMARK --save-mark 
     591else 
     592mwnote "Fast Balancer is unavailable due to missing netfilter statistics module, resorting to standard route based load balancer." 
     593iptables -t mangle -A FastBalancer -j MARK --set-mark 0x123 
     594iptables -t mangle -A FastBalancer -j CONNMARK --save-mark 
     595fi 
     596 
    581597iptables -t mangle -I PREROUTING -j MultiWan 
    582598iptables -t mangle -I PREROUTING 2 -j MultiWanPreHandler 
    583599iptables -t mangle -I PREROUTING 3 -j MultiWanDNS 
    584600iptables -t mangle -I PREROUTING 4 -j MultiWanRules 
    585 iptables -t mangle -I PREROUTING 5 -j MultiWanLoadBalancer 
     601iptables -t mangle -I PREROUTING 5 -j MultiWanFastBalancer 
    586602 
    587603iptables -t mangle -I FORWARD -j MultiWan 
     
    590606iptables -t mangle -I OUTPUT 2 -j MultiWanDNS 
    591607iptables -t mangle -I OUTPUT 3 -j MultiWanRules 
    592 iptables -t mangle -I OUTPUT 4 -j MultiWanLoadBalancer 
     608iptables -t mangle -I OUTPUT 4 -j MultiWanFastBalancer 
    593609iptables -t mangle -I OUTPUT 5 -j MultiWanPostHandler 
    594610 
     
    604620config_foreach mwanrule mwanfw 
    605621 
    606 if [ "$default_route" != "balancer" ]; then  
     622if [ "$default_route" != "balancer" -a "$default_route" != "fastbalancer" ]; then  
    607623default_route_id=$(query_config wanid $default_route) 
    608624iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j FW${default_route_id}MARK 
     625elif [ "$default_route" == "fastbalancer" ]; then 
     626iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j FastBalancer 
    609627else 
    610628iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j LoadBalancer 
     
    637655local pre_nexthop_chk 
    638656local rand_probability 
    639 local last_probability 
    640657local total_weight 
    641 local total_wans 
    642 local roundme 
    643 local roundlen 
    644658local i 
    645 local x 
    646 local n 
    647659 
    648660echo "## Refreshing Load Balancer ##" 
     
    663675         done 
    664676 
    665 iptables -F MultiWanLoadBalancer -t mangle 
     677iptables -F MultiWanFastBalancer -t mangle 
    666678 
    667679total_weight=0 
    668 total_wans=0 
    669680 
    670681i=0 
     
    678689        if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then 
    679690                total_weight=$(expr $total_weight + $weight) 
    680                 total_wans=$i 
    681691        fi 
    682692done 
    683  
    684 last_probability=0 
    685 roundme=0 
    686 roundlen=0 
    687 x=0 
    688 n=0  
    689693 
    690694i=0 
     
    701705nexthop="$nexthop nexthop via $gateway dev $ifname weight $weight" 
    702706 
    703 n=$(expr $n + $last_probability) 
    704 last_probability=$(expr $x / $(expr $total_wans - $i + 1)) 
    705 rand_probability=$(expr $(expr $weight \* 1000) / $total_weight) 
    706 roundlen=`expr length $rand_probability - 1` 
    707 roundme=${rand_probability:$roundlen} 
    708 rand_probability=$(echo $rand_probability | sed 's/\(..\)\(.\)/\1/g') 
    709          
    710         if [ $roundme -ge 5 ]; then 
    711                 rand_probability=$(expr $rand_probability + 1) 
    712         fi 
    713  
    714 rand_probability=$(expr $rand_probability + $n + $last_probability) 
    715 x=$rand_probability 
     707rand_probability=$(expr $(expr $weight \* 100) / $total_weight) 
     708total_weight=$(expr $total_weight - $weight) 
    716709 
    717710        if [ $rand_probability -lt 10 ]; then 
     
    724717 
    725718        if [ -z "$CHKFORMODULE" ]; then 
    726                 iptables -A MultiWanLoadBalancer -t mangle -m mark --mark 0x123 -m statistic --mode random --probability $rand_probability -j FW${i}MARK 
     719                iptables -A MultiWanFastBalancer -t mangle -m mark --mark 0x124 -m statistic --mode random --probability $rand_probability -j FW${i}MARK 
    727720        fi 
    728721fi 
Note: See TracChangeset for help on using the changeset viewer.