added the wshaper script
[openwrt/svn-archive/archive.git] / net / wshaper / files / wshaper.htb
1 #!/bin/sh
2 # Wonder Shaper
3 # please read the README before filling out these values
4 #
5 # Set the following values to somewhat less than your actual download
6 # and uplink speed. In kilobits. Also set the device that is to be shaped.
7
8 DOWNLINK=2000
9 UPLINK=240
10 DEV=eth0
11
12 # low priority OUTGOING traffic - you can leave this blank if you want
13 # low priority source netmasks
14 NOPRIOHOSTSRC=
15
16 # low priority destination netmasks
17 NOPRIOHOSTDST=
18
19 # low priority source ports
20 NOPRIOPORTSRC=
21
22 # low priority destination ports
23 NOPRIOPORTDST="21"
24
25 if [ "$1" = "status" ]
26 then
27 tc -s qdisc ls dev $DEV
28 tc -s class ls dev $DEV
29 exit
30 fi
31
32 # clean existing down- and uplink qdiscs, hide errors
33 tc qdisc del dev $DEV root 2> /dev/null > /dev/null
34 tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null
35
36 ###### uplink
37
38 # install root HTB, point default traffic to 1:20:
39
40 tc qdisc add dev $DEV root handle 1: htb default 20
41
42 # shape everything at $UPLINK speed - this prevents huge queues in your
43 # DSL modem which destroy latency:
44
45 tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k
46
47 # high prio class 1:10:
48
49 tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
50 burst 6k prio 1
51
52 # bulk & default class 1:20 - gets slightly less traffic,
53 # and a lower priority:
54
55 tc class add dev $DEV parent 1:1 classid 1:20 htb rate $((9*$UPLINK/10))kbit \
56 burst 6k prio 2
57
58 tc class add dev $DEV parent 1:1 classid 1:30 htb rate $((8*$UPLINK/10))kbit \
59 burst 6k prio 2
60
61 # all get Stochastic Fairness:
62 tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
63 tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
64 tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10
65
66 # TOS Minimum Delay (ssh, NOT scp) in 1:10:
67
68 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
69 match ip tos 0x10 0xff flowid 1:10
70
71 # ICMP (ip protocol 1) in the interactive class 1:10 so we
72 # can do measurements & impress our friends:
73 tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
74 match ip protocol 1 0xff flowid 1:10
75
76 # To speed up downloads while an upload is going on, put ACK packets in
77 # the interactive class:
78
79 tc filter add dev $DEV parent 1: protocol ip prio 10 u32 \
80 match ip protocol 6 0xff \
81 match u8 0x05 0x0f at 0 \
82 match u16 0x0000 0xffc0 at 2 \
83 match u8 0x10 0xff at 33 \
84 flowid 1:10
85
86 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
87
88 # some traffic however suffers a worse fate
89 for a in $NOPRIOPORTDST
90 do
91 tc filter add dev $DEV parent 1: protocol ip prio 14 u32 \
92 match ip dport $a 0xffff flowid 1:30
93 done
94
95 for a in $NOPRIOPORTSRC
96 do
97 tc filter add dev $DEV parent 1: protocol ip prio 15 u32 \
98 match ip sport $a 0xffff flowid 1:30
99 done
100
101 for a in $NOPRIOHOSTSRC
102 do
103 tc filter add dev $DEV parent 1: protocol ip prio 16 u32 \
104 match ip src $a flowid 1:30
105 done
106
107 for a in $NOPRIOHOSTDST
108 do
109 tc filter add dev $DEV parent 1: protocol ip prio 17 u32 \
110 match ip dst $a flowid 1:30
111 done
112
113 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
114
115 tc filter add dev $DEV parent 1: protocol ip prio 18 u32 \
116 match ip dst 0.0.0.0/0 flowid 1:20
117
118
119 ########## downlink #############
120 # slow downloads down to somewhat less than the real speed to prevent
121 # queuing at our ISP. Tune to see how high you can set it.
122 # ISPs tend to have *huge* queues to make sure big downloads are fast
123 #
124 # attach ingress policer:
125
126 tc qdisc add dev $DEV handle ffff: ingress
127
128 # filter *everything* to it (0.0.0.0/0), drop everything that's
129 # coming in too fast:
130
131 tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
132 0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1