Tc

From SOWNWiki
Jump to: navigation, search

About tc

tc is a program which can set a maximum speed to any connection or multiple connections matched by an iptable rule.

A good tutorial on tc is available [here].

How SOWN uses tc

All traffic that is to be limited will be limited by the same tc rule. The packets will be tagged to have this rule applied to it if it is bound for the users internet connection, and is not heading for the University.

First load the 'htb' ip scheduler:

/sbin/insmod sch_htb

Now we need to create a queue:

/usr/sbin/tc qdisc add dev eth0 root handle 1:0 htb default 12

The queue is attached to an interface, and uses a specific ip-scheduler (htb).

Now add a rule to describe all the traffic. We assume you have a 128kbit upload internet connection.

/usr/sbin/tc class add dev eth0 parent 1:0 classid 1:1 htb rate 128kbit

Now we set the limit we wish to apply The line below will limit the maximum speed of all SOWN users connected to this node, to 32kbit per second. Note this is only limiting the upload speed of the connection. As a consequence this is probably to little for most home users who will only have 400kbit/s upload speed with BT 8mbit/s Home ADSL. A 64kbit limit may be more appropriate. It should be noted that effective traffic control can only really be done by the router which can see all the traffic traversing the home users link.

 /usr/sbin/tc class add dev eth0 parent 1:1 classid 1:11 htb rate 32kbit ceil 32kbit

Finally the firewall must be told to mark packets for shaping. This rule marks all traffic which is bound for the ethernet connection, and is not bound for the University to be restricted.

 /usr/sbin/iptables -t mangle -A POSTROUTING -o eth0 -d ! 152.78.0.0/16 -j CLASSIFY --set-class 1:11