Blame SOURCES/0433-network-support-multiple-vlan-team-bridge-and-bond.patch

18971c
From 7a90c8b3434a27a347f6a963d0e673e04feb485a Mon Sep 17 00:00:00 2001
18971c
From: Harald Hoyer <harald@redhat.com>
18971c
Date: Mon, 4 Jul 2016 11:31:49 +0200
18971c
Subject: [PATCH] network: support multiple vlan, team, bridge and bond
18971c
18971c
---
18971c
 modules.d/40network/ifup.sh         | 386 ++++++++++++++--------------
18971c
 modules.d/40network/net-genrules.sh |  27 +-
18971c
 modules.d/40network/net-lib.sh      |   9 +-
18971c
 modules.d/40network/parse-bridge.sh |  30 +--
18971c
 modules.d/40network/parse-team.sh   |  47 +---
18971c
 modules.d/40network/parse-vlan.sh   |  27 +-
18971c
 modules.d/45ifcfg/write-ifcfg.sh    |  26 +-
18971c
 7 files changed, 254 insertions(+), 298 deletions(-)
18971c
18971c
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
18971c
index cedf9a77..d7503c7f 100755
18971c
--- a/modules.d/40network/ifup.sh
18971c
+++ b/modules.d/40network/ifup.sh
18971c
@@ -17,79 +17,12 @@ type ip_to_var >/dev/null 2>&1 || . /lib/net-lib.sh
18971c
 
18971c
 # $netif reads easier than $1
18971c
 netif=$1
18971c
-use_bridge='false'
18971c
-use_vlan='false'
18971c
 
18971c
-# enslave this interface to bond?
18971c
-for i in /tmp/bond.*.info; do
18971c
-    [ -e "$i" ] || continue
18971c
-    unset bondslaves
18971c
-    unset bondname
18971c
-    . "$i"
18971c
-    for slave in $bondslaves ; do
18971c
-        if [ "$netif" = "$slave" ] ; then
18971c
-            netif=$bondname
18971c
-            break 2
18971c
-        fi
18971c
-    done
18971c
-done
18971c
-
18971c
-for i in /tmp/team.*.info; do
18971c
-    [ -e "$i" ] || continue
18971c
-    unset teamslaves
18971c
-    unset teammaster
18971c
-    . "$i"
18971c
-    for slave in $teamslaves ; do
18971c
-        if [ "$netif" = "$slave" ] ; then
18971c
-            netif=$teammaster
18971c
-        fi
18971c
-    done
18971c
-done
18971c
-
18971c
-if [ -e /tmp/vlan.info ]; then
18971c
-    . /tmp/vlan.info
18971c
-    if [ "$netif" = "$phydevice" ]; then
18971c
-        if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then
18971c
-            : # We need to really setup bond (recursive call)
18971c
-        elif [ "$netif" = "$teammaster" ] && [ -n "$DO_TEAM_SETUP" ] ; then
18971c
-            : # We need to really setup team (recursive call)
18971c
-        else
18971c
-            netif="$vlanname"
18971c
-            use_vlan='true'
18971c
-        fi
18971c
-    fi
18971c
-fi
18971c
-
18971c
-# bridge this interface?
18971c
-if [ -e /tmp/bridge.info ]; then
18971c
-    . /tmp/bridge.info
18971c
-    for ethname in $bridgeslaves ; do
18971c
-        if [ "$netif" = "$ethname" ]; then
18971c
-            if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then
18971c
-                : # We need to really setup bond (recursive call)
18971c
-            elif [ "$netif" = "$teammaster" ] && [ -n "$DO_TEAM_SETUP" ] ; then
18971c
-                : # We need to really setup team (recursive call)
18971c
-            elif [ "$netif" = "$vlanname" ] && [ -n "$DO_VLAN_SETUP" ]; then
18971c
-                : # We need to really setup vlan (recursive call)
18971c
-            else
18971c
-                netif="$bridgename"
18971c
-                use_bridge='true'
18971c
-            fi
18971c
-        fi
18971c
-    done
18971c
-fi
18971c
-
18971c
-# disable manual ifup while netroot is set for simplifying our logic
18971c
-# in netroot case we prefer netroot to bringup $netif automaticlly
18971c
-[ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
18971c
-
18971c
-if [ -n "$manualup" ]; then
18971c
-    >/tmp/net.$netif.manualup
18971c
-    rm -f /tmp/net.${netif}.did-setup
18971c
-else
18971c
-    [ -e /tmp/net.${netif}.did-setup ] && exit 0
18971c
-    [ -e /sys/class/net/$netif/address ] && \
18971c
-        [ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && exit 0
18971c
+# loopback is always handled the same way
18971c
+if [ "$netif" = "lo" ] ; then
18971c
+    ip link set lo up
18971c
+    ip addr add 127.0.0.1/8 dev lo
18971c
+    exit 0
18971c
 fi
18971c
 
18971c
 # Run dhclient
18971c
@@ -199,158 +132,213 @@ do_static() {
18971c
     return 0
18971c
 }
18971c
 
18971c
-# loopback is always handled the same way
18971c
-if [ "$netif" = "lo" ] ; then
18971c
-    ip link set lo up
18971c
-    ip addr add 127.0.0.1/8 dev lo
18971c
+get_vid() {
18971c
+    case "$1" in
18971c
+    vlan*)
18971c
+        echo ${1#vlan}
18971c
+        ;;
18971c
+    *.*)
18971c
+        echo ${1##*.}
18971c
+        ;;
18971c
+    esac
18971c
+}
18971c
+
18971c
+# check, if we need VLAN's for this interface
18971c
+if [ -z "$DO_VLAN_PHY" ] && [ -e /tmp/vlan.${netif}.phy ]; then
18971c
+    unset DO_VLAN
18971c
+    NO_AUTO_DHCP=yes DO_VLAN_PHY=yes ifup "$netif"
18971c
+    modprobe -b -q 8021q
18971c
+
18971c
+    for i in /tmp/vlan.*.${netif}; do
18971c
+        [ -e "$i" ] || continue
18971c
+        read vlanname < "$i"
18971c
+        if [ -n "$vlanname" ]; then
18971c
+            linkup "$netif"
18971c
+            ip link add dev "$vlanname" link "$netif" type vlan id "$(get_vid $vlanname)"
18971c
+            ifup "$vlanname"
18971c
+        fi
18971c
+    done
18971c
     exit 0
18971c
 fi
18971c
 
18971c
-# start bond if needed
18971c
-if [ -e /tmp/bond.${netif}.info ]; then
18971c
-    . /tmp/bond.${netif}.info
18971c
+# Check, if interface is VLAN interface
18971c
+if ! [ -e /tmp/vlan.${netif}.phy ]; then
18971c
+    for i in /tmp/vlan.${netif}.*; do
18971c
+        [ -e "$i" ] || continue
18971c
+        export DO_VLAN=yes
18971c
+        break
18971c
+    done
18971c
+fi
18971c
 
18971c
-    if [ "$netif" = "$bondname" ] && [ ! -e /tmp/net.$bondname.setup ] ; then # We are master bond device
18971c
-        modprobe bonding
18971c
-        udevadm settle
18971c
-        if ! [ -e /sys/class/net/${netif} ]; then
18971c
-            echo "+$netif" >  /sys/class/net/bonding_masters
18971c
-        fi
18971c
-        ip link set $netif down
18971c
-
18971c
-        # Stolen from ifup-eth
18971c
-        # add the bits to setup driver parameters here
18971c
-        for arg in $bondoptions ; do
18971c
-            key=${arg%%=*};
18971c
-            value=${arg##*=};
18971c
-            # %{value:0:1} is replaced with non-bash specific construct
18971c
-            if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then
18971c
-                OLDIFS=$IFS;
18971c
-                IFS=',';
18971c
-                for arp_ip in $value; do
18971c
-                    echo +$arp_ip > /sys/class/net/${netif}/bonding/$key
18971c
-                done
18971c
-                IFS=$OLDIFS;
18971c
-            else
18971c
-                echo $value > /sys/class/net/${netif}/bonding/$key
18971c
+# bridge this interface?
18971c
+if [ -z "$NO_BRIDGE_MASTER" ]; then
18971c
+    for i in /tmp/bridge.*.info; do
18971c
+        [ -e "$i" ] || continue
18971c
+        unset bridgeslaves
18971c
+        unset bridgename
18971c
+        . "$i"
18971c
+        for ethname in $bridgeslaves ; do
18971c
+            [ "$netif" != "$ethname" ] && continue
18971c
+
18971c
+            NO_BRIDGE_MASTER=yes NO_AUTO_DHCP=yes ifup $ethname
18971c
+            linkup $ethname
18971c
+            if [ ! -e /tmp/bridge.$bridgename.up ]; then
18971c
+                brctl addbr $bridgename
18971c
+                brctl setfd $bridgename 0
18971c
+                > /tmp/bridge.$bridgename.up
18971c
             fi
18971c
+            brctl addif $bridgename $ethname
18971c
+            ifup $bridgename
18971c
+            exit 0
18971c
         done
18971c
+    done
18971c
+fi
18971c
 
18971c
-        linkup $netif
18971c
-
18971c
+# enslave this interface to bond?
18971c
+if [ -z "$NO_BOND_MASTER" ]; then
18971c
+    for i in /tmp/bond.*.info; do
18971c
+        [ -e "$i" ] || continue
18971c
+        unset bondslaves
18971c
+        unset bondname
18971c
+        . "$i"
18971c
         for slave in $bondslaves ; do
18971c
-            ip link set $slave down
18971c
-            cat /sys/class/net/$slave/address > /tmp/net.${netif}.${slave}.hwaddr
18971c
-            echo "+$slave" > /sys/class/net/$bondname/bonding/slaves
18971c
-            linkup $slave
18971c
-        done
18971c
+            [ "$netif" != "$slave" ] && continue
18971c
 
18971c
-        # add the bits to setup the needed post enslavement parameters
18971c
-        for arg in $BONDING_OPTS ; do
18971c
-            key=${arg%%=*};
18971c
-            value=${arg##*=};
18971c
-            if [ "${key}" = "primary" ]; then
18971c
-                echo $value > /sys/class/net/${netif}/bonding/$key
18971c
-            fi
18971c
+            # already setup
18971c
+            [ -e /tmp/bond.$bondname.up ] && exit 0
18971c
+
18971c
+            # wait for all slaves to show up
18971c
+            for slave in $bondslaves ; do
18971c
+                # try to create the slave (maybe vlan or bridge)
18971c
+                NO_BOND_MASTER=yes NO_AUTO_DHCP=yes ifup $slave
18971c
+
18971c
+                if ! ip link show dev $slave >/dev/null 2>&1; then
18971c
+                    # wait for the last slave to show up
18971c
+                    exit 0
18971c
+                fi
18971c
+            done
18971c
+
18971c
+            modprobe -q -b bonding
18971c
+            echo "+$bondname" >  /sys/class/net/bonding_masters 2>/dev/null
18971c
+            ip link set $bondname down
18971c
+
18971c
+            # Stolen from ifup-eth
18971c
+            # add the bits to setup driver parameters here
18971c
+            for arg in $bondoptions ; do
18971c
+                key=${arg%%=*};
18971c
+                value=${arg##*=};
18971c
+                # %{value:0:1} is replaced with non-bash specific construct
18971c
+                if [ "${key}" = "arp_ip_target" -a "${#value}" != "0" -a "+${value%%+*}" != "+" ]; then
18971c
+                    OLDIFS=$IFS;
18971c
+                    IFS=',';
18971c
+                    for arp_ip in $value; do
18971c
+                        echo +$arp_ip > /sys/class/net/${bondname}/bonding/$key
18971c
+                    done
18971c
+                    IFS=$OLDIFS;
18971c
+                else
18971c
+                    echo $value > /sys/class/net/${bondname}/bonding/$key
18971c
+                fi
18971c
+            done
18971c
+
18971c
+            linkup $bondname
18971c
+
18971c
+            for slave in $bondslaves ; do
18971c
+                cat /sys/class/net/$slave/address > /tmp/net.${bondname}.${slave}.hwaddr
18971c
+                ip link set $slave down
18971c
+                echo "+$slave" > /sys/class/net/$bondname/bonding/slaves
18971c
+                linkup $slave
18971c
+            done
18971c
+
18971c
+            # add the bits to setup the needed post enslavement parameters
18971c
+            for arg in $bondoptions ; do
18971c
+                key=${arg%%=*};
18971c
+                value=${arg##*=};
18971c
+                if [ "${key}" = "primary" ]; then
18971c
+                    echo $value > /sys/class/net/${bondname}/bonding/$key
18971c
+                fi
18971c
+            done
18971c
+
18971c
+            > /tmp/bond.$bondname.up
18971c
+
18971c
+            NO_BOND_MASTER=yes ifup $bondname
18971c
+            exit $?
18971c
         done
18971c
-        > /tmp/net.$bondname.setup
18971c
-    fi
18971c
+    done
18971c
 fi
18971c
 
18971c
-if [ -e /tmp/team.${netif}.info ]; then
18971c
-    . /tmp/team.${netif}.info
18971c
-    if [ "$netif" = "$teammaster" ] && [ ! -e /tmp/net.$teammaster.setup ] ; then
18971c
-        # We shall only bring up those _can_ come up
18971c
-        # in case of some slave is gone in active-backup mode
18971c
-        working_slaves=""
18971c
+if [ -z "$NO_TEAM_MASTER" ]; then
18971c
+    for i in /tmp/team.*.info; do
18971c
+        [ -e "$i" ] || continue
18971c
+        unset teammaster
18971c
+        unset teamslaves
18971c
+        . "$i"
18971c
         for slave in $teamslaves ; do
18971c
-            teamdctl ${teammaster} port present ${slave} 2>/dev/null \
18971c
-                     && continue
18971c
-            ip link set dev $slave up 2>/dev/null
18971c
-            if wait_for_if_up $slave; then
18971c
-                working_slaves+="$slave "
18971c
-            fi
18971c
-        done
18971c
-        # Do not add slaves now
18971c
-        teamd -d -U -n -N -t $teammaster -f /etc/teamd/$teammaster.conf
18971c
-        for slave in $working_slaves; do
18971c
-            # team requires the slaves to be down before joining team
18971c
-            ip link set dev $slave down
18971c
-            (
18971c
-                unset TEAM_PORT_CONFIG
18971c
-                _hwaddr=$(cat /sys/class/net/$slave/address)
18971c
-                _subchannels=$(iface_get_subchannels "$slave")
18971c
-                if [ -n "$_hwaddr" ] && [ -e "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf" ]; then
18971c
-                    . "/etc/sysconfig/network-scripts/mac-${_hwaddr}.conf"
18971c
-                elif [ -n "$_subchannels" ] && [ -e "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf" ]; then
18971c
-                    . "/etc/sysconfig/network-scripts/ccw-${_subchannels}.conf"
18971c
-                elif [ -e "/etc/sysconfig/network-scripts/ifcfg-${slave}" ]; then
18971c
-                    . "/etc/sysconfig/network-scripts/ifcfg-${slave}"
18971c
-                fi
18971c
+            [ "$netif" != "$slave" ] && continue
18971c
+
18971c
+            [ -e /tmp/team.$teammaster.up ] && exit 0
18971c
 
18971c
-                if [ -n "${TEAM_PORT_CONFIG}" ]; then
18971c
-                    /usr/bin/teamdctl ${teammaster} port config update ${slave} "${TEAM_PORT_CONFIG}"
18971c
+            # wait for all slaves to show up
18971c
+            for slave in $teamslaves ; do
18971c
+                # try to create the slave (maybe vlan or bridge)
18971c
+                NO_BOND_MASTER=yes NO_AUTO_DHCP=yes ifup $slave
18971c
+
18971c
+                if ! ip link show dev $slave >/dev/null 2>&1; then
18971c
+                    # wait for the last slave to show up
18971c
+                    exit 0
18971c
                 fi
18971c
-            )
18971c
-            teamdctl $teammaster port add $slave
18971c
-        done
18971c
-        ip link set dev $teammaster up
18971c
-        > /tmp/net.$teammaster.setup
18971c
-    fi
18971c
-fi
18971c
+            done
18971c
+
18971c
+            if [ ! -e /tmp/team.$teammaster.up ] ; then
18971c
+                # We shall only bring up those _can_ come up
18971c
+                # in case of some slave is gone in active-backup mode
18971c
+                working_slaves=""
18971c
+                for slave in $teamslaves ; do
18971c
+                    ip link set $slave up 2>/dev/null
18971c
+                    if wait_for_if_up $slave; then
18971c
+                        working_slaves="$working_slaves$slave "
18971c
+                    fi
18971c
+                done
18971c
+                # Do not add slaves now
18971c
+                teamd -d -U -n -N -t $teammaster -f /etc/teamd/$teammaster.conf
18971c
+                for slave in $working_slaves; do
18971c
+                    # team requires the slaves to be down before joining team
18971c
+                    ip link set $slave down
18971c
+                    teamdctl $teammaster port add $slave
18971c
+                done
18971c
 
18971c
-# XXX need error handling like dhclient-script
18971c
+                ip link set $teammaster up
18971c
 
18971c
-if [ -e /tmp/bridge.info ]; then
18971c
-    . /tmp/bridge.info
18971c
-# start bridge if necessary
18971c
-    if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.setup ]; then
18971c
-        brctl addbr $bridgename
18971c
-        brctl setfd $bridgename 0
18971c
-        for ethname in $bridgeslaves ; do
18971c
-            if [ "$ethname" = "$bondname" ] ; then
18971c
-                DO_BOND_SETUP=yes ifup $bondname -m
18971c
-            elif [ "$ethname" = "$teammaster" ] ; then
18971c
-                DO_TEAM_SETUP=yes ifup $teammaster -m
18971c
-            elif [ "$ethname" = "$vlanname" ]; then
18971c
-                DO_VLAN_SETUP=yes ifup $vlanname -m
18971c
-            else
18971c
-                linkup $ethname
18971c
+                > /tmp/team.$teammaster.up
18971c
+                NO_TEAM_MASTER=yes ifup $teammaster
18971c
+                exit $?
18971c
             fi
18971c
-            brctl addif $bridgename $ethname
18971c
         done
18971c
-        > /tmp/net.$bridgename.setup
18971c
-    fi
18971c
+    done
18971c
 fi
18971c
 
18971c
-get_vid() {
18971c
-    case "$1" in
18971c
-    vlan*)
18971c
-        echo ${1#vlan}
18971c
-        ;;
18971c
-    *.*)
18971c
-        echo ${1##*.}
18971c
-        ;;
18971c
-    esac
18971c
-}
18971c
+# all synthetic interfaces done.. now check if the interface is available
18971c
+if ! ip link show dev $netif >/dev/null 2>&1; then
18971c
+    exit 1
18971c
+fi
18971c
 
18971c
-if [ "$netif" = "$vlanname" ] && [ ! -e /tmp/net.$vlanname.up ]; then
18971c
-    modprobe 8021q
18971c
-    if [ "$phydevice" = "$bondname" ] ; then
18971c
-        DO_BOND_SETUP=yes ifup $phydevice -m
18971c
-    elif [ "$phydevice" = "$teammaster" ] ; then
18971c
-        DO_TEAM_SETUP=yes ifup $phydevice -m
18971c
-    else
18971c
-        linkup "$phydevice"
18971c
-    fi
18971c
-    ip link add dev "$vlanname" link "$phydevice" type vlan id "$(get_vid $vlanname)"
18971c
-    ip link set "$vlanname" up
18971c
+# disable manual ifup while netroot is set for simplifying our logic
18971c
+# in netroot case we prefer netroot to bringup $netif automaticlly
18971c
+[ -n "$2" -a "$2" = "-m" ] && [ -z "$netroot" ] && manualup="$2"
18971c
+
18971c
+if [ -n "$manualup" ]; then
18971c
+    >/tmp/net.$netif.manualup
18971c
+    rm -f /tmp/net.${netif}.did-setup
18971c
+else
18971c
+    [ -e /tmp/net.${netif}.did-setup ] && exit 0
18971c
+    [ -z "$DO_VLAN" ] && \
18971c
+        [ -e /sys/class/net/$netif/address ] && \
18971c
+        [ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && exit 0
18971c
 fi
18971c
 
18971c
 # No ip lines default to dhcp
18971c
 ip=$(getarg ip)
18971c
 
18971c
-if [ -z "$ip" ]; then
18971c
+if [ -z "$NO_AUTO_DHCP" ] && [ -z "$ip" ]; then
18971c
     if [ "$netroot" = "dhcp6" ]; then
18971c
         do_dhcp -6
18971c
     else
18971c
@@ -415,7 +403,7 @@ for p in $(getargs ip=); do
18971c
     if [ $ret -eq 0 ]; then
18971c
         > /tmp/net.${netif}.up
18971c
 
18971c
-        if [ -e /sys/class/net/${netif}/address ]; then
18971c
+        if [ -z "$DO_VLAN" ] && [ -e /sys/class/net/${netif}/address ]; then
18971c
             > /tmp/net.$(cat /sys/class/net/${netif}/address).up
18971c
         fi
18971c
 
18971c
@@ -444,7 +432,7 @@ if [ -n "$DO_BOND_SETUP" -o -n "$DO_TEAM_SETUP" -o -n "$DO_VLAN_SETUP" ]; then
18971c
 fi
18971c
 
18971c
 # no ip option directed at our interface?
18971c
-if [ ! -e /tmp/net.${netif}.up ]; then
18971c
+if  [ -z "$NO_AUTO_DHCP" ] && [ ! -e /tmp/net.${netif}.up ]; then
18971c
     if [ -e /tmp/net.bootdev ]; then
18971c
         BOOTDEV=$(cat /tmp/net.bootdev)
18971c
         if [ "$netif" = "$BOOTDEV" ] || [ "$BOOTDEV" = "$(cat /sys/class/net/${netif}/address)" ]; then
18971c
diff --git a/modules.d/40network/net-genrules.sh b/modules.d/40network/net-genrules.sh
18971c
index 526dd5cf..08072fbe 100755
18971c
--- a/modules.d/40network/net-genrules.sh
18971c
+++ b/modules.d/40network/net-genrules.sh
18971c
@@ -1,6 +1,4 @@
18971c
 #!/bin/sh
18971c
-# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
18971c
-# ex: ts=8 sw=4 sts=4 et filetype=sh
18971c
 
18971c
 getargbool 0 rd.neednet && NEEDNET=1
18971c
 
18971c
@@ -14,11 +12,14 @@ command -v fix_bootif >/dev/null || . /lib/net-lib.sh
18971c
 # Write udev rules
18971c
 {
18971c
     # bridge: attempt only the defined interface
18971c
-    if [ -e /tmp/bridge.info ]; then
18971c
-        . /tmp/bridge.info
18971c
+    for i in /tmp/bridge.*.info; do
18971c
+        [ -e "$i" ] || continue
18971c
+        unset bridgeslaves
18971c
+        unset bridgename
18971c
+        . "$i"
18971c
         RAW_IFACES="$RAW_IFACES $bridgeslaves"
18971c
         MASTER_IFACES="$MASTER_IFACES $bridgename"
18971c
-    fi
18971c
+    done
18971c
 
18971c
     # bond: attempt only the defined interface (override bridge defines)
18971c
     for i in /tmp/bond.*.info; do
18971c
@@ -40,11 +41,19 @@ command -v fix_bootif >/dev/null || . /lib/net-lib.sh
18971c
         MASTER_IFACES="$MASTER_IFACES ${teammaster}"
18971c
     done
18971c
 
18971c
-    if [ -e /tmp/vlan.info ]; then
18971c
-        . /tmp/vlan.info
18971c
+    for j in /tmp/vlan.*.phy; do
18971c
+        [ -e "$j" ] || continue
18971c
+        unset phydevice
18971c
+	read phydevice < "$j"
18971c
         RAW_IFACES="$RAW_IFACES $phydevice"
18971c
-        MASTER_IFACES="$MASTER_IFACES ${vlanname}"
18971c
-    fi
18971c
+        for i in /tmp/vlan.*.${phydevice}; do
18971c
+            [ -e "$i" ] || continue
18971c
+            unset vlanname
18971c
+	    read vlanname < "$i"
18971c
+            MASTER_IFACES="$MASTER_IFACES ${vlanname}"
18971c
+        done
18971c
+    done
18971c
+
18971c
     MASTER_IFACES="$(trim "$MASTER_IFACES")"
18971c
     RAW_IFACES="$(trim "$RAW_IFACES")"
18971c
 
18971c
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
18971c
index 71201938..de334d98 100755
18971c
--- a/modules.d/40network/net-lib.sh
18971c
+++ b/modules.d/40network/net-lib.sh
18971c
@@ -102,7 +102,8 @@ ifdown() {
18971c
     ip addr flush dev $netif
18971c
     echo "#empty" > /etc/resolv.conf
18971c
     rm -f -- /tmp/net.$netif.did-setup
18971c
-    [ -e /sys/class/net/$netif/address ] && \
18971c
+    [ -z "$DO_VLAN" ] && \
18971c
+        [ -e /sys/class/net/$netif/address ] && \
18971c
         rm -f -- /tmp/net.$(cat /sys/class/net/$netif/address).did-setup
18971c
     # TODO: send "offline" uevent?
18971c
 }
18971c
@@ -111,7 +112,8 @@ setup_net() {
18971c
     local netif="$1" f="" gw_ip="" netroot_ip="" iface="" IFACES=""
18971c
     local _p
18971c
     [ -e /tmp/net.$netif.did-setup ] && return
18971c
-    [ -e /sys/class/net/$netif/address ] && \
18971c
+    [ -z "$DO_VLAN" ] && \
18971c
+        [ -e /sys/class/net/$netif/address ] && \
18971c
         [ -e /tmp/net.$(cat /sys/class/net/$netif/address).did-setup ] && return
18971c
     [ -e "/tmp/net.ifaces" ] && read IFACES < /tmp/net.ifaces
18971c
     [ -z "$IFACES" ] && IFACES="$netif"
18971c
@@ -168,7 +170,8 @@ setup_net() {
18971c
     unset layer2
18971c
 
18971c
     > /tmp/net.$netif.did-setup
18971c
-    [ -e /sys/class/net/$netif/address ] && \
18971c
+    [ -z "$DO_VLAN" ] && \
18971c
+        [ -e /sys/class/net/$netif/address ] && \
18971c
         > /tmp/net.$(cat /sys/class/net/$netif/address).did-setup
18971c
 }
18971c
 
18971c
diff --git a/modules.d/40network/parse-bridge.sh b/modules.d/40network/parse-bridge.sh
18971c
index a9101094..5c3af292 100755
18971c
--- a/modules.d/40network/parse-bridge.sh
18971c
+++ b/modules.d/40network/parse-bridge.sh
18971c
@@ -1,6 +1,4 @@
18971c
 #!/bin/sh
18971c
-# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
18971c
-# ex: ts=8 sw=4 sts=4 et filetype=sh
18971c
 #
18971c
 # Format:
18971c
 #       bridge=<bridgename>:<bridgeslaves>
18971c
@@ -9,14 +7,6 @@
18971c
 #       bridge without parameters assumes bridge=br0:eth0
18971c
 #
18971c
 
18971c
-# return if bridge already parsed
18971c
-[ -n "$bridgename" ] && return
18971c
-
18971c
-# Check if bridge parameter is valid
18971c
-if getarg bridge= >/dev/null ; then
18971c
-    command -v brctl >/dev/null 2>&1 || die "No 'brctl' installed" 
18971c
-fi
18971c
-
18971c
 parsebridge() {
18971c
     local v=${1}:
18971c
     set --
18971c
@@ -24,8 +14,6 @@ parsebridge() {
18971c
         set -- "$@" "${v%%:*}"
18971c
         v=${v#*:}
18971c
     done
18971c
-
18971c
-    unset bridgename bridgeslaves
18971c
     case $# in
18971c
         0)  bridgename=br0; bridgeslaves=$iface ;;
18971c
         1)  die "bridge= requires two parameters" ;;
18971c
@@ -34,14 +22,13 @@ parsebridge() {
18971c
     esac
18971c
 }
18971c
 
18971c
-unset bridgename bridgeslaves
18971c
-
18971c
-iface=eth0
18971c
-
18971c
 # Parse bridge for bridgename and bridgeslaves
18971c
-if bridge="$(getarg bridge)"; then
18971c
+for bridge in $(getargs bridge=); do
18971c
+    unset bridgename
18971c
+    unset bridgeslaves
18971c
+    iface=eth0
18971c
     # Read bridge= parameters if they exist
18971c
-    if [ -n "$bridge" ]; then
18971c
+    if [ "$bridge" != "bridge" ]; then
18971c
         parsebridge $bridge
18971c
     fi
18971c
     # Simple default bridge
18971c
@@ -49,7 +36,6 @@ if bridge="$(getarg bridge)"; then
18971c
         bridgename=br0
18971c
         bridgeslaves=$iface
18971c
     fi
18971c
-    echo "bridgename=$bridgename" > /tmp/bridge.info
18971c
-    echo "bridgeslaves=\"$bridgeslaves\"" >> /tmp/bridge.info
18971c
-    return
18971c
-fi
18971c
+    echo "bridgename=$bridgename" > /tmp/bridge.${bridgename}.info
18971c
+    echo "bridgeslaves=\"$bridgeslaves\"" >> /tmp/bridge.${bridgename}.info
18971c
+done
18971c
diff --git a/modules.d/40network/parse-team.sh b/modules.d/40network/parse-team.sh
18971c
index a836d688..136c3705 100755
18971c
--- a/modules.d/40network/parse-team.sh
18971c
+++ b/modules.d/40network/parse-team.sh
18971c
@@ -6,14 +6,6 @@
18971c
 #       teamslaves is a comma-separated list of physical (ethernet) interfaces
18971c
 #
18971c
 
18971c
-# return if team already parsed
18971c
-[ -n "$teammaster" ] && return
18971c
-
18971c
-# Check if team parameter is valid
18971c
-if getarg team= >/dev/null ; then
18971c
-    :
18971c
-fi
18971c
-
18971c
 parseteam() {
18971c
     local v=${1}:
18971c
     set --
18971c
@@ -22,33 +14,22 @@ parseteam() {
18971c
         v=${v#*:}
18971c
     done
18971c
 
18971c
-    unset teammaster teamslaves
18971c
     case $# in
18971c
-        2)  teammaster=$1; teamslaves=$(str_replace "$2" "," " ") ;;
18971c
-        *)  warn "team= requires two parameters"; return 1;;
18971c
+    2)  teammaster=$1; teamslaves=$(str_replace "$2" "," " ") ;;
18971c
+    *)  die "team= requires two parameters" ;;
18971c
     esac
18971c
-    return 0
18971c
 }
18971c
 
18971c
-unset teammaster teamslaves
18971c
-
18971c
-if getarg team>/dev/null; then
18971c
-    # Read team= parameters if they exist
18971c
-    for team in $(getargs team); do
18971c
-        [ "$team" = "team" ] && continue
18971c
-
18971c
-        unset teammaster
18971c
-        unset teamslaves
18971c
 
18971c
-        parseteam "$team" || continue
18971c
-
18971c
-        echo "teammaster=$teammaster" > /tmp/team.${teammaster}.info
18971c
-        echo "teamslaves=\"$teamslaves\"" >> /tmp/team.${teammaster}.info
18971c
-
18971c
-        if ! [ -e /etc/teamd/${teammaster}.conf ]; then
18971c
-            warn "Team master $teammaster specified, but no /etc/teamd/$teammaster.conf present. Using activebackup."
18971c
-            mkdir -p /etc/teamd
18971c
-            printf -- "%s" '{"runner": {"name": "activebackup"}, "link_watch": {"name": "ethtool"}}' > "/etc/teamd/${teammaster}.conf"
18971c
-        fi
18971c
-    done
18971c
-fi
18971c
+for team in $(getargs team=); do
18971c
+    unset teammaster teamslaves
18971c
+    parseteam "$(getarg team=)"
18971c
+
18971c
+    echo "teammaster=$teammaster" > /tmp/team.${teammaster}.info
18971c
+    echo "teamslaves=\"$teamslaves\"" >> /tmp/team.${teammaster}.info
18971c
+    if ! [ -e /etc/teamd/${teammaster}.conf ]; then
18971c
+        warn "Team master $teammaster specified, but no /etc/teamd/$teammaster.conf present. Using activebackup."
18971c
+        mkdir -p /etc/teamd
18971c
+        printf -- "%s" '{"runner": {"name": "activebackup"}, "link_watch": {"name": "ethtool"}}' > "/etc/teamd/${teammaster}.conf"
18971c
+    fi
18971c
+done
18971c
diff --git a/modules.d/40network/parse-vlan.sh b/modules.d/40network/parse-vlan.sh
18971c
index 3ba22892..5a747f0f 100755
18971c
--- a/modules.d/40network/parse-vlan.sh
18971c
+++ b/modules.d/40network/parse-vlan.sh
18971c
@@ -4,14 +4,6 @@
18971c
 #	vlan=<vlanname>:<phydevice>
18971c
 #
18971c
 
18971c
-# return if vlan already parsed
18971c
-[ -n "$vlanname" ] && return
18971c
-
18971c
-# Check if vlan parameter is valid
18971c
-if getarg vlan= >/dev/null ; then
18971c
-    :
18971c
-fi
18971c
-
18971c
 parsevlan() {
18971c
     local v=${1}:
18971c
     set --
18971c
@@ -27,16 +19,11 @@ parsevlan() {
18971c
     esac
18971c
 }
18971c
 
18971c
-unset vlanname phydevice
18971c
-
18971c
-if getarg vlan >/dev/null; then
18971c
-    # Read vlan= parameters if they exist
18971c
-    vlan="$(getarg vlan=)"
18971c
-    if [ ! "$vlan" = "vlan" ]; then
18971c
-        parsevlan "$(getarg vlan=)"
18971c
-    fi
18971c
+for vlan in $(getargs vlan=); do
18971c
+    unset vlanname
18971c
+    unset phydevice
18971c
+    parsevlan "$vlan"
18971c
 
18971c
-    echo "vlanname=\"$vlanname\"" > /tmp/vlan.info
18971c
-    echo "phydevice=\"$phydevice\"" >> /tmp/vlan.info
18971c
-    return
18971c
-fi
18971c
+    echo "$phydevice" > /tmp/vlan.${phydevice}.phy
18971c
+    echo "$vlanname" > /tmp/vlan.${vlanname}.${phydevice}
18971c
+done
18971c
diff --git a/modules.d/45ifcfg/write-ifcfg.sh b/modules.d/45ifcfg/write-ifcfg.sh
18971c
index cab74772..a077da1c 100755
18971c
--- a/modules.d/45ifcfg/write-ifcfg.sh
18971c
+++ b/modules.d/45ifcfg/write-ifcfg.sh
18971c
@@ -7,14 +7,6 @@ type is_persistent_ethernet_name >/dev/null 2>&1 || . /lib/net-lib.sh
18971c
 
18971c
 udevadm settle --timeout=30
18971c
 
18971c
-if [ -e /tmp/bridge.info ]; then
18971c
-    . /tmp/bridge.info
18971c
-fi
18971c
-
18971c
-if [ -e /tmp/vlan.info ]; then
18971c
-    . /tmp/vlan.info
18971c
-fi
18971c
-
18971c
 mkdir -m 0755 -p /tmp/ifcfg/
18971c
 mkdir -m 0755 -p /tmp/ifcfg-leases/
18971c
 
18971c
@@ -24,7 +16,7 @@ get_config_line_by_subchannel()
18971c
     local line
18971c
 
18971c
     CHANNELS="$1"
18971c
-    while read line; do
18971c
+    while read line || [ -n "$line" ]; do
18971c
         if strstr "$line" "$CHANNELS"; then
18971c
             echo $line
18971c
             return 0
18971c
@@ -132,6 +124,8 @@ for netup in /tmp/net.*.did-setup ; do
18971c
     unset bondslaves
18971c
     unset bondname
18971c
     unset bondoptions
18971c
+    unset bridgename
18971c
+    unset bridgeslaves
18971c
     unset uuid
18971c
     unset ip
18971c
     unset gw
18971c
@@ -141,8 +135,10 @@ for netup in /tmp/net.*.did-setup ; do
18971c
     unset slave
18971c
     unset ethname
18971c
     unset vlan
18971c
+    unset phydevice
18971c
 
18971c
     [ -e /tmp/bond.${netif}.info ] && . /tmp/bond.${netif}.info
18971c
+    [ -e /tmp/bridge.${netif}.info ] && . /tmp/bridge.${netif}.info
18971c
     [ -e /tmp/team.${netif}.info ] && . /tmp/team.${netif}.info
18971c
     [ -e /tmp/net.${netif}.override ] && . /tmp/net.${netif}.override
18971c
 
18971c
@@ -152,11 +148,17 @@ for netup in /tmp/net.*.did-setup ; do
18971c
     elif [ "$netif" = "$teammaster" ]; then
18971c
         team=yes
18971c
     elif [ "$netif" = "$bondname" ]; then
18971c
-    # $netif can't be bridge and bond at the same time
18971c
+        # $netif can't be bridge and bond at the same time
18971c
         bond=yes
18971c
     fi
18971c
-    if [ "$netif" = "$vlanname" ]; then
18971c
-        vlan=yes
18971c
+
18971c
+    if ! [ -e /tmp/vlan.${netif}.phy ]; then
18971c
+        for i in /tmp/vlan.${netif}.*; do
18971c
+            [ ! -e "$i" ] && continue
18971c
+            phydevice=${i##/tmp/vlan.${netif}.}
18971c
+            vlan=yes
18971c
+            break
18971c
+        done
18971c
     fi
18971c
 
18971c
     # skip team interfaces for now, the host config must be in sync