summaryrefslogtreecommitdiffstats
path: root/main/vlan/vlan.pre-up
diff options
context:
space:
mode:
Diffstat (limited to 'main/vlan/vlan.pre-up')
-rw-r--r--main/vlan/vlan.pre-up57
1 files changed, 57 insertions, 0 deletions
diff --git a/main/vlan/vlan.pre-up b/main/vlan/vlan.pre-up
new file mode 100644
index 000000000..450e0d335
--- /dev/null
+++ b/main/vlan/vlan.pre-up
@@ -0,0 +1,57 @@
+#!/bin/sh
+do_vlan_config() {
+ local device="$1"
+ local id="$2"
+ local newname="$3"
+ local nametype="$4"
+ vconfig set_name_type ${nametype}
+ vconfig add ${device} ${id}
+}
+
+
+# Preferred method:
+# Autoguess construction from #520147
+case "$IFACE" in
+ *#*) exit 0 ;;
+ *:*) exit 0 ;;
+ vlan*.*) exit 0 ;;
+ vlan*) VLAN_ID="${IFACE#vlan}" NAME1=VLAN;;
+ *.*) RAW_DEVICE="${IFACE%.*}"; VLAN_ID="${IFACE##*.}" NAME1=DEV;;
+ *) [ -n "${IF_VLAN_ID}" -o -n "${IF_VLAN_RAW_DEVICE}" ] || exit 0 ;;
+esac
+case "$VLAN_ID" in
+ [1-9]*) NAME2=VID_NO_PAD;;
+ 0???) NAME2=VID;;
+ 0*) NAME2=VID_NO_PAD;; # Failsafe fallback in case of backward compatability
+esac
+if [ -n "$IF_VLAN_RAW_DEVICE" ]; then
+ RAW_DEVICE="$IF_VLAN_RAW_DEVICE"
+fi
+
+# Strip leading 0s
+VLAN_ID="${VLAN_ID#0}"
+VLAN_ID="${VLAN_ID#0}"
+VLAN_ID="${VLAN_ID#0}"
+VLAN_ID="${VLAN_ID#0}"
+VLAN_ID="$(($VLAN_ID))"
+if [ -n "$IF_VLAN_ID" ]; then
+ VLAN_ID="$IF_VLAN_ID"
+fi
+
+if [ -z "$VLAN_ID" -o -z "$RAW_DEVICE" ]; then
+ exit 1
+fi
+
+if [ -n "$RAW_DEVICE" ] && [ -n "$VLAN_ID" ]; then
+ if ! ip link show dev "$RAW_DEVICE" > /dev/null; then
+ echo "$RAW_DEVICE does not exist, unable to create $IFACE"
+ exit 1
+ fi
+ ip link set up dev "$RAW_DEVICE"
+ do_vlan_config "$RAW_DEVICE" "$VLAN_ID" "$IFACE" "${NAME1}_PLUS_${NAME2}"
+ if ! ip link show dev "$IFACE" > /dev/null; then
+ echo "Failed to create vlan device $IFACE on device $RAW_DEVICE with tag $VLAN_ID"
+ exit 1
+ fi
+fi
+