From nobody Mon Feb 2 07:31:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1769610813; cv=none; d=zohomail.com; s=zohoarc; b=Sf3b/YRvKt08MA1wILoUQ5OvAEPozIesTnBUmbJb8e8cK/phTt/fOjEc2ybAp0b2iWfyIBgpUA5vCKNWQz2/tezKPC93jX91kJq22RCVOK4B+rE85HwBlLrBMg5/XAV7nYX1xkZ9UsNRbgkME1yXuFQ/N0idApDY3j3l4Tv3Xvg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769610813; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=iRLfF0fOrtR+Am4KK1EVD1fBmFj+m3B3F9tEbmAEeBw=; b=byCLqXvmCLsF8NGczRaAwE2rSpdu6AUroLnhWmIGzq4xYIFIk78tT40JxwUF4AojGtYy6jHZDAvE4VoE4J1wnsp9qKI596CvnaofAXLikpu0qLZc+zNjhyk52w1/R/4OFBd+Js/vgO9tJSCLtBZHVd3/v/Y/rBByI2S2eFsIblw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1769610813311144.51225296780103; Wed, 28 Jan 2026 06:33:33 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 4E3EB43DB8; Wed, 28 Jan 2026 09:33:32 -0500 (EST) Received: from [172.19.199.3] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id B3F2F43DD8; Wed, 28 Jan 2026 09:31:03 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 1946B3F30A; Wed, 28 Jan 2026 09:30:54 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 85ED13F30A for ; Wed, 28 Jan 2026 09:30:53 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-45-1UkR2Iu1NN-3xwitzf546A-1; Wed, 28 Jan 2026 09:30:50 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E12771800614 for ; Wed, 28 Jan 2026 14:30:49 +0000 (UTC) Received: from moe (unknown [10.43.3.236]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4AD40195419E for ; Wed, 28 Jan 2026 14:30:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769610653; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iRLfF0fOrtR+Am4KK1EVD1fBmFj+m3B3F9tEbmAEeBw=; b=SU1A2UIryspfbTfmJFKrnHMM2OPQiK5ywE4B+g0I4cL1oiGtQD5W9Q8gr4fg+F2Kg1nvSY fKwVeSc49KCfNUA6Ia/IvW702RV85HH7g5Ls0cHzHbL8BwxefEt1Mt1eKmVeIlcAb7ShkX kFPcbbcN0ViJ4vX2GQFl89ZzRh4Civo= X-MC-Unique: 1UkR2Iu1NN-3xwitzf546A-1 X-Mimecast-MFC-AGG-ID: 1UkR2Iu1NN-3xwitzf546A_1769610650 To: devel@lists.libvirt.org Subject: [PATCH 03/20] network: Move decision on dnsmasq need into a separate function Date: Wed, 28 Jan 2026 15:30:24 +0100 Message-ID: <58abe7c8495e82284629a04be956c9bdf1e3185f.1769610369.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ARXrKp-_unotY31i10LkM7A7zY-Q4DEFz_YjnALLKN4_1769610650 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 2OVNWMMFGZZSW6ADZFB24TPNYULUP5GJ X-Message-ID-Hash: 2OVNWMMFGZZSW6ADZFB24TPNYULUP5GJ X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Michal Privoznik via Devel Reply-To: Michal Privoznik X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1769610814474158500 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Michal Privoznik 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 --- src/network/bridge_driver.c | 36 ++++++++++++++++++++------------ src/network/bridge_driver_priv.h | 3 +++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index d7004771b7..e7a4e5e1b7 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1516,34 +1516,44 @@ networkBuildDhcpDaemonCommandLine(virNetworkDriverS= tate *driver, } =20 =20 -static int -networkStartDhcpDaemon(virNetworkDriverState *driver, - virNetworkObj *obj) +bool +networkNeedsDnsmasq(const virNetworkDef* def) { - g_autoptr(virNetworkDriverConfig) cfg =3D virNetworkDriverGetConfig(dr= iver); - virNetworkDef *def =3D virNetworkObjGetDef(obj); virNetworkIPDef *ipdef; size_t i; - bool needDnsmasq =3D false; - g_autoptr(virCommand) cmd =3D NULL; - g_autofree char *pidfile =3D NULL; - pid_t dnsmasqPid; - g_autoptr(dnsmasqContext) dctx =3D NULL; =20 /* see if there are any IP addresses that need a dhcp server */ i =3D 0; while ((ipdef =3D virNetworkDefGetIPByIndex(def, AF_UNSPEC, i))) { i++; if (ipdef->nranges || ipdef->nhosts || ipdef->tftproot) - needDnsmasq =3D true; + return true; } =20 /* no IP addresses at all, so we don't need to run */ if (i =3D=3D 0) - return 0; + return false; =20 /* no DHCP services needed, and user disabled DNS service */ - if (!needDnsmasq && def->dns.enable =3D=3D VIR_TRISTATE_BOOL_NO) + if (def->dns.enable =3D=3D VIR_TRISTATE_BOOL_NO) + return false; + + return true; +} + + +static int +networkStartDhcpDaemon(virNetworkDriverState *driver, + virNetworkObj *obj) +{ + g_autoptr(virNetworkDriverConfig) cfg =3D virNetworkDriverGetConfig(dr= iver); + virNetworkDef *def =3D virNetworkObjGetDef(obj); + g_autoptr(virCommand) cmd =3D NULL; + g_autofree char *pidfile =3D NULL; + pid_t dnsmasqPid; + g_autoptr(dnsmasqContext) dctx =3D NULL; + + if (!networkNeedsDnsmasq(def)) return 0; =20 if (g_mkdir_with_parents(cfg->pidDir, 0777) < 0) { diff --git a/src/network/bridge_driver_priv.h b/src/network/bridge_driver_p= riv.h index 7f21ed7ad6..c7d1d8268d 100644 --- a/src/network/bridge_driver_priv.h +++ b/src/network/bridge_driver_priv.h @@ -23,3 +23,6 @@ networkDnsmasqConfContents(virNetworkObj *obj, char **hostsfilestr, dnsmasqContext *dctx, dnsmasqCaps *caps); + +bool +networkNeedsDnsmasq(const virNetworkDef* def); --=20 2.52.0