mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
nwfilter: keep track of active filter bindings
Currently the nwfilter driver does not keep any record of what filter bindings it has active. This means that when it needs to recreate filters, it has to rely on triggering callbacks provided by the virt drivers. This introduces a hash table recording the virNWFilterBinding objects so the driver has a record of all active filters. Reviewed-by: John Ferlan <jferlan@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
ec7c01832c
commit
57f5621f46
@ -22,6 +22,7 @@
|
|||||||
# include "internal.h"
|
# include "internal.h"
|
||||||
|
|
||||||
# include "nwfilter_conf.h"
|
# include "nwfilter_conf.h"
|
||||||
|
# include "virnwfilterbindingobjlist.h"
|
||||||
|
|
||||||
typedef struct _virNWFilterObj virNWFilterObj;
|
typedef struct _virNWFilterObj virNWFilterObj;
|
||||||
typedef virNWFilterObj *virNWFilterObjPtr;
|
typedef virNWFilterObj *virNWFilterObjPtr;
|
||||||
@ -37,7 +38,10 @@ struct _virNWFilterDriverState {
|
|||||||
|
|
||||||
virNWFilterObjListPtr nwfilters;
|
virNWFilterObjListPtr nwfilters;
|
||||||
|
|
||||||
|
virNWFilterBindingObjListPtr bindings;
|
||||||
|
|
||||||
char *configDir;
|
char *configDir;
|
||||||
|
char *bindingDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
virNWFilterDefPtr
|
virNWFilterDefPtr
|
||||||
|
@ -38,7 +38,6 @@
|
|||||||
#include "domain_conf.h"
|
#include "domain_conf.h"
|
||||||
#include "domain_nwfilter.h"
|
#include "domain_nwfilter.h"
|
||||||
#include "nwfilter_driver.h"
|
#include "nwfilter_driver.h"
|
||||||
#include "virnwfilterbindingdef.h"
|
|
||||||
#include "nwfilter_gentech_driver.h"
|
#include "nwfilter_gentech_driver.h"
|
||||||
#include "configmake.h"
|
#include "configmake.h"
|
||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
@ -174,7 +173,6 @@ nwfilterStateInitialize(bool privileged,
|
|||||||
virStateInhibitCallback callback ATTRIBUTE_UNUSED,
|
virStateInhibitCallback callback ATTRIBUTE_UNUSED,
|
||||||
void *opaque ATTRIBUTE_UNUSED)
|
void *opaque ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
char *base = NULL;
|
|
||||||
DBusConnection *sysbus = NULL;
|
DBusConnection *sysbus = NULL;
|
||||||
|
|
||||||
if (virDBusHasSystemBus() &&
|
if (virDBusHasSystemBus() &&
|
||||||
@ -191,6 +189,9 @@ nwfilterStateInitialize(bool privileged,
|
|||||||
if (!(driver->nwfilters = virNWFilterObjListNew()))
|
if (!(driver->nwfilters = virNWFilterObjListNew()))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (!(driver->bindings = virNWFilterBindingObjListNew()))
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (!privileged)
|
if (!privileged)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -230,30 +231,35 @@ nwfilterStateInitialize(bool privileged,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0)
|
if (VIR_STRDUP(driver->configDir, SYSCONFDIR "/libvirt/nwfilter") < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virAsprintf(&driver->configDir,
|
|
||||||
"%s/nwfilter", base) == -1)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
VIR_FREE(base);
|
|
||||||
|
|
||||||
if (virFileMakePathWithMode(driver->configDir, S_IRWXU) < 0) {
|
if (virFileMakePathWithMode(driver->configDir, S_IRWXU) < 0) {
|
||||||
virReportSystemError(errno, _("cannot create config directory '%s'"),
|
virReportSystemError(errno, _("cannot create config directory '%s'"),
|
||||||
driver->configDir);
|
driver->configDir);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (VIR_STRDUP(driver->bindingDir, LOCALSTATEDIR "/run/libvirt/nwfilter-binding") < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (virFileMakePathWithMode(driver->bindingDir, S_IRWXU) < 0) {
|
||||||
|
virReportSystemError(errno, _("cannot create config directory '%s'"),
|
||||||
|
driver->bindingDir);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (virNWFilterObjListLoadAllConfigs(driver->nwfilters, driver->configDir) < 0)
|
if (virNWFilterObjListLoadAllConfigs(driver->nwfilters, driver->configDir) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (virNWFilterBindingObjListLoadAllConfigs(driver->bindings, driver->bindingDir) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
nwfilterDriverUnlock();
|
nwfilterDriverUnlock();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(base);
|
|
||||||
nwfilterDriverUnlock();
|
nwfilterDriverUnlock();
|
||||||
nwfilterStateCleanup();
|
nwfilterStateCleanup();
|
||||||
|
|
||||||
@ -333,9 +339,12 @@ nwfilterStateCleanup(void)
|
|||||||
nwfilterDriverRemoveDBusMatches();
|
nwfilterDriverRemoveDBusMatches();
|
||||||
|
|
||||||
VIR_FREE(driver->configDir);
|
VIR_FREE(driver->configDir);
|
||||||
|
VIR_FREE(driver->bindingDir);
|
||||||
nwfilterDriverUnlock();
|
nwfilterDriverUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virObjectUnref(driver->bindings);
|
||||||
|
|
||||||
/* free inactive nwfilters */
|
/* free inactive nwfilters */
|
||||||
virNWFilterObjListFree(driver->nwfilters);
|
virNWFilterObjListFree(driver->nwfilters);
|
||||||
|
|
||||||
@ -647,13 +656,35 @@ nwfilterInstantiateFilter(const char *vmname,
|
|||||||
const unsigned char *vmuuid,
|
const unsigned char *vmuuid,
|
||||||
virDomainNetDefPtr net)
|
virDomainNetDefPtr net)
|
||||||
{
|
{
|
||||||
virNWFilterBindingDefPtr binding;
|
virNWFilterBindingObjPtr obj;
|
||||||
|
virNWFilterBindingDefPtr def;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!(binding = virNWFilterBindingDefForNet(vmname, vmuuid, net)))
|
obj = virNWFilterBindingObjListFindByPortDev(driver->bindings, net->ifname);
|
||||||
|
if (obj) {
|
||||||
|
virNWFilterBindingObjEndAPI(&obj);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(def = virNWFilterBindingDefForNet(vmname, vmuuid, net)))
|
||||||
return -1;
|
return -1;
|
||||||
ret = virNWFilterInstantiateFilter(driver, binding);
|
|
||||||
virNWFilterBindingDefFree(binding);
|
obj = virNWFilterBindingObjListAdd(driver->bindings,
|
||||||
|
def);
|
||||||
|
if (!obj) {
|
||||||
|
virNWFilterBindingDefFree(def);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = virNWFilterInstantiateFilter(driver, def);
|
||||||
|
|
||||||
|
if (ret >= 0)
|
||||||
|
virNWFilterBindingObjSave(obj, driver->bindingDir);
|
||||||
|
else
|
||||||
|
virNWFilterBindingObjListRemove(driver->bindings, obj);
|
||||||
|
|
||||||
|
virNWFilterBindingObjEndAPI(&obj);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,18 +692,21 @@ nwfilterInstantiateFilter(const char *vmname,
|
|||||||
static void
|
static void
|
||||||
nwfilterTeardownFilter(virDomainNetDefPtr net)
|
nwfilterTeardownFilter(virDomainNetDefPtr net)
|
||||||
{
|
{
|
||||||
virNWFilterBindingDef binding = {
|
virNWFilterBindingObjPtr obj;
|
||||||
.portdevname = net->ifname,
|
virNWFilterBindingDefPtr def;
|
||||||
.linkdevname = (net->type == VIR_DOMAIN_NET_TYPE_DIRECT ?
|
if (!net->ifname)
|
||||||
net->data.direct.linkdev : NULL),
|
return;
|
||||||
.mac = net->mac,
|
|
||||||
.filter = net->filter,
|
obj = virNWFilterBindingObjListFindByPortDev(driver->bindings, net->ifname);
|
||||||
.filterparams = net->filterparams,
|
if (!obj)
|
||||||
.ownername = NULL,
|
return;
|
||||||
.owneruuid = {0},
|
|
||||||
};
|
def = virNWFilterBindingObjGetDef(obj);
|
||||||
if ((net->ifname) && (net->filter))
|
virNWFilterTeardownFilter(def);
|
||||||
virNWFilterTeardownFilter(&binding);
|
virNWFilterBindingObjDelete(obj, driver->bindingDir);
|
||||||
|
|
||||||
|
virNWFilterBindingObjListRemove(driver->bindings, obj);
|
||||||
|
virNWFilterBindingObjEndAPI(&obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user