From nobody Tue Feb 10 23:32:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1696959400; cv=none; d=zohomail.com; s=zohoarc; b=auVpJe3utZ2djzb6lP0CeRT8Hds2rtCWQCIy9XaAfK6Ue/Yop3CvCh/jbLW48D/AA+m7kjeeP8LWF1tNPZhPlcTWLHTPb8Xr/kmcddpZiaLrDwJfHfqtW2RgEMM2k+j0nPsPTv5x3lMF4gRVuZaZ5iGwsYVcusZ0TZgPqvNuZOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696959400; 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=WvY1hMkWMQiafo5NxrDhvgQrzm1EL3CKW/Q8TEMCEg0=; b=H12eWrENRTtZYda3pVZh24B9rc86GRJlh4MUW9uEUD664KyBo6WjjipwjEdzXK9cYlkFKDDIn1sVje9N1PqPWxgTkwH/mPNMH6myn6u5+mJ9k8lSH4BTszGoT9UKoWHQ0wQ/dlkXqlJujH2l+JSSgfpl0r4shAC4Us5vQVVT2aE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1696959399894445.0292919297425; Tue, 10 Oct 2023 10:36:39 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-45-khY31imeOtWxCs-qZitKRg-1; Tue, 10 Oct 2023 13:36:33 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 EA6302825EAE; Tue, 10 Oct 2023 17:36:24 +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 D26D41BA2; Tue, 10 Oct 2023 17:36:24 +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 517AC1946A54; Tue, 10 Oct 2023 17:36:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1DD351946597 for ; Tue, 10 Oct 2023 17:36:22 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 0D336C0F789; Tue, 10 Oct 2023 17:36:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8536C0F78B for ; Tue, 10 Oct 2023 17:36:21 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 9A195811E94 for ; Tue, 10 Oct 2023 17:36:21 +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-15-p_BYftAZOkC_htdspfwxhQ-1; Tue, 10 Oct 2023 13:36:19 -0400 Received: from mx0.riseup.net (mx0-pn.riseup.net [10.0.1.42]) (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 4S4jW500bmzDqkZ for ; Tue, 10 Oct 2023 17:26:40 +0000 (UTC) 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 mx0.riseup.net (Postfix) with ESMTPS id 4S4jW25vDYz9t6j for ; Tue, 10 Oct 2023 17:26:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews02-sea.riseup.net (Postfix) with ESMTPSA id 4S4jW14c9PzFpcn; Tue, 10 Oct 2023 17:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696959399; 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=WvY1hMkWMQiafo5NxrDhvgQrzm1EL3CKW/Q8TEMCEg0=; b=ERjYqG/RyBWKC2piE/re34wF17M9YR5oP9UiQdqTMUQwhlEmBMNjIPhPt9LbbWN1qH+rCi VQTCgn8/46OHHhCHD1EQlgV0cmyDqRTUKcyqMRbD76clMUN84ZYszcGRbr+vEW2fwLwsOF av2UXSIQJAsI4MBvGicF3QGUQoY5174= X-MC-Unique: khY31imeOtWxCs-qZitKRg-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: p_BYftAZOkC_htdspfwxhQ-1 X-Riseup-User-ID: E77986D09203A7E5DE048A34BCEB3705F515B43655B95483117E8109741EBB3F From: K Shiva Kiran To: libvir-list@redhat.com Subject: [PATCH v2 05/11] virsh: Add new command `nwfilter-metadata` Date: Tue, 10 Oct 2023 22:48:37 +0530 Message-ID: <20231010172509.103884-6-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.8 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.4.1 on 10.11.54.1 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: 1696959400619100002 Content-Type: text/plain; charset="utf-8"; x-default="true" With the new command `nwfilter-metadata`, users will be able to view and modify the `` field of the Network Filter XML. Signed-off-by: K Shiva Kiran --- docs/manpages/virsh.rst | 48 ++++++++++++++ tools/virsh-nwfilter.c | 142 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 3c7cbf1e11..e15f1832e7 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -8174,6 +8174,54 @@ If neither of *--edit* or *--new-desc* are specified= , the title or description is displayed instead of being modified. =20 =20 +nwfilter-metadata +----------------- + + nwfilter-metadata [--nwfilter] nwfilter-name [--uri] uri + [--edit] [[--key] nskey] [--set new-metadata-xml] + [--remove] + +Show or modify custom XML metadata of a network filter. + +The metadata is a user defined XML that allows storing arbitrary XML data +in the network filter definition. +Multiple separate custom metadata pieces can be stored in the +network filter XML. The pieces are identified by a private XML namespace +provided via the *uri* argument. +(See also ``nwfilter-desc`` that works with textual metadata of +a network filter, such as title and description.) + +- *--uri* + + Specifies the URI for the private namespace. + +- *--edit* + + Opens an editor with the metadata identified by the *uri* argument. + Modifications to the contents will be saved back. + Alternatively, the new contents can be provided via the *--set* argument. + +- *--key* + + Specifies the namespace key to be used. + +- *--set* + + Validates and stores the provided metadata string. + + **Note:** When setting metadata via *--edit* or *--set* the *--key* arg= ument + must be specified and is used to prefix the custom elements to bind them + to the private namespace. + +If neither of *--edit* and *--set* are specified the XML metadata correspo= nding +to the *uri* namespace is displayed instead of being modified. + +- *--remove* + + Specifies that the metadata element specified by the *--uri* argument sh= ould + be removed rather than updated. + + NWFILTER BINDING COMMANDS =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =20 diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index 615d126def..801a52746e 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -971,6 +971,142 @@ cmdNWFilterDesc(vshControl *ctl, const vshCmd *cmd) } =20 =20 +/* + * "nwfilter-metadata" command + */ +static const vshCmdInfo info_nwfilter_metadata[] =3D { + {.name =3D "help", + .data =3D N_("show or set network filter's custom XML metadata") + }, + {.name =3D "desc", + .data =3D N_("Shows or modifies the XML metadata of a network filter.= ") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_nwfilter_metadata[] =3D { + {.name =3D "nwfilter", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("network filter name or uuid"), + .completer =3D virshNWFilterNameCompleter, + }, + {.name =3D "uri", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ, + .help =3D N_("URI of the namespace") + }, + {.name =3D "edit", + .type =3D VSH_OT_BOOL, + .help =3D N_("use an editor to change the metadata") + }, + {.name =3D "key", + .type =3D VSH_OT_STRING, + .help =3D N_("key to be used as a namespace identifier"), + }, + {.name =3D "set", + .type =3D VSH_OT_STRING, + .completer =3D virshCompleteEmpty, + .help =3D N_("new metadata to set"), + }, + {.name =3D "remove", + .type =3D VSH_OT_BOOL, + .help =3D N_("remove the metadata corresponding to an uri") + }, + {.name =3D NULL} +}; + +/* helper to add new metadata using the --edit option */ +static char * +virshNWFilterGetEditMetadata(vshControl *ctl G_GNUC_UNUSED, + virNWFilterPtr nwfilter, + const char *uri, + unsigned int flags) +{ + char *ret; + + if (!(ret =3D virNWFilterGetMetadata(nwfilter, VIR_NWFILTER_METADATA_E= LEMENT, + uri, flags))) { + vshResetLibvirtError(); + ret =3D g_strdup("\n"); + } + + return ret; +} + +static bool +cmdNWFilterMetadata(vshControl *ctl, const vshCmd *cmd) +{ + g_autoptr(virshNWFilter) nwfilter =3D NULL; + bool edit =3D vshCommandOptBool(cmd, "edit"); + bool rem =3D vshCommandOptBool(cmd, "remove"); + const char *set =3D NULL; + const char *uri =3D NULL; + const char *key =3D NULL; + unsigned int flags =3D 0; + bool ret =3D false; + + VSH_EXCLUSIVE_OPTIONS("edit", "set"); + VSH_EXCLUSIVE_OPTIONS("remove", "set"); + VSH_EXCLUSIVE_OPTIONS("remove", "edit"); + + if (!(nwfilter =3D virshCommandOptNWFilter(ctl, cmd, NULL))) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "uri", &uri) < 0 || + vshCommandOptStringReq(ctl, cmd, "key", &key) < 0 || + vshCommandOptStringReq(ctl, cmd, "set", &set) < 0) + return false; + + if ((set || edit) && !key) { + vshError(ctl, "%s", + _("namespace key is required when modifying metadata")); + return false; + } + + if (set || rem) { + if (virNWFilterSetMetadata(nwfilter, VIR_NWFILTER_METADATA_ELEMENT, + set, key, uri, flags)) + return false; + + if (rem) + vshPrintExtra(ctl, "%s\n", _("Metadata removed")); + else + vshPrintExtra(ctl, "%s\n", _("Metadata modified")); + } else if (edit) { +#define EDIT_GET_XML \ + virshNWFilterGetEditMetadata(ctl, nwfilter, uri, flags) +#define EDIT_NOT_CHANGED \ + do { \ + vshPrintExtra(ctl, "%s", _("Metadata not changed")); \ + ret =3D true; \ + goto edit_cleanup; \ + } while (0) + +#define EDIT_DEFINE \ + (virNWFilterSetMetadata(nwfilter, VIR_NWFILTER_METADATA_ELEMENT, d= oc_edited, \ + key, uri, flags) =3D=3D 0) +#include "virsh-edit.c" + + vshPrintExtra(ctl, "%s\n", _("Metadata modified")); + } else { + g_autofree char *data =3D NULL; + + /* get */ + if (!(data =3D virNWFilterGetMetadata(nwfilter, VIR_NWFILTER_METAD= ATA_ELEMENT, + uri, flags))) + return false; + + vshPrint(ctl, "%s\n", data); + } + + ret =3D true; + + cleanup: + return ret; +} + + const vshCmdDef nwfilterCmds[] =3D { {.name =3D "nwfilter-define", .handler =3D cmdNWFilterDefine, @@ -1032,5 +1168,11 @@ const vshCmdDef nwfilterCmds[] =3D { .info =3D info_nwfilter_desc, .flags =3D 0 }, + {.name =3D "nwfilter-metadata", + .handler =3D cmdNWFilterMetadata, + .opts =3D opts_nwfilter_metadata, + .info =3D info_nwfilter_metadata, + .flags =3D 0 + }, {.name =3D NULL} }; --=20 2.42.0