]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bridge_driver: Enable virMacMap iff dnsmasq is started
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 9 Aug 2022 11:31:41 +0000 (13:31 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 9 Aug 2022 15:35:22 +0000 (17:35 +0200)
The virMacMap module is used only for libvirt_guests NSS module
as it records list of MAC addresses used by certain guest. But
the module itself is usable if and only if the network assigns IP
addresses (i.e. has dnsmasq running). If it's some other
authority that assigns IP addresses then we do not need the
virMacMap module at all.

For instance, a network with no <forward/> type and no DHCP set
won't create /var/lib/libvirt/dnsmasq/ dir which is what the
module expects to exist. But there's no need for the module to
even care about such network.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/348
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/network/bridge_driver.c

index 7098054f77c2348f3485ce8cd7ef7dc9cd1359f4..f6538d263838cebca59da8916723f0d452cef288 100644 (file)
@@ -484,9 +484,6 @@ networkUpdateState(virNetworkObj *obj,
         if (!(def->bridge && virNetDevExists(def->bridge) == 1))
             virNetworkObjSetActive(obj, false);
 
-        if (networkSetMacMap(driver, obj) < 0)
-            return -1;
-
         break;
 
     case VIR_NETWORK_FORWARD_BRIDGE:
@@ -521,6 +518,9 @@ networkUpdateState(virNetworkObj *obj,
     if (virNetworkObjIsActive(obj) && def->ips && (def->nips > 0)) {
         pid_t dnsmasqPid;
 
+        if (networkSetMacMap(driver, obj) < 0)
+            return -1;
+
         ignore_value(virPidFileReadIfAlive(driver->pidDir,
                                            def->name,
                                            &dnsmasqPid,
@@ -1974,9 +1974,6 @@ networkStartNetworkVirtual(virNetworkDriverState *driver,
     if (virNetDevBridgeCreate(def->bridge, &def->mac) < 0)
         return -1;
 
-    if (networkSetMacMap(driver, obj) < 0)
-        goto error;
-
     /* Set bridge options */
 
     if (def->mtu && virNetDevSetMTU(def->bridge, def->mtu) < 0)
@@ -2056,6 +2053,9 @@ networkStartNetworkVirtual(virNetworkDriverState *driver,
 
     /* start dnsmasq if there are any IP addresses (v4 or v6) */
     if (v4present || v6present) {
+        if (networkSetMacMap(driver, obj) < 0)
+            goto error;
+
         if (networkStartDhcpDaemon(driver, obj) < 0)
             goto error;