2018-05-10 14:29:46 +00:00
|
|
|
/*
|
|
|
|
* virnwfilterbindingobjlist.c: nwfilter binding object list utilities
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "virnwfilterbindingobjlist.h"
|
|
|
|
#include "viralloc.h"
|
|
|
|
#include "virfile.h"
|
|
|
|
#include "virlog.h"
|
|
|
|
#include "virstring.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NWFILTER
|
|
|
|
|
|
|
|
VIR_LOG_INIT("conf.virnwfilterbindingobjlist");
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virClass *virNWFilterBindingObjListClass;
|
2018-05-10 14:29:46 +00:00
|
|
|
static void virNWFilterBindingObjListDispose(void *obj);
|
|
|
|
|
|
|
|
struct _virNWFilterBindingObjList {
|
|
|
|
virObjectRWLockable parent;
|
|
|
|
|
|
|
|
/* port dev name -> virNWFilterBindingObj mapping
|
2022-03-08 16:56:05 +00:00
|
|
|
* for O(1), lookup-by-port dev */
|
2020-10-22 17:04:18 +00:00
|
|
|
GHashTable *objs;
|
2018-05-10 14:29:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int virNWFilterBindingObjListOnceInit(void)
|
|
|
|
{
|
|
|
|
if (!VIR_CLASS_NEW(virNWFilterBindingObjList, virClassForObjectRWLockable()))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-20 17:23:29 +00:00
|
|
|
VIR_ONCE_GLOBAL_INIT(virNWFilterBindingObjList);
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjList *
|
2018-05-10 14:29:46 +00:00
|
|
|
virNWFilterBindingObjListNew(void)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjList *bindings;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
if (virNWFilterBindingObjListInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(bindings = virObjectRWLockableNew(virNWFilterBindingObjListClass)))
|
|
|
|
return NULL;
|
|
|
|
|
2022-07-13 20:26:51 +00:00
|
|
|
bindings->objs = virHashNew(virObjectUnref);
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
return bindings;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
virNWFilterBindingObjListDispose(void *obj)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjList *bindings = obj;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
2021-11-30 13:13:28 +00:00
|
|
|
g_clear_pointer(&bindings->objs, g_hash_table_unref);
|
2018-05-10 14:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNWFilterBindingObj *
|
|
|
|
virNWFilterBindingObjListFindByPortDevLocked(virNWFilterBindingObjList *bindings,
|
2018-05-10 14:29:46 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *obj;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
obj = virHashLookup(bindings->objs, name);
|
|
|
|
if (obj) {
|
2019-03-19 13:39:20 +00:00
|
|
|
virObjectRef(obj);
|
2018-05-10 14:29:46 +00:00
|
|
|
virObjectLock(obj);
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bindings: NWFilterBinding object list
|
|
|
|
* @name: Name to search the bindings->objs table
|
|
|
|
*
|
|
|
|
* Lookup the @name in the bindings->objs hash table and return a
|
|
|
|
* locked and ref counted binding object if found. Caller is expected
|
|
|
|
* to use the virNWFilterBindingObjEndAPI when done with the object.
|
|
|
|
*/
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *
|
|
|
|
virNWFilterBindingObjListFindByPortDev(virNWFilterBindingObjList *bindings,
|
2018-05-10 14:29:46 +00:00
|
|
|
const char *name)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *obj;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
virObjectRWLockRead(bindings);
|
|
|
|
obj = virNWFilterBindingObjListFindByPortDevLocked(bindings, name);
|
|
|
|
virObjectRWUnlock(bindings);
|
|
|
|
|
2021-11-10 08:57:42 +00:00
|
|
|
if (obj && virNWFilterBindingObjGetRemoving(obj))
|
|
|
|
virNWFilterBindingObjEndAPI(&obj);
|
2019-03-19 13:39:20 +00:00
|
|
|
|
2018-05-10 14:29:46 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bindings: NWFilterBinding object list pointer
|
|
|
|
* @binding: NWFilterBinding object to be added
|
|
|
|
*
|
|
|
|
* Upon entry @binding should have at least 1 ref and be locked.
|
|
|
|
*
|
|
|
|
* Add the @binding into the @bindings->objs hash
|
|
|
|
* tables. Once successfully added into a table, increase the
|
|
|
|
* reference count since upon removal in virHashRemoveEntry
|
|
|
|
* the virObjectUnref will be called since the hash tables were
|
2022-07-13 20:26:51 +00:00
|
|
|
* configured to call virObjectUnref when the object is
|
2018-05-10 14:29:46 +00:00
|
|
|
* removed from the hash table.
|
|
|
|
*
|
|
|
|
* Returns 0 on success with 2 references and locked
|
|
|
|
* -1 on failure with 1 reference and locked
|
|
|
|
*/
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjListAddObjLocked(virNWFilterBindingObjList *bindings,
|
|
|
|
virNWFilterBindingObj *binding)
|
2018-05-10 14:29:46 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingDef *def = virNWFilterBindingObjGetDef(binding);
|
2018-05-10 14:29:46 +00:00
|
|
|
if (virHashAddEntry(bindings->objs, def->portdevname, binding) < 0)
|
|
|
|
return -1;
|
|
|
|
virObjectRef(binding);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* virNWFilterBindingObjListAddLocked:
|
|
|
|
*
|
|
|
|
* The returned @binding from this function will be locked and ref
|
|
|
|
* counted. The caller is expected to use virNWFilterBindingObjEndAPI
|
|
|
|
* when it completes usage.
|
|
|
|
*/
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNWFilterBindingObj *
|
|
|
|
virNWFilterBindingObjListAddLocked(virNWFilterBindingObjList *bindings,
|
|
|
|
virNWFilterBindingDef *def)
|
2018-05-10 14:29:46 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *binding;
|
2019-03-20 08:59:48 +00:00
|
|
|
bool stealDef = false;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
/* See if a binding with matching portdev already exists */
|
2019-03-19 13:39:20 +00:00
|
|
|
binding = virNWFilterBindingObjListFindByPortDevLocked(bindings, def->portdevname);
|
|
|
|
if (binding) {
|
|
|
|
if (virNWFilterBindingObjGetRemoving(binding)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
2023-03-09 10:20:54 +00:00
|
|
|
_("binding '%1$s' is already being removed"),
|
2019-03-19 13:39:20 +00:00
|
|
|
def->portdevname);
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
2023-03-09 10:20:54 +00:00
|
|
|
_("binding '%1$s' already exists"),
|
2019-03-19 13:39:20 +00:00
|
|
|
def->portdevname);
|
|
|
|
}
|
2018-05-10 14:29:46 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(binding = virNWFilterBindingObjNew()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
virNWFilterBindingObjSetDef(binding, def);
|
2019-03-20 08:59:48 +00:00
|
|
|
stealDef = true;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
if (virNWFilterBindingObjListAddObjLocked(bindings, binding) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return binding;
|
|
|
|
|
|
|
|
error:
|
2019-03-20 08:59:48 +00:00
|
|
|
if (stealDef)
|
|
|
|
virNWFilterBindingObjStealDef(binding);
|
2018-05-10 14:29:46 +00:00
|
|
|
virNWFilterBindingObjEndAPI(&binding);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *
|
|
|
|
virNWFilterBindingObjListAdd(virNWFilterBindingObjList *bindings,
|
|
|
|
virNWFilterBindingDef *def)
|
2018-05-10 14:29:46 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *ret;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
virObjectRWLockWrite(bindings);
|
|
|
|
ret = virNWFilterBindingObjListAddLocked(bindings, def);
|
|
|
|
virObjectRWUnlock(bindings);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The caller must hold lock on 'bindings' in addition to 'virNWFilterBindingObjListRemove'
|
|
|
|
* requirements
|
|
|
|
*
|
|
|
|
* Can be used to remove current element while iterating with
|
|
|
|
* virNWFilterBindingObjListForEach
|
|
|
|
*/
|
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjListRemoveLocked(virNWFilterBindingObjList *bindings,
|
|
|
|
virNWFilterBindingObj *binding)
|
2018-05-10 14:29:46 +00:00
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingDef *def = virNWFilterBindingObjGetDef(binding);
|
2018-05-10 14:29:46 +00:00
|
|
|
virHashRemoveEntry(bindings->objs, def->portdevname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @bindings: Pointer to the binding object list
|
|
|
|
* @binding: NWFilterBinding pointer from either after Add or FindBy* API where the
|
|
|
|
* @binding was successfully added to the bindings->objs
|
|
|
|
* hash tables that now would need to be removed.
|
|
|
|
*
|
|
|
|
* The caller must hold a lock on the driver owning 'bindings',
|
|
|
|
* and must also have locked and ref counted 'binding', to ensure
|
|
|
|
* no one else is either waiting for 'binding' or still using it.
|
|
|
|
*
|
|
|
|
* When this function returns, @binding will be removed from the hash
|
|
|
|
* tables and returned with lock and refcnt that was present upon entry.
|
|
|
|
*/
|
|
|
|
void
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjListRemove(virNWFilterBindingObjList *bindings,
|
|
|
|
virNWFilterBindingObj *binding)
|
2018-05-10 14:29:46 +00:00
|
|
|
{
|
|
|
|
virNWFilterBindingObjSetRemoving(binding, true);
|
|
|
|
virObjectRef(binding);
|
|
|
|
virObjectUnlock(binding);
|
|
|
|
virObjectRWLockWrite(bindings);
|
|
|
|
virObjectLock(binding);
|
|
|
|
virNWFilterBindingObjListRemoveLocked(bindings, binding);
|
|
|
|
virObjectUnref(binding);
|
|
|
|
virObjectRWUnlock(bindings);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virNWFilterBindingObj *
|
|
|
|
virNWFilterBindingObjListLoadStatus(virNWFilterBindingObjList *bindings,
|
2018-05-10 14:29:46 +00:00
|
|
|
const char *statusDir,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
char *statusFile = NULL;
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *obj = NULL;
|
|
|
|
virNWFilterBindingDef *def;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
if ((statusFile = virNWFilterBindingObjConfigFile(statusDir, name)) == NULL)
|
|
|
|
goto error;
|
|
|
|
|
2022-09-22 13:06:40 +00:00
|
|
|
if (!(obj = virNWFilterBindingObjParse(statusFile)))
|
2018-05-10 14:29:46 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
def = virNWFilterBindingObjGetDef(obj);
|
|
|
|
if (virHashLookup(bindings->objs, def->portdevname) != NULL) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2023-03-09 10:20:54 +00:00
|
|
|
_("unexpected binding %1$s already exists"),
|
2018-05-10 14:29:46 +00:00
|
|
|
def->portdevname);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virNWFilterBindingObjListAddObjLocked(bindings, obj) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
VIR_FREE(statusFile);
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virNWFilterBindingObjEndAPI(&obj);
|
|
|
|
VIR_FREE(statusFile);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjListLoadAllConfigs(virNWFilterBindingObjList *bindings,
|
2018-05-10 14:29:46 +00:00
|
|
|
const char *configDir)
|
|
|
|
{
|
2020-10-25 21:50:51 +00:00
|
|
|
g_autoptr(DIR) dir = NULL;
|
2018-05-10 14:29:46 +00:00
|
|
|
struct dirent *entry;
|
|
|
|
int ret = -1;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
VIR_INFO("Scanning for configs in %s", configDir);
|
|
|
|
|
|
|
|
if ((rc = virDirOpenIfExists(&dir, configDir)) <= 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
virObjectRWLockWrite(bindings);
|
|
|
|
|
|
|
|
while ((ret = virDirRead(dir, &entry, configDir)) > 0) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *binding;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
2019-03-06 14:30:04 +00:00
|
|
|
if (!virStringStripSuffix(entry->d_name, ".xml"))
|
2018-05-10 14:29:46 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* NB: ignoring errors, so one malformed config doesn't
|
|
|
|
kill the whole process */
|
|
|
|
VIR_INFO("Loading config file '%s.xml'", entry->d_name);
|
|
|
|
binding = virNWFilterBindingObjListLoadStatus(bindings,
|
|
|
|
configDir,
|
|
|
|
entry->d_name);
|
|
|
|
if (binding)
|
|
|
|
virNWFilterBindingObjEndAPI(&binding);
|
|
|
|
else
|
2023-03-09 10:20:54 +00:00
|
|
|
VIR_ERROR(_("Failed to load config for binding '%1$s'"), entry->d_name);
|
2018-05-10 14:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virObjectRWUnlock(bindings);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct virNWFilterBindingListIterData {
|
|
|
|
virNWFilterBindingObjListIterator callback;
|
|
|
|
void *opaque;
|
|
|
|
int ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virNWFilterBindingObjListHelper(void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2018-05-10 14:29:46 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
struct virNWFilterBindingListIterData *data = opaque;
|
|
|
|
|
|
|
|
if (data->callback(payload, data->opaque) < 0)
|
|
|
|
data->ret = -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjListForEach(virNWFilterBindingObjList *bindings,
|
2018-05-10 14:29:46 +00:00
|
|
|
virNWFilterBindingObjListIterator callback,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
struct virNWFilterBindingListIterData data = {
|
|
|
|
callback, opaque, 0,
|
|
|
|
};
|
|
|
|
virObjectRWLockRead(bindings);
|
2020-10-23 07:49:36 +00:00
|
|
|
virHashForEachSafe(bindings->objs, virNWFilterBindingObjListHelper, &data);
|
2018-05-10 14:29:46 +00:00
|
|
|
virObjectRWUnlock(bindings);
|
|
|
|
return data.ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct virNWFilterBindingListData {
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj **bindings;
|
2018-05-10 14:29:46 +00:00
|
|
|
size_t nbindings;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virNWFilterBindingObjListCollectIterator(void *payload,
|
2020-10-21 11:31:16 +00:00
|
|
|
const char *name G_GNUC_UNUSED,
|
2018-05-10 14:29:46 +00:00
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
struct virNWFilterBindingListData *data = opaque;
|
|
|
|
|
|
|
|
data->bindings[data->nbindings++] = virObjectRef(payload);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjListFilter(virNWFilterBindingObj ***list,
|
2018-05-10 14:29:46 +00:00
|
|
|
size_t *nbindings,
|
|
|
|
virConnectPtr conn,
|
|
|
|
virNWFilterBindingObjListACLFilter filter)
|
|
|
|
{
|
|
|
|
size_t i = 0;
|
|
|
|
|
|
|
|
while (i < *nbindings) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *binding = (*list)[i];
|
|
|
|
virNWFilterBindingDef *def;
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
virObjectLock(binding);
|
|
|
|
|
|
|
|
def = virNWFilterBindingObjGetDef(binding);
|
|
|
|
/* do not list the object if:
|
|
|
|
* 1) it's being removed.
|
|
|
|
* 2) connection does not have ACL to see it
|
|
|
|
* 3) it doesn't match the filter
|
|
|
|
*/
|
|
|
|
if (virNWFilterBindingObjGetRemoving(binding) ||
|
|
|
|
(filter && !filter(conn, def))) {
|
2021-11-10 08:57:42 +00:00
|
|
|
virNWFilterBindingObjEndAPI(&binding);
|
2018-05-10 14:29:46 +00:00
|
|
|
VIR_DELETE_ELEMENT(*list, i, *nbindings);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
virObjectUnlock(binding);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjListCollect(virNWFilterBindingObjList *domlist,
|
2018-05-10 14:29:46 +00:00
|
|
|
virConnectPtr conn,
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj ***bindings,
|
2018-05-10 14:29:46 +00:00
|
|
|
size_t *nbindings,
|
|
|
|
virNWFilterBindingObjListACLFilter filter)
|
|
|
|
{
|
|
|
|
struct virNWFilterBindingListData data = { NULL, 0 };
|
|
|
|
|
|
|
|
virObjectRWLockRead(domlist);
|
2021-03-11 07:16:13 +00:00
|
|
|
data.bindings = g_new0(virNWFilterBindingObj *, virHashSize(domlist->objs));
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
virHashForEach(domlist->objs, virNWFilterBindingObjListCollectIterator, &data);
|
|
|
|
virObjectRWUnlock(domlist);
|
|
|
|
|
|
|
|
virNWFilterBindingObjListFilter(&data.bindings, &data.nbindings, conn, filter);
|
|
|
|
|
|
|
|
*nbindings = data.nbindings;
|
|
|
|
*bindings = data.bindings;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObjListExport(virNWFilterBindingObjList *bindings,
|
2018-05-10 14:29:46 +00:00
|
|
|
virConnectPtr conn,
|
|
|
|
virNWFilterBindingPtr **bindinglist,
|
|
|
|
virNWFilterBindingObjListACLFilter filter)
|
|
|
|
{
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj **bindingobjs = NULL;
|
2018-05-10 14:29:46 +00:00
|
|
|
size_t nbindings = 0;
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (virNWFilterBindingObjListCollect(bindings, conn, &bindingobjs,
|
|
|
|
&nbindings, filter) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (bindinglist) {
|
2020-10-07 19:15:50 +00:00
|
|
|
*bindinglist = g_new0(virNWFilterBindingPtr, nbindings + 1);
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nbindings; i++) {
|
2021-03-11 07:16:13 +00:00
|
|
|
virNWFilterBindingObj *binding = bindingobjs[i];
|
|
|
|
virNWFilterBindingDef *def = virNWFilterBindingObjGetDef(binding);
|
2018-05-10 14:29:46 +00:00
|
|
|
|
|
|
|
virObjectLock(binding);
|
|
|
|
(*bindinglist)[i] = virGetNWFilterBinding(conn, def->portdevname,
|
|
|
|
def->filter);
|
|
|
|
virObjectUnlock(binding);
|
|
|
|
|
|
|
|
if (!(*bindinglist)[i])
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = nbindings;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virObjectListFreeCount(bindingobjs, nbindings);
|
|
|
|
if (ret < 0) {
|
|
|
|
virObjectListFreeCount(*bindinglist, nbindings);
|
|
|
|
*bindinglist = NULL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|