Ignore:
Timestamp:
2010-05-10T02:55:25+02:00 (6 years ago)
Author:
craigc
Message:

[packages] multiwan:

  • Now makes use of statistic module/random for better equal multipath load balancing
  • Seperated mangle rules out for better connmark handling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • packages/net/multiwan/files/usr/bin/multiwan

    r21343 r21413  
    564564iptables -t mangle -N MultiWanPreHandler 
    565565iptables -t mangle -N MultiWanPostHandler 
     566iptables -t mangle -N MultiWanLoadBalancer 
    566567 
    567568echo "## Creating FW Rules ##" 
     
    579580 
    580581iptables -t mangle -I PREROUTING -j MultiWan 
     582iptables -t mangle -I PREROUTING 2 -j MultiWanPreHandler 
     583iptables -t mangle -I PREROUTING 3 -j MultiWanDNS 
     584iptables -t mangle -I PREROUTING 4 -j MultiWanRules 
     585iptables -t mangle -I PREROUTING 5 -j MultiWanLoadBalancer 
     586 
    581587iptables -t mangle -I FORWARD -j MultiWan 
     588 
    582589iptables -t mangle -I OUTPUT -j MultiWan 
     590iptables -t mangle -I OUTPUT 2 -j MultiWanDNS 
     591iptables -t mangle -I OUTPUT 3 -j MultiWanRules 
     592iptables -t mangle -I OUTPUT 4 -j MultiWanLoadBalancer 
     593iptables -t mangle -I OUTPUT 5 -j MultiWanPostHandler 
     594 
     595 
    583596iptables -t mangle -I POSTROUTING -j MultiWan 
     597iptables -t mangle -I POSTROUTING 2 -j MultiWanPostHandler 
    584598 
    585599iptables -t mangle -A MultiWan -j CONNMARK --restore-mark 
    586 iptables -t mangle -A MultiWan -j MultiWanPreHandler 
    587600 
    588601refresh_dns 
     
    597610iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j LoadBalancer 
    598611fi 
    599  
    600 iptables -t mangle -A MultiWan -j MultiWanRules 
    601 iptables -t mangle -A MultiWan -j MultiWanDNS 
    602 iptables -t mangle -A MultiWan -j MultiWanPostHandler 
    603612 
    604613i=0 
     
    612621 
    613622if [ ! -z "$CHKFORQOS" ]; then 
    614 iptables -t mangle -A MultiWan -j MultiWanQoS 
     623iptables -t mangle -I PREROUTING 6 -j MultiWanQoS 
     624iptables -t mangle -A FORWARD -j MultiWanQoS 
     625iptables -t mangle -A OUTPUT -j MultiWanQoS 
     626iptables -t mangle -A POSTROUTING -j MultiWanQoS 
    615627fi 
    616628} 
     
    624636local nexthop 
    625637local pre_nexthop_chk 
     638local rand_probability 
     639local total_weight 
    626640local i 
    627  
    628641 
    629642echo "## Refreshing Load Balancer ##" 
     
    644657         done 
    645658 
     659total_weight=0 
     660 
     661iptables -F MultiWanLoadBalancer -t mangle 
     662 
     663i=0 
     664while [ $i -lt $wancount ]; do  
     665i=`expr $i + 1`  
     666group=$(query_config group $i) 
     667weight=`uci -q -P /var/state get multiwan.${group}.weight` 
     668total_weight=$(expr $total_weight + $weight) 
     669done 
     670 
    646671i=0 
    647672while [ $i -lt $wancount ]; do  
     
    656681if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then 
    657682nexthop="$nexthop nexthop via $gateway dev $ifname weight $weight" 
    658 fi 
     683rand_probability=$(expr $(expr $weight \* 100) / $total_weight) 
     684 
     685        if [ $rand_probability -lt 10 ]; then 
     686                rand_probability="0.0${rand_probability}" 
     687        else  
     688                rand_probability="0.${rand_probability}" 
     689        fi 
     690 
     691        if [ -z "$CHKFORMODULE" ]; then 
     692                iptables -A MultiWanLoadBalancer -t mangle -m mark --mark 0x123 -m statistic --mode random --probability $rand_probability -j FW${i}MARK 
     693        fi 
     694fi 
     695 
    659696done 
    660697 
     
    774811flush 
    775812 
    776 refresh_loadbalancer 
    777813 
    778814echo "## IP Rules Initialization ##" 
     
    785821refresh_routes 
    786822iptables_init 
     823 
     824refresh_loadbalancer 
    787825 
    788826RP_PATH=/proc/sys/net/ipv4/conf 
     
    10031041 
    10041042CHKFORQOS=`iptables -n -L Default -t mangle 2>&1 | grep "Chain Default"` 
     1043CHKFORMODULE=`iptables -m statistic 2>&1 | grep -o "File not found"` 
    10051044 
    10061045jobfile="/tmp/.mwan/jobqueue" 
Note: See TracChangeset for help on using the changeset viewer.