bridge_driver: Enable virMacMap iff dnsmasq is started

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>
This commit is contained in:
Michal Privoznik 2022-08-09 13:31:41 +02:00
parent 2efd0dd9c3
commit a4e1a82668

View 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;