]>
code.delx.au - monosys/blob - scripts/shaper
3 # Docs: http://lartc.org/howto
7 VOIP_HOST
="203.2.134.1"
18 # Symbolic 'constants'
30 # Print status of classes
31 if [ "$1" = "status" ]
33 tc
-s qdisc
ls dev
${IFACE}
34 tc
-s class
ls dev
${IFACE}
39 # clean existing down- and uplink qdiscs, hide errors
40 tc qdisc del dev
${IFACE} root
2> /dev
/null
> /dev
/null
41 tc qdisc del dev
${IFACE} ingress
2> /dev
/null
> /dev
/null
50 ########## uplink #############
52 # install root HTB, point default traffic to NORM_TRAFFIC
53 tc qdisc add dev
${IFACE} \
54 root handle
${ROOT}:0 \
55 htb default
${NORM_TRAFFIC} r2q
${R2Q}
58 # LIMIT class shapes everything at $UPLINK_RATE speed
59 # this prevents huge queues in the DSL modem which destroy latency
60 tc class add dev
${IFACE} \
61 parent
${ROOT}:0 classid ${ROOT}:${LIMIT} \
62 htb rate
${UPLINK_RATE}Kbit ceil
${UPLINK_RATE}Kbit
65 # VoIP traffic class gets guaranteed bandwidth
66 tc class add dev
${IFACE} \
67 parent
${ROOT}:${LIMIT} classid ${ROOT}:${VOIP_TRAFFIC} \
68 htb rate
${VOIP_RATE}Kbit ceil $
[3*${VOIP_RATE}/2]Kbit prio
0
70 # High priority traffic
71 tc class add dev
${IFACE} \
72 parent
${ROOT}:${LIMIT} classid ${ROOT}:${HIGH_TRAFFIC} \
73 htb rate
${HIGH_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
1
75 # Normal priority traffic
76 tc class add dev
${IFACE} \
77 parent
${ROOT}:${LIMIT} classid ${ROOT}:${NORM_TRAFFIC} \
78 htb rate
${NORM_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
2
80 # Bulk traffic gets little default allowance
81 tc class add dev
${IFACE} \
82 parent
${ROOT}:${LIMIT} classid ${ROOT}:${BULK_TRAFFIC} \
83 htb rate
${BULK_RATE}Kbit ceil
${UPLINK_RATE}Kbit prio
3
86 tc qdisc add dev
${IFACE} \
87 parent
${ROOT}:${HIGH_TRAFFIC} handle ${HIGH_TRAFFIC}:0 \
89 tc qdisc add dev
${IFACE} \
90 parent
${ROOT}:${NORM_TRAFFIC} handle ${NORM_TRAFFIC}:0 \
92 tc qdisc add dev
${IFACE} \
93 parent
${ROOT}:${BULK_TRAFFIC} handle ${BULK_TRAFFIC}:0 \
100 # Match VoIP traffic as highest priority
101 tc filter add dev
${IFACE} \
102 parent
${ROOT}:0 protocol ip prio
10 u32 \
103 match ip dst
${VOIP_HOST} flowid ${ROOT}:${VOIP_TRAFFIC}
105 # ICMP (ip protocol 1) in the HIGH_TRAFFIC class
106 tc filter add dev
${IFACE} \
107 parent
${ROOT}:0 protocol ip prio
10 u32 \
108 match ip protocol
1 0xff flowid
${ROOT}:${HIGH_TRAFFIC}
110 # To speed up downloads while an upload is going on, ACK is HIGH_TRAFFIC
111 tc filter add dev
${IFACE} \
112 parent
${ROOT}:0 protocol ip prio
10 u32 \
113 match ip protocol
6 0xff \
114 match u8
0x05 0x0f at 0 \
115 match u16
0x0000 0xffc0 at 2 \
116 match u8
0x10 0xff at 33 \
117 flowid
${ROOT}:${HIGH_TRAFFIC}
119 # TOS Minimum-Delay (eg ssh but not scp) in HIGH_TRAFFIC
120 tc filter add dev
${IFACE} \
121 parent
${ROOT}:0 protocol ip prio
10 u32 \
122 match ip tos
0x10 0xff flowid
${ROOT}:${HIGH_TRAFFIC}
124 # TOS Maximise-Throughput (eg rtorrent) in BULK_TRAFFIC
125 tc filter add dev
${IFACE} \
126 parent
${ROOT}:0 protocol ip prio
10 u32 \
127 match ip tos
0x08 0xff flowid
${ROOT}:${BULK_TRAFFIC}