Attached is the parser of this bridging plan. Bridge details if parsed
from cmdline are written to /tmp/bridge.info for later use by network
scripts with the following behavior. Any comments?
SYNTAX
======
bridge=<bridgename>:<ethname>
If bridge without parameters, assume bridge=br0:eth0
BASIC IDEA
==========
* When <ethname> would be configured by network scripts, instead create
a bridge named <bridgename> then add <ethname> to that bridge.
* <bridgename> automatically inherits the MAC address of <ethname>.
BOOTIF thus should be optionally workable.
* Then $netif becomes <bridgename> instead of <ethname> and all existing
scripts process netroot mount via this new $netif instead of <ethname>.
* Try only the one specified <ethname> interface, do not try others. (I
suppose trying others in the "bridge root=dhcp" case would be possible,
but let's get the basics working first.)
* write-ifcfg.sh writes out both ifcfg-<bridgename> and ifcfg-<ethname>
files for later use by NetworkManager.
BOOT EXAMPLE
============
ifconfig eth0 up
brctl addbr br0
brctl setfd br0 0
brctl addif br0 eth0
dhclient br0
ifconfig br0 <parameters>
mount -t nfs server:/path /sysroot
switch_root /sysroot
ifcfg-br0 example
=================
# Generated by dracut initrd
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=dhcp
STP=off
USERCTL=no
ifcfg-eth0 example
==================
# Generated by dracut initrd
TYPE=Ethernet
DEVICE=eth0
HWADDR=52:54:00:12:34:56
ONBOOT=yes
BRIDGE=br0
USERCTL=no
Warren Togami
wtogami@xxxxxxxxxx
>From 329b0b77e7d63ebe2092111de31f471fd22a5b06 Mon Sep 17 00:00:00 2001
From: Warren Togami <wtogami@xxxxxxxxxx>
Date: Thu, 16 Jul 2009 00:09:07 -0400
Subject: [PATCH] Bridge parsing example
---
modules.d/40network/check | 2 +-
modules.d/40network/install | 3 +-
modules.d/40network/parse-bridge.sh | 55 +++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 2 deletions(-)
create mode 100755 modules.d/40network/parse-bridge.sh
diff --git a/modules.d/40network/check b/modules.d/40network/check
index 79a6d97..3d45030 100755
--- a/modules.d/40network/check
+++ b/modules.d/40network/check
@@ -1,4 +1,4 @@
#!/bin/sh
-which ip dhclient hostname >/dev/null 2>&1 || exit 1
+which ip dhclient hostname brctl >/dev/null 2>&1 || exit 1
exit 255
diff --git a/modules.d/40network/install b/modules.d/40network/install
index 0b76cbd..216d203 100755
--- a/modules.d/40network/install
+++ b/modules.d/40network/install
@@ -1,5 +1,5 @@
#!/bin/bash
-dracut_install ip dhclient hostname
+dracut_install ip dhclient hostname brctl
# Include wired net drivers, excluding wireless
for modname in $(find "/lib/modules/$kernel/kernel/drivers" -name '*.ko'); do
if nm -uPA $modname | grep -q eth_type_trans; then
@@ -18,6 +18,7 @@ instmods ecb arc4
inst_hook pre-udev 60 "$moddir/net-genrules.sh"
inst_hook cmdline 91 "$moddir/dhcp-root.sh"
inst_hook cmdline 99 "$moddir/parse-ip-opts.sh"
+inst_hook cmdline 98 "$moddir/parse-bridge.sh"
inst_hook pre-pivot 10 "$moddir/kill-dhclient.sh"
# TODO ifcfg config style is redhat specific, this should probably
diff --git a/modules.d/40network/parse-bridge.sh b/modules.d/40network/parse-bridge.sh
new file mode 100755
index 0000000..adc28bb
--- /dev/null
+++ b/modules.d/40network/parse-bridge.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+#
+# Format:
+# bridge=<bridgename>:<ethname>
+#
+# bridge without parameters assumes bridge=br0:eth0
+#
+
+# return if bridge already parsed
+[ -n "$bridgename" ] && return
+
+# Check if bridge parameter is valid
+if getarg ip= >/dev/null ; then
+ if [ -z "$netroot" ] ; then
+ die "No netboot configured, bridge is invalid"
+ fi
+fi
+
+parsebridge() {
+ local v=${1}:
+ set --
+ while [ -n "$v" ]; do
+ set -- "$@" "${v%%:*}"
+ v=${v#*:}
+ done
+
+ unset bridgename ethname
+ case $# in
+ 0) bridgename=br0; ethname=eth0 ;;
+ 1) die "bridge= requires two parameters" ;;
+ 2) bridgename=$1; ethname=$2 ;;
+ *) die "bridge= requires two parameters" ;;
+ esac
+}
+
+unset bridgename ethname
+
+# Simple bridge
+if getarg bridge; then
+ bridgename=br0
+ ethname=eth0
+ echo "bridgename=$bridgename" > /tmp/bridge.info
+ echo "ethname=$ethname" >> /tmp/bridge.info
+ return
+fi
+
+# Defined bridge
+bridge="$(getarg bridge=)"
+if [ -n "$bridge" ]; then
+ parsebridge "$bridge"
+ unset bridge
+ echo "bridgename=$bridgename" > /tmp/bridge.info
+ echo "ethname=$ethname" >> /tmp/bridge.info
+ return
+fi
--
1.6.2.5