From: "Nataniel Klug" Date: Wed, 11 Jan 2006 01:20:27 +0000 Subject: Re: [LARTC] control p2p upload bandwidth rate Message-Id: <002401c6164d$34bde1b0$9a0023ac@NATANIEL> MIME-Version: 1 Content-Type: multipart/mixed; boundary="===============0785425778==" List-Id: References: <43AAE878.10404@phreaker.net> In-Reply-To: <43AAE878.10404@phreaker.net> To: lartc@vger.kernel.org This is a multi-part message in MIME format. --===============0785425778== Content-Type: multipart/alternative; boundary="----=_NextPart_000_0021_01C6163C.70DC6A60" This is a multi-part message in MIME format. ------=_NextPart_000_0021_01C6163C.70DC6A60 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Jody, I have a script that makes connections for every user with his auth. So, = in this script, I have two mark tags. Can I use this tip you give to = ro0ot? My doubt is if I use this every time some user log it will be all = executed again, it will not make me trouble? Now I mark all packts from a client and forward this to some cbq/htb = band control rules. It is working fine, but I have never made a test for = longer time... Thanks for your cooperation. Att, Nataniel Klug ----- Original Message -----=20 From: Jody Shumaker=20 To: lartc@mailman.ds9a.nl=20 Sent: Thursday, December 22, 2005 5:48 PM Subject: Re: [LARTC] control p2p upload bandwidth rate Seems like eth0 is your IF connected to the itnernet, you need to do = shaping on that for the upload. Modifying the rates and using the same = tc comands but on eth0 would likely do it. Also your script is flawed, the layer7 matching for most if not all of = those protocols will only match on the first packet or two. After that = the data for those connections won't match. I suggest you look into = using CONNMARK target/matching so you can match all of the data, not = just the first few packets.=20 With your setup it'd be used something along these lines: #before setting mark: #restores any saved mark iptables -t mangle -A PREROUTING -p tcp -j CONNMARK --restore-mark #accepts the packet if it has a mark besides the default 0 and = prevents the saved mark from being changed=20 iptables -t mangle -A PREROUTING -p tcp -m mark ! --mark 0 -j ACCEPT #use "-j MARK --set-mark #" here #after all the --set-mark's iptables -t mangle -A PREROUTING -p tcp -m mark ! --mark 0 -j CONNMARK = --save-mark=20 iptables -t mangle -A PREROUTING -p tcp -m mark ! --mark 0 -j ACCEPT Without this, I'm not really sure how you were matching all packets = for your download shaping. Normally, only the first packet or two will = have matching data in the TCP connection, and if you don't somehow mark = the whole connection using the above, the majority of the bandwidth = won't be shaped correctly.=20 - Jody On 12/22/05, ro0ot wrote: Hi all, I am running Slackware 10.1 with Kernel 2.6.14.3 includes iptables = 1.3.4 with layer 7 My network diagram below: - INTERNET --- LINUX_ROUTER_FW --- PCs Below is my simple iptables script: -=20 echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -t mangle -A POSTROUTING -m layer7 --l7proto applejuice -j = MARK --set-mark 1 iptables -t mangle -A POSTROUTING -m layer7 --l7proto ares -j MARK=20 --set-mark 1 iptables -t mangle -A POSTROUTING -m layer7 --l7proto bittorrent -j = MARK --set-mark 1 iptables -t mangle -A POSTROUTING -m layer7 --l7proto directconnect = -j MARK --set-mark 1 iptables -t mangle -A POSTROUTING -m layer7 --l7proto edonkey -j = MARK=20 --set-mark 1 iptables -t mangle -A POSTROUTING -m layer7 --l7proto fasttrack -j = MARK --set-mark 1 iptables -t mangle -A POSTROUTING -m layer7 --l7proto gnucleuslan -j MARK --set-mark 1 iptables -t mangle -A POSTROUTING -m layer7 --l7proto gnutella -j = MARK=20 --set-mark 1 iptables -t mangle -A POSTROUTING -m layer7 --l7proto napster -j = MARK --set-mark 1 iptables -t mangle -A POSTROUTING -m layer7 --l7proto openft -j MARK --set-mark 1 Below is my simple tc script: -=20 tc qdisc del dev eth1 root tc qdisc add dev eth1 root handle 1: htb default 20 tc class add dev eth1 parent 1: classid 1:1 htb rate 10240kbit ceil 10240kbit tc class add dev eth1 parent 1:1 classid 1:11 htb rate 32kbit ceil = 512kbit=20 tc filter add dev eth1 protocol ip parent 1:0 prio 1 handle 1 fw classid 1:11 tc qdisc add dev eth1 parent 1:11 sfq perturb 10 I have no problem shaping the "PCs" p2p download bandwidth rate. = How=20 can I control the "PCs" p2p upload bandwidth rate? Please = help...thanks, :) Regards, ro0ot _______________________________________________ LARTC mailing list LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc -------------------------------------------------------------------------= ----- _______________________________________________ LARTC mailing list LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc ------=_NextPart_000_0021_01C6163C.70DC6A60 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Jody,
 
I have a script that makes connections = for every=20 user with his auth. So, in this script, I have two mark tags. Can I use = this tip=20 you give to ro0ot? My doubt is if I use this every time some user log it = will be=20 all executed again, it will not make me trouble?
 
Now I mark all packts from a client and = forward=20 this to some cbq/htb band control rules. It is working fine, but I have = never=20 made a test for longer time...
 
Thanks for your = cooperation.
 
Att,
 
Nataniel Klug
----- Original Message -----
From:=20 Jody=20 Shumaker
Sent: Thursday, December 22, = 2005 5:48=20 PM
Subject: Re: [LARTC] control = p2p upload=20 bandwidth rate

Seems like eth0 is your IF connected to the itnernet, = you need=20 to do shaping on that for the upload.  Modifying the rates and = using the=20 same tc comands but on eth0 would likely do it.

Also your = script is=20 flawed, the layer7 matching for most if not all of those protocols = will only=20 match on the first packet or two. After that the data for those = connections=20 won't match. I suggest you look into using CONNMARK target/matching so = you can=20 match all of the data, not just the first few packets.

With = your setup=20 it'd be used something along these lines:
#before setting=20 mark:
#restores any saved mark
iptables -t mangle -A PREROUTING = -p tcp=20 -j CONNMARK --restore-mark
#accepts the packet if it has a mark = besides the=20 default 0 and prevents the saved mark from being changed
iptables = -t=20 mangle -A PREROUTING -p tcp -m mark ! --mark 0 -j ACCEPT

#use = "-j MARK=20 --set-mark #" here

#after all the --set-mark's
iptables -t = mangle -A=20 PREROUTING -p tcp -m mark ! --mark 0 -j CONNMARK --save-mark =
iptables -t=20 mangle -A PREROUTING -p tcp -m mark ! --mark 0 -j = ACCEPT

Without this,=20 I'm not really sure how you were matching all packets for your = download=20 shaping.  Normally, only the first packet or two will have = matching data=20 in the TCP connection, and if you don't somehow mark the whole = connection=20 using the above, the majority of the bandwidth won't be shaped = correctly.=20

- Jody


On 12/22/05, ro0ot=20 <ro0ot@phreaker.net>=20 wrote:
Hi=20 all,

I am running Slackware 10.1 with Kernel 2.6.14.3 includes iptables = 1.3.4
with layer=20 7

My network diagram below: -
INTERNET --- LINUX_ROUTER_FW = ---=20 PCs

Below is my simple iptables script: -

echo 1 > = /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o = eth0 -j=20 MASQUERADE
iptables -t mangle -A POSTROUTING -m layer7 --l7proto=20 applejuice -j MARK
--set-mark 1
iptables -t mangle -A = POSTROUTING -m=20 layer7 --l7proto ares -j MARK
--set-mark 1
iptables -t mangle = -A=20 POSTROUTING -m layer7 --l7proto bittorrent -j MARK
--set-mark=20 1
iptables -t mangle -A POSTROUTING -m layer7 --l7proto = directconnect=20 -j
MARK --set-mark 1
iptables -t mangle -A POSTROUTING -m = layer7=20 --l7proto edonkey -j MARK
--set-mark 1
iptables -t mangle -A=20 POSTROUTING -m layer7 --l7proto fasttrack -j MARK
--set-mark=20 1
iptables -t mangle -A POSTROUTING -m layer7 --l7proto = gnucleuslan=20 -j
MARK --set-mark 1
iptables -t mangle -A POSTROUTING -m = layer7=20 --l7proto gnutella -j MARK
--set-mark 1
iptables -t mangle -A = POSTROUTING -m layer7 --l7proto napster -j MARK
--set-mark = 1
iptables=20 -t mangle -A POSTROUTING -m layer7 --l7proto openft -j = MARK
--set-mark=20 1

Below is my simple tc script: -

tc qdisc del dev = eth1=20 root
tc qdisc add dev eth1 root handle 1: htb default 20
tc = class add=20 dev eth1 parent 1: classid 1:1 htb rate 10240kbit = ceil
10240kbit
tc=20 class add dev eth1 parent 1:1 classid 1:11 htb rate 32kbit ceil = 512kbit=20
tc filter add dev eth1 protocol ip parent 1:0 prio 1 = handle  1=20 fw
classid 1:11
tc qdisc add dev eth1 parent 1:11 sfq perturb=20 10

I have no problem shaping the "PCs" p2p download bandwidth = rate.  How
can I control the "PCs" p2p upload = bandwidth=20 rate?  Please help...thanks,=20 = :)

Regards,
ro0ot





______________________= _________________________
LARTC=20 mailing list
LARTC@mailman.ds9a.nl
http://mai= lman.ds9a.nl/cgi-bin/mailman/listinfo/lartc


_______________________________________________
LARTC = mailing=20 = list
LARTC@mailman.ds9a.nl
http://mailman.ds9a.nl/cgi-bin/mailman/l= istinfo/lartc
------=_NextPart_000_0021_01C6163C.70DC6A60-- --===============0785425778== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ LARTC mailing list LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/cgi-bin/mailman/listinfo/lartc --===============0785425778==--