From 21928b97b0c7a182161e2ea726d57dc9019dcafb Mon Sep 17 00:00:00 2001 From: Cong Wang Date: Thu, 31 May 2012 22:07:38 +0800 Subject: [PATCH] Handle multiple underlying devices of a bridge A bridge device with only one underlying ethernet device is almost useless, for sure we want to support a bridge with multiple underlying devices. This patch adds the support by extending in the original bridge= cmdline to a comma-separated list of ethernet interfaces. Cc: Harald Hoyer Cc: Dave Young Cc: Vivek Goyal Signed-off-by: Cong Wang --- dracut.cmdline.7.asc | 5 ++-- modules.d/40network/ifup.sh | 38 +++++++++++++++++------------ modules.d/40network/net-genrules.sh | 2 +- modules.d/40network/parse-bridge.sh | 17 +++++++------ 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc index 651582ddc..8a74cf598 100644 --- a/dracut.cmdline.7.asc +++ b/dracut.cmdline.7.asc @@ -326,8 +326,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=__:__**:: - Setup bridge with . Bridge without parameters assumes bridge=br0:eth0 +**bridge=__:__**:: + Setup bridge with . is a comma-separated + list of physical (ethernet) interfaces. Bridge without parameters assumes bridge=br0:eth0 NFS diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh index 1aaa1a816..c9516bb3d 100755 --- a/modules.d/40network/ifup.sh +++ b/modules.d/40network/ifup.sh @@ -31,13 +31,15 @@ fi # bridge this interface? if [ -e /tmp/bridge.info ]; then . /tmp/bridge.info - if [ "$netif" = "$ethname" ]; then - if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then - : # We need to really setup bond (recursive call) - else - netif="$bridgename" + for ethname in $ethnames ; do + if [ "$netif" = "$ethname" ]; then + if [ "$netif" = "$bondname" ] && [ -n "$DO_BOND_SETUP" ] ; then + : # We need to really setup bond (recursive call) + else + netif="$bridgename" + fi fi - fi + done fi if [ -e /tmp/vlan.info ]; then @@ -175,18 +177,22 @@ fi # XXX need error handling like dhclient-script +if [ -e /tmp/bridge.info ]; then + . /tmp/bridge.info # start bridge if necessary -if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.up ]; then - if [ "$ethname" = "$bondname" ] ; then - DO_BOND_SETUP=yes ifup $bondname - else - ip link set $ethname up + if [ "$netif" = "$bridgename" ] && [ ! -e /tmp/net.$bridgename.up ]; then + brctl addbr $bridgename + brctl setfd $bridgename 0 + for ethname in $ethnames ; do + if [ "$ethname" = "$bondname" ] ; then + DO_BOND_SETUP=yes ifup $bondname + else + ip link set $ethname up + fi + wait_for_if_up $ethname + brctl addif $bridgename $ethname + done fi - wait_for_if_up $ethname - # Create bridge and add eth to bridge - brctl addbr $bridgename - brctl setfd $bridgename 0 - brctl addif $bridgename $ethname fi get_vid() { diff --git a/modules.d/40network/net-genrules.sh b/modules.d/40network/net-genrules.sh index ca47b2b0d..2d3dff265 100755 --- a/modules.d/40network/net-genrules.sh +++ b/modules.d/40network/net-genrules.sh @@ -21,7 +21,7 @@ fix_bootif() { # bridge: attempt only the defined interface if [ -e /tmp/bridge.info ]; then . /tmp/bridge.info - IFACES=$ethname + IFACES=${ethnames%% *} fi # bond: attempt only the defined interface (override bridge defines) diff --git a/modules.d/40network/parse-bridge.sh b/modules.d/40network/parse-bridge.sh index 6e1fee1b3..5728fb6a3 100755 --- a/modules.d/40network/parse-bridge.sh +++ b/modules.d/40network/parse-bridge.sh @@ -3,8 +3,9 @@ # ex: ts=8 sw=4 sts=4 et filetype=sh # # Format: -# bridge=: +# bridge=: # +# is a comma-separated list of physical (ethernet) interfaces # bridge without parameters assumes bridge=br0:eth0 # @@ -24,16 +25,16 @@ parsebridge() { v=${v#*:} done - unset bridgename ethname + unset bridgename ethnames case $# in - 0) bridgename=br0; ethname=$iface ;; + 0) bridgename=br0; ethnames=$iface ;; 1) die "bridge= requires two parameters" ;; - 2) bridgename=$1; ethname=$2 ;; + 2) bridgename=$1; ethnames=$(echo $2|tr "," " ") ;; *) die "bridge= requires two parameters" ;; esac } -unset bridgename ethname +unset bridgename ethnames iface=eth0 if [ -e /tmp/bond.info ]; then @@ -43,7 +44,7 @@ if [ -e /tmp/bond.info ]; then fi fi -# Parse bridge for bridgename and ethname +# Parse bridge for bridgename and ethnames if bridge="$(getarg bridge)"; then # Read bridge= parameters if they exist if [ -n "$bridge" ]; then @@ -52,9 +53,9 @@ if bridge="$(getarg bridge)"; then # Simple default bridge if [ -z "$bridgename" ]; then bridgename=br0 - ethname=$iface + ethnames=$iface fi echo "bridgename=$bridgename" > /tmp/bridge.info - echo "ethname=$ethname" >> /tmp/bridge.info + echo "ethnames=\"$ethnames\"" >> /tmp/bridge.info return fi -- 2.47.3