From nobody Fri Dec 19 19:16:00 2025 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1714501105751286.3006036041463; Tue, 30 Apr 2024 11:18:25 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AAE0F24EC; Tue, 30 Apr 2024 14:18:24 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D9F9C2495; Tue, 30 Apr 2024 13:46:15 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 24AA62398; Tue, 30 Apr 2024 13:44:36 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 2CD731E61 for ; Tue, 30 Apr 2024 13:44:26 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-119-7Vo7x8XjPU-Y6kbRHLAwFg-1; Tue, 30 Apr 2024 13:44:23 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43AF018065B8 for ; Tue, 30 Apr 2024 17:44:23 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.16.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BF6B581C9 for ; Tue, 30 Apr 2024 17:44:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: 7Vo7x8XjPU-Y6kbRHLAwFg-1 From: Laine Stump To: devel@lists.libvirt.org Subject: [PATCH v4 20/30] conf: add a virFirewall object to virNetworkObj Date: Tue, 30 Apr 2024 13:44:09 -0400 Message-ID: <20240430174420.371179-21-laine@redhat.com> In-Reply-To: <20240430174420.371179-1-laine@redhat.com> References: <20240430174420.371179-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 3QO4DR3OPVRFI5WERCM3O7WH4JRFGTBR X-Message-ID-Hash: 3QO4DR3OPVRFI5WERCM3O7WH4JRFGTBR X-MailFrom: laine@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1714501106946100001 This virFirewall object will store the list of actions required to remove the firewall that was added for the currently active instance of the network, so it has been named "fwRemoval" (and when parsed into XML, the element will have the name "fwRemoval"). There are no uses of the fwRemoval object in the virNetworkObj yet, but everything is in place to add it to the XML when formatted, parse it from the XML when reading network status, and free the virFirewall object when the virNetworkObj is freed. Signed-off-by: Laine Stump Reviewed-by: Daniel P. Berrang=C3=A9 --- src/conf/virnetworkobj.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/conf/virnetworkobj.h | 8 ++++++++ src/libvirt_private.syms | 2 ++ 3 files changed, 50 insertions(+) diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index d5aa121e20..f5db4c5804 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -55,6 +55,11 @@ struct _virNetworkObj { =20 unsigned int taint; =20 + /* fwRemoval contains all commands needed to remove the firewall + * that was added for this network. + */ + virFirewall *fwRemoval; + /* Immutable pointer, self locking APIs */ virMacMap *macmap; =20 @@ -239,6 +244,24 @@ virNetworkObjSetFloorSum(virNetworkObj *obj, } =20 =20 +virFirewall * +virNetworkObjGetFwRemoval(virNetworkObj *obj) +{ + return obj->fwRemoval; +} + + +void +virNetworkObjSetFwRemoval(virNetworkObj *obj, + virFirewall *fwRemoval) +{ + obj->fwRemoval =3D fwRemoval; + /* give it a name so it's identifiable in the XML */ + if (fwRemoval) + virFirewallSetName(fwRemoval, "fwRemoval"); +} + + void virNetworkObjSetMacMap(virNetworkObj *obj, virMacMap **macmap) @@ -444,6 +467,7 @@ virNetworkObjDispose(void *opaque) virNetworkDefFree(obj->newDef); virBitmapFree(obj->classIdMap); virObjectUnref(obj->macmap); + virFirewallFree(obj->fwRemoval); } =20 =20 @@ -792,6 +816,9 @@ virNetworkObjFormat(virNetworkObj *obj, if (virNetworkDefFormatBuf(&buf, obj->def, xmlopt, flags) < 0) return NULL; =20 + if (obj->fwRemoval && virFirewallFormat(&buf, obj->fwRemoval) < 0) + return NULL; + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, ""); =20 @@ -826,6 +853,7 @@ virNetworkLoadState(virNetworkObjList *nets, g_autofree char *configFile =3D NULL; g_autoptr(virNetworkDef) def =3D NULL; virNetworkObj *obj =3D NULL; + g_autoptr(virFirewall) fwRemoval =3D NULL; g_autoptr(xmlDoc) xml =3D NULL; xmlNodePtr node =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; @@ -868,6 +896,7 @@ virNetworkLoadState(virNetworkObjList *nets, g_autofree char *classIdStr =3D NULL; g_autofree char *floor_sum =3D NULL; g_autofree xmlNodePtr *nodes =3D NULL; + xmlNodePtr fwNode; =20 ctxt->node =3D node; if ((classIdStr =3D virXPathString("string(./class_id[1]/@bitmap)", @@ -902,6 +931,15 @@ virNetworkLoadState(virNetworkObjList *nets, taint |=3D (1 << flag); } } + if ((fwNode =3D virXPathNode("./firewall", ctxt))) { + g_autoptr(virFirewall) fwTmp =3D NULL; + + if (virFirewallParseXML(&fwTmp, fwNode, ctxt) < 0) + return NULL; + + if (STREQ_NULLABLE(virFirewallGetName(fwTmp), "fwRemoval")) + fwRemoval =3D g_steal_pointer(&fwTmp); + } } =20 /* create the object */ @@ -910,6 +948,8 @@ virNetworkLoadState(virNetworkObjList *nets, =20 def =3D NULL; =20 + virNetworkObjSetFwRemoval(obj, g_steal_pointer(&fwRemoval)); + /* assign status data stored in the network object */ if (classIdMap) { virBitmapFree(obj->classIdMap); diff --git a/src/conf/virnetworkobj.h b/src/conf/virnetworkobj.h index d3847d3422..6ebc6c49f5 100644 --- a/src/conf/virnetworkobj.h +++ b/src/conf/virnetworkobj.h @@ -23,6 +23,7 @@ =20 #include "network_conf.h" #include "virnetworkportdef.h" +#include "virfirewall.h" =20 typedef struct _virNetworkObj virNetworkObj; =20 @@ -76,6 +77,13 @@ void virNetworkObjSetFloorSum(virNetworkObj *obj, unsigned long long floor_sum); =20 +virFirewall * +virNetworkObjGetFwRemoval(virNetworkObj *obj); + +void +virNetworkObjSetFwRemoval(virNetworkObj *obj, + virFirewall *fwRemoval); + void virNetworkObjSetMacMap(virNetworkObj *obj, virMacMap **macmap); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9ba1edb37e..e8c15232d9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1300,6 +1300,7 @@ virNetworkObjGetClassIdMap; virNetworkObjGetDef; virNetworkObjGetDnsmasqPid; virNetworkObjGetFloorSum; +virNetworkObjGetFwRemoval; virNetworkObjGetMacMap; virNetworkObjGetMetadata; virNetworkObjGetNewDef; @@ -1331,6 +1332,7 @@ virNetworkObjSetDef; virNetworkObjSetDefTransient; virNetworkObjSetDnsmasqPid; virNetworkObjSetFloorSum; +virNetworkObjSetFwRemoval; virNetworkObjSetMacMap; virNetworkObjSetMetadata; virNetworkObjTaint; --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org