int refctr;
virNWFilterTechDriverPtr techdriver;
- char *ifname;
+ virNWFilterBindingDefPtr binding;
int ifindex;
- char *linkdev;
char ifkey[VIR_IFKEY_LEN];
- virMacAddr macaddr;
- char *filtername;
- virHashTablePtr vars;
virNWFilterDriverStatePtr driver;
/* start and end of lease list, ordered by lease time */
virNWFilterSnoopIPLeasePtr start;
req = ipl->snoopReq;
- /* protect req->ifname */
+ /* protect req->binding->portdevname */
virNWFilterSnoopReqLock(req);
- if (virNWFilterIPAddrMapAddIPAddr(req->ifname, ipaddr) < 0)
+ if (virNWFilterIPAddrMapAddIPAddr(req->binding->portdevname, ipaddr) < 0)
goto exit_snooprequnlock;
if (!instantiate) {
/* instantiate the filters */
- if (req->ifname) {
- virNWFilterBindingDef binding = {
- .portdevname = req->ifname,
- .linkdevname = req->linkdev,
- .mac = req->macaddr,
- .filter = req->filtername,
- .filterparams = req->vars,
- .ownername = NULL,
- .owneruuid = {0},
- };
+ if (req->binding->portdevname) {
rc = virNWFilterInstantiateFilterLate(req->driver,
- &binding,
+ req->binding,
req->ifindex);
}
virNWFilterSnoopReqLeaseDel(req, &ipl->ipAddress, false, false);
/* free all req data */
- VIR_FREE(req->ifname);
- VIR_FREE(req->linkdev);
- VIR_FREE(req->filtername);
- virHashFree(req->vars);
+ virNWFilterBindingDefFree(req->binding);
virMutexDestroy(&req->lock);
virCondDestroy(&req->threadStatusCond);
if (update_leasefile)
virNWFilterSnoopLeaseFileSave(ipl);
- ipAddrLeft = virNWFilterIPAddrMapDelIPAddr(req->ifname, ipstr);
+ ipAddrLeft = virNWFilterIPAddrMapDelIPAddr(req->binding->portdevname, ipstr);
if (!req->threadkey || !instantiate)
goto skip_instantiate;
if (ipAddrLeft) {
- virNWFilterBindingDef binding = {
- .portdevname = req->ifname,
- .linkdevname = req->linkdev,
- .mac = req->macaddr,
- .filter = req->filtername,
- .filterparams = req->vars,
- .ownername = NULL,
- .owneruuid = {0},
- };
ret = virNWFilterInstantiateFilterLate(req->driver,
- &binding,
+ req->binding,
req->ifindex);
} else {
virNWFilterVarValuePtr dhcpsrvrs =
- virHashLookup(req->vars, NWFILTER_VARNAME_DHCPSERVER);
+ virHashLookup(req->binding->filterparams,
+ NWFILTER_VARNAME_DHCPSERVER);
if (req->techdriver &&
- req->techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr,
+ req->techdriver->applyDHCPOnlyRules(req->binding->portdevname,
+ &req->binding->mac,
dhcpsrvrs, false) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("virNWFilterSnoopListDel failed"));
* inside the DHCP response
*/
if (!fromVM) {
- if (virMacAddrCmpRaw(&req->macaddr,
+ if (virMacAddrCmpRaw(&req->binding->mac,
(unsigned char *)&pd->d_chaddr) != 0)
return -2;
}
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Instantiation of rules failed on "
- "interface '%s'"), req->ifname);
+ "interface '%s'"), req->binding->portdevname);
}
virAtomicIntDecAndTest(job->qCtr);
VIR_FREE(job);
/* whoever started us increased the reference counter for the req for us */
- /* protect req->ifname & req->threadkey */
+ /* protect req->binding->portdevname & req->threadkey */
virNWFilterSnoopReqLock(req);
- if (req->ifname && req->threadkey) {
+ if (req->binding->portdevname && req->threadkey) {
for (i = 0; i < ARRAY_CARDINALITY(pcapConf); i++) {
pcapConf[i].handle =
- virNWFilterSnoopDHCPOpen(req->ifname, &req->macaddr,
+ virNWFilterSnoopDHCPOpen(req->binding->portdevname,
+ &req->binding->mac,
pcapConf[i].filter,
pcapConf[i].dir);
if (!pcapConf[i].handle) {
}
fds[i].fd = pcap_fileno(pcapConf[i].handle);
}
- tmp = virNetDevGetIndex(req->ifname, &ifindex);
+ tmp = virNetDevGetIndex(req->binding->portdevname, &ifindex);
ignore_value(VIR_STRDUP(threadkey, req->threadkey));
worker = virThreadPoolNew(1, 1, 0,
virNWFilterDHCPDecodeWorker,
/* error reading from socket */
tmp = -1;
- /* protect req->ifname */
+ /* protect req->binding->portdevname */
virNWFilterSnoopReqLock(req);
- if (req->ifname)
- tmp = virNetDevValidateConfig(req->ifname, NULL, ifindex);
+ if (req->binding->portdevname)
+ tmp = virNetDevValidateConfig(req->binding->portdevname, NULL, ifindex);
virNWFilterSnoopReqUnlock(req);
pcap_close(pcapConf[i].handle);
pcapConf[i].handle = NULL;
- /* protect req->ifname */
+ /* protect req->binding->portdevname */
virNWFilterSnoopReqLock(req);
virReportError(VIR_ERR_INTERNAL_ERROR,
_("interface '%s' failing; "
"reopening"),
- req->ifname);
- if (req->ifname)
+ req->binding->portdevname);
+ if (req->binding->portdevname)
pcapConf[i].handle =
- virNWFilterSnoopDHCPOpen(req->ifname, &req->macaddr,
+ virNWFilterSnoopDHCPOpen(req->binding->portdevname,
+ &req->binding->mac,
pcapConf[i].filter,
pcapConf[i].dir);
last_displayed_queue = time(0);
VIR_WARN("Worker thread for interface '%s' has a "
"job queue that is too long",
- req->ifname);
+ req->binding->portdevname);
}
continue;
}
if (time(0) - last_displayed > 10) {
last_displayed = time(0);
VIR_WARN("Too many DHCP packets on interface '%s'",
- req->ifname);
+ req->binding->portdevname);
}
continue;
}
&pcapConf[i].qCtr) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Job submission failed on "
- "interface '%s'"), req->ifname);
+ "interface '%s'"), req->binding->portdevname);
error = true;
break;
}
/* protect IfNameToKey */
virNWFilterSnoopLock();
- /* protect req->ifname & req->threadkey */
+ /* protect req->binding->portdevname & req->threadkey */
virNWFilterSnoopReqLock(req);
virNWFilterSnoopCancel(&req->threadkey);
ignore_value(virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey,
- req->ifname));
+ req->binding->portdevname));
- VIR_FREE(req->ifname);
+ VIR_FREE(req->binding->portdevname);
virNWFilterSnoopReqUnlock(req);
virNWFilterSnoopUnlock();
int
virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
- const char *ifname,
- const char *linkdev,
- const unsigned char *vmuuid,
- const virMacAddr *macaddr,
- const char *filtername,
- virHashTablePtr filterparams,
+ virNWFilterBindingDefPtr binding,
virNWFilterDriverStatePtr driver)
{
virNWFilterSnoopReqPtr req;
virNWFilterVarValuePtr dhcpsrvrs;
bool threadPuts = false;
- virNWFilterSnoopIFKeyFMT(ifkey, vmuuid, macaddr);
+ virNWFilterSnoopIFKeyFMT(ifkey, binding->owneruuid, &binding->mac);
req = virNWFilterSnoopReqGetByIFKey(ifkey);
isnewreq = (req == NULL);
virNWFilterSnoopReqPut(req);
return 0;
}
- /* a recycled req may still have filtername and vars */
- VIR_FREE(req->filtername);
- virHashFree(req->vars);
+ virNWFilterBindingDefFree(req->binding);
+ req->binding = NULL;
} else {
req = virNWFilterSnoopReqNew(ifkey);
if (!req)
req->driver = driver;
req->techdriver = techdriver;
- tmp = virNetDevGetIndex(ifname, &req->ifindex);
- virMacAddrSet(&req->macaddr, macaddr);
- req->vars = virNWFilterHashTableCreate(0);
- req->linkdev = NULL;
-
- if (VIR_STRDUP(req->ifname, ifname) < 0 ||
- VIR_STRDUP(req->filtername, filtername) < 0 ||
- VIR_STRDUP(req->linkdev, linkdev) < 0)
+ if ((tmp = virNetDevGetIndex(binding->portdevname, &req->ifindex)) < 0)
goto exit_snoopreqput;
-
- if (!req->vars || tmp < 0)
+ if (!(req->binding = virNWFilterBindingDefCopy(binding)))
goto exit_snoopreqput;
/* check that all tools are available for applying the filters (late) */
goto exit_snoopreqput;
}
- dhcpsrvrs = virHashLookup(filterparams,
+ dhcpsrvrs = virHashLookup(binding->filterparams,
NWFILTER_VARNAME_DHCPSERVER);
- if (techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr,
+ if (techdriver->applyDHCPOnlyRules(req->binding->portdevname,
+ &req->binding->mac,
dhcpsrvrs, false) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("applyDHCPOnlyRules "
goto exit_snoopreqput;
}
- if (virNWFilterHashTablePutAll(filterparams, req->vars) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("virNWFilterDHCPSnoopReq: can't copy variables"
- " on if %s"), ifkey);
- goto exit_snoopreqput;
- }
-
virNWFilterSnoopLock();
- if (virHashAddEntry(virNWFilterSnoopState.ifnameToKey, ifname,
+ if (virHashAddEntry(virNWFilterSnoopState.ifnameToKey,
+ req->binding->portdevname,
req->ifkey) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterDHCPSnoopReq ifname map failed"
- " on interface \"%s\" key \"%s\""), ifname,
+ " on interface \"%s\" key \"%s\""), binding->portdevname,
ifkey);
goto exit_snoopunlock;
}
virHashAddEntry(virNWFilterSnoopState.snoopReqs, ifkey, req) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterDHCPSnoopReq req add failed on"
- " interface \"%s\" ifkey \"%s\""), ifname,
+ " interface \"%s\" ifkey \"%s\""), binding->portdevname,
ifkey);
goto exit_rem_ifnametokey;
}
req) != 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterDHCPSnoopReq virThreadCreate "
- "failed on interface '%s'"), ifname);
+ "failed on interface '%s'"), binding->portdevname);
goto exit_snoopreq_unlock;
}
if (!req->threadkey) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Activation of snoop request failed on "
- "interface '%s'"), req->ifname);
+ "interface '%s'"), req->binding->portdevname);
goto exit_snoopreq_unlock;
}
if (virNWFilterSnoopReqRestore(req) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Restoring of leases failed on "
- "interface '%s'"), req->ifname);
+ "interface '%s'"), req->binding->portdevname);
goto exit_snoop_cancel;
}
exit_snoopreq_unlock:
virNWFilterSnoopReqUnlock(req);
exit_rem_ifnametokey:
- virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey, ifname);
+ virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey, binding->portdevname);
exit_snoopunlock:
virNWFilterSnoopUnlock();
exit_snoopreqput:
{
virNWFilterSnoopReqPtr req = (virNWFilterSnoopReqPtr)payload;
- /* protect req->ifname */
+ /* protect req->binding->portdevname */
virNWFilterSnoopReqLock(req);
- if (req->ifname) {
+ if (req->binding->portdevname) {
ignore_value(virHashRemoveEntry(virNWFilterSnoopState.ifnameToKey,
- req->ifname));
+ req->binding->portdevname));
/*
* Remove all IP addresses known to be associated with this
* interface so that a new thread will be started on this
* interface
*/
- virNWFilterIPAddrMapDelIPAddr(req->ifname, NULL);
+ virNWFilterIPAddrMapDelIPAddr(req->binding->portdevname, NULL);
- VIR_FREE(req->ifname);
+ VIR_FREE(req->binding->portdevname);
}
virNWFilterSnoopReqUnlock(req);
goto cleanup;
}
- /* protect req->ifname & req->threadkey */
+ /* protect req->binding->portdevname & req->threadkey */
virNWFilterSnoopReqLock(req);
/* keep valid lease req; drop interface association */
virNWFilterSnoopCancel(&req->threadkey);
- VIR_FREE(req->ifname);
+ VIR_FREE(req->binding->portdevname);
virNWFilterSnoopReqUnlock(req);
int
virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver ATTRIBUTE_UNUSED,
- const char *ifname ATTRIBUTE_UNUSED,
- const char *linkdev ATTRIBUTE_UNUSED,
- const unsigned char *vmuuid ATTRIBUTE_UNUSED,
- const virMacAddr *macaddr ATTRIBUTE_UNUSED,
- const char *filtername ATTRIBUTE_UNUSED,
- virHashTablePtr filterparams ATTRIBUTE_UNUSED,
+ virNWFilterBindingDefPtr binding ATTRIBUTE_UNUSED,
virNWFilterDriverStatePtr driver ATTRIBUTE_UNUSED)
{
virReportError(VIR_ERR_INTERNAL_ERROR,