From nobody Tue Feb 10 13:36:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=riseup.net ARC-Seal: i=1; a=rsa-sha256; t=1696959414; cv=none; d=zohomail.com; s=zohoarc; b=YoATylCLnIejUS77sGBe8bIaaisdlGJ9RNb9uP0tRQNjmb+Vu8niEcCkX2hTRhgaL3hfrndL7yYPMdeWNDqApvn+atkLoQ/UzBSB+DF60t5a3wxB5DKubZeBgNawa9xu3D97IGlzlOCrvdZzTLBxeuV49EV76qPaeRinfW4cVeg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696959414; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UFJgvGYV9AoRFiGNsMB8Bd9RfYyuQYHXL3RJo7iuOd8=; b=oKuaFfzyeoVezXZhlR88RCPN/u8GQAJoxBdkXdUGwJsnHSrZ9uXIu0/BzSynz6jE0U5Lz6lfFdn3yXx7yVf+yCrGVrbpygca9uaxgsUy6yQ2Bk/3c4pNuEhO1wfcMV6zUK4912E6CFNVp1YLCVxJW+6BTg60vmrN+/oVy8p7XkE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 169695941459552.46132863797072; Tue, 10 Oct 2023 10:36:54 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-658-xr3vp4o0MFiRu597lrtshQ-1; Tue, 10 Oct 2023 13:36:44 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EB706858F1B; Tue, 10 Oct 2023 17:36:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D851E492B04; Tue, 10 Oct 2023 17:36:29 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C871F19465B8; Tue, 10 Oct 2023 17:36:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 669571946597 for ; Tue, 10 Oct 2023 17:36:28 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3C3FE492B06; Tue, 10 Oct 2023 17:36:28 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34B65492B04 for ; Tue, 10 Oct 2023 17:36:28 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-inbound-delivery-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D9B00101B041 for ; Tue, 10 Oct 2023 17:36:27 +0000 (UTC) Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-C2juxObFORin0pR336_B3A-1; Tue, 10 Oct 2023 13:36:18 -0400 Received: from fews02-sea.riseup.net (fews02-sea-pn.riseup.net [10.0.1.112]) (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 mx1.riseup.net (Postfix) with ESMTPS id 4S4jVw1Xx0zDqdM for ; Tue, 10 Oct 2023 17:26:32 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews02-sea.riseup.net (Postfix) with ESMTPSA id 4S4jVv0N2mzFqjK; Tue, 10 Oct 2023 17:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696959413; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UFJgvGYV9AoRFiGNsMB8Bd9RfYyuQYHXL3RJo7iuOd8=; b=XJPeACiQQiEnVWK0fgna3Q4Zyljer9OI4hSg3pBp6Bf9iJdxXKZ7RZxZ/AEFbhAD73ujsv iXUyEyNd+W5CIFVCwZ51hx1n6mmNh9cny3Dz75YPM5QI/TU1HE2fJgF550Z1xZxIwCrxA5 YgZWYYpekd8wyWH2UO+SZnKoJdL3N5E= X-MC-Unique: xr3vp4o0MFiRu597lrtshQ-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: C2juxObFORin0pR336_B3A-1 X-Riseup-User-ID: 0932CB7BFABE482F5E95C6427BFEE36007FCA5DD7E74DD00EB00C0F456714576 From: K Shiva Kiran To: libvir-list@redhat.com Subject: [PATCH v2 01/11] nwfilter_conf: Add schema and parser logic for nwfilter metadata Date: Tue, 10 Oct 2023 22:48:33 +0530 Message-ID: <20231010172509.103884-2-shiva_kr@riseup.net> In-Reply-To: <20231010172509.103884-1-shiva_kr@riseup.net> References: <20231010172509.103884-1-shiva_kr@riseup.net> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: K Shiva Kiran Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: riseup.net Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1696959416461100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Adds three new elements , <description> and <metadata> Signed-off-by: K Shiva Kiran <shiva_kr@riseup.net> --- docs/formatnwfilter.rst | 31 ++++++++++++++++++++++ src/conf/nwfilter_conf.c | 30 +++++++++++++++++++++ src/conf/nwfilter_conf.h | 5 ++++ src/conf/schemas/nwfilter.rng | 9 +++++++ tests/nwfilterxml2xmlin/metadata-test.xml | 12 +++++++++ tests/nwfilterxml2xmlout/metadata-test.xml | 10 +++++++ tests/nwfilterxml2xmltest.c | 1 + 7 files changed, 98 insertions(+) create mode 100644 tests/nwfilterxml2xmlin/metadata-test.xml create mode 100644 tests/nwfilterxml2xmlout/metadata-test.xml diff --git a/docs/formatnwfilter.rst b/docs/formatnwfilter.rst index 434da5b1fd..94a35abfce 100644 --- a/docs/formatnwfilter.rst +++ b/docs/formatnwfilter.rst @@ -419,6 +419,37 @@ better organized for more efficient processing by the = firewall subsystem of the underlying host. Currently the system only supports the chains ``root, ipv4, ipv6, arp and rarp``. =20 +General Metadata +~~~~~~~~~~~~~~~~ + +:: + + <filter name=3D'clean-traffic' filter=3D'arp'> + <uuid>6ef53069-ba34-94a0-d33d-17751b9b8cb1</uuid> + <title>A short description - title - of the filter + Some human readable description + + .. + .. + + ... + + +``title`` + The optional element ``title`` provides space for a short description o= f the + filter. The title should not contain any newlines. :since:`Since 9.9.0`= . +``description`` + The content of the ``description`` element provides a human readable + description of the filter. This data is not used by libvirt in any + way, it can contain any information the user wants. :since:`Since 9.9.0` +``metadata`` + The ``metadata`` node can be used by applications to store custom metad= ata in + the form of XML nodes/trees. Applications must use custom namespaces on= their + XML nodes/trees, with only one top-level element per namespace (if the + application needs structure, they should have sub-elements to their nam= espace + element). :since:`Since 9.9.0` + + References to other filters ~~~~~~~~~~~~~~~~~~~~~~~~~~~ =20 diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 35f6efbbe2..d03f78af4d 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -327,6 +327,10 @@ virNWFilterDefFree(virNWFilterDef *def) g_free(def->filterEntries); g_free(def->chainsuffix); =20 + g_free(def->title); + g_free(def->description); + xmlFreeNode(def->metadata); + g_free(def); } =20 @@ -2516,6 +2520,7 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) virNWFilterEntry *entry; int chain_priority; const char *name_prefix; + xmlNodePtr metadataNode =3D NULL; =20 ret =3D g_new0(virNWFilterDef, 1); =20 @@ -2582,6 +2587,23 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) } } =20 + /* Extract short description of filter (title) */ + ret->title =3D virXPathString("string(./title[1])", ctxt); + if (ret->title && strchr(ret->title, '\n')) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Network filter title can't contain newlines")); + return NULL; + } + + /* Extract documentation if present */ + ret->description =3D virXPathString("string(./description[1])", ctxt); + + /* Extract custom metadata */ + if ((metadataNode =3D virXPathNode("./metadata[1]", ctxt)) !=3D NULL) { + ret->metadata =3D xmlCopyNode(metadataNode, 1); + virXMLNodeSanitizeNamespaces(ret->metadata); + } + curr =3D curr->children; =20 while (curr !=3D NULL) { @@ -2873,6 +2895,14 @@ virNWFilterDefFormat(const virNWFilterDef *def) virUUIDFormat(def->uuid, uuid); virBufferAsprintf(&buf, "%s\n", uuid); =20 + virBufferEscapeString(&buf, "%s\n", def->title); + + virBufferEscapeString(&buf, "%s\n", + def->description); + + if (virXMLFormatMetadata(&buf, def->metadata) < 0) + return NULL; + for (i =3D 0; i < def->nentries; i++) { if (virNWFilterEntryFormat(&buf, def->filterEntries[i]) < 0) return NULL; diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h index 22c2fb51f0..34de6eab3d 100644 --- a/src/conf/nwfilter_conf.h +++ b/src/conf/nwfilter_conf.h @@ -517,6 +517,11 @@ struct _virNWFilterDef { =20 size_t nentries; virNWFilterEntry **filterEntries; + + /* User-defined metadata */ + char* title; + char* description; + xmlNodePtr metadata; }; =20 =20 diff --git a/src/conf/schemas/nwfilter.rng b/src/conf/schemas/nwfilter.rng index 262bd551e3..c56bbac732 100644 --- a/src/conf/schemas/nwfilter.rng +++ b/src/conf/schemas/nwfilter.rng @@ -14,6 +14,15 @@ + + + + + + + + + diff --git a/tests/nwfilterxml2xmlin/metadata-test.xml b/tests/nwfilterxml2= xmlin/metadata-test.xml new file mode 100644 index 0000000000..db2c7d2828 --- /dev/null +++ b/tests/nwfilterxml2xmlin/metadata-test.xml @@ -0,0 +1,12 @@ + + 81ff0d90-c91e-6742-64da-4a736edb9a8e + This is a title + This is a description. +It can contain newlines. + + + + fooish + barish + + diff --git a/tests/nwfilterxml2xmlout/metadata-test.xml b/tests/nwfilterxml= 2xmlout/metadata-test.xml new file mode 100644 index 0000000000..fe8bdfee01 --- /dev/null +++ b/tests/nwfilterxml2xmlout/metadata-test.xml @@ -0,0 +1,10 @@ + + 81ff0d90-c91e-6742-64da-4a736edb9a8e + This is a title + This is a description. +It can contain newlines. + + fooish + barish + + diff --git a/tests/nwfilterxml2xmltest.c b/tests/nwfilterxml2xmltest.c index c2481481ee..6a378a853a 100644 --- a/tests/nwfilterxml2xmltest.c +++ b/tests/nwfilterxml2xmltest.c @@ -130,6 +130,7 @@ mymain(void) DO_TEST("iter-test3", false); =20 DO_TEST("ipset-test", false); + DO_TEST("metadata-test", false); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.42.0