aboutsummaryrefslogtreecommitdiffstats
path: root/main/vlan/vlan.pre-up
blob: f45672b7654c73bbf9b0ffba5dcf34989663a479 (plain)
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
#!/bin/sh
set -eu

# guessing parameters
case "$IFACE" in
	*#*) exit 0 ;;
	*:*) exit 0 ;;
	vlan*.*) exit 0 ;;
	vlan*) GUESSED_VLAN_ID="${IFACE#vlan}" ;;
	*.*)
		GUESSED_RAW_DEVICE="${IFACE%.*}"
		GUESSED_VLAN_ID="${IFACE##*.}"
		;;
	*) [ -n "${IF_VLAN_ID:-}" -o -n "${IF_VLAN_RAW_DEVICE:-}" ] || exit 0 ;;
esac

RAW_DEVICE="${IF_VLAN_RAW_DEVICE:-${GUESSED_RAW_DEVICE:-}}"
VLAN_ID="$(expr ${IF_VLAN_ID:-${GUESSED_VLAN_ID:-0}} + 0 || :)"

if ! [ "$VLAN_ID" -gt 0 ]; then
	echo "VLAN_ID for $IFACE is not set"
	exit 1
fi

if [ -z "$RAW_DEVICE" ]; then
	echo "RAW_DEVICE for $IFACE is not set"
	exit 1
fi

if [ -e /sys/class/net/$IFACE ]; then
	exit 0
fi

if ! ip link show "$RAW_DEVICE" >/dev/null; then
	echo "Device $RAW_DEVICE for $IFACE does not exist"
	exit 1
fi

if ! [ -d /proc/net/vlan ]; then
	modprobe 8021q
fi

ip link set dev "$RAW_DEVICE" up
ip link add link "$RAW_DEVICE" name "$IFACE" type vlan id "$VLAN_ID"