dracut/modules.d/40network/parse-bridge.sh
Cong Wang 21928b97b0 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 <ethname> in the original
bridge= cmdline to a comma-separated list of ethernet interfaces.

Cc: Harald Hoyer <harald@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
2012-06-04 11:06:53 +02:00

62 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
#
# Format:
# bridge=<bridgename>:<ethnames>
#
# <ethnames> is a comma-separated list of physical (ethernet) interfaces
# bridge without parameters assumes bridge=br0:eth0
#
# return if bridge already parsed
[ -n "$bridgename" ] && return
# Check if bridge parameter is valid
if getarg bridge= >/dev/null ; then
command -v brctl >/dev/null 2>&1 || die "No 'brctl' installed"
fi
parsebridge() {
local v=${1}:
set --
while [ -n "$v" ]; do
set -- "$@" "${v%%:*}"
v=${v#*:}
done
unset bridgename ethnames
case $# in
0) bridgename=br0; ethnames=$iface ;;
1) die "bridge= requires two parameters" ;;
2) bridgename=$1; ethnames=$(echo $2|tr "," " ") ;;
*) die "bridge= requires two parameters" ;;
esac
}
unset bridgename ethnames
iface=eth0
if [ -e /tmp/bond.info ]; then
. /tmp/bond.info
if [ -n "$bondname" ] ; then
iface=$bondname
fi
fi
# Parse bridge for bridgename and ethnames
if bridge="$(getarg bridge)"; then
# Read bridge= parameters if they exist
if [ -n "$bridge" ]; then
parsebridge $bridge
fi
# Simple default bridge
if [ -z "$bridgename" ]; then
bridgename=br0
ethnames=$iface
fi
echo "bridgename=$bridgename" > /tmp/bridge.info
echo "ethnames=\"$ethnames\"" >> /tmp/bridge.info
return
fi