Ticket #13310: tc.sh

File tc.sh, 1.6 KB (added by aenertia@…, 5 years ago)

An example of a startup per client based tc implementation for lan rate limtiing

Line 
1#!/bin/sh
2#
3
4insmod cls_fw >/dev/null 2>&1
5insmod cls_u32 >/dev/null 2>&1
6insmod sch_htb >/dev/null 2>&1
7insmod sch_sfq >/dev/null 2>&1
8insmod sch_ingress >/dev/null 2>&1
9
10DEV="br-lan"
11CLIENT_MAC=00:11:22:33:44:55
12CLIENT_IP=172.16.0.128
13LIMIT_DOWN=200
14LIMIT_DOWN_BURST=400
15LIMIT_UP=400
16
17start() {
18
19tc qdisc del dev "$DEV" root handle 77:
20tc qdisc add dev "$DEV" root handle 77: htb
21tc class add dev "$DEV" parent 77: classid 77:1 htb rate 20000kbit
22tc class add dev "$DEV" parent 77:1 classid 77:10 htb rate ${LIMIT_DOWN}kbit ceil ${LIMIT_DOWN_BURST}kbit prio 2
23tc qdisc add dev "$DEV" parent 77:10 handle 78: sfq perturb 10
24tc qdisc add dev "$DEV" ingress
25tc filter add dev "$DEV" parent 77: protocol ip prio 2 handle 80 fw flowid 77:10
26tc filter add dev "$DEV" parent ffff: protocol ip prio 1 handle 79 fw police rate ${LIMIT_UP}kbit mtu 6k burst 6k drop
27iptables -t mangle -I PREROUTING -m mac --mac-source $CLIENT_MAC -j MARK --set-mark 79
28iptables -t mangle -I POSTROUTING -d $CLIENT_IP -j MARK --set-mark 80
29
30}
31
32stop() {
33
34tc qdisc del dev $DEV root
35iptables -F -t mangle
36
37}
38
39restart() {
40
41    stop
42    sleep 1
43    start
44
45}
46
47show() {
48
49    tc -s qdisc ls dev $DEV
50
51}
52
53case "$1" in
54
55  start)
56
57    echo -n "Starting bandwidth shaping: "
58    start
59    echo "done"
60    ;;
61
62  stop)
63
64    echo -n "Stopping bandwidth shaping: "
65    stop
66    echo "done"
67    ;;
68
69  restart)
70
71    echo -n "Restarting bandwidth shaping: "
72    restart
73    echo "done"
74    ;;
75
76  show)
77
78    echo "Bandwidth shaping status for $IF:"
79    show
80    echo ""
81    ;;
82
83  *)
84
85    pwd=$(pwd)
86    echo "Usage: tc.bash {start|stop|restart|show}"
87    ;;
88
89esac
90
91exit 0