From 5754dbd56d4738112a86776c09e810e32f7c3224 Mon Sep 17 00:00:00 2001 From: Laine Stump Date: Wed, 9 Feb 2011 03:28:12 -0500 Subject: [PATCH] Give each virtual network bridge its own fixed MAC address This fixes https://bugzilla.redhat.com/show_bug.cgi?id=609463 The problem was that, since a bridge always acquires the MAC address of the connected interface with the numerically lowest MAC, as guests are started and stopped, it was possible for the MAC address to change over time, and this change in the network was being detected by Windows 7 (it sees the MAC of the default route change), so on each reboot it would bring up a dialog box asking about this "new network". The solution is to create a dummy tap interface with a MAC guaranteed to be lower than any guest interface's MAC, and attach that tap to the bridge as soon as it's created. Since all guest MAC addresses start with 0xFE, we can just generate a MAC with the standard "0x52, 0x54, 0" prefix, and it's guaranteed to always win (physical interfaces are never connected to these bridges, so we don't need to worry about competing numerically with them). Note that the dummy tap is never set to IFF_UP state - that's not necessary in order for the bridge to take its MAC, and not setting it to UP eliminates the clutter of having an (eg) "virbr0-nic" displayed in the output of the ifconfig command. I chose to not auto-generate the MAC address in the network XML parser, as there are likely to be consumers of that API that don't need or want to have a MAC address associated with the bridge. Instead, in bridge_driver.c when the network is being defined, if there is no MAC, one is generated. To account for virtual network configs that already exist when upgrading from an older version of libvirt, I've added a %post script to the specfile that searches for all network definitions in both the config directory (/etc/libvirt/qemu/networks) and the state directory (/var/lib/libvirt/network) that are missing a mac address, generates a random address, and adds it to the config (and a matching address to the state file, if there is one). docs/formatnetwork.html.in: document docs/schemas/network.rng: add nac address to schema libvirt.spec.in: %post script to update existing networks src/conf/network_conf.[ch]: parse and format src/libvirt_private.syms: export a couple private symbols we need src/network/bridge_driver.c: auto-generate mac address when needed, create dummy interface if mac address is present. tests/networkxml2xmlin/isolated-network.xml tests/networkxml2xmlin/routed-network.xml tests/networkxml2xmlout/isolated-network.xml tests/networkxml2xmlout/routed-network.xml: add mac address to some tests --- docs/formatnetwork.html.in | 21 ++++++- docs/schemas/network.rng | 8 +++ libvirt.spec.in | 40 ++++++++++++ src/conf/network_conf.c | 30 +++++++++ src/conf/network_conf.h | 5 ++ src/libvirt_private.syms | 2 + src/network/bridge_driver.c | 65 ++++++++++++++++++++ tests/networkxml2xmlin/isolated-network.xml | 1 + tests/networkxml2xmlin/routed-network.xml | 1 + tests/networkxml2xmlout/isolated-network.xml | 1 + tests/networkxml2xmlout/routed-network.xml | 1 + 11 files changed, 173 insertions(+), 2 deletions(-) diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in index b1b04859ba..c6969eb1a3 100644 --- a/docs/formatnetwork.html.in +++ b/docs/formatnetwork.html.in @@ -105,12 +105,15 @@

Addressing

- The final set of elements define the IPv4 address range available, - and optionally enable DHCP sevices. + The final set of elements define the addresses (IPv4 and/or + IPv6, as well as MAC) to be assigned to the bridge device + associated with the virtual network, and optionally enable DHCP + services.

         ...
+        <mac address='00:16:3E:5D:C7:9E'/>
         <ip address="192.168.122.1" netmask="255.255.255.0">
           <dhcp>
             <range start="192.168.122.100" end="192.168.122.254" />
@@ -121,6 +124,20 @@
       </network>
+
mac
+
The address attribute defines a MAC + (hardware) address formatted as 6 groups of 2-digit + hexadecimal numbers, the groups separated by colons + (eg, "52:54:00:1C:DA:2F"). This MAC address is + assigned to the bridge device when it is created. Generally + it is best to not specify a MAC address when creating a + network - in this case, if a defined MAC address is needed for + proper operation, libvirt will automatically generate a random + MAC address and save it in the config. Allowing libvirt to + generate the MAC address will assure that it is compatible + with the idiosyncrasies of the platform where libvirt is + running. Since 0.8.8 +
ip
The address attribute defines an IPv4 address in dotted-decimal format, or an IPv6 address in standard diff --git a/docs/schemas/network.rng b/docs/schemas/network.rng index 4252f30f56..6d01b06082 100644 --- a/docs/schemas/network.rng +++ b/docs/schemas/network.rng @@ -50,6 +50,14 @@ + + + + + + + +