iptables -t mangle -N MultiWanDNS
iptables -t mangle -N MultiWanPreHandler
iptables -t mangle -N MultiWanPostHandler
+iptables -t mangle -N MultiWanLoadBalancer
echo "## Creating FW Rules ##"
i=0
iptables -t mangle -A LoadBalancer -j CONNMARK --save-mark
iptables -t mangle -I PREROUTING -j MultiWan
+iptables -t mangle -I PREROUTING 2 -j MultiWanPreHandler
+iptables -t mangle -I PREROUTING 3 -j MultiWanDNS
+iptables -t mangle -I PREROUTING 4 -j MultiWanRules
+iptables -t mangle -I PREROUTING 5 -j MultiWanLoadBalancer
+
iptables -t mangle -I FORWARD -j MultiWan
+
iptables -t mangle -I OUTPUT -j MultiWan
+iptables -t mangle -I OUTPUT 2 -j MultiWanDNS
+iptables -t mangle -I OUTPUT 3 -j MultiWanRules
+iptables -t mangle -I OUTPUT 4 -j MultiWanLoadBalancer
+iptables -t mangle -I OUTPUT 5 -j MultiWanPostHandler
+
+
iptables -t mangle -I POSTROUTING -j MultiWan
+iptables -t mangle -I POSTROUTING 2 -j MultiWanPostHandler
iptables -t mangle -A MultiWan -j CONNMARK --restore-mark
-iptables -t mangle -A MultiWan -j MultiWanPreHandler
refresh_dns
iptables -t mangle -A MultiWanRules -m mark --mark 0x0 -j LoadBalancer
fi
-iptables -t mangle -A MultiWan -j MultiWanRules
-iptables -t mangle -A MultiWan -j MultiWanDNS
-iptables -t mangle -A MultiWan -j MultiWanPostHandler
-
i=0
while [ $i -lt $wancount ]; do
i=`expr $i + 1`
done
if [ ! -z "$CHKFORQOS" ]; then
-iptables -t mangle -A MultiWan -j MultiWanQoS
+iptables -t mangle -I PREROUTING 6 -j MultiWanQoS
+iptables -t mangle -A FORWARD -j MultiWanQoS
+iptables -t mangle -A OUTPUT -j MultiWanQoS
+iptables -t mangle -A POSTROUTING -j MultiWanQoS
fi
}
local weight
local nexthop
local pre_nexthop_chk
+local rand_probability
+local total_weight
local i
-
echo "## Refreshing Load Balancer ##"
CHKIPROUTE=`cat /etc/iproute2/rt_tables | grep LoadBalancer`
done
done
+total_weight=0
+
+iptables -F MultiWanLoadBalancer -t mangle
+
+i=0
+while [ $i -lt $wancount ]; do
+i=`expr $i + 1`
+group=$(query_config group $i)
+weight=`uci -q -P /var/state get multiwan.${group}.weight`
+total_weight=$(expr $total_weight + $weight)
+done
+
i=0
while [ $i -lt $wancount ]; do
i=`expr $i + 1`
if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then
nexthop="$nexthop nexthop via $gateway dev $ifname weight $weight"
+rand_probability=$(expr $(expr $weight \* 100) / $total_weight)
+
+ if [ $rand_probability -lt 10 ]; then
+ rand_probability="0.0${rand_probability}"
+ else
+ rand_probability="0.${rand_probability}"
+ fi
+
+ if [ -z "$CHKFORMODULE" ]; then
+ iptables -A MultiWanLoadBalancer -t mangle -m mark --mark 0x123 -m statistic --mode random --probability $rand_probability -j FW${i}MARK
+ fi
fi
+
done
pre_nexthop_chk=`echo $nexthop | awk -F "nexthop" '{print NF-1}'`
mwan_kill
flush
-refresh_loadbalancer
echo "## IP Rules Initialization ##"
i=0
refresh_routes
iptables_init
+refresh_loadbalancer
+
RP_PATH=/proc/sys/net/ipv4/conf
for IFACE in `ls $RP_PATH`; do
echo 0 > $RP_PATH/$IFACE/rp_filter
update_cache
CHKFORQOS=`iptables -n -L Default -t mangle 2>&1 | grep "Chain Default"`
+CHKFORMODULE=`iptables -m statistic 2>&1 | grep -o "File not found"`
jobfile="/tmp/.mwan/jobqueue"