wl500g traffic shaping done
Hello everyone,
After some research, I've managed to create a script which actually works. Now enhanced-ctorrent client runs on wl500g without setting any upload limit, still, my pings are <100ms and my desktop has priority over bittorrent traffic (skype, ssh, etc... are fast).
I ended up modifying the wondershaper script heavily. It had a few bugs in it (did it ever work for anybody?).
So, here's how it's done.
First, I added 3 new lines to my /usr/local/sbin/post-firewall:
Code:
ip link set dev $1 qlen 30
iptables -A PREROUTING -t mangle -s 10.0.1.0/30 -j MARK --set-mark 6
/usr/local/sbin/wshaper start $1 3600 240
The first line sets the queue length to 30 - you can play around with this value, I found it to be good (though this is not a thorough experimentation).
The second line marks all packets coming from my desktops, so they can get a higher priority than the rest of the traffic (which is basically bittorrent running on the wl500g itself). Don't forget to adjust the netmask to match your desktops you want to prioritize.
The third line starts the modified wondershaper script, which I've put into /usr/local/sbin. The '3600' is the allowed download rate, and the '240' is the allowed upload rate. Set these values to roughly 5% less than your real network speed. There is _absolutely_ no need to go lower than 90% of your bandwidth (I'm saying this because I've found some sources on the net which say you should set it to 50% of your total bandwidth, but that's nonsense, most probably caused by not disabling bursting/throttling).
Now, here's the /usr/local/sbin/wshaper script:
Code:
#!/bin/sh
DOWNLINK=$3
UPLINK=$4
DEV=$2
if [ "$1" = "status" ]
then
tc -s qdisc ls dev $DEV
tc -s class ls dev $DEV
exit
fi
# clean existing down- and uplink qdiscs, hide errors
tc qdisc del dev $DEV root 2> /dev/null > /dev/null
tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null
if [ "$1" = "stop" ]
then
exit
fi
###### uplink
# install root HTB, point default traffic to 1:30:
tc qdisc add dev $DEV root handle 1: htb default 30 r2q 1
# shape everything at $UPLINK speed - this prevents huge queues in your
# DSL modem which destroy latency:
tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 1 cburst 1
# high prio class 1:10:
tc class add dev $DEV parent 1:1 classid 1:10 htb rate $((6*$UPLINK/10))kbit ceil ${UPLINK}kbit burst 1 cburst 1 prio 0
# desktop class 1:20
tc class add dev $DEV parent 1:1 classid 1:20 htb rate $((3*$UPLINK/10))kbit ceil $((9*$UPLINK/10))kbit burst 1 cburst 1 prio 1
# bulk data/bittorrent class 1:30
tc class add dev $DEV parent 1:1 classid 1:30 htb rate $((1*$UPLINK/10))kbit ceil $((8*$UPLINK/10))kbit burst 1 cburst 1 prio 2
# all get Stochastic Fairness:
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10
# TOS Minimum Delay (ssh, NOT scp) in 1:10:
tc filter add dev $DEV parent 1:0 protocol ip prio 1 u32 \
match ip tos 0x10 0x10 flowid 1:10
# ICMP (ip protocol 1) in the interactive class 1:10 so we
# can do measurements & impress our friends:
tc filter add dev $DEV parent 1:0 protocol ip prio 1 u32 \
match ip protocol 1 0xff flowid 1:10
# To speed up downloads while an upload is going on, put ACK packets in
# the interactive class:
tc filter add dev $DEV parent 1: protocol ip prio 1 u32 \
match ip protocol 6 0xff \
match u8 0x05 0x0f at 0 \
match u16 0x0000 0xffc0 at 2 \
match u8 0x10 0xff at 33 \
flowid 1:10
# prioritize small packets (<64 bytes)
tc filter add dev $DEV parent 1: protocol ip prio 1 u32 \
match ip protocol 6 0xff \
match u8 0x05 0x0f at 0 \
match u16 0x0000 0xffc0 at 2 \
flowid 1:10
# from desktops - mark 6
tc filter add dev $DEV parent 1: protocol ip prio 20 handle 6 fw flowid 1:20
########## downlink #############
# slow downloads down to somewhat less than the real speed to prevent
# queuing at our ISP. Tune to see how high you can set it.
# ISPs tend to have *huge* queues to make sure big downloads are fast
#
# attach ingress policer:
tc qdisc add dev $DEV handle ffff: ingress
# filter *everything* to it (0.0.0.0/0), drop everything that's
# coming in too fast:
tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
It pretty much works.
A thing which has caused me quite a bit of trouble. By default, wondershaper does allow throttling (aka bursting), which is basically allows any queue (including the bittorrent one) to pass all the shaping and go directly to the network interface, until it's tokens are used up (read some docs about htb if you want to know more). This clogs the upload link, killing off any interactive traffic every 10-30 seconds (this is how much time the buckets need to refill). That's why I needed to add the cburst and burst options to the class definitions.
This shaper also honors the TOS minimize delay bit, and puts every packet which matches that to the highest priority queue. You can set the minimize delay bit in the prerouting chain, mangle table on your wl500g, or directly on your desktop.
Limit 1 internal IP but keep internal speed?
What would be the best way to limit 1 internal IP but keep the speed for the internal net?
# 192.168.0.9 should get an up/down like 10k/50k to the external net
# internal net - 192.168.0.x transfers (also to 192.168.0.9) have to run on 100MBit
# all other hosts will still run on defaults
edit the /sbin/wshaper or in the post-firewall?
running on WL500g default config
network changed to 192.168.0.x
Thanks in advance!
Mike