Contributed by deanna on from the straw-or-pipe dept.
It's been a good week for my home net - finally got around to dropping a gig card into my workstation and replacing my central switch with something gigabit-capable. Unfortunately that means I can now oversaturate my cable modem faster than ever before. Pf and altq to the rescue. I found I had two main requirements - traffic prioritization, and rate limiting. Or to put it another way: how do I make my bittorrent go fast, get my share ratio up, keep the finalgear.com forums responsive, and prevent the di.fm streams from losing bits?First up is the workstation which generates most of the outbound traffic. This configuration doesn't do any filtering - it only assigns traffic to queues. I trust myself to keep my openbsd workstation from beating up on my openbsd laptop and vice versa. Note that I am using "flags any" - this allows pf to pick up a state in the middle of a connection. I do that so I can flush states and force all connections to be requeued.
Be careful when using "flags any" - I can get away with doing that here because I'm passing everything anyway, I'm using pass rules to assign flows to queues, and I have a front end box doing full scrubbing and filtering with "flags S/SA".
INT="re0"
#SLOW hosts will be throttled.
# 300Kb is probably good if you have 500Kb up
# re0 is a gigabit adapter, so even 1% blows the chips off the cable modem
# inbound connections (and their replies) will default to the slow queue
# on-net traffic is uncapped.
# Useful protocols go first. SSH, mail, dns, time and web
# This rule will tag everything as fast, with TCP ACKs and IPTOS_LOWDELAY
# And if $INT's ip is in SLOW, then all traffic will be throttled. |
Now it becomes an easy thing to control the network speed just by dropping a ip address of this machine into the SLOW table. Or removing it from the table. These can be done easily by a cron job, which is what I do; during times when I'd want the net to be responsive to interactive traffic, I have my server throttle itself, and during times when I'm unlikely to want to use the net, I let it uncap itself. I'm sure the simple rate limiting could be rolled into my main firewall's altq configuration, but I wanted a machine that I could use to experiment with various control strategies without having to munge my main ruleset, which we shall now examine.
INT="sis2" EXT="sis0" # 600Kb is probably a good rate if you have 640Kb up UP="600Kb" DN="5Mb"
# set up priority queuing. The two lowest classes are using the Random Early
# There is much wailing and gnashing of teeth if ssh, dns or ntp are laggy.
# Block everything unless otherwise allowed, and queue any state that
#allow in some basic services
pass in on $EXT proto {tcp udp} to port $INBOUND queue slow
# queue packets so they go faster
# Each of the other queues is allowed to knock it up a notch if it's |
Antispoofing and NAT are not discussed here. I've deleted a bunch of other stuff, such as anchors for ftp-proxy, authpf and spamd; they are not relevant to this discussion.
In this ruleset I am allowing in two ports at elevated priority, two ports at an intermediate priority, and a few others at reduced priority. You may need to experiment to determine your optimal upload bandwidth.
Thanks to everyone who contributed to the pf.conf(5) manpage and the examples in /usr/share/pf. While I did snoop at a few other people's pf configurations, everything I needed was in the pf.conf manpage.
(Comments are closed)
By Jason L. Wright (65.101.74.153) jason@openbsd.org on http://www.thought.net/jason
By Anonymous Coward (69.70.207.240) on
What I'm curious though is how a Gb NIC would affect cable modem speed; in other words, a 10/100/1000 NIC vs a 10/100 NIC - how would this make a difference? And over-saturating the link? Is this the same as prioritizing ACK's such as: http://www.benzedrine.cx/ackpri.html ?
Thanks in advance!
Comments
By Joachim Schipper (82.134.241.64) on
> school studies...
>
> What I'm curious though is how a Gb NIC would affect cable modem speed; in
> other words, a 10/100/1000 NIC vs a 10/100 NIC - how would this make a
> difference? And over-saturating the link? Is this the same as prioritizing
> ACK's such as: http://www.benzedrine.cx/ackpri.html ?
I'm no expert, but I don't think a gigabit NIC is going to help much with usual
cable speeds (as in, a couple of Mbps). It would be quite useful for inter-host
communication, though.
Prioritizing ACKs is a different matter altogether, although it's also a
typical application of altq.
Joachim
By Chris Kuethe (68.148.116.122) ckuethe@ on
Of course that just means it takes even less time to shove more traffic than my cable modem can handle. "Oversaturating" was a bit of hyperbole. Like Jason running FDDI behind a 28k8 modem, upgrading from fast ethernet to gigabit behind a 512k cable modem doesn't make the interspam flow any faster...
The prioritized ACKs are handled by the second ruleset. Two queues are sufficient to accomplish that. I used more queues so that some types of traffic (as differentiated by port) are prioritized over others, but each class gets the benefits of the prioritized ACKs.
By Anonymous Coward (60.51.114.69) on
-anonymous coward-