aboutsummaryrefslogtreecommitdiffstats
path: root/main/vlan/vlan.pre-up
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/vlan.pre-up
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/vlan.pre-up')
-rw-r--r--main/vlan/vlan.pre-up83
1 files changed, 34 insertions, 49 deletions
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