local rand_probability
local last_probability
local total_weight
+local total_wans
local i
+local x
+local y
echo "## Refreshing Load Balancer ##"
done
total_weight=0
+total_wans=0
last_probability=0
+x=0
+y=0
iptables -F MultiWanLoadBalancer -t mangle
weight=`uci -q -P /var/state get multiwan.${group}.weight`
if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then
total_weight=$(expr $total_weight + $weight)
+ total_wans=$i
fi
done
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 + $last_probability)
-last_probability=$rand_probability
+y=$last_probability
+last_probability=$(expr $x / $(expr $wancount - $i + 1))
+rand_probability=$(expr $(expr $(expr $weight \* 100) / $total_weight) + $last_probability + $y)
+x=$rand_probability
if [ $rand_probability -lt 10 ]; then
rand_probability="0.0${rand_probability}"
- elif [ $rand_probability -lt 100 -a $i != $wancount ]; then
+ elif [ $rand_probability -lt 100 -a $i != $total_wans ]; then
rand_probability="0.${rand_probability}"
else
rand_probability="1.0"