[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: skrypt imq pod dwa łącza





adam wrote:
Czy ma może ktoś jakiś skrypt pod imq dla dwóch łączy,
Ponieważ mam zrobiony load balancing i jak odpalam skrypt
Imq, to strasznie wolno idą wszelkiego typu zapytania do WWW,
Mimo tego, że puściłem to w klasie uprzywilejowanej,
Jakby ktoś miał taki skrypcik to prosiłbym o wysłanie na maila.

Spróbuj to...

Statystyki moich sieci:
http://stats.zabierzow.net/
http://stats.opat.hopto.org/

W Opatkowicach tesuje nowy skrypcik. Na razie na serwerze jest duży
ping, ale u klientów niski. Pracuje nad tym.

Skrypt jest chwilowo w przebudowie. Wysyłam jego poprzednią wersję.
htb0.5.2 i obecną htb0.5.3, w trakcie rozwoju... działającą już
połowicznie (poza ruchem po LANie).

0.5.3 nie powinien mieć problemu z dwoma interfejsami, 0.5.2 potrzebuje
jeszcze jednej pęli na outpucie.

Musisz pamiętać o tym, żeby na IMQ nałożyc patch NATujący, lub w jądrze
2.6 wybrac sposób wrzucania do IMQ na AB. (PREROUTING AFTER NAT)
(POSTROUTING BEFORE NAT)

Skrypt wymaga pakietu bc. I chyba tyle uwag.
0.5.2 korzysta z niestandardowego IMQ z http://pupa.da.ru/imq/

--
Lenthir

#!/bin/bash
#
# rc.htb 0.5.2, (C)Lenthir 2oo4, GNU GPL
#
VER="0.5.2"
DAT="2004-08-13 19:30"

MAX=3330
#######################
#Konfiguracja interfejsów:
out="eth0"                                      #wyj¶cie na ¶wiat

lan="`/home/scorpio/router/adresyIP`"           #adresy IP dla interfejsów lan, bez IP serwera
ext="`/home/scorpio/routeradresyIPsrv`"         #zewnêtrzne adresy IP
srv="83.17.20.134"                              #IP zewnêtrzny serwera
srv_l="192.168.200.5 192.168.201.5"             #Wewnetrzne IP serwera

ile=`echo ${lan}|awk '{print NF}'`                 #ilo¶ci komputerów w podsieciach, bez serwera

TC=/sbin/tc                                        #¶cie¿ka do tc
MODPROBE=/sbin/modprobe                            #¶cie¿ka do modprobe
IP=/sbin/ip                                        #¶cie¿ka do ip
IPTABLES=/usr/local/sbin/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

#(1Mbit = 1024kbit = 1048576bity = 0,125MB/s = 128kB/s = 131072B/s):
wan_dwl=1020                                    #prêdko¶æ ³acza na ¶wiat w kbit/s
wan_upl=220
ratio_d=1                                       #prêdko¶æ maksymalna jak± mog± osi±gaæ u¿ytkownicy (1 = 100%)
ratio_u=1

#Konfiguracja serwera
srv_dwl=8                                       #minimalna prêdko¶æ downloadu z serwera
srv_upl=8                                       #minimalna prêdko¶æ uploadu z serwera

#Konfiguracja LAN
lan_dwl[0]=20                                    #prêdko¶æ sieci LAN w Mbit/s (warto¶æ rzeczywista!!)
lan_upl[0]=20
lan_dwl[1]=20
lan_upl[1]=20
#######################

if [[ $ile -ge $MAX ]]
        then
        echo "Niedopuszczalnie du¿o komputerów!"
        exit 1
        fi

#######################

stop()
{
$TC qdisc del root dev $out 2> /dev/null
$TC qdisc del root dev imq 2> /dev/null
$IP link set imq down
}
start()
{ stop

# download
tmp=$(echo "($wan_dwl-$srv_dwl)%$ile" | bc)
srv_dwl=$(echo "$srv_dwl+$tmp" | bc)
min=$(echo "($wan_dwl-$srv_dwl)/$ile" | bc)
pri_min=$(echo "$min/2+$min%2" | bc)
sec_min=$(echo "$min/2" | bc)
max=$(echo "$wan_dwl*$ratio_d" | bc)

echo " Ilo¶æ komputerów: $ile"
echo "%===================================================================%"
echo " Ustawianie kolejki downloadu."
echo " Maksymalny download: $max kbit/s"
echo " Minimalny download serwera: $srv_dwl kbit/s"
echo " Minimalny download userów: $min kbit/s"
echo " Primary: $pri_min kbit/s    Secondary: $sec_min kbit/s"
echo " "

if [[ u_r2q=="" ]]; then
$TC qdisc add dev imq root handle 1:0 htb
else
$TC qdisc add dev imq root handle 1:0 htb r2q $u_r2q
fi

$TC class add dev imq parent 1:0 classid 1:1 htb rate ${wan_dwl}kbit ceil ${wan_dwl}kbit

# Serwer
$TC class add dev imq parent 1:1 classid 1:2 htb rate ${srv_dwl}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev imq parent 1:2 sfq perturb 10
$TC filter add dev imq protocol ip parent 1:0 u32 match ip dst $srv flowid 1:2

j=3
for usr in $lan
        do
        $TC class add dev imq parent 1:1 classid 1:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum
        $TC class add dev imq parent 1:$j classid 1:$(($j+1)) htb rate ${pri_min}kbit ceil ${max}kbit quantum $u_quantum
        $TC class add dev imq parent 1:$j classid 1:$(($j+2)) htb rate ${sec_min}kbit ceil ${max}kbit quantum $u_quantum
        $TC qdisc add dev imq parent 1:$(($j+1)) sfq perturb 10
        $TC qdisc add dev imq parent 1:$(($j+2)) sfq perturb 10
        $TC filter add dev imq 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 imq 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 imq 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 imq protocol ip parent 1:$j pref 3 u32 match ip protocol 1 0xff flowid 1:$(($j+1))
                 fi
        $TC filter add dev imq protocol ip parent 1:$j pref 4 u32 match ip dst $usr flowid 1:$((j+2))
        let "j=j+3"
        done
i=0
for uvs in $srv_l
        do
        $TC class add dev imq parent 1:0 classid 1:$j htb rate ${lan_dwl[$i]}Mbit ceil ${lan_dwl[$i]}Mbit quantum $u_quantum
        $TC qdisc add dev imq parent 1:$j sfq perturb 10
        $TC filter add dev imq protocol ip parent 1:0 pref 1 u32 match ip dst $uvs flowid 1:$j
        let "j=j+1"
        let "i=i+1"
        done

$IP link set imq up

# upload
tmp=$(echo "($wan_upl-$srv_upl)%$ile" | bc)
srv_upl=$(echo "$srv_upl+$tmp" | bc)
min=$(echo "($wan_upl-$srv_upl)/$ile" | bc)
pri_min=$(echo "$min/2+$min%2" | bc)
sec_min=$(echo "$min/2" | bc)
max=$(echo "$wan_upl*$ratio_u" | bc)

echo " Ustawianie kolejki uploadu."
echo " Maksymalny upload: $max kbit/s"
echo " Minimalny upload serwera: $srv_upl kbit/s"
echo " Minimalny upload userów: $min kbit/s"
echo " Primary: $pri_min kbit/s    Secondary: $sec_min kbit/s"
echo "%===================================================================%"

if [[ u_r2q=="" ]]; then
$TC qdisc add dev $out root handle 2:0 htb
else
$TC qdisc add dev $out root handle 2:0 htb r2q $u_r2q
fi

$TC class add dev $out parent 2:0 classid 2:1 htb rate ${wan_upl}kbit ceil ${wan_upl}kbit

$TC class add dev $out parent 2:1 classid 2:2 htb rate ${srv_upl}kbit ceil ${max}kbit quantum $u_quantum
$TC qdisc add dev $out parent 2:2 sfq perturb 10
$IPTABLES -t mangle -A POSTROUTING -s $srv -j MARK --set-mark 1
$TC filter add dev $out protocol ip parent 2:0 handle 1 fw flowid 2:2

j=3
for usr in $lan
        do
        $TC class add dev $out parent 2:1 classid 2:$j htb rate ${min}kbit ceil ${max}kbit quantum $u_quantum
        $TC class add dev $out parent 2:$j classid 2:$(($j+1)) htb rate ${pri_min}kbit ceil ${max}kbit quantum $u_quantum
        $TC class add dev $out parent 2:$j classid 2:$(($j+2)) htb rate ${sec_min}kbit ceil ${max}kbit quantum $u_quantum
        $TC qdisc add dev $out parent 2:$(($j+1)) sfq perturb 10
        $TC qdisc add dev $out parent 2:$(($j+2)) sfq perturb 10
        $IPTABLES -t mangle -A POSTROUTING -s $usr -j MARK --set-mark $j
        $TC filter add dev $out protocol ip parent 2:0 pref 2 handle $j fw flowid 2:$j
	for prt in $porty_tcp
                 do
                 $TC filter add dev $out 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 $out 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 $out protocol ip parent 2:$j pref 3 u32 match ip protocol 1 0xff flowid 2:$(($j+1))
                 fi
        $TC filter add dev $out protocol ip parent 2:$j pref 4 handle $j fw flowid 2:$(($j+2))
        let "j=j+3"
        done

i=0
for uvs in $srv_l
        do
        $TC class add dev $out parent 2:0 classid 2:$j htb rate ${lan_upl[$i]}Mbit ceil ${lan_upl[$i]}Mbit quantum $u_quantum
        $TC qdisc add dev $out parent 2:$j sfq perturb 10
        $IPTABLES -t mangle -A POSTROUTING -s $uvs -j MARK --set-mark $j
        $TC filter add dev $out protocol ip parent 2:0 pref 1 handle $j fw flowid 2:$j
        let "j=j+1"
        let "i=i+1"
        done
}
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 imq!"
      echo "%====================================%"
      $TC class show dev imq | grep root
      $TC class show dev imq | grep -v root | sort | nl
      echo "Klasy na interfejsie ${out}!"
      echo "%====================================%"
      $TC class show dev $out | grep root
      $TC class show dev $out | 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 imq | grep -A 3 \"htb 1:2 \" && tc -s class show dev $out | grep -A 3 \"htb 2:2 \""
      elif [[ "$2" == "lan" ]]; then
      j=3
        for usr in $lan
                do
                let "j=j+3"
                done
      i=0;trs="echo \"Transfer: klient -> serwer -> klient \""
        for uvs in $srv_l
                do
                trs="$trs && echo \"Lan[$i]:\" && tc -s class show dev imq | grep -A 3 \"htb 1:$j \" && tc -s class show dev $out | grep -A 3 \"htb 2:$j \""
                let "j=j+1"
                let "i=i+1"
                done
        watch -d -n 1 "$trs"
      else
      j=3
        for usr in $lan
                do
                if [[ "$2" == "$usr" ]]; then
                        watch -d -n 1 "echo \"Download: \" && tc -s class show dev imq | grep -A 3 \"htb 1:$j \" && tc -s class show dev imq | grep -A 3 \"1:$(($j+1)) \" && tc -s class show dev imq | grep -A 3 \"1:$(($j+2)) \" && echo && echo \"Upload: \" && tc -s class show dev $out | grep -A 3 \"htb 2:$j \" && tc -s class show dev $out | grep -A 3 \"2:$(($j+1)) \" && tc -s class show dev $out | 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 <server|adress IP>"
      exit 1
      ;;
esac

#!/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
ext="`/etc/router/ext.cfg`" 		        #zewnêtrzne adresy IP

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]=2;  int_upl[0]=2
int_dwl[1]=2;  int_upl[1]=2
int_dwl[2]=80; int_upl[2]=80

TC=/sbin/tc                                        #¶cie¿ka do tc
MODPROBE=/sbin/modprobe                            #¶cie¿ka do modprobe
IP=/sbin/ip                                        #¶cie¿ka do ip
IPTABLES=/usr/local/sbin/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

#######################

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

#Sprawdza czy wszystkie srv_ext s± te¿ w ext, jesli nie dopisuje
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)

# 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 $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/$ntr/}
        do
               $TC filter add dev imq0 protocol ip parent 1:0 pref 1 u32 match ip dst $ntr match ip src $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 " 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 $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/$ntr/}
        do
                $TC filter add dev imq1 protocol ip parent 2:0 pref 1 u32 match ip src $ntr match ip dst $ipek flowid 2:$j
        done
        let "j=j+1"
        let "i=i+1"
        done

#for uvs in $srv_l
#        do
#        $TC class add dev imq1 parent 2:0 classid 2:$j htb rate ${lan_upl[$i]}Mbit ceil ${lan_upl[$i]}Mbit quantum $u_quantum
#        $TC qdisc add dev imq1 parent 2:$j sfq
#        $IPTABLES -t mangle -A POSTROUTING -s $uvs -j MARK --set-mark $j
#        $TC filter add dev imq1 protocol ip parent 2:0 pref 1 handle $j fw flowid 2:$j
#        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 ${out}!"
      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: klient -> serwer -> klient \""
#        for uvs in $srv_l
#                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

Reply to: