]>
code.delx.au - monosys/blob - scripts/shaper
5 VOIP_HOST
="203.2.134.1"
20 # Print status of classes
21 if [ "$1" = "status" ]
23 tc
-s qdisc
ls dev
${IFACE}
24 tc
-s class
ls dev
${IFACE}
29 # clean existing down- and uplink qdiscs, hide errors
30 tc qdisc del dev
${IFACE} root
2> /dev
/null
> /dev
/null
31 tc qdisc del dev
${IFACE} ingress
2> /dev
/null
> /dev
/null
39 # Symbolic 'constants'
49 ########## uplink #############
51 # install root HTB, point default traffic to NORM_TRAFFIC
52 tc qdisc add dev
${IFACE} \
53 root handle
${ROOT}:0 \
54 htb default
${NORM_TRAFFIC} r2q
${R2Q}
57 # LIMIT class shapes everything at $UPLINK_RATE speed
58 # this prevents huge queues in the DSL modem which destroy latency
59 tc class add dev
${IFACE} \
60 parent
${ROOT}:0 classid ${ROOT}:${LIMIT} \
61 htb rate
${UPLINK_RATE}Kbit ceil
${UPLINK_RATE}Kbit
64 # VoIP traffic class gets guaranteed bandwidth
65 tc class add dev
${IFACE} \
66 parent
${ROOT}:${LIMIT} classid ${ROOT}:${VOIP_TRAFFIC} \
67 htb rate
${VOIP_RATE}Kbit ceil $
[3*${VOIP_RATE}/2]Kbit prio
0
69 # High priority traffic
70 tc class add dev
${IFACE} \
71 parent
${ROOT}:${LIMIT} classid ${ROOT}:${HIGH_TRAFFIC} \
72 htb rate
${HIGH_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
1
74 # Normal priority traffic
75 tc class add dev
${IFACE} \
76 parent
${ROOT}:${LIMIT} classid ${ROOT}:${NORM_TRAFFIC} \
77 htb rate
${NORM_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
2
79 # Bulk traffic gets little default allowance
80 tc class add dev
${IFACE} \
81 parent
${ROOT}:${LIMIT} classid ${ROOT}:${BULK_TRAFFIC} \
82 htb rate
${BULK_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
3
85 tc qdisc add dev
${IFACE} \
86 parent
${ROOT}:${HIGH_TRAFFIC} handle ${HIGH_TRAFFIC}:0 \
88 tc qdisc add dev
${IFACE} \
89 parent
${ROOT}:${NORM_TRAFFIC} handle ${NORM_TRAFFIC}:0 \
91 tc qdisc add dev
${IFACE} \
92 parent
${ROOT}:${BULK_TRAFFIC} handle ${BULK_TRAFFIC}:0 \
99 # Match VoIP traffic as highest priority
100 tc filter add dev
${IFACE} \
101 parent
${ROOT}:0 protocol ip prio
10 u32 \
102 match ip dst
${VOIP_HOST} flowid ${ROOT}:${VOIP_TRAFFIC}
104 # ICMP (ip protocol 1) in the HIGH_TRAFFIC class
105 tc filter add dev
${IFACE} \
106 parent
${ROOT}:0 protocol ip prio
10 u32 \
107 match ip protocol
1 0xff flowid
${ROOT}:${HIGH_TRAFFIC}
109 # TOS Minimum-Delay (eg ssh but not scp) in HIGH_TRAFFIC
110 tc filter add dev
${IFACE} \
111 parent
${ROOT}:0 protocol ip prio
10 u32 \
112 match ip tos
0x10 0xff flowid
${ROOT}:${HIGH_TRAFFIC}
114 # TOS Maximise-Throughput (eg rtorrent) in BULK_TRAFFIC
115 tc filter add dev
${IFACE} \
116 parent
${ROOT}:0 protocol ip prio
10 u32 \
117 match ip tos
0x08 0xff flowid
${ROOT}:${BULK_TRAFFIC}
119 # To speed up downloads while an upload is going on, ACK is HIGH_TRAFFIC
120 tc filter add dev
${IFACE} \
121 parent
${ROOT}:0 protocol ip prio
10 u32 \
122 match ip protocol
6 0xff \
123 match u8
0x05 0x0f at 0 \
124 match u16
0x0000 0xffc0 at 2 \
125 match u8
0x10 0xff at 33 \
126 flowid
${ROOT}:${HIGH_TRAFFIC}
130 ########## downlink #############
132 tc qdisc add dev
${IFACE} \
135 # Matching incoming VoIP traffic here so it isn't policed by the next rule
136 tc filter add dev
${IFACE} \
137 parent ffff
: protocol ip prio
1 u32 \
138 match ip src
${VOIP_HOST}/32 \
141 # Police everything else - drop packets coming in faster than DOWNLINK_RATE
142 tc filter add dev
${IFACE} \
143 parent ffff
: protocol ip prio
2 u32 \
144 match ip src
0.0.0.0/0 \
145 police rate
${DOWNLINK_RATE}Kbit burst
10k drop flowid
:2