-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprv-net-helper.in
65 lines (55 loc) · 1.1 KB
/
prv-net-helper.in
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
62
63
64
65
#!/bin/bash
source @datadir@/gnt-networking/common.sh
function usage {
echo "Usage: $0 <mode> <parent interface> <prv min> <prv max> <offset>"
exit 1
}
if [ $# -ne 5 ]; then
usage
fi
function up {
iface=$1
prv_min=$2
prv_max=$3
offset=$4
echo "Adding VLANs $2 - $3"
if [ ! -f /proc/net/vlan/config ]; then
$MODPROBE 8021q
fi
$VCONFIG set_name_type DEV_PLUS_VID_NO_PAD
for prv in $(seq $prv_min $prv_max); do
vlan=$(($prv+$offset))
bridge=prv$prv
$VCONFIG add $iface $vlan
$IP_CMD link set dev $iface.$vlan up
$BRCTL addbr $bridge
$BRCTL setfd $bridge 0
$BRCTL addif $bridge $iface.$vlan # dev_plus_vid
$IP_CMD link set dev $bridge up
done
}
function down {
iface=$1
prv_min=$2
prv_max=$3
offset=$4
echo "Removing VLANs $2 - $3"
for prv in $(seq $prv_min $prv_max); do
vlan=$(($prv+$offset))
bridge=prv$prv
(
$IP_CMD link set dev $bridge down
$BRCTL delif $bridge $iface.$vlan # dev_plus_vid
$VCONFIG rem $iface.$vlan
$BRCTL delbr $bridge
) 2>/dev/null
done
}
mode=$1; shift
if [ "$mode" = "up" ]; then
up $@
elif [ "$mode" = "down" ]; then
down $@
else
usage
fi