Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/Makefile.am | 1 +
data/org.libvirt.NWFilter.xml | 7 +++++
src/Makefile.am | 1 +
src/connect.c | 6 ++++
src/connect.h | 1 +
src/nwfilter.c | 65 +++++++++++++++++++++++++++++++++++++++++++
src/nwfilter.h | 9 ++++++
src/util.c | 32 +++++++++++++++++++++
src/util.h | 15 ++++++++++
9 files changed, 137 insertions(+)
create mode 100644 data/org.libvirt.NWFilter.xml
create mode 100644 src/nwfilter.c
create mode 100644 src/nwfilter.h
diff --git a/data/Makefile.am b/data/Makefile.am
index 5a085cd..fdec857 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -22,6 +22,7 @@ interfaces_files = \
org.libvirt.Connect.xml \
org.libvirt.Domain.xml \
org.libvirt.Network.xml \
+ org.libvirt.NWFilter.xml \
org.libvirt.Secret.xml \
org.libvirt.StoragePool.xml
interfacesdir = $(DBUS_INTERFACES_DIR)
diff --git a/data/org.libvirt.NWFilter.xml b/data/org.libvirt.NWFilter.xml
new file mode 100644
index 0000000..c025d30
--- /dev/null
+++ b/data/org.libvirt.NWFilter.xml
@@ -0,0 +1,7 @@
+<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection
1.0//EN"
+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
+
+<node name="/org/libvirt/nwfilter">
+ <interface name="org.libvirt.NWFilter">
+ </interface>
+</node>
diff --git a/src/Makefile.am b/src/Makefile.am
index 6b2887b..22128c2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,7 @@ DAEMON_SOURCES = \
events.c events.h \
gdbus.c gdbus.h \
network.c network.h \
+ nwfilter.c nwfilter.h \
secret.c secret.h \
storagepool.c storagepool.h
diff --git a/src/connect.c b/src/connect.c
index 0b33bc5..136f7ae 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -2,6 +2,7 @@
#include "domain.h"
#include "events.h"
#include "network.h"
+#include "nwfilter.h"
#include "secret.h"
#include "storagepool.h"
#include "util.h"
@@ -1394,6 +1395,7 @@ virtDBusConnectFree(virtDBusConnect *connect)
g_free(connect->domainPath);
g_free(connect->networkPath);
+ g_free(connect->nwfilterPath);
g_free(connect->secretPath);
g_free(connect->storagePoolPath);
g_free(connect);
@@ -1451,6 +1453,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
if (error && *error)
return;
+ virtDBusNWFilterRegister(connect, error);
+ if (error && *error)
+ return;
+
virtDBusSecretRegister(connect, error);
if (error && *error)
return;
diff --git a/src/connect.h b/src/connect.h
index 08e1b68..fe672ed 100644
--- a/src/connect.h
+++ b/src/connect.h
@@ -14,6 +14,7 @@ struct virtDBusConnect {
const gchar *connectPath;
gchar *domainPath;
gchar *networkPath;
+ gchar *nwfilterPath;
gchar *secretPath;
gchar *storagePoolPath;
virConnectPtr connection;
diff --git a/src/nwfilter.c b/src/nwfilter.c
new file mode 100644
index 0000000..4d20162
--- /dev/null
+++ b/src/nwfilter.c
@@ -0,0 +1,65 @@
+#include "nwfilter.h"
+#include "util.h"
+
+#include <libvirt/libvirt.h>
+
+static virtDBusGDBusPropertyTable virtDBusNWFilterPropertyTable[] = {
+ { 0 }
+};
+
+static virtDBusGDBusMethodTable virtDBusNWFilterMethodTable[] = {
+ { 0 }
+};
+
+static gchar **
+virtDBusNWFilterEnumerate(gpointer userData)
+{
+ virtDBusConnect *connect = userData;
+ g_autoptr(virNWFilterPtr) nwfilters = NULL;
+ gint num = 0;
+ gchar **ret = NULL;
+
+ if (!virtDBusConnectOpen(connect, NULL))
+ return NULL;
+
+ num = virConnectListAllNWFilters(connect->connection, &nwfilters, 0);
+ if (num < 0)
+ return NULL;
+
+ if (num == 0)
+ return NULL;
+
+ ret = g_new0(gchar *, num + 1);
+
+ for (gint i = 0; i < num; i++) {
+ ret[i] = virtDBusUtilBusPathForVirNWFilter(nwfilters[i],
+ connect->nwfilterPath);
+ }
+
+ return ret;
+}
+
+static GDBusInterfaceInfo *interfaceInfo;
+
+void
+virtDBusNWFilterRegister(virtDBusConnect *connect,
+ GError **error)
+{
+ connect->nwfilterPath = g_strdup_printf("%s/nwfilter",
+ connect->connectPath);
+
+ if (!interfaceInfo) {
+ interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_NWFILTER_INTERFACE,
+ error);
+ if (!interfaceInfo)
+ return;
+ }
+
+ virtDBusGDBusRegisterSubtree(connect->bus,
+ connect->nwfilterPath,
+ interfaceInfo,
+ virtDBusNWFilterEnumerate,
+ virtDBusNWFilterMethodTable,
+ virtDBusNWFilterPropertyTable,
+ connect);
+}
diff --git a/src/nwfilter.h b/src/nwfilter.h
new file mode 100644
index 0000000..7afd27f
--- /dev/null
+++ b/src/nwfilter.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "connect.h"
+
+#define VIRT_DBUS_NWFILTER_INTERFACE "org.libvirt.NWFilter"
+
+void
+virtDBusNWFilterRegister(virtDBusConnect *connect,
+ GError **error);
diff --git a/src/util.c b/src/util.c
index 9dd901c..f6aa210 100644
--- a/src/util.c
+++ b/src/util.c
@@ -247,6 +247,38 @@ virtDBusUtilVirNetworkListFree(virNetworkPtr *networks)
g_free(networks);
}
+virNWFilterPtr
+virtDBusUtilVirNWFilterFromBusPath(virConnectPtr connection,
+ const gchar *path,
+ const gchar *nwfilterPath)
+{
+ g_autofree gchar *name = NULL;
+ gsize prefixLen = strlen(nwfilterPath) + 1;
+
+ name = virtDBusUtilDecodeUUID(path+prefixLen);
+
+ return virNWFilterLookupByUUIDString(connection, name);
+}
+
+gchar *
+virtDBusUtilBusPathForVirNWFilter(virNWFilterPtr nwfilter,
+ const gchar *nwfilterPath)
+{
+ gchar uuid[VIR_UUID_STRING_BUFLEN] = "";
+ g_autofree gchar *newUuid = NULL;
+ virNWFilterGetUUIDString(nwfilter, uuid);
+ newUuid = virtDBusUtilEncodeUUID(uuid);
+ return g_strdup_printf("%s/%s", nwfilterPath, newUuid);
+}
+
+void
+virtDBusUtilVirNWFilterListFree(virNWFilterPtr *nwfilters)
+{
+ for (gint i = 0; nwfilters[i] != NULL; i++)
+ virNWFilterFree(nwfilters[i]);
+
+ g_free(nwfilters);
+}
void
virtDBusUtilStringListFree(virtDBusCharArray *item)
{
diff --git a/src/util.h b/src/util.h
index 2f37933..09546e3 100644
--- a/src/util.h
+++ b/src/util.h
@@ -72,6 +72,21 @@ virtDBusUtilVirNetworkListFree(virNetworkPtr *networks);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetwork, virNetworkFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetworkPtr, virtDBusUtilVirNetworkListFree);
+virNWFilterPtr
+virtDBusUtilVirNWFilterFromBusPath(virConnectPtr connection,
+ const gchar *path,
+ const gchar *nwfilterPath);
+
+gchar *
+virtDBusUtilBusPathForVirNWFilter(virNWFilterPtr nwfilter,
+ const gchar *nwfilterPath);
+
+void
+virtDBusUtilVirNWFilterListFree(virNWFilterPtr *nwfilters);
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNWFilter, virNWFilterFree);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNWFilterPtr, virtDBusUtilVirNWFilterListFree);
+
typedef gchar *virtDBusCharArray;
void
--
2.15.0