Skip to contentSkip to conversation

Add vlan support in network module

PATCH New Cong Wang 1 participant 7 messages May 22, 2012 1 message not in the archive

lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/7 Add vlan support in network module

From: Cong Wang <[email protected]>

This patch adds basic vlan support in network module.

The cmdline syntax for vlan is:

vlan=<vlanname>:<phydevice>

for an example:

        vlan=eth0.2:eth0

or

        vlan=vlan2:eth0

See the doc in patch 2/7.

Cc Dave Young <[email protected]>
Cc Harald Hoyer <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 modules.d/40network/ifup.sh         |   29 ++++++++++++++++++++++
 modules.d/40network/module-setup.sh |    3 ++
 modules.d/40network/net-genrules.sh |    5 ++++
 modules.d/40network/parse-vlan.sh   |   45 +++++++++++++++++++++++++++++++++++
 4 files changed, 82 insertions(+), 0 deletions(-)
 create mode 100644 modules.d/40network/parse-vlan.sh
modules.d/40network/ifup.sh +29 -0
index 71b869d..c03838f 100755
@@ -40,6 +40,17 @@ if [ -e /tmp/bridge.info ]; then
     fi
 fi
 
+if [ -e /tmp/vlan.info ]; then
+    . /tmp/vlan.info
+    if [ "$netif" = "$phydevice" ]; then
+        if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then
+            : # We need to really setup bond (recursive call)
+        else
+            netif="$vlanname"
+        fi
+    fi
+fi
+
 # disable manual ifup while netroot is set for simplifying our logic
 # in netroot case we prefer netroot to bringup $netif automaticlly
 [ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
@@ -178,6 +189,24 @@ if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.up ]; then
     brctl addif $bridgename $ethname
 fi
 
+get_vid() {
+    case "$1" in
+    vlan*)
+        return ${1#vlan}
+        ;;
+    *.*)
+        return ${1##*.}
+        ;;
+    esac
+}
+
+if [ "$netif" = "$vlanname" ] && [ ! -e /tmp/net.$vlanname.up ]; then
+    modprobe 8021q
+    ip link set "$phydevice" up
+    wait_for_if_up "$phydevice"
+    ip link add dev "$vlanname" link "$phydevice" type vlan id "$(get_vid $vlanname; echo $?)"
+fi
+
 # No ip lines default to dhcp
 ip=$(getarg ip)
 
modules.d/40network/module-setup.sh +3 -0
index d49b594..f28286c 100755
@@ -68,6 +68,8 @@ installkernel() {
     instmods ipv6
     # bonding
     instmods bonding
+    # vlan
+    instmods 8021q
 }
 
 install() {
@@ -82,6 +84,7 @@ install() {
     inst_hook pre-udev 50 "$moddir/ifname-genrules.sh"
     inst_hook pre-udev 60 "$moddir/net-genrules.sh"
     inst_hook cmdline 91 "$moddir/dhcp-root.sh"
+    inst_hook cmdline 95 "$moddir/parse-vlan.sh"
     inst_hook cmdline 96 "$moddir/parse-bond.sh"
     inst_hook cmdline 97 "$moddir/parse-bridge.sh"
     inst_hook cmdline 98 "$moddir/parse-ip-opts.sh"
modules.d/40network/net-genrules.sh +5 -0
index 7176681..142634e 100755
@@ -31,6 +31,11 @@ fix_bootif() {
         IFACES=${bondslaves%% *}
     fi
 
+    if [ -e /tmp/vlan.info ]; then
+        . /tmp/vlan.info
+        IFACES=$phydevice
+    fi
+
     ifup='/sbin/ifup $env{INTERFACE}'
     [ -z "$netroot" ] && ifup="$ifup -m"
 
modules.d/40network/parse-vlan.sh new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
1.7.7.6
author
#2 lore raw

PATCH 2/7 Add doc for vlan= cmdline

In reply to a message not in the archive

From: Cong Wang <[email protected]>

Document vlan= cmdline in dracut.cmdline(7).

Cc Dave Young <[email protected]>
Cc Harald Hoyer <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 dracut.cmdline.7.asc |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
dracut.cmdline.7.asc +5 -0
index 61cd139..95c6aea 100644
@@ -304,6 +304,11 @@ auto6::: do IPv6 autoconfiguration
 **rd.neednet=1**::
     boolean, bring up network even without netroot set
 
+**vlan=_<vlanname>_:_<phydevice>_**::
+    Setup vlan device named <vlanname> on <phydeivce>.
+    We support the four styles of vlan names: VLAN_PLUS_VID (vlan0005), VLAN_PLUS_VID_NO_PAD (vlan5),
+    DEV_PLUS_VID (eth0.0005), DEV_PLUS_VID_NO_PAD (eth0.5)
+
 NFS
 ~~~
 **root=**[_<server-ip>_:]_<root-dir>_[:_<nfs-options>_]::
Signature · 1 line
1.7.7.6
author
#3 lore raw

PATCH 3/7 Add doc for bond= cmdline

In reply to a message not in the archive

From: Cong Wang <[email protected]>

Document bond= cmdline in dracut.cmdline(7).

Cc Dave Young <[email protected]>
Cc Harald Hoyer <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 dracut.cmdline.7.asc |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
dracut.cmdline.7.asc +9 -0
index 95c6aea..79a4577 100644
@@ -309,6 +309,15 @@ auto6::: do IPv6 autoconfiguration
     We support the four styles of vlan names: VLAN_PLUS_VID (vlan0005), VLAN_PLUS_VID_NO_PAD (vlan5),
     DEV_PLUS_VID (eth0.0005), DEV_PLUS_VID_NO_PAD (eth0.5)
 
+**bond=_<bondname>_[:_<bondslaves>_:[:_<options>_]]**::
+    Setup bonding device <bondname> on top of <bondslaves>.
+    <bondslaves> is a comma-separated list of physical (ethernet) interfaces.
+    <options> is a comma-separated list on bonding options (modinfo bonding for details)
+    in format compatible with initscripts. If <options> includes multi-valued arp_ip_target option,
+    then its values should be separated by semicolon.
+    Bond without parameters assumes bond=bond0:eth0,eth1:mode=balance-rr
+
+
 NFS
 ~~~
 **root=**[_<server-ip>_:]_<root-dir>_[:_<nfs-options>_]::
Signature · 1 line
1.7.7.6
author
#4 lore raw

PATCH 4/7 Add doc for bridge= cmdline

In reply to a message not in the archive

From: Cong Wang <[email protected]>

Document bridge= cmdline in dracut.cmdline(7).

Cc Dave Young <[email protected]>
Cc Harald Hoyer <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 dracut.cmdline.7.asc |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
dracut.cmdline.7.asc +3 -0
index 79a4577..c131f1c 100644
@@ -317,6 +317,9 @@ auto6::: do IPv6 autoconfiguration
     then its values should be separated by semicolon.
     Bond without parameters assumes bond=bond0:eth0,eth1:mode=balance-rr
 
+**bridge=_<bridgename>_:_<ethname>_**::
+    Setup bridge <bridgename> with <ethname>. Bridge without parameters assumes bridge=br0:eth0
+
 
 NFS
 ~~~
Signature · 1 line
1.7.7.6
author
#5 lore raw

PATCH 5/7 Remove netroot check in cmdline parsing code

In reply to a message not in the archive

From: Cong Wang <[email protected]>

Relax the rules for kdump, we don't specify netroot in kdump.

Cc Dave Young <[email protected]>
Cc Harald Hoyer <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 modules.d/40network/parse-bond.sh   |    3 ---
 modules.d/40network/parse-bridge.sh |    3 ---
 modules.d/40network/parse-vlan.sh   |    3 ---
 3 files changed, 0 insertions(+), 9 deletions(-)
modules.d/40network/parse-bond.sh +0 -3
index ae0ae97..5822685 100755
@@ -15,9 +15,6 @@
 
 # Check if bond parameter is valid
 if getarg bond= >/dev/null ; then
-    if [ -z "$netroot" ] ; then
-        die "No netboot configured, bond is invalid"
-    fi
     command -v ifenslave >/dev/null 2>&1 || die "No 'ifenslave' installed"
 fi
 
modules.d/40network/parse-bridge.sh +0 -3
index aaa5a54..6e1fee1 100755
@@ -13,9 +13,6 @@
 
 # Check if bridge parameter is valid
 if getarg bridge= >/dev/null ; then
-    if [ -z "$netroot" ] ; then
-        die "No netboot configured, bridge is invalid"
-    fi
     command -v brctl >/dev/null 2>&1 || die "No 'brctl' installed" 
 fi
 
modules.d/40network/parse-vlan.sh +0 -3
index 60b09d8..3ba2289 100644
@@ -9,9 +9,6 @@
 
 # Check if vlan parameter is valid
 if getarg vlan= >/dev/null ; then
-    if [ -z "$netroot" ] ; then
-        die "No netboot configured, vlan is invalid"
-    fi
     :
 fi
 
Signature · 1 line
1.7.7.6
author
#6 lore raw

PATCH 6/7 Do not use ifenslave

In reply to a message not in the archive

From: Cong Wang <[email protected]>

ifenslave could be dropped, use the /sys interface.

Cc Dave Young <[email protected]>
Cc Harald Hoyer <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 modules.d/40network/ifup.sh         |    2 +-
 modules.d/40network/module-setup.sh |    2 +-
 modules.d/40network/parse-bond.sh   |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
modules.d/40network/ifup.sh +1 -1
index c03838f..1aaa1a8 100755
@@ -156,7 +156,7 @@ if [ -e /tmp/bond.info ]; then
 
         for slave in $bondslaves ; do
             ip link set $slave down
-            ifenslave $bondname $slave
+            echo "+$slave" > /sys/class/net/$bondname/bonding/slaves
             ip link set $slave up
             wait_for_if_up $slave
         done
modules.d/40network/module-setup.sh +1 -1
index f28286c..da58521 100755
@@ -75,7 +75,7 @@ installkernel() {
 install() {
     local _arch _i _dir
     dracut_install ip arping tr dhclient
-    dracut_install -o brctl ifenslave
+    dracut_install -o brctl
     inst "$moddir/ifup.sh" "/sbin/ifup"
     inst "$moddir/netroot.sh" "/sbin/netroot"
     inst "$moddir/dhclient-script.sh" "/sbin/dhclient-script"
modules.d/40network/parse-bond.sh +1 -1
index 5822685..933ad27 100755
@@ -15,7 +15,7 @@
 
 # Check if bond parameter is valid
 if getarg bond= >/dev/null ; then
-    command -v ifenslave >/dev/null 2>&1 || die "No 'ifenslave' installed"
+    :
 fi
 
 # We translate list of slaves to space-separated here to mwke it easier to loop over them in ifup
Signature · 1 line
1.7.7.6
author
#7 lore raw

PATCH 7/7 Avoid generating udev rules for master interfaces

In reply to a message not in the archive

From: Cong Wang <[email protected]>

Vlan/bridge/bonding device has the same mac address with its underlying physical device, if we generate udev rules for vlan NIC too, its physical device name will be override.

This looks a little ugly, but I can't find any better way to handle this.

Cc Dave Young <[email protected]>
Cc Harald Hoyer <[email protected]>
Cc Vivek Goyal <[email protected]>
---
 modules.d/40network/ifname-genrules.sh |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
modules.d/40network/ifname-genrules.sh +7 -1
index e188c88..89621a2 100755
@@ -8,9 +8,15 @@ if ! getarg ifname= >/dev/null ; then
 fi
 
 {
+    [ -e /tmp/vlan.info ] && source /tmp/vlan.info
+    [ -e /tmp/bridge.info ] && source /tmp/bridge.info
+    [ -e /tmp/bond.info ] && source /tmp/bond.info
     for p in $(getargs ifname=); do
         parse_ifname_opts $p
-        printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", ATTR{type}=="1", NAME="%s"\n' "$ifname_mac" "$ifname_if"
+        #Hack: vlan, bridge, bonding devices may have the same mac address with its physical device
+        if [ "$ifname_if" != "$vlanname" ] && [ "$ifname_if" != "$bridgename" ] && [ "$ifname_if" != "$bondname" ]; then
+            printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", ATTR{type}=="1", NAME="%s"\n' "$ifname_mac" "$ifname_if"
+        fi
     done
 
     # Rename non named interfaces out of the way for named ones.
Signature · 1 line
1.7.7.6