Changeset 21831


Ignore:
Timestamp:
2010-06-18T05:22:19+02:00 (7 years ago)
Author:
craigc
Message:

[packages] multiwan:
Routing tables now begin at 300+, to stay away from default routing tables.
Changed message for fastbalancer failure.
Changed QoS portion to allow more WANs, added check to make sure same interface doesnt receive qos configuration twice.
Restructured order of iptables so DNS comes last, and utilizing differnt fwmark for load balancing.

Location:
packages/net/multiwan
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • packages/net/multiwan/Makefile

    r21487 r21831  
    99 
    1010PKG_NAME:=multiwan 
    11 PKG_VERSION:=1.0.12 
    12 PKG_RELEASE:=2 
     11PKG_VERSION:=1.0.13 
     12PKG_RELEASE:=1 
    1313 
    1414include $(INCLUDE_DIR)/package.mk 
     
    2626An agent script that makes Multi-WAN configuration simple, 
    2727easy and manageable. Complete with load balancing, failover and an easy 
    28 to manage traffic ruleset. Allows for configuration of up to 9 wan links. 
     28to manage traffic ruleset. 
    2929endef 
    3030 
  • packages/net/multiwan/files/usr/bin/multiwan

    r21487 r21831  
    153153 
    154154acquire_wan_data() { 
    155 if [ $wancount -lt 9 ]; then 
    156  
    157155local ipaddr 
    158156local gateway 
     
    199197                iptables -D MultiWanPreHandler -t mangle -i $old_$ifname -m state --state NEW -j FW${get_wanid}MARK 
    200198                iptables -A MultiWanPreHandler -t mangle -i $ifname -m state --state NEW -j FW${get_wanid}MARK  
    201                 iptables -D MultiWanPostHandler -t mangle -o $old_$ifname -m mark --mark 0x123 -j FW${get_wanid}MARK 
    202                 iptables -A MultiWanPostHandler -t mangle -o $ifname -m mark --mark 0x123 -j FW${get_wanid}MARK  
     199                iptables -D MultiWanPostHandler -t mangle -o $old_$ifname -m mark --mark 0x1 -j FW${get_wanid}MARK 
     200                iptables -A MultiWanPostHandler -t mangle -o $ifname -m mark --mark 0x1 -j FW${get_wanid}MARK  
    203201                fi  
    204202 
     
    215213                update_cache 
    216214        fi 
    217 else 
    218 wancount=9 
    219 fi 
    220215} 
    221216 
     
    278273                ifup $group > /dev/null 2>&1 & 
    279274        done 
    280  
    281 if [ ! -z "$CHKFORQOS" ]; then 
    282 /etc/init.d/qos restart & > /dev/null 2>&1 
    283 fi 
    284275 
    285276echo "## Unloaded, updating syslog and exiting. ##" 
     
    344335i=`expr $i + 1`  
    345336group=$(query_config group $i) 
    346 iptables -t mangle -F MultiWanQoS_${group} 
    347 iptables -t mangle -F MultiWanQoS_${group}_ct 
    348 iptables -t mangle -X MultiWanQoS_${group} 
    349 iptables -t mangle -X MultiWanQoS_${group}_ct 
     337iptables -t mangle -F ${group} 
     338iptables -t mangle -F ${group}_ct 
     339iptables -t mangle -X ${group} 
     340iptables -t mangle -X ${group}_ct 
    350341done 
    351342 
     
    361352local add_qos_tc 
    362353local execute 
     354local iprule 
     355local qos_if_test 
    363356local i  
    364357local p 
    365358 
    366359ifname=$(query_config ifname $1) 
     360iprule=$(expr $2 \* 10) 
    367361 
    368362if [ "$ifname" == "x" ]; then 
     
    370364fi 
    371365 
     366qos_if_test=$(echo $qos_if_done | grep $ifname.) 
     367 
     368if [ ! -z "$qos_if_test" ]; then 
     369return 
     370fi 
     371 
     372qos_if_done=$(echo ${qos_if_done}.${ifname}) 
     373 
    372374queue_count=$(tc filter list dev $ifname | tail -n 1 | awk -F " " '{print $10}' | sed "s/0x//g") 
    373375 
     
    378380queue_count=`expr $queue_count + 1` 
    379381 
    380 iptables -t mangle -N MultiWanQoS_${1} 
    381 iptables -t mangle -N MultiWanQoS_${1}_ct 
     382iptables -t mangle -N ${1} 
     383iptables -t mangle -N ${1}_ct 
    382384 
    383385get_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")  
    384 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") 
     386get_wan_iptables=$(iptables-save | egrep  '(-A Default )|(-A Default_ct )' | grep -v "MultiWanQoS" | sed -e "s/Default /${1} /g" -e "s/Default_ct /${1}_ct /g" -e "s/-A/iptables -t mangle -A/g") 
     387 
    385388 
    386389i=0 
    387390while [ $i -lt $queue_count ]; do  
    388 echo "s/\(0x$i \|0x$i\/0xffffffff\)/0x${2}${i} /g" >> /tmp/.mwan/qos.$1.sedfilter 
     391echo "s/\(0x$i \|0x$i\/0xffffffff\)/0x$(expr $iprule + $i) /g" >> /tmp/.mwan/qos.$1.sedfilter 
    389392i=`expr $i + 1`  
    390393done 
     
    406409i=0 
    407410while [ $i -lt $queue_count ]; do 
    408   p=`expr $i + $2 \* 10` 
     411  p=`expr $i + $(expr $2 \* 10) + 300` 
    409412if [ $i -lt $(expr $queue_count - 1) ]; then 
    410   ip rule add fwmark 0x$(expr $p + 1) table $(expr $2 \* 10) prio $(expr $p + 2) 
    411 fi 
    412   iptables -t mangle -A MultiWanQoS -m mark --mark 0x$p -j MultiWanQoS_${1} 
     413  ip rule add fwmark 0x$(expr $p + 1 - 300) table $(expr $iprule + 300) prio $(expr $p + 2) 
     414fi 
     415  iptables -t mangle -A MultiWanQoS -m mark --mark 0x$(expr $p - 300) -j ${1} 
    413416  i=`expr $i + 1` 
    414417done 
     
    516519echo "$dns" | while read dns_server  
    517520do 
    518         iptables -t mangle -A MultiWanDNS -d $dns_server -j FW${i}MARK 
     521        iptables -t mangle -A MultiWanDNS -d $dns_server -p tcp --dport 53 -j FW${i}MARK 
     522        iptables -t mangle -A MultiWanDNS -d $dns_server -p udp --dport 53 -j FW${i}MARK 
    519523 
    520524                compile_dns="nameserver $dns_server" 
     
    571575iptables -t mangle -N MultiWanPreHandler 
    572576iptables -t mangle -N MultiWanPostHandler 
    573 iptables -t mangle -N MultiWanFastBalancer 
     577iptables -t mangle -N MultiWanLoadBalancer 
    574578 
    575579echo "## Creating FW Rules ##" 
     
    583587done 
    584588 
    585 iptables -t mangle -A LoadBalancer -j MARK --set-mark 0x123 
     589iptables -t mangle -A LoadBalancer -j MARK --set-mark 0x1 
    586590iptables -t mangle -A LoadBalancer -j CONNMARK --save-mark 
    587591 
    588592if [ -z "$CHKFORMODULE" ]; then 
    589 iptables -t mangle -A FastBalancer -j MARK --set-mark 0x124 
     593iptables -t mangle -A FastBalancer -j MARK --set-mark 0x2 
    590594iptables -t mangle -A FastBalancer -j CONNMARK --save-mark 
    591595else 
    592 mwnote "Fast Balancer is unavailable due to current kernel limitations.." 
    593 mwnote "All Fast Balancer traffic will be diverted to the Load Balancer." 
    594 iptables -t mangle -A FastBalancer -j MARK --set-mark 0x123 
     596mwnote "Performance load balancer(fastbalanacer) is unavailable due to current kernel limitations.." 
     597iptables -t mangle -A FastBalancer -j MARK --set-mark 0x1 
    595598iptables -t mangle -A FastBalancer -j CONNMARK --save-mark 
    596599fi 
     
    598601iptables -t mangle -I PREROUTING -j MultiWan 
    599602iptables -t mangle -I PREROUTING 2 -j MultiWanPreHandler 
    600 iptables -t mangle -I PREROUTING 3 -j MultiWanDNS 
    601 iptables -t mangle -I PREROUTING 4 -j MultiWanRules 
    602 iptables -t mangle -I PREROUTING 5 -j MultiWanFastBalancer 
     603iptables -t mangle -I PREROUTING 3 -j MultiWanRules 
     604iptables -t mangle -I PREROUTING 4 -j MultiWanLoadBalancer 
     605iptables -t mangle -I PREROUTING 5 -j MultiWanDNS 
     606 
    603607 
    604608iptables -t mangle -I FORWARD -j MultiWan 
    605609 
    606610iptables -t mangle -I OUTPUT -j MultiWan 
    607 iptables -t mangle -I OUTPUT 2 -j MultiWanDNS 
    608 iptables -t mangle -I OUTPUT 3 -j MultiWanRules 
    609 iptables -t mangle -I OUTPUT 4 -j MultiWanFastBalancer 
    610 iptables -t mangle -I OUTPUT 5 -j MultiWanPostHandler 
     611iptables -t mangle -I OUTPUT 2 -j MultiWanRules 
     612iptables -t mangle -I OUTPUT 3 -j MultiWanLoadBalancer 
     613iptables -t mangle -I OUTPUT 4 -j MultiWanPostHandler 
     614iptables -t mangle -I OUTPUT 5 -j MultiWanDNS 
    611615 
    612616 
     
    636640ifname=$(query_config ifname $group) 
    637641iptables -t mangle -A MultiWanPreHandler -i $ifname -m state --state NEW -j FW${i}MARK 
    638 iptables -t mangle -A MultiWanPostHandler -o $ifname -m mark --mark 0x123 -j FW${i}MARK 
     642iptables -t mangle -A MultiWanPostHandler -o $ifname -m mark --mark 0x1 -j FW${i}MARK 
    639643done 
    640644 
     
    663667CHKIPROUTE=`cat /etc/iproute2/rt_tables | grep LoadBalancer` 
    664668 if [ -z "$CHKIPROUTE" ]; then 
    665 echo "123     LoadBalancer" >> /etc/iproute2/rt_tables 
     669echo "300     LoadBalancer" >> /etc/iproute2/rt_tables 
    666670 fi 
    667 ip rule del prio 123 > /dev/null 2>&1  
    668 ip route flush table 123 > /dev/null 2>&1 
    669  
    670         for TABLE in 123 
     671ip rule del prio 300 > /dev/null 2>&1  
     672ip route flush table 300 > /dev/null 2>&1 
     673 
     674        for TABLE in 300 
    671675        do 
    672676                ip route | grep link | grep -Ev ^default | while read ROUTE 
     
    676680         done 
    677681 
    678 iptables -F MultiWanFastBalancer -t mangle 
     682iptables -F MultiWanLoadBalancer -t mangle 
    679683 
    680684total_weight=0 
     
    718722 
    719723        if [ -z "$CHKFORMODULE" ]; then 
    720                 iptables -A MultiWanFastBalancer -t mangle -m mark --mark 0x124 -m statistic --mode random --probability $rand_probability -j FW${i}MARK 
     724                iptables -A MultiWanLoadBalancer -t mangle -m mark --mark 0x2 -m statistic --mode random --probability $rand_probability -j FW${i}MARK 
    721725        fi 
    722726fi 
     
    726730pre_nexthop_chk=`echo $nexthop | awk -F "nexthop" '{print NF-1}'` 
    727731if [ "$pre_nexthop_chk" == "1" ]; then 
    728 ip route add default via $(echo $nexthop | awk -F " " '{print $3}') dev $(echo $nexthop | awk -F " " '{print $5}') proto static table 123 
     732ip route add default via $(echo $nexthop | awk -F " " '{print $3}') dev $(echo $nexthop | awk -F " " '{print $5}') proto static table 300 
    729733elif [ "$pre_nexthop_chk" -gt "1" ]; then 
    730 ip route add proto static table 123 default scope global $nexthop 
    731 fi 
    732  
    733 ip rule add fwmark 0x123 table 123 prio 123 
     734ip route add proto static table 300 default scope global $nexthop 
     735fi 
     736 
     737ip rule add fwmark 0x1 table 300 prio 300 
    734738ip route flush cache 
    735739} 
     
    754758ipaddr=$(query_config ipaddr $group) 
    755759 
    756 iprule=$(expr $i \* 10) 
     760iprule=$(expr $(expr $i \* 10) + 300) 
    757761ip route flush table $iprule > /dev/null 2>&1 
    758762 
     
    781785local ipaddr 
    782786 
    783 iprule=$(expr $1 \* 10) 
     787iprule=$(expr $(expr $1 \* 10) + 300) 
    784788group=$(query_config group $1) 
    785789gateway=$(query_config gateway $group) 
     
    788792CHKIPROUTE=`cat /etc/iproute2/rt_tables | grep MWAN${1}` 
    789793 if [ -z "$CHKIPROUTE" ]; then 
    790 echo "$iprule      MWAN${1}" >> /etc/iproute2/rt_tables 
     794echo "$iprule     MWAN${1}" >> /etc/iproute2/rt_tables 
    791795 fi 
    792796 
     
    796800if [ "$gateway" != "x" -a "$ipaddr" != "x" ]; then 
    797801ip rule add from $ipaddr table $iprule prio $iprule 
    798 ip rule add fwmark 0x${iprule} table $iprule prio $(expr $iprule + 1) 
     802ip rule add fwmark 0x$(expr $iprule - 300) table $iprule prio $(expr $iprule + 1) 
    799803fi 
    800804} 
     
    810814ip rule add lookup default prio 32767 > /dev/null 2>&1 
    811815 
    812 ip route flush table 123 > /dev/null 
     816ip route flush table 300 > /dev/null 
    813817 
    814818        i=0 
     
    972976fi 
    973977 
     978sh /usr/sbin/natloopback.sh $1 lan 
     979 
    974980sleep $health_interval 
    975981done 
Note: See TracChangeset for help on using the changeset viewer.