From: "Lenthir" <lth@wp.pl>
To: lartc@vger.kernel.org
Subject: Re: [LARTC] Little problem with IMQ
Date: Tue, 10 Aug 2004 08:47:17 +0000 [thread overview]
Message-ID: <002201c47eb6$a6935e80$4603a8c0@neo> (raw)
In-Reply-To: <003501c47e25$a7aae0e0$4603a8c0@neo>
[-- Attachment #1: Type: text/plain, Size: 509 bytes --]
Ok.... I attached my script...
rc.htb is now working for me. But packet addressed to server don't match
correct class.
htb1.2rc3 don't work because i can't discern traffic to LAN and traffic to
server.
in script
prs it is address of server
lan[0], lan[1] - lists of IP address to each interfaces... (defined in
dev_lan)
I tried on two types of compiled kernel - 2.4.26 with only IMQ patch and
2.4.26 with IMQ and NAT patch.
I don't see any differences...
I have iptables 1.2.11 compiled with the kernel.
[-- Attachment #2: rc.htb --]
[-- Type: application/octet-stream, Size: 7834 bytes --]
#!/bin/bash
#
# rc.htb 1.2_rc3, (C)Lenthir 2oo4, GNU GPL
# 2004-08-03 18:00
VER=1.2
MAX=4999
#######################
#Konfiguracja interfejsów:
dev_wan="eth0" #interfejs WAN
dev_lan="eth1 eth2" #interfejsy LAN - 4999 u¿ytkowników MAX
lan[0]="`/sbin/lan200` `/sbin/wan200`" #adresy IP dla interfejsów lan, bez IP serwera
lan[1]=`/sbin/lan201`
prs="217.153.104.34" #IP zewnêtrzny serwera
ile[0]=`echo ${lan[0]}|awk '{print NF}'` #ilo¶ci komputerów w podsieciach, bez serwera
ile[1]=`echo ${lan[1]}|awk '{print NF}'`
TC=/sbin/tc #¶cie¿ka do tc
IPTABLES=/usr/local/sbin/iptables #¶cie¿ka do iptables
MODPROBE=/sbin/modprobe #¶cie¿ka do modprobe
IP=/sbin/ip #¶cie¿ka do ip
u_r2q=10 #r2q
u_quantum=1500 #quantum
#Konfiguracja prêdko¶ci (1Mbit=1024kbit=1048576bity=0,125MB/s=128kB/s=131072B/s):
#Wszystkie prêdko¶ci s± rzeczywiste. (ok. 98% prêdko¶ci teoretycznej dla WAN)
wan_dwl[0]=480 #maksymalna prêdko¶æ downloadu interfejsów WAN w kbit/s minus 5kbit/s na pasmo awaryjne
wan_upl[0]=480
ratio_d=1 # 1 = 100%
ratio_u=1
#Konfiguracja serwera
srv_dwl=16 #minimalna prêdko¶æ downloadu z serwera
srv_upl=16 #minimalna prêdko¶æ uploadu z serwera
#######################
i=0;ilosc=0
for x in $dev_lan #ilo¶æ komputerów
do
let "ilosc=$ilosc+${ile[$i]}"
let "i=$i+1"
done
if [[ $ilosc -ge $MAX ]]
then
echo "Niedopuszczalnie du¿o komputerów!"
exit 1
fi
#######################
stop()
{
$TC qdisc del root dev imq0 2> /dev/null #input
$TC qdisc del root dev imq1 2> /dev/null #output
$IP link set imq0 down #opuszczanie interfejsów
$IP link set imq1 down
/etc/init.d/rc.iptables restart
}
start()
{ stop
$IPTABLES -t mangle -N znaczek
$IPTABLES -t mangle -A znaczek -d 192.168.200.5 -j MARK --set-mark 2
$IPTABLES -t mangle -A znaczek -d 192.168.201.5 -j MARK --set-mark 2
$IPTABLES -t mangle -A znaczek -s $prs -j MARK --set-mark 2
$IPTABLES -t mangle -A znaczek -d $prs -j MARK --set-mark 2
i=0;j=3
for x in $dev_lan
do
for usr in ${lan[$i]}
do
$IPTABLES -t mangle -A znaczek -s $usr -j MARK --set-mark $j
$IPTABLES -t mangle -A znaczek -d $usr -j MARK --set-mark $j
let "j=j+1"
done
let "i=i+1"
done
$IPTABLES -t mangle -A znaczek -j RETURN
# download
$IPTABLES -t mangle -A FORWARD -i $dev_wan -j znaczek
$IPTABLES -t mangle -A INPUT -i $dev_wan -j znaczek
$IPTABLES -t mangle -A FORWARD -i $dev_wan -j IMQ --todev 0
$IPTABLES -t mangle -A INPUT -i $dev_wan -j IMQ --todev 0
tmp=$(echo "($wan_dwl-$srv_dwl)%$ilosc" | bc)
srv_dwl=$(echo "$srv_dwl+$tmp" | bc)
min=$(echo "($wan_dwl-$srv_dwl)/$ilosc" | bc)
max=$(echo "$wan_dwl*$ratio_d" | bc)
echo " Ilo¶æ komputerów: $ilosc"
echo "%===================================================================%"
echo " Ustawianie kolejki imq0"
echo " Maksymalny download: $max kbit/s"
echo " Minimalny download serwera: $srv_dwl kbit/s"
echo " Minimalny download userów: $min kbit/s"
echo " "
$TC qdisc add dev imq0 root handle 1:0 htb default 1 r2q $u_r2q
$TC class add dev imq0 parent 1:0 classid 1:1 htb rate ${wan_dwl[0]}kbit ceil ${wan_dwl[0]}kbit
# Serwer
$TC class add dev imq0 parent 1:1 classid 1:2 htb rate ${srv_dwl}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq0 parent 1:2 sfq perturb 10
$TC filter add dev imq0 protocol ip parent 1:0 handle 2 fw flowid 1:2
i=0;j=3
for x in $dev_lan
do
for usr in ${lan[$i]}
do
$TC class add dev imq0 parent 1:1 classid 1:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq0 parent 1:$j sfq perturb 10
$TC filter add dev imq0 protocol ip parent 1:0 handle $j fw flowid 1:$j
let "j=j+1"
done
let "i=i+1"
done
$IP link set imq0 up
# upload
$IPTABLES -t mangle -A FORWARD -o $dev_wan -j znaczek
$IPTABLES -t mangle -A OUTPUT -o $dev_wan -j znaczek
$IPTABLES -t mangle -A FORWARD -o $dev_wan -j IMQ --todev 1
$IPTABLES -t mangle -A OUTPUT -o $dev_wan -j IMQ --todev 1
tmp=$(echo "($wan_upl-$srv_upl)%$ilosc" | bc)
srv_upl=$(echo "$srv_upl+$tmp" | bc)
min=$(echo "($wan_upl-$srv_upl)/$ilosc" | bc)
max=$(echo "$wan_upl*$ratio_u" | bc)
echo " Ustawianie kolejki imq1"
echo " Maksymalny upload: $max kbit/s"
echo " Minimalny upload serwera: $srv_upl kbit/s"
echo " Minimalny upload userów: $min kbit/s"
echo "%===================================================================%"
$TC qdisc add dev imq1 root handle 2:0 htb default 1 r2q $u_r2q
$TC class add dev imq1 parent 2:0 classid 2:1 htb rate ${wan_upl[0]}kbit ceil ${wan_upl[0]}kbit
$TC class add dev imq1 parent 2:1 classid 2:2 htb rate ${srv_upl}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq1 parent 2:2 sfq perturb 10
$TC filter add dev imq1 protocol ip parent 2:0 handle 2 fw flowid 2:2
i=0;j=3
for x in $dev_lan
do
for usr in ${lan[$i]}
do
$TC class add dev imq1 parent 2:1 classid 2:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq1 parent 2:$j sfq perturb 10
$TC filter add dev imq1 protocol ip parent 2:0 handle $j fw flowid 2:$j
let "j=j+1"
done
let "i=i+1"
done
$IP link set imq1 up
}
echo "rc.htb 1.2_rc3, (C)Lenthir 2oo4, GNU GPL"
echo "2004-08-03 18:00"
case "$1" in
'start')
echo "Uruchamianie kolejkowania..."
start
echo "Chyba wszystko OK"
exit 0
;;
'stop')
echo -n "Zatrzymywanie kolejkowania..."
stop
echo " wykonano."
;;
'restart')
echo "Restartowanie kolejkowania..."
start
echo "Chyba wszystko OK"
;;
'status')
echo "Klasy na interfejsie imq0 - download"
echo "%====================================%"
$TC class show dev imq0 | grep root
$TC class show dev imq0 | grep -v root | sort | nl
echo "Klasy na interfejsie imq1 - upload"
echo "%====================================%"
$TC class show dev imq1 | grep root
$TC class show dev imq1 | grep -v root | sort | nl
;;
'stat')
if [[ "$2" == "" ]]; then
echo "Script need second argument - adress IP"
exit 1
elif [[ "$2" == "server" ]]; then
watch -d -n 1 "echo \"Serwer:\" && tc -s class show dev imq0 | grep -A 3 \"1:2 \" && tc -s class show dev imq1 | grep -A 3 \"2:2 \""
else
i=0;j=3
for x in $dev_lan
do
for usr in ${lan[$i]}
do
if [[ "$2" == "$usr" ]]; then
watch -d -n 1 "echo \"Download: \" && tc -s class show dev imq0 | grep -A 3 \"1:$j \" && echo && echo \"Upload: \" && tc -s class show dev imq1 | grep -A 3 \"2:$j \""
echo "Zakoñczono."
exit 0
fi
let "j=j+1"
done
let "i=i+1"
done
fi
;;
*)
echo
echo "U¿ycie: rc.htb start|stop|restart|status"
echo "rc.htb stat <server|adress IP>"
exit 1
;;
esac
[-- Attachment #3: htb1.2rc3 --]
[-- Type: application/octet-stream, Size: 7892 bytes --]
#!/bin/bash
#
# rc.htb 1.2_rc3, (C)Lenthir 2oo4, GNU GPL
# 2004-08-03 18:00
VER=1.2
MAX=4999
#######################
#Konfiguracja interfejsów:
dev_wan="eth0" #interfejs WAN
dev_lan="eth1 eth2" #interfejsy LAN - 4999 u¿ytkowników MAX
lan[0]="`/sbin/lan200` `/sbin/wan200`" #adresy IP dla interfejsów lan, bez IP serwera
lan[1]=`/sbin/lan201`
prs="217.153.104.34" #IP zewnêtrzny serwera
ile[0]=`echo ${lan[0]}|awk '{print NF}'` #ilo¶ci komputerów w podsieciach, bez serwera
ile[1]=`echo ${lan[1]}|awk '{print NF}'`
TC=/sbin/tc #¶cie¿ka do tc
IPTABLES=/usr/local/sbin/iptables #¶cie¿ka do iptables
MODPROBE=/sbin/modprobe #¶cie¿ka do modprobe
IP=/sbin/ip #¶cie¿ka do ip
u_r2q=10 #r2q
u_quantum=1500 #quantum
#Konfiguracja prêdko¶ci (1Mbit=1024kbit=1048576bity=0,125MB/s=128kB/s=131072B/s):
#Wszystkie prêdko¶ci s± rzeczywiste. (ok. 98% prêdko¶ci teoretycznej dla WAN)
wan_dwl[0]=480 #maksymalna prêdko¶æ downloadu interfejsów WAN w kbit/s minus 5kbit/s na pasmo awaryjne
wan_upl[0]=480
ratio_d=1 # 1 = 100%
ratio_u=1
#Konfiguracja serwera
srv_dwl=16 #minimalna prêdko¶æ downloadu z serwera
srv_upl=16 #minimalna prêdko¶æ uploadu z serwera
#######################
i=0;ilosc=0
for x in $dev_lan #ilo¶æ komputerów
do
let "ilosc=$ilosc+${ile[$i]}"
let "i=$i+1"
done
if [[ $ilosc -ge $MAX ]]
then
echo "Niedopuszczalnie du¿o komputerów!"
exit 1
fi
#######################
stop()
{
$TC qdisc del root dev imq0 2> /dev/null #input
$TC qdisc del root dev imq1 2> /dev/null #output
$IP link set imq0 down #opuszczanie interfejsów
$IP link set imq1 down
/etc/init.d/rc.iptables restart
}
start()
{ stop
$IPTABLES -t mangle -N znaczek
$IPTABLES -t mangle -A znaczek -d $prs -j MARK --set-mark 1
$IPTABLES -t mangle -A znaczek -s $prs -j MARK --set-mark 2
i=0;j=3
for x in $dev_lan
do
for usr in ${lan[$i]}
do
$IPTABLES -t mangle -A znaczek -s $usr -j MARK --set-mark $j
$IPTABLES -t mangle -A znaczek -d $usr -j MARK --set-mark $j
let "j=j+1"
done
let "i=i+1"
done
$IPTABLES -t mangle -A znaczek -j RETURN
# download
$IPTABLES -t mangle -A PREROUTING -i $dev_wan -j znaczek
$IPTABLES -t mangle -A PREROUTING -i $dev_wan -j IMQ --todev 0
tmp=$(echo "($wan_dwl-$srv_dwl)%$ilosc" | bc)
srv_dwl=$(echo "$srv_dwl+$tmp" | bc)
min=$(echo "($wan_dwl-$srv_dwl)/$ilosc" | bc)
max=$(echo "$wan_dwl*$ratio_d" | bc)
echo " Ilo¶æ komputerów: $ilosc"
echo "%===================================================================%"
echo " Ustawianie kolejki imq0"
echo " Maksymalny download: $max kbit/s"
echo " Minimalny download serwera: $srv_dwl kbit/s"
echo " Minimalny download userów: $min kbit/s"
echo " "
$TC qdisc add dev imq0 root handle 1:0 htb default 1 r2q $u_r2q
$TC class add dev imq0 parent 1:0 classid 1:1 htb rate ${wan_dwl[0]}kbit ceil ${wan_dwl[0]}kbit
# Serwer
$TC class add dev imq0 parent 1:1 classid 1:2 htb rate ${srv_dwl}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq0 parent 1:2 sfq perturb 10
$TC filter add dev imq0 protocol ip parent 1:0 handle 1 fw flowid 1:2
$TC filter add dev imq0 protocol ip parent 1:0 u32 match ip dst $prs flowid 1:2
$TC filter add dev imq0 protocol ip parent 1:0 u32 match ip dst 127.0.0.1 flowid 1:2
$TC filter add dev imq0 protocol ip parent 1:0 u32 match ip dst 192.168.200.5 flowid 1:2
$TC filter add dev imq0 protocol ip parent 1:0 u32 match ip dst 192.168.201.5 flowid 1:2
i=0;j=3
for x in $dev_lan
do
for usr in ${lan[$i]}
do
$TC class add dev imq0 parent 1:1 classid 1:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq0 parent 1:$j sfq perturb 10
$TC filter add dev imq0 protocol ip parent 1:0 handle $j fw flowid 1:$j
let "j=j+1"
done
let "i=i+1"
done
$IP link set imq0 up
# upload
$IPTABLES -t mangle -A POSTROUTING -o $dev_wan -j znaczek
$IPTABLES -t mangle -A POSTROUTING -o $dev_wan -j IMQ --todev 1
tmp=$(echo "($wan_upl-$srv_upl)%$ilosc" | bc)
srv_upl=$(echo "$srv_upl+$tmp" | bc)
min=$(echo "($wan_upl-$srv_upl)/$ilosc" | bc)
max=$(echo "$wan_upl*$ratio_u" | bc)
echo " Ustawianie kolejki imq1"
echo " Maksymalny upload: $max kbit/s"
echo " Minimalny upload serwera: $srv_upl kbit/s"
echo " Minimalny upload userów: $min kbit/s"
echo "%===================================================================%"
$TC qdisc add dev imq1 root handle 2:0 htb default 1 r2q $u_r2q
$TC class add dev imq1 parent 2:0 classid 2:1 htb rate ${wan_upl[0]}kbit ceil ${wan_upl[0]}kbit
$TC class add dev imq1 parent 2:1 classid 2:2 htb rate ${srv_upl}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq1 parent 2:2 sfq perturb 10
$TC filter add dev imq1 protocol ip parent 2:0 handle 2 fw flowid 2:2
i=0;j=3
for x in $dev_lan
do
for usr in ${lan[$i]}
do
$TC class add dev imq1 parent 2:1 classid 2:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq1 parent 2:$j sfq perturb 10
$TC filter add dev imq1 protocol ip parent 2:0 handle $j fw flowid 2:$j
let "j=j+1"
done
let "i=i+1"
done
$IP link set imq1 up
}
echo "rc.htb 1.2_rc3, (C)Lenthir 2oo4, GNU GPL"
echo "2004-08-03 18:00"
case "$1" in
'start')
echo "Uruchamianie kolejkowania..."
start
echo "Chyba wszystko OK"
exit 0
;;
'stop')
echo -n "Zatrzymywanie kolejkowania..."
stop
echo " wykonano."
;;
'restart')
echo "Restartowanie kolejkowania..."
start
echo "Chyba wszystko OK"
;;
'status')
echo "Klasy na interfejsie imq0 - download"
echo "%====================================%"
$TC class show dev imq0 | grep root
$TC class show dev imq0 | grep -v root | sort | nl
echo "Klasy na interfejsie imq1 - upload"
echo "%====================================%"
$TC class show dev imq1 | grep root
$TC class show dev imq1 | grep -v root | sort | nl
;;
'stat')
if [[ "$2" == "" ]]; then
echo "Script need second argument - adress IP"
exit 1
elif [[ "$2" == "server" ]]; then
watch -d -n 1 "echo \"Serwer:\" && tc -s class show dev imq0 | grep -A 3 \"1:2 \" && tc -s class show dev imq1 | grep -A 3 \"2:2 \""
else
i=0;j=3
for x in $dev_lan
do
for usr in ${lan[$i]}
do
if [[ "$2" == "$usr" ]]; then
watch -d -n 1 "echo \"Download: \" && tc -s class show dev imq0 | grep -A 3 \"1:$j \" && echo && echo \"Upload: \" && tc -s class show dev imq1 | grep -A 3 \"2:$j \""
echo "Zakoñczono."
exit 0
fi
let "j=j+1"
done
let "i=i+1"
done
fi
;;
*)
echo
echo "U¿ycie: rc.htb start|stop|restart|status"
echo "rc.htb stat <server|adress IP>"
exit 1
;;
esac
next prev parent reply other threads:[~2004-08-10 8:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-09 15:29 [LARTC] Little problem with IMQ Lenthir
2004-08-09 21:03 ` Andre Correa
2004-08-10 8:47 ` Lenthir [this message]
2004-08-11 3:05 ` Roy
2004-08-11 7:47 ` Lenthir
2004-08-11 9:56 ` Lenthir
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='002201c47eb6$a6935e80$4603a8c0@neo' \
--to=lth@wp.pl \
--cc=lartc@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.