aboutsummaryrefslogtreecommitdiffstats
path: root/main/vlan/vlan.pre-up
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2012-03-15 13:35:13 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2012-03-15 13:35:13 +0000
commit9146859d63fb9bc88018664950a7d70086ec51eb (patch)
treea03c9c4b7b0944b8042d8e9dff63370e1a023548 /main/vlan/vlan.pre-up
parent36681224a041c8256f2054f62d7b075743c9c1c6 (diff)
downloadaports-9146859d63fb9bc88018664950a7d70086ec51eb.tar.bz2
aports-9146859d63fb9bc88018664950a7d70086ec51eb.tar.xz
main/vlan: move from testing
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 0000000000..450e0d3358
--- /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
+