Statistics
| Branch: | Tag: | Revision:

root / vlans / vlan @ cf51ea5b

History | View | Annotate | Download (1.2 kB)

1
#!/bin/sh
2
#
3

    
4
add_vlan() {
5
	if [ -n "`echo -n "$1" | tr -d '[0-9]'`" ]; then
6
		echo "Invalid vlan tag $1"
7
		exit 1
8
	fi
9
		
10
	vlan=$1
11
	ifce=$2
12

    
13
	if [ -d "/sys/class/net/vlan${vlan}/bridge" ]; then
14
		echo "Vlan $vlan already configured"
15
		exit 0
16
	fi
17

    
18
	if ( grep -q "iface vlan${vlan}$" /etc/network/interfaces ); then
19
		echo "Vlan $vlan configured but down, bringing up"
20
	else
21
		echo "Adding vlan $vlan to /etc/network/interfaces"
22
		cat >>/etc/network/interfaces <<EOF
23
auto vlan${vlan}
24
iface vlan${vlan} inet manual
25
	bridge_ports	${ifce}.${vlan}
26
	bridge_stp	off
27
	bridge_maxwait	0
28
	bridge_fd	0
29

    
30
EOF
31
	fi
32

    
33
	/sbin/ifup "vlan${vlan}" >/dev/null 2>&1
34
	exit 0
35
}
36

    
37
list_vlans() {
38
	for iface in /sys/class/net/vlan*; do
39
		if [ -d "$iface/bridge" ]; then
40
			vlan=`basename "$iface"`
41
			( grep -q "iface $vlan$" /etc/network/interfaces )
42
			if [ $? == 0 ]; then
43
				echo "${vlan##vlan}"
44
			else
45
				echo "${vlan##vlan} (unconfigured)"
46
			fi
47
		fi
48
	done
49

    
50
}
51

    
52
case "$1" in
53
	add)
54
	if [ x"$3" != x"" ]; then
55
		ifce=$3
56
	else
57
		ifce="bond0"
58
	fi
59
	add_vlan "$2" "$ifce"
60
	;;
61
	remove)
62
	remove_vlan "$2"
63
	;;
64
	list)
65
	list_vlans
66
	;;
67
	*)
68
	echo "Usage: vlan (add number [ifce="bond0"]|remove number|list)"
69
	;;
70
esac;
71