aboutsummaryrefslogtreecommitdiffstats
path: root/main/vlan
diff options
context:
space:
mode:
authorAlex Laskin <alex@lask.in>2017-09-25 21:54:05 +0300
committerNatanael Copa <ncopa@alpinelinux.org>2017-09-27 09:55:55 +0000
commit8faf34e75443a768375e2250f961952183d30858 (patch)
tree98da6ebcf4e39b8c5581939d8129c5bcf3125008 /main/vlan
parented7bfce2007122394886c658e0db30a6ba91d751 (diff)
downloadaports-8faf34e75443a768375e2250f961952183d30858.tar.bz2
aports-8faf34e75443a768375e2250f961952183d30858.tar.xz
main/vlan: rewrite to /sbin/ip and better error handling
Diffstat (limited to 'main/vlan')
-rw-r--r--main/vlan/APKBUILD25
-rw-r--r--main/vlan/mvlan.post-down31
-rw-r--r--main/vlan/mvlan.pre-up36
-rw-r--r--main/vlan/vlan.post-down27
-rw-r--r--main/vlan/vlan.pre-up83
5 files changed, 91 insertions, 111 deletions
diff --git a/main/vlan/APKBUILD b/main/vlan/APKBUILD
index e6de49cdbb..958dd5121e 100644
--- a/main/vlan/APKBUILD
+++ b/main/vlan/APKBUILD
@@ -1,12 +1,13 @@
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=vlan
-pkgver=1.9
-pkgrel=1
+pkgver=2.0
+pkgrel=0
pkgdesc="Scripts for configuring VLAN network interfaces"
url="http://wiki.alpinelinux.org/wiki/Vlan"
arch="noarch"
license="GPL"
+options="!check"
depends=""
makedepends=""
install=""
@@ -17,17 +18,6 @@ source="mvlan.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
}
@@ -40,8 +30,7 @@ package() {
done
done
}
-
-sha512sums="3cd966ebd44036bd5a50e5a80292d2fca3a24e851f5231c57c07418f5d36d2ab06e9ef07dd097be2a7585906cfc1c8d52f18ab5b4ba595028287e436680762d9 mvlan.post-down
-4e75059fbd347427835359842dfc63a19825eaa254539e2a658a5521278b59ae05fba1c2bf83951b8cccbb99cbb5a890a9a1d9069fb39c7d0c1707880652fcce mvlan.pre-up
-0219db488ea99aa88018925a3e817c52ccfb95304f0c62fe6e139fc5b8d7b6d1d9919161dc4ba42c51908efa02963ada0972859c83a81cde27c33965de5e54b8 vlan.post-down
-99c02b3407bded7f5d971195281d6bbc44df456c046a7462eb49e6291b6611ee70a55af2c6c3c19593f80e4a6b1065af64d95d7c7024b08e024be13f2bdcd8f9 vlan.pre-up"
+sha512sums="f00c8521830b1472f1e71223943c14446d28f2667f7e2fd3690c8402c7d3f34982bc4d27201b3dc9c1eb9a635e38ea23dee6e044487615cbc68ba519d940c0f7 mvlan.post-down
+955ccc68398ed2d515f794d5ef4164fec2dcfc4504e2e29d427c1687c8b9d6ecff1ea7247dc751963bb7be1db5025940fb66efef3fb6287aa19fe014088573ac mvlan.pre-up
+7a6e74957d2fcfb04023d2cf8246e8889a780171f669ec37a56882276d96fb0219180b37cc51ecd87421bcbd0f0d489602423859a6f5605781f703cf143e5bae vlan.post-down
+d4f0c4d838c716c950e553311bf0171997e9a46cb06d5e35feb9a9f52e13dcf4a1553ccc85aaf771057fef6229fcae29ff23c4e2ce384b0ba68a4b8de6a77fec vlan.pre-up"
diff --git a/main/vlan/mvlan.post-down b/main/vlan/mvlan.post-down
index 229fc0e7f5..a18db48822 100644
--- a/main/vlan/mvlan.post-down
+++ b/main/vlan/mvlan.post-down
@@ -1,14 +1,25 @@
#!/bin/sh
+set -eu
+
+# guessing parameters
case "$IFACE" in
- *#[0-9]*)
- MVLANID="${IFACE##*#}"
- IF_MVLAN_RAW_DEVICE="${IFACE%#*}"
- ;;
- *)
- ;;
+ *:*) exit 0 ;;
+ *.*) exit 0 ;;
+ vlan*) exit 0 ;;
+ *#[0-9]*) GUESSED_RAW_DEVICE="${IFACE%#*}" ;;
+ *) [ -n "${IF_MVLAN_RAW_DEVICE:-}" ] || exit 0 ;;
esac
-if [ -n "$IF_MVLAN_RAW_DEVICE" ]
-then
- # Kernel new style configuration
- ip link del link dev "$IFACE"
+
+RAW_DEVICE="${IF_MVLAN_RAW_DEVICE:-${GUESSED_RAW_DEVICE:-}}"
+
+if [ -z "$RAW_DEVICE" ]; then
+ echo "RAW_DEVICE for $IFACE is not set"
+ exit 1
fi
+
+if ! ip link show dev "$RAW_DEVICE" >/dev/null; then
+ echo "Device $RAW_DEVICE for $IFACE does not exist"
+ exit 1
+fi
+
+ip link delete dev "$IFACE" type macvlan
diff --git a/main/vlan/mvlan.pre-up b/main/vlan/mvlan.pre-up
index 6713f3115a..8c6f67cbfa 100644
--- a/main/vlan/mvlan.pre-up
+++ b/main/vlan/mvlan.pre-up
@@ -1,14 +1,30 @@
#!/bin/sh
+set -eu
+
+# guessing parameters
case "$IFACE" in
- *#[0-9]*)
- MVLANID="${IFACE##*#}"
- IF_MVLAN_RAW_DEVICE="${IFACE%#*}"
- ;;
- *)
- ;;
+ *:*) exit 0 ;;
+ *.*) exit 0 ;;
+ vlan*) exit 0 ;;
+ *#[0-9]*) GUESSED_RAW_DEVICE="${IFACE%#*}" ;;
+ *) [ -n "${IF_MVLAN_RAW_DEVICE:-}" ] || exit 0 ;;
esac
-if [ -n "$IF_MVLAN_RAW_DEVICE" ]
-then
- # Kernel new style configuration
- ip link add link $IF_MVLAN_RAW_DEVICE name $IFACE type macvlan
+
+RAW_DEVICE="${IF_MVLAN_RAW_DEVICE:-${GUESSED_RAW_DEVICE:-}}"
+
+if [ -z "$RAW_DEVICE" ]; then
+ echo "RAW_DEVICE for $IFACE is not set"
+ exit 1
+fi
+
+if ! ip link show "$RAW_DEVICE" >/dev/null; then
+ echo "Device $RAW_DEVICE for $IFACE does not exist"
+ exit 1
+fi
+
+ip link add link "$RAW_DEVICE" name "$IFACE" type macvlan
+
+if ! ip link show "$IFACE" >/dev/null; then
+ echo "Failed to create vlan device $IFACE on device $RAW_DEVICE with tag $VLAN_ID"
+ exit 1
fi
diff --git a/main/vlan/vlan.post-down b/main/vlan/vlan.post-down
index bf887ef149..33098fd629 100644
--- a/main/vlan/vlan.post-down
+++ b/main/vlan/vlan.post-down
@@ -1,27 +1,6 @@
#!/bin/sh
+set -eu
-# 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}"
+if [ -e "/proc/net/vlan/${IFACE}" ]; then
+ ip link delete dev "${IFACE}" type vlan
fi
diff --git a/main/vlan/vlan.pre-up b/main/vlan/vlan.pre-up
index be66cff5f1..a1a2822376 100644
--- a/main/vlan/vlan.pre-up
+++ b/main/vlan/vlan.pre-up
@@ -1,60 +1,45 @@
#!/bin/sh
-do_vlan_config() {
- local device="$1"
- local id="$2"
- local newname="$3"
- local nametype="$4"
- if ! [ -d /proc/net/vlan ]; then
- modprobe 8021q
- fi
- vconfig set_name_type ${nametype}
- vconfig add ${device} ${id}
-}
-
-
-# Preferred method:
-# Autoguess construction from #520147
+set -eu
+
+# guessing parameters
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
+ *#*) 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
-if [ -n "$IF_VLAN_RAW_DEVICE" ]; then
- RAW_DEVICE="$IF_VLAN_RAW_DEVICE"
+
+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
-# 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"
+if [ -z "$RAW_DEVICE" ]; then
+ echo "RAW_DEVICE for $IFACE is not set"
+ exit 1
fi
-if [ -z "$VLAN_ID" -o -z "$RAW_DEVICE" ]; then
- exit 1
+if ! ip link show "$RAW_DEVICE" >/dev/null; then
+ echo "Device $RAW_DEVICE for $IFACE does not exist"
+ 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
+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"
+
+if ! ip link show "$IFACE" >/dev/null; then
+ echo "Failed to create vlan device $IFACE on device $RAW_DEVICE with tag $VLAN_ID"
+ exit 1
+fi