Package: vlan
Version: 1.9-3
Severity: minor
Tags: patch
I was reviewing the /etc/network/*.d/vlan scripts to write an
ip-vlan script to allow the same thing to be done entirely with
'ip' and I found a few anomalies
1) Doesn't handle arbitrarily named raw devices.
2) Doesn't catch the typo of padded vlan ID (IE eth0.01)
3) Extensive use of sed when ${VARIABLE%pattern} and ${VARIABLE#pattern}
would suffice.
4) A fair amount of 'repeat yourself'
Attached is one rewritten 'vlan' that is to be placed in
/etc/network/if-pre-up.d and a symlink to ../pre-up.d/vlan should be
placed in /etc/network/if-post-down.d
Attached as the patch is the rewritten vlan script.
-- System Information:
Debian Release: 5.0
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.26-1-686 (SMP w/1 CPU core)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages vlan depends on:
ii iproute 20080725-2 networking and traffic control too
ii libc6 2.9-3 GNU C Library: Shared libraries
vlan recommends no packages.
vlan suggests no packages.
-- no debconf information
#!/bin/sh
CONF=/etc/default/vlan
VCONFIG=/sbin/vconfig
IP=/sbin/ip
# Allow this to be disabled in favor of ip-vlan
if [ -r "$CONF" ]; then
. "$CONF"
fi
if [ "$USE_IPROUTE2" = "true" ]; then
exit 0
fi
case "$IFACE" in
*:*) exit 0 ;;
vlan*.*) exit 0 ;;
vlan*) VLANID="${IFACE#vlan}" NAME1=VLAN;;
*.*) RAW="${IFACE%.*}"; VLANID="${IFACE##*.}" NAME1=DEV;;
*) exit 0 ;;
esac
case "$VLANID" in
[1-9]*) NAME2=VID_NO_PAD ;;
0???) NAME2=VID ;;
0*) echo "VLANID needs to be exactly 4 digits for padded"; exit 1 ;;
esac
if [ -n "$IF_VLAN_RAW_DEVICE" ]; then
RAW="$IF_VLAN_RAW_DEVICE"
fi
if [ -n "$IF_VLAN_VLANID" ]; then
VLANID="$IF_VLAN_VLANID"
fi
if [ -z "$VLANID" -o -z "$RAW" ]; then
exit 1
fi
case "$MODE" in
start)
if ! $IP link show dev "$RAW" > /dev/null; then
echo "$RAW does not exist, unable to create $IFACE"
exit 1
fi
$IP link set up dev $RAW
$VCONFIG set_name_type "${NAME1}_PLUS_${NAME2}"
$VCONFIG add $RAW $VLANID
r=$?
# Yes this shouldn't be here.
if [ -n "$IF_HW_MAC_ADDRESS" ]; then
$IP link set $IFACE address $IF_HW_MAC_ADDRESS
fi
;;
stop)
$VCONFIG rem $IFACE
;;
esac
exit $r