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