Balanceamento de links
Pessoal,
Tenho 3 Links (2 GVT e 1 BrT) e o seguinte problema, através da
documentação do LARTC (http://lartc.org) adaptei um módulo ao meu
script de firewall, porém, ao efetuar o balanceamento noto que muitos
pacotes (principalmente FTP) se perdem no meio.
Nos testes que fiz hoje um arquivo de 500MB teve apenas 9MB enviados
ao servidor em um momento e 450MB em outro. Utilizei o FTP em modo
ativo e passivo, nao há regras de firewall que relacionem ao controle
disto (em ambos os casos o firewall utilizado foi mínimo, apenas
habilitando roteamento e mascarando os pacotes).
Já é o terceiro mês que este problema fica pendente e gostaria de
saber se alguém passou por algo semelhande ou se fez funcionar
corretamente o balanceamento.
OBS: Abaixo o módulo adicional ao firewall:
# BALANCE v1.1 - load balancing across multiple links to linux 2.4 and linux 2.6
function out_balance24(){
if [ $# -eq 3 ] || [ $# -eq 4 ]; then
# Add the NAT rules
$ipt -t nat -A POSTROUTING -o $1 -j SNAT --to-source $2
$ipt -t nat -A POSTROUTING -o $1 -j MASQUERADE
# Disable filtering of "martians" packets
echo 0 > /proc/sys/net/ipv4/conf/$1/rp_filter
# Add the current interface to iproute's default route
blc=${blc}"nexthop via $3 dev $1 "
[ ! "$4" == "" ] && blc=$blc"weight $4 "
export blc
fi
}
function out_balance26(){
if [ $# -eq 5 ] || [ $# -eq 6 ]; then
# Add the NAT rules
$ipt -t nat -A POSTROUTING -o $1 -j SNAT --to-source $2
$ipt -t nat -A POSTROUTING -o $1 -j MASQUERADE
# Disable filtering of "martians" packets
echo 0 > /proc/sys/net/ipv4/conf/$1/rp_filter
# Set rt_tables table fixes
( cat /etc/iproute2/rt_tables | grep $4 > /dev/null
2>&1 ) || echo
"$4 $4" >> /etc/iproute2/rt_tables
# Set the kernel routing table
$ip rule add prio $4 from $5 table $4
$ip route add default via $3 dev $1 src $2 proto static table $4
$ip route append prohibit default table $4 metric 1 proto static
# Add the current interface to iproute's default route
blc=${blc}"nexthop via $3 dev $1 "
[ ! -z "$6" ] && blc=$blc"weight $6 "
export blc
fi
}
function start_blc(){
# Detect the running kernel and load the proper rules
( uname -r | grep ^2.6 > /dev/null 2>&1 ) && export kernel="2.6"
( uname -r | grep ^2.4 > /dev/null 2>&1 ) && export kernel="2.4"
[ -z "$kernel" ] && kernel="2.6"
[ "$kernel" == "2.4" ] && {
for n in 0 $(seq $(( $nwan-1))); do
out_balance24 ${waniface[$n]} ${wanaddr[$n]}
${wangwaddr[$n]} ${wanmetric[$n]}
done
}
[ "$kernel" == "2.6" ] && {
for n in 0 $(seq $(( $nwan-1))); do
out_balance26 ${waniface[$n]} ${wanaddr[$n]} ${wangwaddr[$n]}
${wanrttable[$n]} ${lannetaddr[0]} ${wanmetric[$n]}
done
( cat /etc/iproute2/rt_tables | grep $mainrttable > /dev/null 2>&1 )
|| echo "$mainrttable $mainrttable" >> /etc/iproute2/rt_tables
$ip rule add prio $mainrttable table $mainrttable
}
# Clean the kernel routing table
$ip route del default > /dev/null 2>&1
# Add the new one, with load ballancing
$ip route add default $blc > /dev/null 2>&1
# Flush the kernel routing table to avoid errors
$ip route flush cache > /dev/null 2>&1
}
function stop_blc(){
# Clean the kernel routing table
$ip route del default > /dev/null 2>&1
# Add the new one
$ip route add default nexthop via ${wangwaddr[0]} dev ${waniface[0]}
> /dev/null 2>&1
# Flush the kernel routing table to avoid errors
$ip route flush cache > /dev/null 2>&1
}
case $1 in
start)
start_blc
;;
about)
[ "${verbose:=false}" == "true" ] && echo " -
lib_balance v1.1 by
Maxwillian Miorim <max@belcom.com.br>"
;;
stop)
stop_blc
;;
esac
Dando uma resumida, quando chamado pelo firewall este módulo faz o seguinte:
* Verifica o kernel (no 2.4 eu não precisei fazer algumas coisas)
* cria as regras de roteamento: tabelas, regras e rotas
* cria a rota default
O procedimento é feito corretamente, porém durante a utilização há
ocorrência de muitos pacotes perdidos, principalemente quando há uma
grande quantidade para a mesma origem/destino.
Grato desde já,
Maxwillian Miorim
Reply to: