3 # please read the README before filling out these values
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.
8 # All config needs to be done in /etc/config/wshaper
12 for s
in downlink uplink network nopriohostdst nopriohostsrc noprioportdst noprioportsrc
; do
13 config_get
$s settings
$s
16 device
=$
(uci_get_state network
"$network" ifname
"$network")
17 [ -z "$device" ] && logger
-t wondershaper
"Error: Could not find the device for network $network, aborting." && exit 1
18 [ -z "$downlink" ] && logger
-t wondershaper
"Error: Downlink speed not set, aborting." && exit 1
19 [ -z "$uplink" ] && logger
-t wondershaper
"Error: Uplink speed not set, aborting." && exit 1
21 MODULES
='sch_ingress sch_sfq sch_htb cls_u32 act_police'
26 # low priority OUTGOING traffic - you can leave this blank if you want
27 # low priority source netmasks
28 NOPRIOHOSTSRC
="$nopriohostsrc"
30 # low priority destination netmasks
31 NOPRIOHOSTDST
="$nopriohostdst"
33 # low priority source ports
34 NOPRIOPORTSRC
="$noprioportsrc"
36 # low priority destination ports
37 NOPRIOPORTDST
="$noprioportdst"
39 if [ "$1" = "status" ]
41 tc
-s qdisc
ls dev
$DEV
42 tc
-s class
ls dev
$DEV
47 # clean existing down- and uplink qdiscs, hide errors
48 tc qdisc del dev
$DEV root
2> /dev
/null
> /dev
/null
49 tc qdisc del dev
$DEV ingress
2> /dev
/null
> /dev
/null
53 for i
in $MODULES ; do
59 for i
in $MODULES ; do
65 # install root HTB, point default traffic to 1:20:
67 tc qdisc add dev
$DEV root handle
1: htb default
20
69 # shape everything at $UPLINK speed - this prevents huge queues in your
70 # DSL modem which destroy latency:
72 tc class add dev
$DEV parent
1: classid
1:1 htb rate
${UPLINK}kbit burst
6k
74 # high prio class 1:10:
76 tc class add dev
$DEV parent
1:1 classid
1:10 htb rate
${UPLINK}kbit \
79 # bulk & default class 1:20 - gets slightly less traffic,
80 # and a lower priority:
82 tc class add dev
$DEV parent
1:1 classid
1:20 htb rate $
((9*$UPLINK/10))kbit \
85 tc class add dev
$DEV parent
1:1 classid
1:30 htb rate $
((8*$UPLINK/10))kbit \
88 # all get Stochastic Fairness:
89 tc qdisc add dev
$DEV parent
1:10 handle
10: sfq perturb
10
90 tc qdisc add dev
$DEV parent
1:20 handle
20: sfq perturb
10
91 tc qdisc add dev
$DEV parent
1:30 handle
30: sfq perturb
10
93 # TOS Minimum Delay (ssh, NOT scp) in 1:10:
95 tc filter add dev
$DEV parent
1:0 protocol ip prio
10 u32 \
96 match ip tos
0x10 0xff flowid
1:10
98 # ICMP (ip protocol 1) in the interactive class 1:10 so we
99 # can do measurements & impress our friends:
100 tc filter add dev
$DEV parent
1:0 protocol ip prio
10 u32 \
101 match ip protocol
1 0xff flowid
1:10
103 # To speed up downloads while an upload is going on, put ACK packets in
104 # the interactive class:
106 tc filter add dev
$DEV parent
1: protocol ip prio
10 u32 \
107 match ip protocol
6 0xff \
108 match u8
0x05 0x0f at 0 \
109 match u16
0x0000 0xffc0 at 2 \
110 match u8
0x10 0xff at 33 \
113 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
115 # some traffic however suffers a worse fate
116 for a
in $NOPRIOPORTDST
118 tc filter add dev
$DEV parent
1: protocol ip prio
14 u32 \
119 match ip dport
$a 0xffff flowid
1:30
122 for a
in $NOPRIOPORTSRC
124 tc filter add dev
$DEV parent
1: protocol ip prio
15 u32 \
125 match ip sport
$a 0xffff flowid
1:30
128 for a
in $NOPRIOHOSTSRC
130 tc filter add dev
$DEV parent
1: protocol ip prio
16 u32 \
131 match ip src
$a flowid
1:30
134 for a
in $NOPRIOHOSTDST
136 tc filter add dev
$DEV parent
1: protocol ip prio
17 u32 \
137 match ip dst
$a flowid
1:30
140 # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
142 tc filter add dev
$DEV parent
1: protocol ip prio
18 u32 \
143 match ip dst
0.0.0.0/0 flowid
1:20
146 ########## downlink #############
147 # slow downloads down to somewhat less than the real speed to prevent
148 # queuing at our ISP. Tune to see how high you can set it.
149 # ISPs tend to have *huge* queues to make sure big downloads are fast
151 # attach ingress policer:
153 tc qdisc add dev
$DEV handle ffff
: ingress
155 # filter *everything* to it (0.0.0.0/0), drop everything that's
156 # coming in too fast:
158 tc filter add dev
$DEV parent ffff
: protocol ip prio
50 u32 match ip src \
159 0.0.0.0/0 police rate
${DOWNLINK}kbit burst
10k drop flowid
:1
161 logger
-t wondershaper
"Wondershaper was started on device $device."