Introduces `virNWFilterSetMetadata()` to modify user defined
metadata fields, i.e `<title>`, `<description>` and `<metadata>`
Signed-off-by: K Shiva Kiran <shiva_kr(a)riseup.net>
---
include/libvirt/libvirt-nwfilter.h | 8 +++
src/driver-nwfilter.h | 9 ++++
src/libvirt-nwfilter.c | 87 ++++++++++++++++++++++++++++++
src/libvirt_public.syms | 5 ++
4 files changed, 109 insertions(+)
diff --git a/include/libvirt/libvirt-nwfilter.h b/include/libvirt/libvirt-nwfilter.h
index a9930a1e66..ecab779665 100644
--- a/include/libvirt/libvirt-nwfilter.h
+++ b/include/libvirt/libvirt-nwfilter.h
@@ -173,4 +173,12 @@ typedef enum {
VIR_NWFILTER_METADATA_LAST /* (Since: 9.8.0) */
# endif
} virNWFilterMetadataType;
+
+int virNWFilterSetMetadata(virNWFilterPtr nwfilter,
+ int type,
+ const char *metadata,
+ const char *key,
+ const char *uri,
+ unsigned int flags);
+
#endif /* LIBVIRT_NWFILTER_H */
diff --git a/src/driver-nwfilter.h b/src/driver-nwfilter.h
index 1ec591ece9..3426781fa0 100644
--- a/src/driver-nwfilter.h
+++ b/src/driver-nwfilter.h
@@ -86,6 +86,14 @@ typedef int
typedef int
(*virDrvNWFilterBindingFree)(virNWFilterBindingPtr binding);
+typedef int
+(*virDrvNWFilterSetMetadata)(virNWFilterPtr nwfilter,
+ int type,
+ const char *metadata,
+ const char *key,
+ const char *uri,
+ unsigned int flags);
+
typedef struct _virNWFilterDriver virNWFilterDriver;
@@ -111,4 +119,5 @@ struct _virNWFilterDriver {
virDrvNWFilterBindingCreateXML nwfilterBindingCreateXML;
virDrvNWFilterBindingDelete nwfilterBindingDelete;
virDrvNWFilterBindingGetXMLDesc nwfilterBindingGetXMLDesc;
+ virDrvNWFilterSetMetadata nwfilterSetMetadata;
};
diff --git a/src/libvirt-nwfilter.c b/src/libvirt-nwfilter.c
index ff82cc3b7f..0a0fbdd195 100644
--- a/src/libvirt-nwfilter.c
+++ b/src/libvirt-nwfilter.c
@@ -920,3 +920,90 @@ virNWFilterBindingRef(virNWFilterBindingPtr binding)
virObjectRef(binding);
return 0;
}
+
+
+/**
+ * virNWFilterSetMetadata:
+ * @nwfilter: a network filter object
+ * @type: type of metadata, from virNWFilterMetadataType
+ * @metadata: new metadata text
+ * @key: XML namespace key, or NULL
+ * @uri: XML namespace URI, or NULL
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Sets the appropriate nwfilter element given by @type to the
+ * value of @metadata.
+ * For options VIR_NWFILTER_METADATA_TITLE and VIR_NWFILTER_METADATA_DESCRIPTION
+ * @key and @uri are irrelevant and must be set to NULL.
+ *
+ * For type VIR_NWFILTER_METADATA_ELEMENT @metadata must be a well-formed
+ * XML belonging to namespace defined by @uri with local name @key.
+ *
+ * Passing NULL for @metadata says to remove that element from the
+ * network filter XML (passing the empty string leaves the element present).
+ *
+ * The resulting metadata will be present in virNWFilterGetXMLDesc(),
+ * as well as quick access through virNWFilterGetMetadata().
+ *
+ * Returns 0 on success, -1 in case of failure.
+ *
+ * Since: 9.8.0
+ */
+int
+virNWFilterSetMetadata(virNWFilterPtr nwfilter,
+ int type,
+ const char *metadata,
+ const char *key,
+ const char *uri,
+ unsigned int flags)
+{
+ virConnectPtr conn;
+
+ VIR_DEBUG("nwfilter=%p, type=%d, metadata='%s', key='%s',
uri='%s', flags=0x%x",
+ nwfilter, type, NULLSTR(metadata), NULLSTR(key), NULLSTR(uri),
+ flags);
+
+ virResetLastError();
+
+ virCheckNWFilterReturn(nwfilter, -1);
+ conn = nwfilter->conn;
+
+ virCheckReadOnlyGoto(conn->flags, error);
+
+ switch (type) {
+ case VIR_NWFILTER_METADATA_TITLE:
+ if (metadata && strchr(metadata, '\n')) {
+ virReportInvalidArg(metadata, "%s",
+ _("metadata title can't contain
newlines"));
+ goto error;
+ }
+ G_GNUC_FALLTHROUGH;
+ case VIR_NWFILTER_METADATA_DESCRIPTION:
+ virCheckNullArgGoto(uri, error);
+ virCheckNullArgGoto(key, error);
+ break;
+ case VIR_NWFILTER_METADATA_ELEMENT:
+ virCheckNonNullArgGoto(uri, error);
+ if (metadata)
+ virCheckNonNullArgGoto(key, error);
+ break;
+ default:
+ /* For future expansion */
+ break;
+ }
+
+ if (conn->nwfilterDriver->nwfilterSetMetadata) {
+ int ret;
+ ret = conn->nwfilterDriver->nwfilterSetMetadata(nwfilter, type, metadata,
key, uri,
+ flags);
+ if (ret < 0)
+ goto error;
+ return ret;
+ }
+
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(nwfilter->conn);
+ return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index bd1e916d2a..4e3b17b475 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -938,4 +938,9 @@ LIBVIRT_9.7.0 {
virNetworkSetMetadata;
} LIBVIRT_9.0.0;
+LIBVIRT_9.8.0 {
+ global:
+ virNWFilterSetMetadata;
+} LIBVIRT_9.7.0;
+
# .... define new API here using predicted next version number ....
--
2.42.0