]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
network: Move decision on dnsmasq need into a separate function
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 27 Jan 2026 19:59:20 +0000 (20:59 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 29 Jan 2026 12:38:18 +0000 (13:38 +0100)
Whether a network needs dnsmasq or not is decided at the
beginning of networkStartDhcpDaemon(). Move that code into a
separate function so it can be reused later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/network/bridge_driver.c
src/network/bridge_driver_priv.h

index d7004771b7004d31472ea7ac08fecd19ddc8436f..e7a4e5e1b7ec9bfca6bd75b822a58cf368310dd8 100644 (file)
@@ -1516,34 +1516,44 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverState *driver,
 }
 
 
-static int
-networkStartDhcpDaemon(virNetworkDriverState *driver,
-                       virNetworkObj *obj)
+bool
+networkNeedsDnsmasq(const virNetworkDef* def)
 {
-    g_autoptr(virNetworkDriverConfig) cfg = virNetworkDriverGetConfig(driver);
-    virNetworkDef *def = virNetworkObjGetDef(obj);
     virNetworkIPDef *ipdef;
     size_t i;
-    bool needDnsmasq = false;
-    g_autoptr(virCommand) cmd = NULL;
-    g_autofree char *pidfile = NULL;
-    pid_t dnsmasqPid;
-    g_autoptr(dnsmasqContext) dctx = NULL;
 
     /* see if there are any IP addresses that need a dhcp server */
     i = 0;
     while ((ipdef = virNetworkDefGetIPByIndex(def, AF_UNSPEC, i))) {
         i++;
         if (ipdef->nranges || ipdef->nhosts || ipdef->tftproot)
-            needDnsmasq = true;
+            return true;
     }
 
     /* no IP addresses at all, so we don't need to run */
     if (i == 0)
-        return 0;
+        return false;
 
     /* no DHCP services needed, and user disabled DNS service */
-    if (!needDnsmasq && def->dns.enable == VIR_TRISTATE_BOOL_NO)
+    if (def->dns.enable == VIR_TRISTATE_BOOL_NO)
+        return false;
+
+    return true;
+}
+
+
+static int
+networkStartDhcpDaemon(virNetworkDriverState *driver,
+                       virNetworkObj *obj)
+{
+    g_autoptr(virNetworkDriverConfig) cfg = virNetworkDriverGetConfig(driver);
+    virNetworkDef *def = virNetworkObjGetDef(obj);
+    g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *pidfile = NULL;
+    pid_t dnsmasqPid;
+    g_autoptr(dnsmasqContext) dctx = NULL;
+
+    if (!networkNeedsDnsmasq(def))
         return 0;
 
     if (g_mkdir_with_parents(cfg->pidDir, 0777) < 0) {
index 7f21ed7ad6976464b8dfe7e5df51d8a5b86f6817..c7d1d8268d1ed281af920a43bfb4e08cf4b4653c 100644 (file)
@@ -23,3 +23,6 @@ networkDnsmasqConfContents(virNetworkObj *obj,
                            char **hostsfilestr,
                            dnsmasqContext *dctx,
                            dnsmasqCaps *caps);
+
+bool
+networkNeedsDnsmasq(const virNetworkDef* def);