Skip to contentSkip to conversation

Need help with rate-limiting NTTP traffic

DISCUSSION Shane Hickey 2 participants 5 messages Mar 31, 2004 – Apr 2, 2004

lore
Share & tools
lore
#0 lore raw

Howdy all,
Recently, with the help of this list, I migrated my firewall from a
FreeBSD box running ipfilter, ipnat and dummynet to a Gentoo Linux box running netfilter and tc. I have to admit that I'm having problems visualizing tc in my head. So, I was wondering if I could get an assist.
Basically, I have a fat upstream pipe and I can use it basically
all I want, except that my NNTP traffic seems to really clobber everything else. Also, since my NNTP traffic is pretty much constantly ongoing, I'd like to limit it to 800kbit. This was a breeze with dummynet, but I'm not getting how to do it correctly with netfilter.

Here's what I tried:

$IPT -t mangle -N SHAPE-NNTP
$IPT -t mangle -I PREROUTING -i $WANIFACE -j SHAPE-NNTP $IPT -t mangle -A SHAPE-NNTP -p tcp --sport 119 -j MARK --set-mark 119

My thoughts on placing it in PREROUTING is that I'd like to shape the traffic as soon as possible so that my firewall gets the benefit of dealing with the reduced load as soon as possible. But, maybe that's just foolishness?

Here's the tc rules I tried.

tc qdisc add dev $WANIFACE root handle 1: htb default 60
tc class add dev $WANIFACE parent 1: classid 1:1 htb rate 10Mbit tc class add dev $WANIFACE parent 1:1 classid 1:119 htb rate 800kbit tc filter add dev $WANIFACE parent 1:1 protocol ip handle 119 fw flowid 1:119

The one weird thing is that when I do a 'tc filter show dev $WANIFACE' nothing comes back. But 'tc class show dev $WANIFACE' and 'tc qdisc show dev $WANIFACE" return useful information.

Thanks,

Shane

Signature · 4 lines
Shane Hickey <[email protected]>: Network/System Consultant
GPG KeyID: 777CBF3F
Key fingerprint: 254F B2AC 9939 C715 278C  DA95 4109 9F69 777C BF3F
Listening to: american analog set - you own me
#1 lore raw
Quoted 4 lines · Shane Hickey

Basically, I have a fat upstream pipe and I can use it basically
all I want, except that my NNTP traffic seems to really clobber everything else. Also, since my NNTP traffic is pretty much constantly ongoing, I'd like to limit it to 800kbit.

What are you using as your NNTP server? If it's INN, I'm pretty sure that
has its own rate-limiting mechanism as a configuration parameter, and you'd be better off doing rate limiting in the application itself if it's at all possible.

Even if you're using something other than INN, have a look at the configuration options for the server and see if you can solve this problem there before resorting to netfilter and tc.

Regards,

Antony.

Signature · 4 lines
This email was created using 100% recycled electrons.

                                                     Please reply to the list;
                                                           please don't CC me.
#2 lore raw

Antony Stone <[email protected]> [2004-04-01 09:16]:

Quoted 4 lines

What are you using as your NNTP server? If it's INN, I'm pretty sure
that has its own rate-limiting mechanism as a configuration parameter, and you'd be better off doing rate limiting in the application itself if it's at all possible.

I'm not serving NNTP, I'm just constantly connected to an NNTP server
using Pan. I should have made that more clear in my e-mail. There aren't any bandwidth controls in Pan, that I could see, and it will happily stomp over all my other traffic. It was extremely easy to limit only my nntp traffic (that is, traffic coming into my network with a source port of 119) in Dummynet. Can anyone offer ideas with tc and netfilter?

Shane

Signature · 4 lines
Shane Hickey <[email protected]>: Network/System Consultant
GPG KeyID: 777CBF3F
Key fingerprint: 254F B2AC 9939 C715 278C  DA95 4109 9F69 777C BF3F
Listening to: Cypress Hill - Hole In The Head
#3 lore raw
Quoted 9 lines · Shane Hickey

Antony Stone said:
:

Quoted 4 lines

What are you using as your NNTP server? If it's INN, I'm pretty sure
that has its own rate-limiting mechanism as a configuration parameter, and you'd be better off doing rate limiting in the application itself if it's at all possible.

I'm not serving NNTP, I'm just constantly connected to an NNTP server
using Pan.

Ah, okay, yes - I had assumed you meant you were running a server, not a client.

Quoted 1 line

There aren't any bandwidth controls in Pan, that I could see

Doesn't surprise me - I wouldn't necessarily expect that in a client.

Quoted 4 lines

and it will happily stomp over all my other traffic. It was extremely easy to limit only my nntp traffic (that is, traffic coming into my network with a source port of 119) in Dummynet. Can anyone offer ideas with tc and netfilter?

Maybe someone else here can tell you how to do it (I'm not sufficiently familiar with tc to tell you, although I expect it's possible), however one thing puzzles me about your requirement:

If you're using a client, and it's generating enough traffic to swamp your ("fat") upstream connection, then surely that's because there's a lot of
traffic in the newsgroups which you've subscribed to? If you use a traffic
control mechanism to throttle the available bandwidth, you will surely end up losing postings because you can't suck them down fast enough before they expire (if you could, then your current usage would not be consuming so much bandwidth)?

Therefore I don't see how you can maintain access to the newsgroups which are creating all this traffic, at the same time as throttling down your connection to consume less bandwidth....

Just my 2 units of currency....

Regards,

Antony.

Signature · 6 lines
The truth is rarely pure, and never simple.

 - Oscar Wilde

                                                     Please reply to the list;
                                                           please don't CC me.
#4 lore raw
In reply to Shane Hickey

I found the solution to my exact problem (right down the NNTP client) at
http://mail.gnu.org/archive/html/pan-users/2003-11/msg00009.html

For those who want the answer now with now clicking, you can do it all with this:

tc qdisc add dev $WANIFACE handle ffff: ingress
tc filter add dev $WANIFACE parent ffff: protocol ip prio 50 u32 match ip sport 119 0xffff police rate 800kbit burst 15k drop flowid :1

Thanks.

Signature · 4 lines
Shane Hickey <[email protected]>: Network/System Consultant
GPG KeyID: 777CBF3F
Key fingerprint: 254F B2AC 9939 C715 278C  DA95 4109 9F69 777C BF3F
Listening to: Bill Frisell  - Vernon Reid - Small Hands