From: Carlo Marcelo Arenas Belon <carenas-kLeDWSohozoJb6fo7hG9ng@public.gmane.org>
To: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH v2] Use net-tools as a fallback for iproute2 for bridge configuration
Date: Tue, 25 Sep 2007 05:01:44 -0500 [thread overview]
Message-ID: <20070925100144.GA3174@tapir> (raw)
The following patch uses net-tools (ifconfig and netstat) if /sbin/ip is
not available while trying to configure a bridge with the kvm wrapper
and qemu-ifup.
It also adds an option to the kvm wrapper to define which bridge device to
use instead of the hardcoded eth0 value (which is still the default)
Carlo
Signed-off-by: Carlo Marcelo Arenas Belon <carenas-kLeDWSohozoJb6fo7hG9ng@public.gmane.org>
---
kvm | 33 ++++++++++++++++++++++++++++-----
scripts/qemu-ifup | 17 +++++++++++++++--
2 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/kvm b/kvm
index d091c86..2f81ae4 100755
--- a/kvm
+++ b/kvm
@@ -55,6 +55,12 @@ optparser.add_option('--no-tap',
default = not privileged,
)
+optparser.add_option('--bridge',
+ help = 'use this device to build the bridge',
+ dest = 'bridge',
+ default = None,
+ )
+
optparser.add_option('--mac',
help = 'use this specific mac addr',
dest = 'mac',
@@ -191,6 +197,7 @@ bootdisk = 'c'
if options.install:
bootdisk = 'd'
+# kvm always compiles for the x86_64 target
arch = 'x86_64'
if arch == 'x86_64':
@@ -226,15 +233,31 @@ if options.debugger:
if not options.irqchip:
qemu_args += ('-no-kvm-irqchip',)
+def getmac(interface):
+ if os.access('/sbin/ip', os.F_OK):
+ for line in commands.getoutput('/sbin/ip link show ' + interface).splitlines():
+ m = re.match(r'.*link/ether (..:..:..:..:..:..).*', line)
+ if m:
+ mac = m.group(1)
+ return mac
+ else:
+ for line in commands.getoutput('/sbin/ifconfig ' + interface).splitlines():
+ m = re.match(r'.*HWaddr (..:..:..:..:..:..)', line)
+ if m:
+ mac = m.group(1)
+ return mac
+ return False
+
if not options.notap:
+ bridge = options.bridge
+ if not bridge:
+ bridge = 'eth0'
+
mac = options.mac
if not mac:
- for line in commands.getoutput('/sbin/ip link show eth0').splitlines():
- m = re.match(r'.*link/ether (..:..:..:..:..:..).*', line)
- if m:
- mac = m.group(1)
+ mac = getmac(bridge)
if not mac:
- raise Exception, 'Unable to determine eth0 mac address'
+ raise Exception, 'Unable to determine ' + bridge + ' mac address'
mac_components = mac.split(':')
mac_components[0] = 'a0'
mac = ':'.join(mac_components)
diff --git a/scripts/qemu-ifup b/scripts/qemu-ifup
index 3bf8801..989fe9a 100755
--- a/scripts/qemu-ifup
+++ b/scripts/qemu-ifup
@@ -1,5 +1,18 @@
#!/bin/sh
-switch=$(/sbin/ip route list | awk '/^default / { print $NF }')
+if [ -x /sbin/brctl ]; then
+ BRCTL="/sbin/brctl"
+elif [ -x /usr/sbin/brctl ]; then
+ BRCTL="/usr/sbin/brctl"
+else
+ echo "no bridge utils installed"
+ exit 1
+fi
+
+if [ -x /sbin/ip ]; then
+ switch=$(/sbin/ip route list | awk '/^default / { print $NF }')
+else
+ switch=$(/bin/netstat -rn | awk '/^0\.0\.0\.0/ { print $NF }')
+fi
/sbin/ifconfig $1 0.0.0.0 up
-/usr/sbin/brctl addif ${switch} $1
+${BRCTL} addif ${switch} $1
--
1.5.1.6
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
next reply other threads:[~2007-09-25 10:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-25 10:01 Carlo Marcelo Arenas Belon [this message]
2007-09-25 10:07 ` [PATCH v2] Use net-tools as a fallback for iproute2 for bridge configuration Luca
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070925100144.GA3174@tapir \
--to=carenas-kledwsohozojb6fo7hg9ng@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.