Trafficshaping

Backup, Restore und Transfer von Daten
Post Reply
dopefish
Posts: 142
Joined: 2003-02-06 12:57
Location: Karlsruhe
Contact:
 

Trafficshaping

Post by dopefish »

vielleicht für euch auch interessant, ich habe ein kleines script zusammengeschnipselt der trafficshaping lokal auf kiste macht um dafür zu sorgen dass pakete nicht nach FIFO abgearbeitet werden sondern dass gewisse priotirisierung stattfindet. das script ist zusammengeschnipselt aus diverse dokus und relativ schlicht, fall einer bessere ideen hat kann er es gerne modifizieren und hier wieder posten damit alle was davon haben.

ich freue mich natürlich auch wenn ihr einen fehler entdeckt und mir sagt. beim neuen hlds server ist die zeile für counterstrike überflüssig da man hlds sinnigerweise mit -tos aufrufen kann.

DEV ist das interface, STREAM eure lokale Anbindung, sollten beides so korrekt sein.

Code: Select all

#!/bin/bash

DEV=eth0
STREAM=100mbit

if [ "$1" = "status" ]
then
        tc -s qdisc ls dev $DEV
        tc -s class ls dev $DEV
        exit
fi
tc qdisc del dev $DEV root >/dev/null 2>&1
if [ "$1" = "stop" ]
then
        exit
fi

#tc qdisc add dev $DEV root handle 1: prio

# ok, lets start this thing off by instaling the root
tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth $STREAM

# goofing around with our upstream got to set some main things straight
tc class add dev $DEV parent 1: classid 1:1 cbq rate $STREAM allot 1500 prio 5 bounded isolated

# okidookie let's whack some priority into these two queues
# high priority queue
tc class add dev $DEV parent 1:1 classid 1:10 cbq rate $STREAM allot 1600 prio 1 avpkt 1000
# low priority queue
tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $STREAM allot 1600 prio 2 avpkt 1000

# now lets give 'm a little Stochastic Fairness
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10

# what would traffisshaping be without respect for the tos flag ;)
tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 match ip tos 0x10 0xff  flowid 1:10

# this one here is for counterstrike, the main reason i whipped this together
tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 match ip sport 27015 0xffff flowid 1:10

# ACK Packets also get a nice priority, no need to slow them down.
tc filter add dev $DEV parent 1: protocol ip prio 13 u32 
   match ip protocol 6 0xff 
   match u8 0x05 0x0f at 0 
   match u16 0x0000 0xffc0 at 2 
   match u8 0x10 0xff at 33 
   flowid 1:10

# put the rest in the 2.d queue
tc filter add dev $DEV parent 1: protocol ip prio 14 u32 match ip dst 0.0.0.0/0 flowid 1:20
captaincrunch
Userprojekt
Userprojekt
Posts: 7066
Joined: 2002-10-09 14:30
Location: Dorsten
Contact:
 

Re: Trafficshaping

Post by captaincrunch »

Ein Fall für's Datentransfer und Backup
DebianHowTo
echo "[q]sa[ln0=aln256%Pln256/snlbx]sb729901041524823122snlbxq"|dc
bmp
Posts: 116
Joined: 2003-03-13 16:30
 

Re: Trafficshaping

Post by bmp »

DopeFish wrote:

Code: Select all

# this one here is for counterstrike, the main reason i whipped this together
tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 match ip sport 27015 0xffff flowid 1:10
Sehe ich das richtig, das hier alle Pakete mit Port 27015 bevorzugt werden ?
Kann man (du;-) das umschreiben das die Ports 80 und 21 benachteiligt werden ?

mfg

Marcus
dopefish
Posts: 142
Joined: 2003-02-06 12:57
Location: Karlsruhe
Contact:
 

Re: Trafficshaping

Post by dopefish »

geht relativ einfach, setz einfach ein filter für die ports in die 2. queue und alles andere in die erste queue
bmp
Posts: 116
Joined: 2003-03-13 16:30
 

Re: Trafficshaping

Post by bmp »

DopeFish wrote:geht relativ einfach, setz einfach ein filter für die ports in die 2. queue und alles andere in die erste queue
Ã?hhmmm Ja :oops: wenn du das so sagt :roll: .....

Du hast nicht zufällig ein Beispiel parat bei dem Port 21 und 80 als unterstes behandelt werden :D
dopefish
Posts: 142
Joined: 2003-02-06 12:57
Location: Karlsruhe
Contact:
 

Re: Trafficshaping

Post by dopefish »

versuchs mal mit folgenden, habs aber net getestet:

Code: Select all

#!/bin/bash

DEV=eth0
STREAM=100mbit

if [ "$1" = "status" ]
then
        tc -s qdisc ls dev $DEV
        tc -s class ls dev $DEV
        exit
fi
tc qdisc del dev $DEV root >/dev/null 2>&1
if [ "$1" = "stop" ]
then
        exit
fi

#tc qdisc add dev $DEV root handle 1: prio

# ok, lets start this thing off by instaling the root
tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth $STREAM

# goofing around with our upstream got to set some main things straight
tc class add dev $DEV parent 1: classid 1:1 cbq rate $STREAM allot 1500 prio 5 bounded isolated

# okidookie let's whack some priority into these two queues
# high priority queue
tc class add dev $DEV parent 1:1 classid 1:10 cbq rate $STREAM allot 1600 prio 1 avpkt 1000
# low priority queue
tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $STREAM allot 1600 prio 2 avpkt 1000

# now lets give 'm a little Stochastic Fairness
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10

# this one here is for http
tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 match ip sport 80 0xffff flowid 1:20

# this one here is for ftp data channel
tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 match ip sport 20 0xffff flowid 1:20

# this one here is for ftp command channel
tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 match ip sport 21 0xffff flowid 1:20

# put the rest in the 1st queue
tc filter add dev $DEV parent 1: protocol ip prio 14 u32 match ip dst 0.0.0.0/0 flowid 1:10
ich glaube aber kaum dass du damit glücklich werden willst weil FTP ein bescheuertes protokoll ist (firewalltechnisch, besonders PASSIVE mode), da bist du wahrscheins besser dran die pakete von ftp mittels iptables zu markieren und die TOS zu setzen und anhand dessen das trafficshaping zu machen weil iptables connection tracking für ftp sessions (mehr oder minder je nach modus) beherrscht. siehe http://www.sns.ias.edu/~jns/security/ip ... k.html#FTP
bmp
Posts: 116
Joined: 2003-03-13 16:30
 

Re: Trafficshaping

Post by bmp »

DopeFish wrote:versuchs mal mit folgenden, habs aber net getestet:

ich glaube aber kaum dass du damit glücklich werden willst weil FTP ein bescheuertes protokoll ist (firewalltechnisch, besonders PASSIVE mode), da bist du wahrscheins besser dran die pakete von ftp mittels iptables zu markieren und die TOS zu setzen und anhand dessen das trafficshaping zu machen weil iptables connection tracking für ftp sessions (mehr oder minder je nach modus) beherrscht. siehe http://www.sns.ias.edu/~jns/security/ip ... k.html#FTP
Ich Danke dir. :P
Werde es gleich mal testen.
FTP ist eigendlich nebensächlich. Hauptsache ist, das die Downloads per HTTP ein wenig gebremst werden.

Also nochmals vielen Dank...

mfg

Marcus
bmp
Posts: 116
Joined: 2003-03-13 16:30
 

Re: Trafficshaping

Post by bmp »

BMP wrote:Werde es gleich mal testen.
So gerade versucht zu testen.

Code: Select all

SHELL:~ # /etc/init.d/HTTP-FTP-Begrenzung start
/etc/init.d/HTTP-FTP-Begrenzung: Dadurch: command not found
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
RTNETLINK answers: Invalid argument
Weiß da einer rat ??
dopefish
Posts: 142
Joined: 2003-02-06 12:57
Location: Karlsruhe
Contact:
 

Re: Trafficshaping

Post by dopefish »

ändere mal die erste zeile in #!/bin/bash -x damit man sieht was schiefläuft.
es sieht aber eher dannach aus als ob die module für traffic shaping fehlen, solltest du mal im kernel auswählen (networking options -> QOS ) und dananch ein make modules && make modules_install machen (oder fest einkompilieren und rebooten)
bmp
Posts: 116
Joined: 2003-03-13 16:30
 

Re: Trafficshaping

Post by bmp »

DopeFish wrote:ändere mal die erste zeile in #!/bin/bash -x damit man sieht was schiefläuft.
es sieht aber eher dannach aus als ob die module für traffic shaping fehlen, solltest du mal im kernel auswählen (networking options -> QOS ) und dananch ein make modules && make modules_install machen (oder fest einkompilieren und rebooten)
Hmmm,

Code: Select all

essen112:~ # /etc/init.d/HTTP-FTP-Begrenzung start
+ Dadurch werden alle Anfragen die auf anderen Ports laufen bevorzugt behandelt.
/etc/init.d/HTTP-FTP-Begrenzung: Dadurch: command not found
+ DEV=eth0
+ STREAM=100mbit
+ '[' start = status ']'
+ tc qdisc del dev eth0 root
+ '[' start = stop ']'
+ tc qdisc add dev eth0 root handle 1: cbq avpkt 1000 bandwidth 100mbit
RTNETLINK answers: Invalid argument
+ tc class add dev eth0 parent 1: classid 1:1 cbq rate 100mbit allot 1500 prio 5 bounded isolated
RTNETLINK answers: Invalid argument
+ tc class add dev eth0 parent 1:1 classid 1:10 cbq rate 100mbit allot 1600 prio 1 avpkt 1000
RTNETLINK answers: Invalid argument
+ tc class add dev eth0 parent 1:1 classid 1:20 cbq rate 100mbit allot 1600 prio 2 avpkt 1000
RTNETLINK answers: Invalid argument
+ tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
RTNETLINK answers: Invalid argument
+ tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10
RTNETLINK answers: Invalid argument
+ tc filter add dev eth0 parent 1:0 protocol ip prio 10 u32 match ip sport 80 0xffff flowid 1:20
RTNETLINK answers: Invalid argument
+ tc filter add dev eth0 parent 1:0 protocol ip prio 10 u32 match ip sport 20 0xffff flowid 1:20
RTNETLINK answers: Invalid argument
+ tc filter add dev eth0 parent 1:0 protocol ip prio 10 u32 match ip sport 21 0xffff flowid 1:20
RTNETLINK answers: Invalid argument
+ tc filter add dev eth0 parent 1: protocol ip prio 14 u32 match ip dst 0.0.0.0/0 flowid 1:10
RTNETLINK answers: Invalid argument
+ exit 0
Habe auch schon QOS eingebaut und dann make modules && make modules_install +Reeboot.
Kann man feststellen ob QOS Aktiv ist ?
captaincrunch
Userprojekt
Userprojekt
Posts: 7066
Joined: 2002-10-09 14:30
Location: Dorsten
Contact:
 

Re: Trafficshaping

Post by captaincrunch »

Habe auch schon QOS eingebaut und dann make modules && make modules_install +Reeboot.
Kann man feststellen ob QOS Aktiv ist ?
Wie wär's denn, wenn du die nötigen Module einfach mal händisch per modprobe lädst ? ;)
DebianHowTo
echo "[q]sa[ln0=aln256%Pln256/snlbx]sb729901041524823122snlbxq"|dc
bmp
Posts: 116
Joined: 2003-03-13 16:30
 

Re: Trafficshaping

Post by bmp »

CaptainCrunch wrote:Wie wär's denn, wenn du die nötigen Module einfach mal händisch per modprobe lädst ? ;)
Ich bin zu blöd dafür.

Ich habe folgendes gemacht :

1. cd /usr/src/linux
2. make menuconfig
3. QOS Ausgewählt und alle Module als M markiert.
4. make depend
5. make modules && make modules_install
6. modprobe sch_qdisc
aber bei kommt als Ausgabe = modprobe: Can't locate module sch_qdisc

:( :( :(
captaincrunch
Userprojekt
Userprojekt
Posts: 7066
Joined: 2002-10-09 14:30
Location: Dorsten
Contact:
 

Re: Trafficshaping

Post by captaincrunch »

Mach mal ein find /lib/modules/KERNELVERSION/ -name NAMEDERMODULE. Wahrscheinlich heißen die nur anders. Sorry, mit QOS habe ich mich noch nie befasst.
DebianHowTo
echo "[q]sa[ln0=aln256%Pln256/snlbx]sb729901041524823122snlbxq"|dc
moomurray
Posts: 8
Joined: 2002-12-04 15:46
 

Re: Trafficshaping

Post by moomurray »

Ich finde das echt lustig, denn was hier ganz schnell weiterhilft, ist das von mir mal in irgendeinem Beitrag angesprochene PHP-Script, welches einfach Dateien irgendwo auf dem Server liest und und zum Beispiel in 50kb-Blöcken pro Sekunde verfüttert an den Browser. Ich denke, genau diese Lösung wird hier gesucht.
Dennoch finde ich die ganze Diskussion recht interessant :)

Das Script hab ich auf php.net gefunden, aber frag nicht wo, habs jetzt auch gerade nicht zur Hand...
dopefish
Posts: 142
Joined: 2003-02-06 12:57
Location: Karlsruhe
Contact:
 

Re: Trafficshaping

Post by dopefish »

das nenn ich mal ne überflüssige belastung vom server das so zu lösen :p
Post Reply