From c28667cbd5e624e9a290174289ffb7920f37db38 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Fri, 26 Jun 2015 15:04:58 +0200 Subject: [PATCH] VLAN support via boot option "vlan=:" This provides support for something like: ip=10.10.10.42::10.10.10.1:255.255.255.0:grml:eth0:off vlan=301:eth0 to use VID 301 for device eth0. The implementation tries to be close to what dracut provides with its vlan boot option implementation, see http://thread.gmane.org/gmane.linux.kernel.initramfs/2685 Though we aren't 100% identical because we only use (e.g.: 3) instead of dract's (e.g.: VLAN_PLUS_VID (vlan0003), VLAN_PLUS_VID_NO_PAD (vlan3), DEV_PLUS_VID (eth0.0003), DEV_PLUS_VID_NO_PAD (eth0.3)) options but that might be an option once we can bring vlan support into initramfs-tools itself. The vlan-raw-device configuration option in /etc/network/interfaces isn't really needed technically, but we want to make the presence and usage of VLANs more obvious for its users. Development sponsored by Sipwise Gmbh --- components/9990-cmdline-old | 5 +++++ components/9990-grml-networking.sh | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/components/9990-cmdline-old b/components/9990-cmdline-old index d0659c8..521170f 100755 --- a/components/9990-cmdline-old +++ b/components/9990-cmdline-old @@ -266,6 +266,11 @@ Cmdline_old () UNIONTYPE="${_PARAMETER#union=}" export UNIONTYPE ;; + + vlan=*) + VLANS="${VLANS} ${_PARAMETER#vlan=}" + export VLANS + ;; esac done diff --git a/components/9990-grml-networking.sh b/components/9990-grml-networking.sh index f4031cd..ee80f5d 100644 --- a/components/9990-grml-networking.sh +++ b/components/9990-grml-networking.sh @@ -67,10 +67,39 @@ for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*; d method="dhcp" fi - cat >> $IFFILE << EOF + if [ -n "$VLANS" ] ; then + modprobe 8021q + + # vlan=: + for line in $(echo $VLANS | sed 's/ /\n'/) ; do + vlandev=${line#*:} + vlanid=${line%:*} + + if [ -n "$vlandev" ] && [ -n "$vlanid" ] ; then + case "$vlandev" in + "$interface") + vlan_raw_dev=$interface + interface="${vlandev}.${vlanid}" + ;; + esac + fi + done + fi + + if [ -n "$vlan_raw_dev" ] ; then + cat >> $IFFILE << EOF +auto ${interface} +iface ${interface} inet ${method} + vlan-raw-device $vlan_raw_dev +EOF + else + cat >> $IFFILE << EOF allow-hotplug ${interface} iface ${interface} inet ${method} EOF + fi + + unset vlandev vlanid vlan_raw_dev # unset variables to have clean state for next device # DNS for resolvconf and /etc/resolv.conf if [ -e "${netconfig}" ]; then -- 2.1.4