Adapt to VIR_ALLOC and virAsprintf in src/nwfilter/*

This commit is contained in:
Michal Privoznik 2013-07-04 12:12:44 +02:00
parent 9729d847b5
commit 8abed96d21
5 changed files with 33 additions and 91 deletions

View File

@ -303,10 +303,8 @@ virNWFilterSnoopActivate(virNWFilterSnoopReqPtr req)
{
char *key;
if (virAsprintf(&key, "%p-%d", req, req->ifindex) < 0) {
virReportOOMError();
if (virAsprintf(&key, "%p-%d", req, req->ifindex) < 0)
return NULL;
}
virNWFilterSnoopActiveLock();
@ -583,10 +581,8 @@ virNWFilterSnoopReqNew(const char *ifkey)
return NULL;
}
if (VIR_ALLOC(req) < 0) {
virReportOOMError();
if (VIR_ALLOC(req) < 0)
return NULL;
}
req->threadStatus = THREAD_STATUS_NONE;
@ -762,10 +758,8 @@ virNWFilterSnoopReqLeaseAdd(virNWFilterSnoopReqPtr req,
virNWFilterSnoopReqUnlock(req);
if (VIR_ALLOC(pl) < 0) {
virReportOOMError();
if (VIR_ALLOC(pl) < 0)
return -1;
}
*pl = *plnew;
/* protect req->threadkey */
@ -1091,10 +1085,8 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAddr *mac,
* more unlikely parameters first, then go for the MAC
*/
if (virAsprintf(&ext_filter,
"%s and ether src %s", filter, macaddr) < 0) {
virReportOOMError();
"%s and ether src %s", filter, macaddr) < 0)
return NULL;
}
} else {
/*
* Some DHCP servers respond via MAC broadcast; we rely on later
@ -1195,10 +1187,8 @@ virNWFilterSnoopDHCPDecodeJobSubmit(virThreadPoolPtr pool,
if (len <= MIN_VALID_DHCP_PKT_SIZE || len > sizeof(job->packet))
return 0;
if (VIR_ALLOC(job) < 0) {
virReportOOMError();
if (VIR_ALLOC(job) < 0)
return -1;
}
memcpy(job->packet, pep, len);
job->caplen = len;
@ -1633,10 +1623,8 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
VIR_STRDUP(req->linkdev, linkdev) < 0)
goto exit_snoopreqput;
if (!req->vars || tmp < 0) {
virReportOOMError();
if (!req->vars || tmp < 0)
goto exit_snoopreqput;
}
/* check that all tools are available for applying the filters (late) */
if (!techdriver->canApplyBasicRules()) {
@ -1781,7 +1769,6 @@ virNWFilterSnoopLeaseFileWrite(int lfd, const char *ifkey,
ifkey, ipstr, dhcpstr);
if (len < 0) {
virReportOOMError();
ret = -1;
goto cleanup;
}
@ -2089,10 +2076,8 @@ virNWFilterDHCPSnoopInit(void)
if (!virNWFilterSnoopState.ifnameToKey ||
!virNWFilterSnoopState.snoopReqs ||
!virNWFilterSnoopState.active) {
virReportOOMError();
!virNWFilterSnoopState.active)
goto err_exit;
}
virNWFilterSnoopLeaseFileLoad();
virNWFilterSnoopLeaseFileOpen();

View File

@ -178,10 +178,8 @@ nwfilterStateInitialize(bool privileged,
sysbus = virDBusGetSystemBus();
#endif /* WITH_DBUS */
if (VIR_ALLOC(driverState) < 0) {
virReportOOMError();
if (VIR_ALLOC(driverState) < 0)
return -1;
}
if (virMutexInit(&driverState->lock) < 0)
goto err_free_driverstate;
@ -227,7 +225,7 @@ nwfilterStateInitialize(bool privileged,
if (virAsprintf(&driverState->configDir,
"%s/nwfilter", base) == -1)
goto out_of_memory;
goto error;
VIR_FREE(base);
@ -240,9 +238,6 @@ nwfilterStateInitialize(bool privileged,
return 0;
out_of_memory:
virReportOOMError();
error:
VIR_FREE(base);
nwfilterDriverUnlock(driverState);
@ -518,10 +513,8 @@ nwfilterConnectListAllNWFilters(virConnectPtr conn,
goto cleanup;
}
if (VIR_ALLOC_N(tmp_filters, driver->nwfilters.count + 1) < 0) {
virReportOOMError();
if (VIR_ALLOC_N(tmp_filters, driver->nwfilters.count + 1) < 0)
goto cleanup;
}
for (i = 0; i < driver->nwfilters.count; i++) {
obj = driver->nwfilters.objs[i];

View File

@ -494,10 +494,8 @@ ebiptablesAddRuleInst(virNWFilterRuleInstPtr res,
{
ebiptablesRuleInstPtr inst;
if (VIR_ALLOC(inst) < 0) {
virReportOOMError();
if (VIR_ALLOC(inst) < 0)
return -1;
}
inst->commandTemplate = commandTemplate;
inst->neededProtocolChain = neededChain;
@ -3016,10 +3014,8 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst,
break;
}
if (!protostr) {
virReportOOMError();
if (!protostr)
return -1;
}
virBufferAsprintf(&buf,
CMD_DEF("$EBT -t nat -F %s") CMD_SEPARATOR
@ -3393,10 +3389,8 @@ ebtablesApplyDHCPOnlyRules(const char *ifname,
dhcpserver = virNWFilterVarValueGetNthValue(dhcpsrvrs, idx);
if (virAsprintf(&srcIPParam, "--ip-src %s", dhcpserver) < 0) {
virReportOOMError();
if (virAsprintf(&srcIPParam, "--ip-src %s", dhcpserver) < 0)
goto tear_down_tmpebchains;
}
}
/*
@ -3720,10 +3714,8 @@ ebiptablesApplyNewRules(const char *ifname,
if (inst == NULL)
nruleInstances = 0;
if (!chains_in_set || !chains_out_set) {
virReportOOMError();
if (!chains_in_set || !chains_out_set)
goto exit_free_sets;
}
if (nruleInstances > 1 && inst)
qsort(inst, nruleInstances, sizeof(inst[0]),
@ -3736,16 +3728,12 @@ ebiptablesApplyNewRules(const char *ifname,
const char *name = inst[i]->neededProtocolChain;
if (inst[i]->chainprefix == CHAINPREFIX_HOST_IN_TEMP) {
if (virHashUpdateEntry(chains_in_set, name,
&inst[i]->chainPriority) < 0) {
virReportOOMError();
&inst[i]->chainPriority) < 0)
goto exit_free_sets;
}
} else {
if (virHashUpdateEntry(chains_out_set, name,
&inst[i]->chainPriority) < 0) {
virReportOOMError();
&inst[i]->chainPriority) < 0)
goto exit_free_sets;
}
}
}
}
@ -4210,19 +4198,15 @@ ebiptablesDriverInitWithFirewallD(void)
} else {
VIR_INFO("firewalld support enabled for nwfilter");
ignore_value(virAsprintf(&ebtables_cmd_path,
"%s --direct --passthrough eb",
firewall_cmd_path));
ignore_value(virAsprintf(&iptables_cmd_path,
"%s --direct --passthrough ipv4",
firewall_cmd_path));
ignore_value(virAsprintf(&ip6tables_cmd_path,
"%s --direct --passthrough ipv6",
firewall_cmd_path));
if (!ebtables_cmd_path || !iptables_cmd_path ||
!ip6tables_cmd_path) {
virReportOOMError();
if (virAsprintf(&ebtables_cmd_path,
"%s --direct --passthrough eb",
firewall_cmd_path) < 0 ||
virAsprintf(&iptables_cmd_path,
"%s --direct --passthrough ipv4",
firewall_cmd_path) < 0 ||
virAsprintf(&ip6tables_cmd_path,
"%s --direct --passthrough ipv6",
firewall_cmd_path) < 0) {
VIR_FREE(ebtables_cmd_path);
VIR_FREE(iptables_cmd_path);
VIR_FREE(ip6tables_cmd_path);

View File

@ -110,10 +110,8 @@ int
virNWFilterRuleInstAddData(virNWFilterRuleInstPtr res,
void *data)
{
if (VIR_REALLOC_N(res->data, res->ndata+1) < 0) {
virReportOOMError();
if (VIR_REALLOC_N(res->data, res->ndata+1) < 0)
return -1;
}
res->data[res->ndata++] = data;
return 0;
}
@ -201,10 +199,8 @@ virNWFilterHashTablePtr
virNWFilterCreateVarHashmap(char *macaddr,
const virNWFilterVarValuePtr ipaddr) {
virNWFilterHashTablePtr table = virNWFilterHashTableCreate(0);
if (!table) {
virReportOOMError();
if (!table)
return NULL;
}
if (virNWFilterVarHashmapAddStdValues(table, macaddr, ipaddr) < 0) {
virNWFilterHashTableFree(table);
@ -303,10 +299,8 @@ virNWFilterRuleInstantiate(virNWFilterTechDriverPtr techdriver,
int i;
virNWFilterRuleInstPtr ret;
if (VIR_ALLOC(ret) < 0) {
virReportOOMError();
if (VIR_ALLOC(ret) < 0)
return NULL;
}
ret->techdriver = techdriver;
@ -340,10 +334,8 @@ virNWFilterCreateVarsFrom(virNWFilterHashTablePtr vars1,
virNWFilterHashTablePtr vars2)
{
virNWFilterHashTablePtr res = virNWFilterHashTableCreate(0);
if (!res) {
virReportOOMError();
if (!res)
return NULL;
}
if (virNWFilterHashTablePutAll(vars1, res) < 0)
goto err_exit;
@ -415,7 +407,6 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver,
}
if (VIR_REALLOC_N(*insts, (*nEntries)+1) < 0) {
virReportOOMError();
rc = -1;
break;
}
@ -441,7 +432,6 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver,
virNWFilterCreateVarsFrom(inc->params,
vars);
if (!tmpvars) {
virReportOOMError();
rc = -1;
virNWFilterObjUnlock(obj);
break;
@ -553,7 +543,6 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
virNWFilterCreateVarsFrom(inc->params,
vars);
if (!tmpvars) {
virReportOOMError();
rc = -1;
virNWFilterObjUnlock(obj);
break;
@ -611,10 +600,8 @@ virNWFilterRuleInstancesToArray(int nEntries,
if ((*nptrs) == 0)
return 0;
if (VIR_ALLOC_N((*ptrs), (*nptrs)) < 0) {
virReportOOMError();
if (VIR_ALLOC_N((*ptrs), (*nptrs)) < 0)
return -1;
}
(*nptrs) = 0;
@ -674,7 +661,6 @@ virNWFilterInstantiate(const unsigned char *vmuuid ATTRIBUTE_UNUSED,
virNWFilterHashTablePtr missing_vars = virNWFilterHashTableCreate(0);
if (!missing_vars) {
virReportOOMError();
rc = -1;
goto err_exit;
}

View File

@ -143,10 +143,8 @@ virNWFilterLockIface(const char *ifname) {
ifaceLock = virHashLookup(ifaceLockMap, ifname);
if (!ifaceLock) {
if (VIR_ALLOC(ifaceLock) < 0) {
virReportOOMError();
if (VIR_ALLOC(ifaceLock) < 0)
goto err_exit;
}
if (virMutexInitRecursive(&ifaceLock->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -699,16 +697,12 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
return -1;
}
if (VIR_ALLOC(req) < 0) {
virReportOOMError();
if (VIR_ALLOC(req) < 0)
goto err_no_req;
}
ht = virNWFilterHashTableCreate(0);
if (ht == NULL) {
virReportOOMError();
if (ht == NULL)
goto err_free_req;
}
if (virNWFilterHashTablePutAll(filterparams, ht) < 0)
goto err_free_ht;