Traffic Shaping
A while back i had a requirement for shaping traffic down to about 56kbit traveling through a Linux router. After much research i came up with this working configuration. Between eth1 and eth0 it shapes traffic down to 56kbit downstream and 50kbit upstream.
# Setup the 2 eth interfaces
tc qdisc add dev eth0 root handle 1:0 cbq bandwidth
100Mbit avpkt 1000 mpu 64
tc qdisc add dev eth1 root handle 1:0 cbq bandwidth
100Mbit avpkt 1000 mpu 64
# set the download speed
tc class add dev eth0 parent 1:0 classid 1:1 cbq rate
56KBit allot
1514 prio 1 avpkt 1000 bounded
tc filter add dev eth0 parent 1:0 protocol ip handle 1
fw flowid 1:1
# set the upload speed
tc class add dev eth1 parent 1:0 classid 1:1 cbq rate
50KBit allot
1514 prio 1 avpkt 1000 bounded
tc filter add dev eth1 parent 1:0 protocol ip handle 1 fw
flowid 1:1
# Mark the packets with iptables mangle
iptables -t mangle -A PREROUTING -j MARK --set-mark 1