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