Commit 7e7949c0 authored by Katerina Koukiou's avatar Katerina Koukiou

Introduce NWFilter Interface

Signed-off-by: default avatarKaterina Koukiou <kkoukiou@redhat.com>
Reviewed-by: Jano Tomko's avatarJán Tomko <jtomko@redhat.com>
parent bd32e559
......@@ -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)
......
<!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>
......@@ -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
......
......@@ -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"
......@@ -1483,6 +1484,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);
......@@ -1540,6 +1542,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
if (error && *error)
return;
virtDBusNWFilterRegister(connect, error);
if (error && *error)
return;
virtDBusSecretRegister(connect, error);
if (error && *error)
return;
......
......@@ -14,6 +14,7 @@ struct virtDBusConnect {
const gchar *connectPath;
gchar *domainPath;
gchar *networkPath;
gchar *nwfilterPath;
gchar *secretPath;
gchar *storagePoolPath;
virConnectPtr connection;
......
#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);
}
#pragma once
#include "connect.h"
#define VIRT_DBUS_NWFILTER_INTERFACE "org.libvirt.NWFilter"
void
virtDBusNWFilterRegister(virtDBusConnect *connect,
GError **error);
......@@ -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)
{
......
......@@ -74,6 +74,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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment