-
Notifications
You must be signed in to change notification settings - Fork 2
/
8311-vlans-lib.sh
61 lines (47 loc) · 1.28 KB
/
8311-vlans-lib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
TC=$(PATH=/usr/sbin:/sbin /usr/bin/which tc)
tc() {
$TC "$@"
}
tc_flower_selector() {
dev=$(echo "$@" | grep -oE "dev \S+" | head -n1 | cut -d" " -f2)
direction=$(echo "$@" | grep -oE "egress|ingress" | head -n1)
handle=$(echo "$@" | grep -oE "handle \S+" | head -n1 | cut -d" " -f2)
protocol=$(echo "$@" | grep -oE "protocol \S+" | head -n1 | cut -d" " -f2)
pref=$(echo "$@" | grep -oE "pref \S+" | head -n1 | cut -d" " -f2)
if [ "$1" = "-devdironly" ]; then
echo "dev $dev $direction"
else
echo "dev $dev $direction handle $handle pref $pref protocol $protocol flower"
fi
}
tc_exists() {
tc filter get "$@" &>/dev/null
}
tc_flower_get() {
tc filter get $(tc_flower_selector "$@")
}
tc_flower_exists() {
tc_flower_get "$@" &>/dev/null
}
tc_flower_del() {
local selector=$(tc_flower_selector "$@")
echo del $selector
tc_exists "$selector" &&
tc filter del $selector
}
tc_flower_add() {
echo add $@
tc_flower_exists "$@" ||
tc filter add "$@"
}
tc_flower_replace() {
echo replace $@
tc filter del $(tc_flower_selector "$@") 2>/dev/null
tc filter add "$@"
}
tc_flower_clear() {
local selector=$(tc_flower_selector -devdironly "$@")
echo del $selector
tc filter del $selector
}