mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
Remove driver dependency from nwfilter_conf.c
This patch removes the driver dependency from nwfilter_conf.c and moves a callback function calling into the driver into nwfilter_gentech_driver.c and passes a pointer to that callback function upon initialization of nwfilter_conf.c.
This commit is contained in:
parent
285d38931f
commit
0af0ded038
@ -39,7 +39,6 @@
|
||||
#include "nwfilter_params.h"
|
||||
#include "nwfilter_conf.h"
|
||||
#include "domain_conf.h"
|
||||
#include "nwfilter/nwfilter_gentech_driver.h"
|
||||
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NWFILTER
|
||||
@ -2140,56 +2139,7 @@ virNWFilterRegisterCallbackDriver(virNWFilterCallbackDriverPtr cbd)
|
||||
}
|
||||
|
||||
|
||||
enum UpdateStep {
|
||||
STEP_APPLY_NEW,
|
||||
STEP_TEAR_NEW,
|
||||
STEP_TEAR_OLD,
|
||||
};
|
||||
|
||||
struct cbStruct {
|
||||
virConnectPtr conn;
|
||||
enum UpdateStep step;
|
||||
int err;
|
||||
};
|
||||
|
||||
static void
|
||||
virNWFilterDomainFWUpdateCB(void *payload,
|
||||
const char *name ATTRIBUTE_UNUSED,
|
||||
void *data)
|
||||
{
|
||||
virDomainObjPtr obj = payload;
|
||||
virDomainDefPtr vm = obj->def;
|
||||
struct cbStruct *cb = data;
|
||||
int i;
|
||||
|
||||
virDomainObjLock(obj);
|
||||
|
||||
if (virDomainObjIsActive(obj)) {
|
||||
for (i = 0; i < vm->nnets; i++) {
|
||||
virDomainNetDefPtr net = vm->nets[i];
|
||||
if ((net->filter) && (net->ifname)) {
|
||||
switch (cb->step) {
|
||||
case STEP_APPLY_NEW:
|
||||
cb->err = virNWFilterUpdateInstantiateFilter(cb->conn,
|
||||
net);
|
||||
break;
|
||||
|
||||
case STEP_TEAR_NEW:
|
||||
cb->err = virNWFilterRollbackUpdateFilter(cb->conn, net);
|
||||
break;
|
||||
|
||||
case STEP_TEAR_OLD:
|
||||
cb->err = virNWFilterTearOldFilter(cb->conn, net);
|
||||
break;
|
||||
}
|
||||
if (cb->err)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virDomainObjUnlock(obj);
|
||||
}
|
||||
static virHashIterator virNWFilterDomainFWUpdateCB;
|
||||
|
||||
|
||||
static int
|
||||
@ -2197,7 +2147,7 @@ virNWFilterTriggerVMFilterRebuild(virConnectPtr conn)
|
||||
{
|
||||
int i;
|
||||
int err;
|
||||
struct cbStruct cb = {
|
||||
struct domUpdateCBStruct cb = {
|
||||
.conn = conn,
|
||||
.err = 0,
|
||||
.step = STEP_APPLY_NEW,
|
||||
@ -2793,8 +2743,10 @@ char *virNWFilterConfigFile(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
}
|
||||
|
||||
|
||||
int virNWFilterConfLayerInit(void)
|
||||
int virNWFilterConfLayerInit(virHashIterator domUpdateCB)
|
||||
{
|
||||
virNWFilterDomainFWUpdateCB = domUpdateCB;
|
||||
|
||||
if (virMutexInit(&updateMutex))
|
||||
return 1;
|
||||
|
||||
|
@ -432,6 +432,19 @@ struct _virNWFilterRuleInst {
|
||||
};
|
||||
|
||||
|
||||
enum UpdateStep {
|
||||
STEP_APPLY_NEW,
|
||||
STEP_TEAR_NEW,
|
||||
STEP_TEAR_OLD,
|
||||
};
|
||||
|
||||
struct domUpdateCBStruct {
|
||||
virConnectPtr conn;
|
||||
enum UpdateStep step;
|
||||
int err;
|
||||
};
|
||||
|
||||
|
||||
enum virDomainNetType;
|
||||
|
||||
typedef int (*virNWFilterRuleCreateInstance)(virConnectPtr conn,
|
||||
@ -546,7 +559,7 @@ virNWFilterDefPtr virNWFilterDefParseFile(virConnectPtr conn,
|
||||
void virNWFilterPoolObjLock(virNWFilterPoolObjPtr obj);
|
||||
void virNWFilterPoolObjUnlock(virNWFilterPoolObjPtr obj);
|
||||
|
||||
int virNWFilterConfLayerInit(void);
|
||||
int virNWFilterConfLayerInit(virHashIterator domUpdateCB);
|
||||
void virNWFilterConfLayerShutdown(void);
|
||||
|
||||
int virNWFilterParamConfLayerInit(void);
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "memory.h"
|
||||
#include "domain_conf.h"
|
||||
#include "nwfilter_driver.h"
|
||||
#include "nwfilter_gentech_driver.h"
|
||||
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NWFILTER
|
||||
@ -64,7 +65,7 @@ static int
|
||||
nwfilterDriverStartup(int privileged) {
|
||||
char *base = NULL;
|
||||
|
||||
if (virNWFilterConfLayerInit() < 0)
|
||||
if (virNWFilterConfLayerInit(virNWFilterDomainFWUpdateCB) < 0)
|
||||
return -1;
|
||||
|
||||
if (VIR_ALLOC(driverState) < 0)
|
||||
|
@ -681,3 +681,43 @@ virNWFilterTeardownFilter(const virDomainNetDefPtr net)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virNWFilterDomainFWUpdateCB(void *payload,
|
||||
const char *name ATTRIBUTE_UNUSED,
|
||||
void *data)
|
||||
{
|
||||
virDomainObjPtr obj = payload;
|
||||
virDomainDefPtr vm = obj->def;
|
||||
struct domUpdateCBStruct *cb = data;
|
||||
int i;
|
||||
|
||||
virDomainObjLock(obj);
|
||||
|
||||
if (virDomainObjIsActive(obj)) {
|
||||
for (i = 0; i < vm->nnets; i++) {
|
||||
virDomainNetDefPtr net = vm->nets[i];
|
||||
if ((net->filter) && (net->ifname)) {
|
||||
switch (cb->step) {
|
||||
case STEP_APPLY_NEW:
|
||||
cb->err = virNWFilterUpdateInstantiateFilter(cb->conn,
|
||||
net);
|
||||
break;
|
||||
|
||||
case STEP_TEAR_NEW:
|
||||
cb->err = virNWFilterRollbackUpdateFilter(cb->conn, net);
|
||||
break;
|
||||
|
||||
case STEP_TEAR_OLD:
|
||||
cb->err = virNWFilterTearOldFilter(cb->conn, net);
|
||||
break;
|
||||
}
|
||||
if (cb->err)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virDomainObjUnlock(obj);
|
||||
}
|
||||
|
@ -51,4 +51,8 @@ int virNWFilterTeardownFilter(const virDomainNetDefPtr net);
|
||||
virNWFilterHashTablePtr virNWFilterCreateVarHashmap(virConnectPtr conn,
|
||||
char *macaddr);
|
||||
|
||||
void virNWFilterDomainFWUpdateCB(void *payload,
|
||||
const char *name ATTRIBUTE_UNUSED,
|
||||
void *data);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user