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 <[EMAIL PROTECTED]>
---
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/
_______________________________________________
kvm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel