From a4e1a82668f168c9e57d3d03e8c17f6264ac0638 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Tue, 9 Aug 2022 13:31:41 +0200 Subject: [PATCH] bridge_driver: Enable virMacMap iff dnsmasq is started MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 Reviewed-by: Ján Tomko --- src/network/bridge_driver.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 7098054f77..f6538d2638 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -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;