This is a multi-part message in MIME format. --------------020808070404050103000503 Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit Hi everybody! I wrote nice script, but I need some help.... Script is working almost well. My question is: Can I minimalize PING time more than this script can? (nowadays is 70-150ms with large load of link) My first problem is - unreal big PING on router, and almost excellent (nowadays is 70-150ms) PING on computers in network. My users don't complain, but I noticed that the pages is becoming load quickly and when it's almost done.. the transfer is going down!! And second symptom is: when I open pages PING grows to 800ms, and quickly go down. It's almost imperceptible, but it happens. What's wrong? All packets is going to correct pipes. What should I do more? I suspect, that time of change of speed (HTB's reaction time) many queues is long. How can I improve this? Script is very nice, but I need some professional help and advices. Everything You can check when script is working: ./htb0.5.3en stat <IP> (example: ./htb0.5.3en stat 192.168.0.2) ./htb0.5.3en stat lan ./htb0.5.3en stats My network's statistics: http://stats.opat.hopto.org/ http://stats.zabierzow.net/ I attached my script. IMQ with imq_nat.diff patch is required (or AB option in kernels 2.6), patched iptables(IMQ patch) is required, iproute is required and bc is required. I tested this script on 2.6.9 kernel and iproute from .deb package. And second less important problem... How Can I mark squid's MISS packets? Is Debian's Squid Package patched to change TOS? http://stats.zabierzow.net/squid.php :d Someone will help? --------------020808070404050103000503 Content-Type: text/plain; name="htb0.5.3en" Content-Transfer-Encoding: 8bit Content-Disposition: inline; filename="htb0.5.3en" #!/bin/bash # # rc.htb 0.5.3, (C)Lenthir 2oo4, GNU GPL # 2004-11-01 9:30 VER="0.5.3" DAT="2004-11-01 9:30" MAX=3330 ####################### #Configuration: ext_dwl=2000 #speed of link(s)(kbit/s) - download ext_upl=220 #speed of link(s)(kbit/s) - upload int="192.168.0.2 192.168.0.3 192.168.0.4 192.168.1.2" #internal addresses IP ext="80.53.64.3" #external addresses IP with or without external router IP srv_ext="80.53.64.3" #external router IP(machine where you exec this script) lan_int="192.168.0.0/24 192.168.1.0/24 192.168.2.0/24" #subnetworks(pool of addresses) int_dwl[0]=85; int_upl[0]=85 #subnetworks speed(download; upload) in order such how it is above int_dwl[1]=2; int_upl[1]=2 int_dwl[2]=80; int_upl[2]=80 TC=`which iptables` #path to tc MODPROBE=`which modprobe` #path to modprobe IP=`which ip` #path to ip IPTABLES=`which iptables` #path to iptables firewall="/etc/init.d/rc.iptables restart" #how is firewall(iptables) restart? #u_r2q=10 #r2q (optional) u_quantum=1500 #quantum (optional todo, at present required) porty_tcp="20 21 22 23 25 53 80 110 143 220 443 993 995 27015" #tcp preference ports porty_udp="53" #udp preference ports pping=1 # 0 - ping throw in preference queue 1 - ping throw in not preference queue #End ####################### stop() { $TC qdisc del root dev imq0 2> /dev/null $TC qdisc del root dev imq1 2> /dev/null $IP link set imq0 down $IP link set imq1 down } start() { stop #It checks is router adress in ext. ipki="$ext $int" for srvip in $srv_ext do if [[ `echo $ipki | grep $srvip` != $ipki ]]; then ext="$ext $srvip" fi done ile_int=`echo ${int}|awk '{print NF}'` ile_ext=`echo ${ext}|awk '{print NF}'` ile=$(echo "$ile_int + $ile_ext" | bc) if [[ $ile -ge $MAX ]] then echo "Too many computers!" exit 1 fi # download tmp=$(echo "$ext_dwl%$ile" | bc) min=$(echo "$ext_dwl/$ile" | bc) pri_min=$(echo "$min/2+$min%2" | bc) sec_min=$(echo "$min/2" | bc) max=$ext_dwl echo " Quantity of computers: $ile" echo "%===================================================================%" echo " Setting download queue." echo " Minimum download: $min kbit/s" echo " Maximum download: $max kbit/s" echo " Queue: -preference: $pri_min kbit/s -not preference: $sec_min kbit/s" echo " Free: $tmp kbit/s" echo " " if [[ u_r2q=="" ]]; then $TC qdisc add dev imq0 root handle 1:0 htb else $TC qdisc add dev imq0 root handle 1:0 htb r2q $u_r2q fi $TC class add dev imq0 parent 1:0 classid 1:1 htb rate ${ext_dwl}kbit ceil ${ext_dwl}kbit j=2 for usr in $ext do $TC class add dev imq0 parent 1:1 classid 1:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum $TC class add dev imq0 parent 1:$j classid 1:$(($j+1)) htb rate ${pri_min}kbit ceil ${max}kbit quantum $u_quantum $TC class add dev imq0 parent 1:$j classid 1:$(($j+2)) htb rate ${sec_min}kbit ceil ${max}kbit quantum $u_quantum $TC qdisc add dev imq0 parent 1:$(($j+1)) sfq $TC qdisc add dev imq0 parent 1:$(($j+2)) sfq $TC filter add dev imq0 protocol ip parent 1:0 pref 2 u32 match ip dst $usr flowid 1:$j for prt in $porty_tcp do $TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32 match ip protocol 6 0xff match ip sport $prt 0xffff flowid 1:$(($j+1)) $TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32 match ip protocol 6 0xff match ip dport $prt 0xffff flowid 1:$(($j+1)) done for prt in $porty_udp do $TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32 match ip protocol 17 0xff match ip sport $prt 0xffff flowid 1:$(($j+1)) $TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32 match ip protocol 17 0xff match ip dport $prt 0xffff flowid 1:$(($j+1)) done if [[ $pping -eq 1 ]]; then $TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32 match ip protocol 1 0xff flowid 1:$(($j+1)) fi $TC filter add dev imq0 protocol ip parent 1:$j pref 4 u32 match ip dst $usr flowid 1:$((j+2)) let "j=j+3" done for usr in $int do $TC class add dev imq0 parent 1:1 classid 1:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum $TC class add dev imq0 parent 1:$j classid 1:$(($j+1)) htb rate ${pri_min}kbit ceil ${max}kbit quantum $u_quantum $TC class add dev imq0 parent 1:$j classid 1:$(($j+2)) htb rate ${sec_min}kbit ceil ${max}kbit quantum $u_quantum $TC qdisc add dev imq0 parent 1:$(($j+1)) sfq $TC qdisc add dev imq0 parent 1:$(($j+2)) sfq $TC filter add dev imq0 protocol ip parent 1:0 pref 2 u32 match ip dst $usr flowid 1:$j for prt in $porty_tcp do $TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32 match ip protocol 6 0xff match ip sport $prt 0xffff flowid 1:$(($j+1)) done for prt in $porty_udp do $TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32 match ip protocol 17 0xff match ip sport $prt 0xffff flowid 1:$(($j+1)) done if [[ $pping -eq 1 ]]; then $TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32 match ip protocol 1 0xff flowid 1:$(($j+1)) fi $TC filter add dev imq0 protocol ip parent 1:$j pref 4 u32 match ip dst $usr flowid 1:$((j+2)) let "j=j+3" done i=0 for ntr in $lan_int do $TC class add dev imq0 parent 1:0 classid 1:$j htb rate ${int_dwl[$i]}Mbit ceil ${int_dwl[$i]}Mbit quantum $u_quantum $TC qdisc add dev imq0 parent 1:$j sfq for ipek in $ext ${lan_int} do $TC filter add dev imq0 protocol ip parent 1:0 pref 1 u32 match ip src $ntr match ip dst $ipek flowid 1:$j done let "j=j+1" let "i=i+1" done $IPTABLES -t mangle -A PREROUTING -j IMQ --todev 0 $IP link set imq0 up # upload tmp=$(echo "$ext_upl%$ile" | bc) min=$(echo "$ext_upl/$ile" | bc) pri_min=$(echo "$min/2+$min%2" | bc) sec_min=$(echo "$min/2" | bc) max=$ext_upl echo " Setting upload queue." echo " Minimum upload: $min kbit/s" echo " Maximum upload: $max kbit/s" echo " Queue: -preference: $pri_min kbit/s -not preference: $sec_min kbit/s" echo " Free: $tmp kbit/s" echo "%===================================================================%" if [[ u_r2q=="" ]]; then $TC qdisc add dev imq1 root handle 2:0 htb else $TC qdisc add dev imq1 root handle 2:0 htb r2q $u_r2q fi $TC class add dev imq1 parent 2:0 classid 2:1 htb rate ${ext_upl}kbit ceil ${ext_upl}kbit j=2 for usr in $ext do $TC class add dev imq1 parent 2:1 classid 2:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum $TC class add dev imq1 parent 2:$j classid 2:$(($j+1)) htb rate ${pri_min}kbit ceil ${max}kbit quantum $u_quantum $TC class add dev imq1 parent 2:$j classid 2:$(($j+2)) htb rate ${sec_min}kbit ceil ${max}kbit quantum $u_quantum $TC qdisc add dev imq1 parent 2:$(($j+1)) sfq $TC qdisc add dev imq1 parent 2:$(($j+2)) sfq $TC filter add dev imq1 protocol ip parent 2:0 pref 2 u32 match ip src $usr flowid 2:$j for prt in $porty_tcp do $TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32 match ip protocol 6 0xff match ip dport $prt 0xffff flowid 2:$(($j+1)) $TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32 match ip protocol 6 0xff match ip sport $prt 0xffff flowid 2:$(($j+1)) done for prt in $porty_udp do $TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32 match ip protocol 17 0xff match ip dport $prt 0xffff flowid 2:$(($j+1)) $TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32 match ip protocol 17 0xff match ip sport $prt 0xffff flowid 2:$(($j+1)) done if [[ $pping -eq 1 ]]; then $TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32 match ip protocol 1 0xff flowid 2:$(($j+1)) fi $TC filter add dev imq1 protocol ip parent 2:$j pref 4 u32 match ip src $usr flowid 2:$((j+2)) let "j=j+3" done for usr in $int do $TC class add dev imq1 parent 2:1 classid 2:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum $TC class add dev imq1 parent 2:$j classid 2:$(($j+1)) htb rate ${pri_min}kbit ceil ${max}kbit quantum $u_quantum $TC class add dev imq1 parent 2:$j classid 2:$(($j+2)) htb rate ${sec_min}kbit ceil ${max}kbit quantum $u_quantum $TC qdisc add dev imq1 parent 2:$(($j+1)) sfq $TC qdisc add dev imq1 parent 2:$(($j+2)) sfq $TC filter add dev imq1 protocol ip parent 2:0 pref 2 u32 match ip src $usr flowid 2:$j for prt in $porty_tcp do $TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32 match ip protocol 6 0xff match ip dport $prt 0xffff flowid 2:$(($j+1)) done for prt in $porty_udp do $TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32 match ip protocol 17 0xff match ip dport $prt 0xffff flowid 2:$(($j+1)) done if [[ $pping -eq 1 ]]; then $TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32 match ip protocol 1 0xff flowid 2:$(($j+1)) fi $TC filter add dev imq1 protocol ip parent 2:$j pref 4 u32 match ip src $usr flowid 2:$((j+2)) let "j=j+3" done i=0 for ntr in $lan_int do $TC class add dev imq1 parent 2:0 classid 2:$j htb rate ${int_upl[$i]}Mbit ceil ${int_upl[$i]}Mbit quantum $u_quantum $TC qdisc add dev imq1 parent 2:$j sfq for ipek in $ext ${lan_int} do $TC filter add dev imq1 protocol ip parent 2:0 pref 1 u32 match ip dst $ntr match ip src $ipek flowid 2:$j done let "j=j+1" let "i=i+1" done $IPTABLES -t mangle -A POSTROUTING -j IMQ --todev 1 $IP link set imq1 up } echo "rc.htb $VER, (C)Lenthir 2oo4, GNU GPL" echo "$DAT" case "$1" in 'start') echo "Uruchamianie kolejkowania..." start echo "Gotowe." exit 0 ;; 'stop') echo -n "Zatrzymywanie kolejkowania..." stop echo " wykonano." ;; 'restart') echo "Restartowanie kolejkowania..." $firewall start echo "Gotowe." ;; 'status') echo "Klasy na interfejsie imq0!" echo "%====================================%" $TC class show dev imq0 | grep root $TC class show dev imq0 | grep -v root | sort | nl echo "Klasy na interfejsie imq1!" 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" == "lan" ]]; then j=2 for usr in $ext do let "j=j+3" done for usr in $int do let "j=j+3" done i=0;trs="echo \"Transfer w LAN\"" for uvs in $lan_int do trs="$trs && echo \"Lan[$i]:\" && tc -s class show dev imq0 | grep -A 3 \"htb 1:$j \" && tc -s class show dev imq1 | grep -A 3 \"htb 2:$j \"" let "j=j+1" let "i=i+1" done watch -d -n 1 "$trs" else j=2 for usr in $ext do if [[ "$2" == "$usr" ]]; then watch -d -n 1 "echo \"Download: \" && tc -s class show dev imq0 | grep -A 3 \"htb 1:$j \" && tc -s class show dev imq0 | grep -A 3 \"1:$(($j+1)) \" && tc -s class show dev imq0 | grep -A 3 \"1:$(($j+2)) \" && echo && echo \"Upload: \" && tc -s class show dev imq1 | grep -A 3 \"htb 2:$j \" && tc -s class show dev imq1 | grep -A 3 \"2:$(($j+1)) \" && tc -s class show dev imq1 | grep -A 3 \"2:$(($j+2)) \"" echo "Zakończono." exit 0 fi let "j=j+3" done for usr in $int do if [[ "$2" == "$usr" ]]; then watch -d -n 1 "echo \"Download: \" && tc -s class show dev imq0 | grep -A 3 \"htb 1:$j \" && tc -s class show dev imq0 | grep -A 3 \"1:$(($j+1)) \" && tc -s class show dev imq0 | grep -A 3 \"1:$(($j+2)) \" && echo && echo \"Upload: \" && tc -s class show dev imq1 | grep -A 3 \"htb 2:$j \" && tc -s class show dev imq1 | grep -A 3 \"2:$(($j+1)) \" && tc -s class show dev imq1 | grep -A 3 \"2:$(($j+2)) \"" echo "Zakończono." exit 0 fi let "j=j+3" done fi ;; *) echo echo "Użycie: rc.htb start|stop|restart|status" echo "rc.htb stat <lan|adress IP>" exit 1 ;; esac --------------020808070404050103000503--
Can anyone help??
Lenthir wrote: > Hi everybody! > > I wrote nice script, but I need some help.... > Script is working almost well. > > My question is: > Can I minimalize PING time more than this script can? (nowadays is > 70-150ms with large load of link) > My first problem is - unreal big PING on router, and almost excellent > (nowadays is 70-150ms) PING on computers in network. > > My users don't complain, but I noticed that the pages is becoming load > quickly and when it's almost done.. the transfer is going down!! > And second symptom is: when I open pages PING grows to 800ms, and > quickly go down. It's almost imperceptible, but it happens. > What's wrong? All packets is going to correct pipes. What should I do more? > I suspect, that time of change of speed (HTB's reaction time) many > queues is long. How can I improve this? It's a big script - I only looked briefly and may have missed things. Shaping inbound traffic from the wrong end of the bottleneck is hard, HTB would need to be predictive to do it better. For SFQ you can change queue length (SFQ_DEPTH) in net/sched/sch_sfq.c or you could use esfq and choose length with options. How many users do you have? If you have 2mbit link then I think you need to reduce the ceils or you won't have a queue to shape with. > Script is very nice, but I need some professional help and advices. > > Everything You can check when script is working: > ./htb0.5.3en stat <IP> (example: ./htb0.5.3en stat 192.168.0.2) > ./htb0.5.3en stat lan > ./htb0.5.3en stats > > My network's statistics: > http://stats.opat.hopto.org/ > http://stats.zabierzow.net/ > > I attached my script. IMQ with imq_nat.diff patch is required (or AB > option in kernels 2.6), patched iptables(IMQ patch) is required, iproute > is required and bc is required. I tested this script on 2.6.9 kernel and > iproute from .deb package. > > And second less important problem... How Can I mark squid's MISS > packets? Is Debian's Squid Package patched to change TOS? > http://stats.zabierzow.net/squid.php :d I assume a miss is traffic squid gets from the net, if unshaped this will make you go overlimits - so is not neccessarily just a secondary problem. If you are NATing and have IMQ hooking after NAT in PREROUTING then traffic headed for squid will still have your real IP and forwarded local IP. You need to use u32 to seperate it. Andy. > Someone will help?
Andy Furniss wrote: > It's a big script - I only looked briefly and may have missed things. > Shaping inbound traffic from the wrong end of the bottleneck is hard, > HTB would need to be predictive to do it better. So what should I change? > For SFQ you can change queue length (SFQ_DEPTH) in net/sched/sch_sfq.c > or you could use esfq and choose length with options. I made this. SFQ_DEPTH was changed from 128 to 16. > How many users do you have? I have 58 users and it will be more... > If you have 2mbit link then I think you need to reduce the ceils or you > won't have a queue to shape with. I tested real speed - without packet queue (minimum ping, maximum transfer). I have 2mbit link but 2Mbit for download and 256kbit for upload. 2000kbits without queue (even more:P)... and 220 upload without queue. > I assume a miss is traffic squid gets from the net, if unshaped this > will make you go overlimits - so is not neccessarily just a secondary > problem. Squid is switched off. I will not use, as long as I will not make filters. > If you are NATing and have IMQ hooking after NAT in PREROUTING then > traffic headed for squid will still have your real IP and forwarded > local IP. You need to use u32 to seperate it. Can You tell me how? Thanks for answer. I thought, that nobody will write.
Lenthir wrote: > > > Andy Furniss wrote: > >> It's a big script - I only looked briefly and may have missed things. > > >> Shaping inbound traffic from the wrong end of the bottleneck is hard, >> HTB would need to be predictive to do it better. > > So what should I change? > >> For SFQ you can change queue length (SFQ_DEPTH) in net/sched/sch_sfq.c >> or you could use esfq and choose length with options. > > I made this. SFQ_DEPTH was changed from 128 to 16. > >> How many users do you have? > > I have 58 users and it will be more... Hmm - if I had to do this many users on 2meg I would consider a different approach. Assuming I read the script correcty, you are putting interactive traffic whithin each users share so there will be times when you delay while others get their rate. The way I do it is to have a class with a high rate and high prio for interactive - but I do not do per user fairness on it - only on bulk traffic. Doing this with lots of users will mean you really have to be careful about not letting bulk into interactive class. It also means that a user could get more than there share of the link by having bulk and interactive traffic. As a policy the Idea that on a highly contended link interactive should get > than fair share at any time is attractive to me as a gamer. It means that users that 24/7 download / browsers can't leave me with so little bandwidth that gaming is impossible. If you want to do things so that interactive takes from bulk per user and keeps low latency you will need to look at HFSC. > >> If you have 2mbit link then I think you need to reduce the ceils or >> you won't have a queue to shape with. > > I tested real speed - without packet queue (minimum ping, maximum > transfer). > > I have 2mbit link but 2Mbit for download and 256kbit for upload. > 2000kbits without queue (even more:P)... and 220 upload without queue. You need to back off a bit from the inbound link speed so that a queue builds up. There are other tweaks I would do but will post later when I know what you do/use. What sort of DSL do you use (pppoa or e etc) and can you get a cell count out of the modem? > >> I assume a miss is traffic squid gets from the net, if unshaped this >> will make you go overlimits - so is not neccessarily just a secondary >> problem. > > Squid is switched off. I will not use, as long as I will not make filters. > >> If you are NATing and have IMQ hooking after NAT in PREROUTING then >> traffic headed for squid will still have your real IP and forwarded >> local IP. You need to use u32 to seperate it. > > Can You tell me how? I think it should work OK as you do in the script with u32 for local IPs. > > Thanks for answer. I thought, that nobody will write. > _______________________________________________ > LARTC mailing list / LARTC@mailman.ds9a.nl > http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/ >
This is a multi-part message in MIME format.
--------------050109000308080002050504
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
I improved my script.
PING don't grow up when I'm browsing Internet.
I'm testing it now... but I notice improvement.
I recommend this script... is working very nice :)
I invite to help improving this script.
Site in Internet soon.
I haven't written filters for Squid yet.
--------------050109000308080002050504
Content-Type: text/plain;
name="htb0.5.3o"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="htb0.5.3o"
#!/bin/bash
#
# rc.htb 0.5.3, (C)Lenthir 2oo4, GNU GPL
# 2004-11-01 9:30
VER="0.5.3"
DAT="2004-11-01 9:30"
MAX=3330
#######################
#Konfiguracja interfejsów:
ext_dwl=2000 #prędkość łacza(y) na świat
w kbit/s
ext_upl=220
int="`/etc/router/0.cfg` `/etc/router/1.cfg` `/etc/router/2.cfg`"
#adresy IP dla interfejsów lan
srv_ext="80.53.64.3" #zewnętrzne IP
interfejsów wyjściowych
lan_int="192.168.0.0/24 192.168.1.0/24 192.168.2.0/24"
int_dwl[0]=85; int_upl[0]=85
int_dwl[1]=2; int_upl[1]=2
int_dwl[2]=80; int_upl[2]=80
ext[0]="80.53.64.2" #zewnętrzne IP w
podsieciach
ext[1]=""
ext[2]=""
TC=`which tc` #ścieżka do tc
MODPROBE=`which modprobe` #ścieżka do modprobe
IP=`which ip` #ścieżka do ip
IPTABLES=`which iptables` #ścieżka do iptables
firewall="/etc/init.d/rc.iptables restart" #jak
zrestartować firewall
#u_r2q=10 #r2q
u_quantum=1500 #quantum
porty_tcp="20 21 22 23 25 53 80 110 143 220 443 993 995 27015"
porty_udp="53"
pping=1 # 0 - ping w kolejce
normalnej 1 - ping w kolejce priorytetowej
#######################
#Sprawdza czy wszystkie srv_ext są też w ext, jesli nie dopisuje
i=0;
for l in $lan_int
do
let "i=$i+1"
zew="$zew ${ext[$i]}"
done
ipki="$zew $int"
for srvip in $srv_ext
do
if [[ `echo $ipki | grep $srvip` != $ipki ]]; then
zew="$zew $srvip"
fi
done
ile_int=`echo ${int}|awk '{print NF}'`
ile_ext=`echo ${zew}|awk '{print NF}'`
ile=$(echo "$ile_int + $ile_ext" | bc)
if [[ $ile -ge $MAX ]]
then
echo "Niedopuszczalnie dużo komputerów!"
exit 1
fi
stop()
{
$TC qdisc del root dev imq0 2> /dev/null
$TC qdisc del root dev imq1 2> /dev/null
$IP link set imq0 down
$IP link set imq1 down
}
start()
{ stop
# download
tmp=$(echo "$ext_dwl%$ile" | bc)
min=$(echo "$ext_dwl/$ile" | bc)
pri_min=$(echo "$min/2+$min%2" | bc)
sec_min=$(echo "$min/2" | bc)
max=$ext_dwl
echo " Ilość komputerów: $ile"
echo
"%===================================================================%"
echo " Ustawianie kolejki downloadu."
echo " Minimalny download: $min kbit/s"
echo " Maksymalny download: $max kbit/s"
echo " Kolejka: -priorytetowa: $pri_min kbit/s -normalna: $sec_min
kbit/s"
echo " Niewykorzystane: $tmp kbit/s"
echo " "
if [[ u_r2q=="" ]]; then
$TC qdisc add dev imq0 root handle 1:0 htb
else
$TC qdisc add dev imq0 root handle 1:0 htb r2q $u_r2q
fi
$TC class add dev imq0 parent 1:0 classid 1:1 htb rate ${ext_dwl}kbit ceil
${ext_dwl}kbit
j=2
for usr in $zew
do
$TC class add dev imq0 parent 1:1 classid 1:$j htb rate ${min}kbit ceil
${max}kbit quantum $u_quantum
$TC class add dev imq0 parent 1:$j classid 1:$(($j+1)) htb rate
${pri_min}kbit ceil ${max}kbit prio 1 quantum $u_quantum
$TC class add dev imq0 parent 1:$j classid 1:$(($j+2)) htb rate
${sec_min}kbit ceil ${max}kbit prio 2 quantum $u_quantum
$TC qdisc add dev imq0 parent 1:$(($j+1)) sfq
$TC qdisc add dev imq0 parent 1:$(($j+2)) sfq
$TC filter add dev imq0 protocol ip parent 1:0 pref 2 u32 match ip dst
$usr flowid 1:$j
for prt in $porty_tcp
do
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 6 0xff match ip sport $prt 0xffff flowid 1:$(($j+1))
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 6 0xff match ip dport $prt 0xffff flowid 1:$(($j+1))
done
for prt in $porty_udp
do
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 17 0xff match ip sport $prt 0xffff flowid 1:$(($j+1))
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 17 0xff match ip dport $prt 0xffff flowid 1:$(($j+1))
done
if [[ $pping -eq 1 ]]; then
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 1 0xff flowid 1:$(($j+1))
fi
$TC filter add dev imq0 protocol ip parent 1:$j pref 4 u32 match ip dst
$usr flowid 1:$((j+2))
let "j=j+3"
done
for usr in $int
do
$TC class add dev imq0 parent 1:1 classid 1:$j htb rate ${min}kbit ceil
${max}kbit quantum $u_quantum
$TC class add dev imq0 parent 1:$j classid 1:$(($j+1)) htb rate
${pri_min}kbit ceil ${max}kbit prio 1 quantum $u_quantum
$TC class add dev imq0 parent 1:$j classid 1:$(($j+2)) htb rate
${sec_min}kbit ceil ${max}kbit prio 2 quantum $u_quantum
$TC qdisc add dev imq0 parent 1:$(($j+1)) sfq
$TC qdisc add dev imq0 parent 1:$(($j+2)) sfq
$TC filter add dev imq0 protocol ip parent 1:0 pref 2 u32 match ip dst
$usr flowid 1:$j
for prt in $porty_tcp
do
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 6 0xff match ip sport $prt 0xffff flowid 1:$(($j+1))
done
for prt in $porty_udp
do
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 17 0xff match ip sport $prt 0xffff flowid 1:$(($j+1))
done
if [[ $pping -eq 1 ]]; then
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 1 0xff flowid 1:$(($j+1))
fi
$TC filter add dev imq0 protocol ip parent 1:$j pref 4 u32 match ip dst
$usr flowid 1:$((j+2))
let "j=j+3"
done
i=0
for ntr in $lan_int
do
$TC class add dev imq0 parent 1:0 classid 1:$j htb rate ${int_dwl[$i]}Mbit ceil
${int_dwl[$i]}Mbit quantum $u_quantum
$TC qdisc add dev imq0 parent 1:$j sfq
for ipek in $lan_int ${zew}
do
$TC filter add dev imq0 protocol ip parent 1:0 pref 1 u32 match
ip src $ntr match ip dst $ipek flowid 1:$j
done
if [[ ${ext[$i]}!="" ]]; then
for pri in ${ext[$i]}
do
for sec in ${zew/${ext[$i]}/}
do
$TC filter add dev imq0 protocol ip parent 1:0 pref 1 u32 match
ip src $pri match ip dst $sec flowid 1:$j
done
done
fi
let "j=j+1"
let "i=i+1"
done
$IPTABLES -t mangle -A PREROUTING -j IMQ --todev 0
$IP link set imq0 up
# upload
tmp=$(echo "$ext_upl%$ile" | bc)
min=$(echo "$ext_upl/$ile" | bc)
pri_min=$(echo "$min/2+$min%2" | bc)
sec_min=$(echo "$min/2" | bc)
max=$ext_upl
echo " Ustawianie kolejki uploadu."
echo " Maksymalny upload: $max kbit/s"
echo " Minimalny upload userów: $min kbit/s"
echo " Kolejka: -priorytetowa: $pri_min kbit/s -normalna: $sec_min
kbit/s"
echo " Niewykorzystane: $tmp kbit/s"
echo
"%===================================================================%"
if [[ u_r2q=="" ]]; then
$TC qdisc add dev imq1 root handle 2:0 htb
else
$TC qdisc add dev imq1 root handle 2:0 htb r2q $u_r2q
fi
$TC class add dev imq1 parent 2:0 classid 2:1 htb rate ${ext_upl}kbit ceil
${ext_upl}kbit
j=2
for usr in $zew
do
$TC class add dev imq1 parent 2:1 classid 2:$j htb rate ${min}kbit ceil
${max}kbit quantum $u_quantum
$TC class add dev imq1 parent 2:$j classid 2:$(($j+1)) htb rate
${pri_min}kbit ceil ${max}kbit prio 1 quantum $u_quantum
$TC class add dev imq1 parent 2:$j classid 2:$(($j+2)) htb rate
${sec_min}kbit ceil ${max}kbit prio 2 quantum $u_quantum
$TC qdisc add dev imq1 parent 2:$(($j+1)) sfq
$TC qdisc add dev imq1 parent 2:$(($j+2)) sfq
$TC filter add dev imq1 protocol ip parent 2:0 pref 2 u32 match ip src
$usr flowid 2:$j
for prt in $porty_tcp
do
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 6 0xff match ip dport $prt 0xffff flowid 2:$(($j+1))
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 6 0xff match ip sport $prt 0xffff flowid 2:$(($j+1))
done
for prt in $porty_udp
do
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 17 0xff match ip dport $prt 0xffff flowid 2:$(($j+1))
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 17 0xff match ip sport $prt 0xffff flowid 2:$(($j+1))
done
if [[ $pping -eq 1 ]]; then
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 1 0xff flowid 2:$(($j+1))
fi
$TC filter add dev imq1 protocol ip parent 2:$j pref 4 u32 match ip src $usr
flowid 2:$((j+2))
let "j=j+3"
done
for usr in $int
do
$TC class add dev imq1 parent 2:1 classid 2:$j htb rate ${min}kbit ceil
${max}kbit quantum $u_quantum
$TC class add dev imq1 parent 2:$j classid 2:$(($j+1)) htb rate
${pri_min}kbit ceil ${max}kbit prio 1 quantum $u_quantum
$TC class add dev imq1 parent 2:$j classid 2:$(($j+2)) htb rate
${sec_min}kbit ceil ${max}kbit prio 2 quantum $u_quantum
$TC qdisc add dev imq1 parent 2:$(($j+1)) sfq
$TC qdisc add dev imq1 parent 2:$(($j+2)) sfq
$TC filter add dev imq1 protocol ip parent 2:0 pref 2 u32 match ip src
$usr flowid 2:$j
for prt in $porty_tcp
do
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 6 0xff match ip dport $prt 0xffff flowid 2:$(($j+1))
done
for prt in $porty_udp
do
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 17 0xff match ip dport $prt 0xffff flowid 2:$(($j+1))
done
if [[ $pping -eq 1 ]]; then
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 1 0xff flowid 2:$(($j+1))
fi
$TC filter add dev imq1 protocol ip parent 2:$j pref 4 u32 match ip src
$usr flowid 2:$((j+2))
let "j=j+3"
done
i=0
for ntr in $lan_int
do
$TC class add dev imq1 parent 2:0 classid 2:$j htb rate
${int_upl[$i]}Mbit ceil ${int_upl[$i]}Mbit quantum $u_quantum
$TC qdisc add dev imq1 parent 2:$j sfq
for ipek in $lan_int ${zew}
do
$TC filter add dev imq1 protocol ip parent 2:0 pref 1 u32 match
ip src $ipek match ip dst $ntr flowid 2:$j
done
if [[ "${ext[$i]}"!="k" ]]; then
for pri in ${ext[$i]}
do
for sec in ${zew/${ext[$i]}/}
do
$TC filter add dev imq1 protocol ip parent 2:0 pref 1 u32 match
ip src $sec match ip dst $pri flowid 2:$j
done
done
fi
let "j=j+1"
let "i=i+1"
done
$IPTABLES -t mangle -A POSTROUTING -j IMQ --todev 1
$IP link set imq1 up
}
echo "rc.htb $VER, (C)Lenthir 2oo4, GNU GPL"
echo "$DAT"
case "$1" in
'start')
echo "Uruchamianie kolejkowania..."
start
echo "Gotowe."
exit 0
;;
'stop')
echo -n "Zatrzymywanie kolejkowania..."
stop
echo " wykonano."
;;
'restart')
echo "Restartowanie kolejkowania..."
$firewall
start
echo "Gotowe."
;;
'status')
echo "Klasy na interfejsie imq0!"
echo "%====================================%"
$TC class show dev imq0 | grep root
$TC class show dev imq0 | grep -v root | sort | nl
echo "Klasy na interfejsie imq1!"
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" == "lan" ]]; then
j=2
for usr in $zew
do
let "j=j+3"
done
for usr in $int
do
let "j=j+3"
done
i=0;trs="echo \"Transfer w LAN\""
for uvs in $lan_int
do
trs="$trs && echo \"Lan[$i]:\" &&
tc -s class show dev imq0 | grep -A 3 \"htb 1:$j \" && tc -s
class show dev imq1 | grep -A 3 \"htb 2:$j \""
let "j=j+1"
let "i=i+1"
done
watch -d -n 1 "$trs"
else
j=2
for usr in $zew
do
if [[ "$2" == "$usr" ]]; then
watch -d -n 1 "echo \"Download: \"
&& tc -s class show dev imq0 | grep -A 3 \"htb 1:$j \"
&& tc -s class show dev imq0 | grep -A 3 \"1:$(($j+1)) \"
&& tc -s class show dev imq0 | grep -A 3 \"1:$(($j+2)) \"
&& echo && echo \"Upload: \" && tc -s class
show dev imq1 | grep -A 3 \"htb 2:$j \" && tc -s class show
dev imq1 | grep -A 3 \"2:$(($j+1)) \" && tc -s class show dev
imq1 | grep -A 3 \"2:$(($j+2)) \""
echo "Zakończono."
exit 0
fi
let "j=j+3"
done
for usr in $int
do
if [[ "$2" == "$usr" ]]; then
watch -d -n 1 "echo \"Download: \"
&& tc -s class show dev imq0 | grep -A 3 \"htb 1:$j \"
&& tc -s class show dev imq0 | grep -A 3 \"1:$(($j+1)) \"
&& tc -s class show dev imq0 | grep -A 3 \"1:$(($j+2)) \"
&& echo && echo \"Upload: \" && tc -s class
show dev imq1 | grep -A 3 \"htb 2:$j \" && tc -s class show
dev imq1 | grep -A 3 \"2:$(($j+1)) \" && tc -s class show dev
imq1 | grep -A 3 \"2:$(($j+2)) \""
echo "Zakończono."
exit 0
fi
let "j=j+3"
done
fi
;;
*)
echo
echo "Użycie: rc.htb start|stop|restart|status"
echo "rc.htb stat <lan|adress IP>"
exit 1
;;
esac
--------------050109000308080002050504
Content-Type: text/plain;
name="htb0.5.3z"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="htb0.5.3z"
#!/bin/bash
#
# rc.htb 0.5.3, (C)Lenthir 2oo4, GNU GPL
# 2004-11-01 9:30
VER="0.5.3"
DAT="2004-11-01 9:30"
MAX=3330
#######################
#Konfiguracja interfejsów:
ext_dwl=2000 #prędkość łacza(y) na świat
w kbit/s
ext_upl=220
int="`/home/scorpio/router/adresyIP`" #adresy IP dla interfejsów lan
srv_ext="83.17.20.134" #zewnętrzne IP
interfejsów wyjściowych
lan_int="192.168.200.0/24 192.168.201.0/24 192.168.202.0/24"
int_dwl[0]=3; int_upl[0]=3
int_dwl[1]=3; int_upl[1]=3
int_dwl[2]=85; int_upl[2]=85
ext[0]="" #zewnętrzne IP w
podsieciach
ext[1]="83.17.20.131"
ext[2]="83.17.20.130"
TC=`which tc` #ścieżka do tc
MODPROBE=`which modprobe` #ścieżka do modprobe
IP=`which ip` #ścieżka do ip
IPTABLES=`which iptables` #ścieżka do iptables
firewall="/etc/init.d/rc.iptables restart" #jak
zrestartować firewall
#u_r2q=10 #r2q
u_quantum=1500 #quantum
porty_tcp="20 21 22 23 25 53 80 110 143 220 443 993 995 27015"
porty_udp="53"
pping=1 # 0 - ping w kolejce
normalnej 1 - ping w kolejce priorytetowej
#######################
#Sprawdza czy wszystkie srv_ext są też w ext, jesli nie dopisuje
i=0;
for l in $lan_int
do
let "i=$i+1"
zew="$zew ${ext[$i]}"
done
ipki="$zew $int"
for srvip in $srv_ext
do
if [[ `echo $ipki | grep $srvip` != $ipki ]]; then
zew="$zew $srvip"
fi
done
ile_int=`echo ${int}|awk '{print NF}'`
ile_ext=`echo ${zew}|awk '{print NF}'`
ile=$(echo "$ile_int + $ile_ext" | bc)
if [[ $ile -ge $MAX ]]
then
echo "Niedopuszczalnie dużo komputerów!"
exit 1
fi
stop()
{
$TC qdisc del root dev imq0 2> /dev/null
$TC qdisc del root dev imq1 2> /dev/null
$IP link set imq0 down
$IP link set imq1 down
}
start()
{ stop
# download
tmp=$(echo "$ext_dwl%$ile" | bc)
min=$(echo "$ext_dwl/$ile" | bc)
pri_min=$(echo "$min/2+$min%2" | bc)
sec_min=$(echo "$min/2" | bc)
max=$ext_dwl
echo " Ilość komputerów: $ile"
echo
"%===================================================================%"
echo " Ustawianie kolejki downloadu."
echo " Minimalny download: $min kbit/s"
echo " Maksymalny download: $max kbit/s"
echo " Kolejka: -priorytetowa: $pri_min kbit/s -normalna: $sec_min
kbit/s"
echo " Niewykorzystane: $tmp kbit/s"
echo " "
if [[ u_r2q=="" ]]; then
$TC qdisc add dev imq0 root handle 1:0 htb
else
$TC qdisc add dev imq0 root handle 1:0 htb r2q $u_r2q
fi
$TC class add dev imq0 parent 1:0 classid 1:1 htb rate ${ext_dwl}kbit ceil
${ext_dwl}kbit
j=2
for usr in $zew
do
$TC class add dev imq0 parent 1:1 classid 1:$j htb rate ${min}kbit ceil
${max}kbit quantum $u_quantum
$TC class add dev imq0 parent 1:$j classid 1:$(($j+1)) htb rate
${pri_min}kbit ceil ${max}kbit quantum $u_quantum
$TC class add dev imq0 parent 1:$j classid 1:$(($j+2)) htb rate
${sec_min}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq0 parent 1:$(($j+1)) sfq
$TC qdisc add dev imq0 parent 1:$(($j+2)) sfq
$TC filter add dev imq0 protocol ip parent 1:0 pref 2 u32 match ip dst
$usr flowid 1:$j
for prt in $porty_tcp
do
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 6 0xff match ip sport $prt 0xffff flowid 1:$(($j+1))
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 6 0xff match ip dport $prt 0xffff flowid 1:$(($j+1))
done
for prt in $porty_udp
do
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 17 0xff match ip sport $prt 0xffff flowid 1:$(($j+1))
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 17 0xff match ip dport $prt 0xffff flowid 1:$(($j+1))
done
if [[ $pping -eq 1 ]]; then
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 1 0xff flowid 1:$(($j+1))
fi
$TC filter add dev imq0 protocol ip parent 1:$j pref 4 u32 match ip dst
$usr flowid 1:$((j+2))
let "j=j+3"
done
for usr in $int
do
$TC class add dev imq0 parent 1:1 classid 1:$j htb rate ${min}kbit ceil
${max}kbit quantum $u_quantum
$TC class add dev imq0 parent 1:$j classid 1:$(($j+1)) htb rate
${pri_min}kbit ceil ${max}kbit quantum $u_quantum
$TC class add dev imq0 parent 1:$j classid 1:$(($j+2)) htb rate
${sec_min}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq0 parent 1:$(($j+1)) sfq
$TC qdisc add dev imq0 parent 1:$(($j+2)) sfq
$TC filter add dev imq0 protocol ip parent 1:0 pref 2 u32 match ip dst
$usr flowid 1:$j
for prt in $porty_tcp
do
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 6 0xff match ip sport $prt 0xffff flowid 1:$(($j+1))
done
for prt in $porty_udp
do
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 17 0xff match ip sport $prt 0xffff flowid 1:$(($j+1))
done
if [[ $pping -eq 1 ]]; then
$TC filter add dev imq0 protocol ip parent 1:$j pref 3 u32
match ip protocol 1 0xff flowid 1:$(($j+1))
fi
$TC filter add dev imq0 protocol ip parent 1:$j pref 4 u32 match ip dst
$usr flowid 1:$((j+2))
let "j=j+3"
done
i=0
for ntr in $lan_int
do
$TC class add dev imq0 parent 1:0 classid 1:$j htb rate ${int_dwl[$i]}Mbit ceil
${int_dwl[$i]}Mbit quantum $u_quantum
$TC qdisc add dev imq0 parent 1:$j sfq
for ipek in $lan_int ${zew}
do
$TC filter add dev imq0 protocol ip parent 1:0 pref 1 u32 match
ip src $ntr match ip dst $ipek flowid 1:$j
done
if [[ ${ext[$i]}!="" ]]; then
for pri in ${ext[$i]}
do
for sec in ${zew/${ext[$i]}/}
do
$TC filter add dev imq0 protocol ip parent 1:0 pref 1 u32 match
ip src $pri match ip dst $sec flowid 1:$j
done
done
fi
let "j=j+1"
let "i=i+1"
done
$IPTABLES -t mangle -A PREROUTING -j IMQ --todev 0
$IP link set imq0 up
# upload
tmp=$(echo "$ext_upl%$ile" | bc)
min=$(echo "$ext_upl/$ile" | bc)
pri_min=$(echo "$min/2+$min%2" | bc)
sec_min=$(echo "$min/2" | bc)
max=$ext_upl
echo " Ustawianie kolejki uploadu."
echo " Maksymalny upload: $max kbit/s"
echo " Minimalny upload userów: $min kbit/s"
echo " Kolejka: -priorytetowa: $pri_min kbit/s -normalna: $sec_min
kbit/s"
echo " Niewykorzystane: $tmp kbit/s"
echo
"%===================================================================%"
if [[ u_r2q=="" ]]; then
$TC qdisc add dev imq1 root handle 2:0 htb
else
$TC qdisc add dev imq1 root handle 2:0 htb r2q $u_r2q
fi
$TC class add dev imq1 parent 2:0 classid 2:1 htb rate ${ext_upl}kbit ceil
${ext_upl}kbit
j=2
for usr in $zew
do
$TC class add dev imq1 parent 2:1 classid 2:$j htb rate ${min}kbit ceil
${max}kbit quantum $u_quantum
$TC class add dev imq1 parent 2:$j classid 2:$(($j+1)) htb rate
${pri_min}kbit ceil ${max}kbit prio 1 quantum $u_quantum
$TC class add dev imq1 parent 2:$j classid 2:$(($j+2)) htb rate
${sec_min}kbit ceil ${max}kbit prio 2 quantum $u_quantum
$TC qdisc add dev imq1 parent 2:$(($j+1)) sfq
$TC qdisc add dev imq1 parent 2:$(($j+2)) sfq
$TC filter add dev imq1 protocol ip parent 2:0 pref 2 u32 match ip src
$usr flowid 2:$j
for prt in $porty_tcp
do
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 6 0xff match ip dport $prt 0xffff flowid 2:$(($j+1))
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 6 0xff match ip sport $prt 0xffff flowid 2:$(($j+1))
done
for prt in $porty_udp
do
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 17 0xff match ip dport $prt 0xffff flowid 2:$(($j+1))
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 17 0xff match ip sport $prt 0xffff flowid 2:$(($j+1))
done
if [[ $pping -eq 1 ]]; then
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 1 0xff flowid 2:$(($j+1))
fi
$TC filter add dev imq1 protocol ip parent 2:$j pref 4 u32 match ip src $usr
flowid 2:$((j+2))
let "j=j+3"
done
for usr in $int
do
$TC class add dev imq1 parent 2:1 classid 2:$j htb rate ${min}kbit ceil
${max}kbit quantum $u_quantum
$TC class add dev imq1 parent 2:$j classid 2:$(($j+1)) htb rate
${pri_min}kbit ceil ${max}kbit prio 1 quantum $u_quantum
$TC class add dev imq1 parent 2:$j classid 2:$(($j+2)) htb rate
${sec_min}kbit ceil ${max}kbit prio 2 quantum $u_quantum
$TC qdisc add dev imq1 parent 2:$(($j+1)) sfq
$TC qdisc add dev imq1 parent 2:$(($j+2)) sfq
$TC filter add dev imq1 protocol ip parent 2:0 pref 2 u32 match ip src
$usr flowid 2:$j
for prt in $porty_tcp
do
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 6 0xff match ip dport $prt 0xffff flowid 2:$(($j+1))
done
for prt in $porty_udp
do
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 17 0xff match ip dport $prt 0xffff flowid 2:$(($j+1))
done
if [[ $pping -eq 1 ]]; then
$TC filter add dev imq1 protocol ip parent 2:$j pref 3 u32
match ip protocol 1 0xff flowid 2:$(($j+1))
fi
$TC filter add dev imq1 protocol ip parent 2:$j pref 4 u32 match ip src
$usr flowid 2:$((j+2))
let "j=j+3"
done
i=0
for ntr in $lan_int
do
$TC class add dev imq1 parent 2:0 classid 2:$j htb rate
${int_upl[$i]}Mbit ceil ${int_upl[$i]}Mbit quantum $u_quantum
$TC qdisc add dev imq1 parent 2:$j sfq
for ipek in $lan_int ${zew}
do
$TC filter add dev imq1 protocol ip parent 2:0 pref 1 u32 match
ip src $ipek match ip dst $ntr flowid 2:$j
done
if [[ "${ext[$i]}"!="k" ]]; then
for pri in ${ext[$i]}
do
for sec in ${zew/${ext[$i]}/}
do
$TC filter add dev imq1 protocol ip parent 2:0 pref 1 u32 match
ip src $sec match ip dst $pri flowid 2:$j
done
done
fi
let "j=j+1"
let "i=i+1"
done
$IPTABLES -t mangle -A POSTROUTING -j IMQ --todev 1
$IP link set imq1 up
}
echo "rc.htb $VER, (C)Lenthir 2oo4, GNU GPL"
echo "$DAT"
case "$1" in
'start')
echo "Uruchamianie kolejkowania..."
start
echo "Gotowe."
exit 0
;;
'stop')
echo -n "Zatrzymywanie kolejkowania..."
stop
echo " wykonano."
;;
'restart')
echo "Restartowanie kolejkowania..."
$firewall
start
echo "Gotowe."
;;
'status')
echo "Klasy na interfejsie imq0!"
echo "%====================================%"
$TC class show dev imq0 | grep root
$TC class show dev imq0 | grep -v root | sort | nl
echo "Klasy na interfejsie imq1!"
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" == "lan" ]]; then
j=2
for usr in $zew
do
let "j=j+3"
done
for usr in $int
do
let "j=j+3"
done
i=0;trs="echo \"Transfer w LAN\""
for uvs in $lan_int
do
trs="$trs && echo \"Lan[$i]:\" &&
tc -s class show dev imq0 | grep -A 3 \"htb 1:$j \" && tc -s
class show dev imq1 | grep -A 3 \"htb 2:$j \""
let "j=j+1"
let "i=i+1"
done
watch -d -n 1 "$trs"
else
j=2
for usr in $zew
do
if [[ "$2" == "$usr" ]]; then
watch -d -n 1 "echo \"Download: \"
&& tc -s class show dev imq0 | grep -A 3 \"htb 1:$j \"
&& tc -s class show dev imq0 | grep -A 3 \"1:$(($j+1)) \"
&& tc -s class show dev imq0 | grep -A 3 \"1:$(($j+2)) \"
&& echo && echo \"Upload: \" && tc -s class
show dev imq1 | grep -A 3 \"htb 2:$j \" && tc -s class show
dev imq1 | grep -A 3 \"2:$(($j+1)) \" && tc -s class show dev
imq1 | grep -A 3 \"2:$(($j+2)) \""
echo "Zakończono."
exit 0
fi
let "j=j+3"
done
for usr in $int
do
if [[ "$2" == "$usr" ]]; then
watch -d -n 1 "echo \"Download: \"
&& tc -s class show dev imq0 | grep -A 3 \"htb 1:$j \"
&& tc -s class show dev imq0 | grep -A 3 \"1:$(($j+1)) \"
&& tc -s class show dev imq0 | grep -A 3 \"1:$(($j+2)) \"
&& echo && echo \"Upload: \" && tc -s class
show dev imq1 | grep -A 3 \"htb 2:$j \" && tc -s class show
dev imq1 | grep -A 3 \"2:$(($j+1)) \" && tc -s class show dev
imq1 | grep -A 3 \"2:$(($j+2)) \""
echo "Zakończono."
exit 0
fi
let "j=j+3"
done
fi
;;
*)
echo
echo "Użycie: rc.htb start|stop|restart|status"
echo "rc.htb stat <lan|adress IP>"
exit 1
;;
esac
--------------050109000308080002050504--