add wondershaper package from leh. thx
[openwrt/svn-archive/archive.git] / openwrt / package / wondershaper / patches / wondershaper-OpenWrt.patch
1 diff -Nur wondershaper-1.1a/wshaper wondershaper-1.1a_openwrt/wshaper
2 --- wondershaper-1.1a/wshaper 2002-04-16 16:26:35.000000000 +0200
3 +++ wondershaper-1.1a_openwrt/wshaper 2005-09-09 00:46:22.095406568 +0200
4 @@ -1,33 +1,7 @@
5 -#!/bin/bash
6 -
7 +#!/bin/sh
8 # Wonder Shaper
9 -# please read the README before filling out these values
10 -#
11 -# Set the following values to somewhat less than your actual download
12 -# and uplink speed. In kilobits. Also set the device that is to be shaped.
13 -DOWNLINK=800
14 -UPLINK=220
15 -DEV=eth0
16 -
17 -# low priority OUTGOING traffic - you can leave this blank if you want
18 -# low priority source netmasks
19 -NOPRIOHOSTSRC=80
20 -
21 -# low priority destination netmasks
22 -NOPRIOHOSTDST=
23 -
24 -# low priority source ports
25 -NOPRIOPORTSRC=
26 -
27 -# low priority destination ports
28 -NOPRIOPORTDST=
29 -
30 -# Now remove the following two lines :-)
31 -
32 -echo Please read the documentation in 'README' first :-\)
33 -exit
34 -
35 -#########################################################
36 +. /etc/functions.sh
37 +. /etc/wshaper.conf
38
39 if [ "$1" = "status" ]
40 then
41 @@ -46,6 +20,8 @@
42 exit
43 fi
44
45 +
46 +
47 ###### uplink
48
49 # install root CBQ
50 @@ -67,12 +43,12 @@
51 # bulk and default class 1:20 - gets slightly less traffic,
52 # and a lower priority:
53
54 -tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $[9*$UPLINK/10]kbit \
55 +tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $((9*$UPLINK/10))kbit \
56 allot 1600 prio 2 avpkt 1000
57
58 # 'traffic we hate'
59
60 -tc class add dev $DEV parent 1:1 classid 1:30 cbq rate $[8*$UPLINK/10]kbit \
61 +tc class add dev $DEV parent 1:1 classid 1:30 cbq rate $((8*$UPLINK/10))kbit \
62 allot 1600 prio 2 avpkt 1000
63
64 # all get Stochastic Fairness:
65 diff -Nur wondershaper-1.1a/wshaper.conf wondershaper-1.1a_openwrt/wshaper.conf
66 --- wondershaper-1.1a/wshaper.conf 1970-01-01 01:00:00.000000000 +0100
67 +++ wondershaper-1.1a_openwrt/wshaper.conf 2005-09-09 00:31:54.239340744 +0200
68 @@ -0,0 +1,27 @@
69 +# Wonder Shaper
70 +# please read the README before filling out these values
71 +#
72 +# Set the following values to somewhat less than your actual download
73 +# and uplink speed. In kilobits.
74 +DOWNLINK=1000
75 +UPLINK=220
76 +
77 +# low priority OUTGOING traffic - you can leave this blank if you want
78 +# low priority source netmasks
79 +NOPRIOHOSTSRC=80
80 +
81 +# low priority destination netmasks
82 +NOPRIOHOSTDST=
83 +
84 +# low priority source ports
85 +NOPRIOPORTSRC=
86 +
87 +# low priority destination ports
88 +NOPRIOPORTDST=
89 +
90 +# WAN device
91 +DEV=$(nvram get wan_ifname)
92 +
93 +# tc location
94 +TC=/usr/sbin/tc
95 +
96 diff -Nur wondershaper-1.1a/wshaper.htb wondershaper-1.1a_openwrt/wshaper.htb
97 --- wondershaper-1.1a/wshaper.htb 2002-04-16 16:26:51.000000000 +0200
98 +++ wondershaper-1.1a_openwrt/wshaper.htb 2005-09-11 12:03:39.756950000 +0200
99 @@ -1,44 +1,22 @@
100 -#!/bin/bash
101 +#!/bin/ash
102 # Wonder Shaper
103 -# please read the README before filling out these values
104 -#
105 -# Set the following values to somewhat less than your actual download
106 -# and uplink speed. In kilobits. Also set the device that is to be shaped.
107 -
108 -DOWNLINK=800
109 -UPLINK=220
110 -DEV=ppp0
111 -
112 -# low priority OUTGOING traffic - you can leave this blank if you want
113 -# low priority source netmasks
114 -NOPRIOHOSTSRC=
115 -
116 -# low priority destination netmasks
117 -NOPRIOHOSTDST=
118 +. /etc/functions.sh
119 +. /etc/wshaper.conf
120
121 -# low priority source ports
122 -NOPRIOPORTSRC=
123
124 -# low priority destination ports
125 -NOPRIOPORTDST=
126 -
127 -
128 -# Now remove the following two lines :-)
129 -
130 -echo Please read the documentation in 'README' first
131 -exit
132 +# do the magic
133
134 if [ "$1" = "status" ]
135 then
136 - tc -s qdisc ls dev $DEV
137 - tc -s class ls dev $DEV
138 + $TC -s qdisc ls dev $DEV
139 + $TC -s class ls dev $DEV
140 exit
141 fi
142
143
144 # clean existing down- and uplink qdiscs, hide errors
145 -tc qdisc del dev $DEV root 2> /dev/null > /dev/null
146 -tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null
147 +$TC qdisc del dev $DEV root 2> /dev/null > /dev/null
148 +$TC qdisc del dev $DEV ingress 2> /dev/null > /dev/null
149
150 if [ "$1" = "stop" ]
151 then
152 @@ -46,50 +24,65 @@
153 fi
154
155
156 +# wondershaper must be executed everytime an interface comes up
157 +# if we have dynamic interface ppp0 add wondershaper to ip-up
158 +if [ $DEV = "ppp0" ] && ! grep -q wshaper /etc/ppp/ip-up
159 +then
160 + echo "/usr/sbin/wshaper" >> /etc/ppp/ip-up
161 +fi
162 +
163 +
164 +
165 +# load the needed kernel modules
166 +for module in sch_prio sch_htb sch_sfq sch_ingress cls_tcindex cls_fw cls_route cls_u32
167 +do
168 + insmod $module 2> /dev/null > /dev/null
169 +done
170 +
171 ###### uplink
172
173 # install root HTB, point default traffic to 1:20:
174
175 -tc qdisc add dev $DEV root handle 1: htb default 20
176 +$TC qdisc add dev $DEV root handle 1: htb default 20
177
178 # shape everything at $UPLINK speed - this prevents huge queues in your
179 # DSL modem which destroy latency:
180
181 -tc class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k
182 +$TC class add dev $DEV parent 1: classid 1:1 htb rate ${UPLINK}kbit burst 6k
183
184 # high prio class 1:10:
185
186 -tc class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
187 +$TC class add dev $DEV parent 1:1 classid 1:10 htb rate ${UPLINK}kbit \
188 burst 6k prio 1
189
190 # bulk & default class 1:20 - gets slightly less traffic,
191 # and a lower priority:
192
193 -tc class add dev $DEV parent 1:1 classid 1:20 htb rate $[9*$UPLINK/10]kbit \
194 +$TC class add dev $DEV parent 1:1 classid 1:20 htb rate $((9*$UPLINK/10))kbit \
195 burst 6k prio 2
196
197 -tc class add dev $DEV parent 1:1 classid 1:30 htb rate $[8*$UPLINK/10]kbit \
198 +$TC class add dev $DEV parent 1:1 classid 1:30 htb rate $((8*$UPLINK/10))kbit \
199 burst 6k prio 2
200
201 # all get Stochastic Fairness:
202 -tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
203 -tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
204 -tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10
205 +$TC qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
206 +$TC qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
207 +$TC qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10
208
209 # TOS Minimum Delay (ssh, NOT scp) in 1:10:
210
211 -tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
212 +$TC filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
213 match ip tos 0x10 0xff flowid 1:10
214
215 # ICMP (ip protocol 1) in the interactive class 1:10 so we
216 # can do measurements & impress our friends:
217 -tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
218 +$TC filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
219 match ip protocol 1 0xff flowid 1:10
220
221 # To speed up downloads while an upload is going on, put ACK packets in
222 # the interactive class:
223
224 -tc filter add dev $DEV parent 1: protocol ip prio 10 u32 \
225 +$TC filter add dev $DEV parent 1: protocol ip prio 10 u32 \
226 match ip protocol 6 0xff \
227 match u8 0x05 0x0f at 0 \
228 match u16 0x0000 0xffc0 at 2 \
229 @@ -101,31 +94,31 @@
230 # some traffic however suffers a worse fate
231 for a in $NOPRIOPORTDST
232 do
233 - tc filter add dev $DEV parent 1: protocol ip prio 14 u32 \
234 + $TC filter add dev $DEV parent 1: protocol ip prio 14 u32 \
235 match ip dport $a 0xffff flowid 1:30
236 done
237
238 for a in $NOPRIOPORTSRC
239 do
240 - tc filter add dev $DEV parent 1: protocol ip prio 15 u32 \
241 + $TC filter add dev $DEV parent 1: protocol ip prio 15 u32 \
242 match ip sport $a 0xffff flowid 1:30
243 done
244
245 for a in $NOPRIOHOSTSRC
246 do
247 - tc filter add dev $DEV parent 1: protocol ip prio 16 u32 \
248 + $TC filter add dev $DEV parent 1: protocol ip prio 16 u32 \
249 match ip src $a flowid 1:30
250 done
251
252 for a in $NOPRIOHOSTDST
253 do
254 - tc filter add dev $DEV parent 1: protocol ip prio 17 u32 \
255 + $TC filter add dev $DEV parent 1: protocol ip prio 17 u32 \
256 match ip dst $a flowid 1:30
257 done
258
259 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
260
261 -tc filter add dev $DEV parent 1: protocol ip prio 18 u32 \
262 +$TC filter add dev $DEV parent 1: protocol ip prio 18 u32 \
263 match ip dst 0.0.0.0/0 flowid 1:20
264
265
266 @@ -136,12 +129,12 @@
267 #
268 # attach ingress policer:
269
270 -tc qdisc add dev $DEV handle ffff: ingress
271 +$TC qdisc add dev $DEV handle ffff: ingress
272
273 # filter *everything* to it (0.0.0.0/0), drop everything that's
274 # coming in too fast:
275
276 -tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
277 +$TC filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
278 0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
279
280