]> xenbits.xensource.com Git - libvirt.git/commitdiff
Generate a MAC when loading a config instead of package update
authorJán Tomko <jtomko@redhat.com>
Tue, 11 Nov 2014 08:16:09 +0000 (09:16 +0100)
committerJán Tomko <jtomko@redhat.com>
Tue, 2 Dec 2014 14:56:33 +0000 (15:56 +0100)
Partially reverts commit 5754dbd.

The code in the specfile adds a MAC address to every <bridge>,
even for <forward mode='bridge'> for which we don't support
changing MAC addresses.

Remove it completely. For new networks, we have been adding
MAC addresses on definition/creation since the commit mentioned above.
For existing networks (pre-0.9.0), the MAC is added by this commit.

https://bugzilla.redhat.com/show_bug.cgi?id=1156367

libvirt.spec.in
src/conf/network_conf.c

index 3edb7bde0841f5bf15d10afa0a41fd75581c9902..bda28e72a5ee6b693a533d4e4e42bed577dd57fb 100644 (file)
@@ -1643,48 +1643,6 @@ exit 0
 
 %post daemon
 
-    %if %{with_network}
-# All newly defined networks will have a mac address for the bridge
-# auto-generated, but networks already existing at the time of upgrade
-# will not. We need to go through all the network configs, look for
-# those that don't have a mac address, and add one.
-
-network_files=$( (cd %{_localstatedir}/lib/libvirt/network && \
-                  grep -L "mac address" *.xml; \
-                  cd %{_sysconfdir}/libvirt/qemu/networks && \
-                  grep -L "mac address" *.xml) 2>/dev/null \
-                | sort -u)
-
-for file in $network_files
-do
-   # each file exists in either the config or state directory (or both) and
-   # does not have a mac address specified in either. We add the same mac
-   # address to both files (or just one, if the other isn't there)
-
-   mac4=`printf '%X' $(($RANDOM % 256))`
-   mac5=`printf '%X' $(($RANDOM % 256))`
-   mac6=`printf '%X' $(($RANDOM % 256))`
-   for dir in %{_localstatedir}/lib/libvirt/network \
-              %{_sysconfdir}/libvirt/qemu/networks
-   do
-      if test -f $dir/$file
-      then
-         sed -i.orig -e \
-           "s|\(<bridge.*$\)|\0\n  <mac address='52:54:00:$mac4:$mac5:$mac6'/>|" \
-           $dir/$file
-         if test $? != 0
-         then
-             echo "failed to add <mac address='52:54:00:$mac4:$mac5:$mac6'/>" \
-                  "to $dir/$file"
-             mv -f $dir/$file.orig $dir/$file
-         else
-             rm -f $dir/$file.orig
-         fi
-      fi
-   done
-done
-    %endif
-
     %if %{with_systemd}
         %if %{with_systemd_macros}
             %systemd_post virtlockd.socket libvirtd.service libvirtd.socket
index 5052f7c2e71807f4d807856af01db68d7308e80f..97719ed536de9b116066e5dc4990ca1d08620385 100644 (file)
@@ -3139,6 +3139,10 @@ virNetworkObjPtr virNetworkLoadConfig(virNetworkObjListPtr nets,
         def->forward.type == VIR_NETWORK_FORWARD_NAT ||
         def->forward.type == VIR_NETWORK_FORWARD_ROUTE) {
 
+        if (!def->mac_specified) {
+            virNetworkSetBridgeMacAddr(def);
+            virNetworkSaveConfig(configDir, def);
+        }
         /* Generate a bridge if none is specified, but don't check for collisions
          * if a bridge is hardcoded, so the network is at least defined.
          */