]>
code.delx.au - monosys/blob - hacks/shaper
3 # Docs: http://lartc.org/howto
7 VOIP_HOST
="$(dig +short sip.internode.on.net)"
17 # Symbolic 'constants'
26 # Print status of classes
27 if [ "$1" = "status" ]; then
28 tc
-s qdisc
ls dev
${IFACE}
29 tc
-s class
ls dev
${IFACE}
35 # clean existing down- and uplink qdiscs, hide errors
36 tc qdisc del dev
${IFACE} root
2> /dev
/null
> /dev
/null
37 tc qdisc del dev
${IFACE} ingress
2> /dev
/null
> /dev
/null
39 if [ "$1" = "stop" ]; then
46 ########## uplink #############
48 # install root HTB, point default traffic to NORM_TRAFFIC
49 tc qdisc add dev
${IFACE} \
50 root handle
${ROOT}:0 \
51 htb default
${NORM_TRAFFIC}
54 # LIMIT class shapes everything at $UPLINK_RATE speed
55 # this prevents huge queues in the DSL modem which destroy latency
56 tc class add dev
${IFACE} \
57 parent
${ROOT}:0 classid ${ROOT}:${LIMIT} \
58 htb rate
${UPLINK_RATE}Kbit ceil
${UPLINK_RATE}Kbit
61 # VoIP traffic class gets guaranteed bandwidth
62 tc class add dev
${IFACE} \
63 parent
${ROOT}:${LIMIT} classid ${ROOT}:${VOIP_TRAFFIC} \
64 htb rate
${VOIP_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
0
66 # High priority traffic
67 tc class add dev
${IFACE} \
68 parent
${ROOT}:${LIMIT} classid ${ROOT}:${HIGH_TRAFFIC} \
69 htb rate
${HIGH_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
1
71 # Normal priority traffic
72 tc class add dev
${IFACE} \
73 parent
${ROOT}:${LIMIT} classid ${ROOT}:${NORM_TRAFFIC} \
74 htb rate
${NORM_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
2
76 # Bulk traffic gets little default allowance
77 tc class add dev
${IFACE} \
78 parent
${ROOT}:${LIMIT} classid ${ROOT}:${BULK_TRAFFIC} \
79 htb rate
${BULK_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
3
83 tc qdisc add dev
${IFACE} \
84 parent
${ROOT}:${HIGH_TRAFFIC} handle ${HIGH_TRAFFIC}:0 \
86 tc qdisc add dev
${IFACE} \
87 parent
${ROOT}:${NORM_TRAFFIC} handle ${NORM_TRAFFIC}:0 \
89 tc qdisc add dev
${IFACE} \
90 parent
${ROOT}:${BULK_TRAFFIC} handle ${BULK_TRAFFIC}:0 \
94 # Match VoIP traffic as highest priority
95 tc filter add dev
${IFACE} \
96 parent
${ROOT}:0 protocol ip prio
10 u32 \
97 match ip dst
${VOIP_HOST} flowid ${ROOT}:${VOIP_TRAFFIC}
99 # ICMP in the HIGH_TRAFFIC class
100 tc filter add dev
${IFACE} \
101 parent
${ROOT}:0 protocol ip prio
10 u32 \
102 match ip protocol
1 0xff flowid
${ROOT}:${HIGH_TRAFFIC}
104 # To speed up downloads while an upload is going on, ACK is HIGH_TRAFFIC
105 tc filter add dev
${IFACE} \
106 parent
${ROOT}:0 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 \
111 flowid
${ROOT}:${HIGH_TRAFFIC}
113 # TOS Minimum-Delay (eg ssh but not scp) in HIGH_TRAFFIC
114 tc filter add dev
${IFACE} \
115 parent
${ROOT}:0 protocol ip prio
10 u32 \
116 match ip tos
0x10 0xff flowid
${ROOT}:${HIGH_TRAFFIC}
118 # TOS Maximise-Throughput (eg rtorrent) in BULK_TRAFFIC
119 tc filter add dev
${IFACE} \
120 parent
${ROOT}:0 protocol ip prio
10 u32 \
121 match ip tos
0x08 0xff flowid
${ROOT}:${BULK_TRAFFIC}