summaryrefslogtreecommitdiffstats
path: root/main/vlan
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
parent36681224a041c8256f2054f62d7b075743c9c1c6 (diff)
downloadaports-9146859d63fb9bc88018664950a7d70086ec51eb.tar.bz2
aports-9146859d63fb9bc88018664950a7d70086ec51eb.tar.xz
main/vlan: move from testing
Diffstat (limited to 'main/vlan')
-rw-r--r--main/vlan/APKBUILD47
-rw-r--r--main/vlan/mvlan.post-down14
-rw-r--r--main/vlan/mvlan.pre-up14
-rw-r--r--main/vlan/vlan.post-down27
-rw-r--r--main/vlan/vlan.pre-up57
5 files changed, 159 insertions, 0 deletions
diff --git a/main/vlan/APKBUILD b/main/vlan/APKBUILD
new file mode 100644
index 000000000..30910bcb4
--- /dev/null
+++ b/main/vlan/APKBUILD
@@ -0,0 +1,47 @@
+# Contributor: Natanael Copa <ncopa@alpinelinux.org>
+# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
+pkgname=vlan
+pkgver=1.9
+pkgrel=0
+pkgdesc="Scripts for configuring VLAN network interfaces"
+url="http://wiki.alpinelinux.org/wiki/Vlan"
+arch="noarch"
+license="GPL"
+depends=""
+makedepends=""
+install=""
+subpackages=""
+source="mvlan.post-down
+ mvlan.pre-up
+ vlan.post-down
+ vlan.pre-up
+ "
+
+_builddir=
+prepare() {
+ local i
+ cd "$_builddir"
+ for i in $source; do
+ case $i in
+ *.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+ esac
+ done
+}
+
+build() {
+ return 0
+}
+
+package() {
+ cd "$srcdir"
+ for i in vlan mvlan; do
+ for j in pre-up post-down; do
+ install -Dm755 $i.$j "$pkgdir"/etc/network/if-$j.d/$i || return 1
+ done
+ done
+}
+
+md5sums="3683be24d1fc1d8565e945c349c41571 mvlan.post-down
+5b6232674e83b0dbfc24af523dd5ec03 mvlan.pre-up
+cebaa97c933ed0f4cafd92f864ab4bc8 vlan.post-down
+c9acef8c17d8af19590767f57eb11b6b vlan.pre-up"
diff --git a/main/vlan/mvlan.post-down b/main/vlan/mvlan.post-down
new file mode 100644
index 000000000..229fc0e7f
--- /dev/null
+++ b/main/vlan/mvlan.post-down
@@ -0,0 +1,14 @@
+#!/bin/sh
+case "$IFACE" in
+ *#[0-9]*)
+ MVLANID="${IFACE##*#}"
+ IF_MVLAN_RAW_DEVICE="${IFACE%#*}"
+ ;;
+ *)
+ ;;
+esac
+if [ -n "$IF_MVLAN_RAW_DEVICE" ]
+then
+ # Kernel new style configuration
+ ip link del link dev "$IFACE"
+fi
diff --git a/main/vlan/mvlan.pre-up b/main/vlan/mvlan.pre-up
new file mode 100644
index 000000000..6713f3115
--- /dev/null
+++ b/main/vlan/mvlan.pre-up
@@ -0,0 +1,14 @@
+#!/bin/sh
+case "$IFACE" in
+ *#[0-9]*)
+ MVLANID="${IFACE##*#}"
+ IF_MVLAN_RAW_DEVICE="${IFACE%#*}"
+ ;;
+ *)
+ ;;
+esac
+if [ -n "$IF_MVLAN_RAW_DEVICE" ]
+then
+ # Kernel new style configuration
+ ip link add link $IF_MVLAN_RAW_DEVICE name $IFACE type macvlan
+fi
diff --git a/main/vlan/vlan.post-down b/main/vlan/vlan.post-down
new file mode 100644
index 000000000..bf887ef14
--- /dev/null
+++ b/main/vlan/vlan.post-down
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# If IFACE is an automagic vlan interface (without the vlan-raw-device
+# parameter) then let's try to discover the magic here.. Another way would be
+# to just probe for the right device name in /proc/net/vlan
+
+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
+
+if [ -n "$IF_VLAN_RAW_DEVICE" ]; then
+ RAW_DEVICE="$IF_VLAN_RAW_DEVICE"
+fi
+
+if [ -n "$IF_VLAN_ID" ]; then
+ VLAN_ID="$IF_VLAN_ID"
+fi
+
+if [ -n "${RAW_DEVICE}" -o -n "${VLAN_ID}" ]
+then
+ vconfig rem "${IFACE}"
+fi
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
+