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