VLAN support via boot option "vlan=<vid>:<phydevice>"
authorMichael Prokop <mika@grml.org>
Fri, 26 Jun 2015 13:04:58 +0000 (15:04 +0200)
committerEvgeni Golov <evgeni@debian.org>
Fri, 26 Jun 2015 13:04:58 +0000 (15:04 +0200)
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 <vid>
(e.g.: 3) instead of dract's <vlanname> (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
components/9990-grml-networking.sh

index d0659c8..521170f 100755 (executable)
@@ -266,6 +266,11 @@ Cmdline_old ()
                                UNIONTYPE="${_PARAMETER#union=}"
                                export UNIONTYPE
                                ;;
+
+                       vlan=*)
+                               VLANS="${VLANS} ${_PARAMETER#vlan=}"
+                               export VLANS
+                               ;;
                esac
        done
 
index f4031cd..ee80f5d 100644 (file)
@@ -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=<vid>:<phydevice>
+      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