Replace use of virNWFilterReportError with virReportError

Update the network filter driver to use virReportError instead
of the virNWFilterReportError custom macro

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-07-18 12:45:15 +01:00
parent 6d964bcf66
commit fa7ebc174f
6 changed files with 218 additions and 233 deletions

1
cfg.mk
View File

@ -541,7 +541,6 @@ msg_gen_function += virLibNWFilterError
msg_gen_function += virLibSecretError msg_gen_function += virLibSecretError
msg_gen_function += virLibStoragePoolError msg_gen_function += virLibStoragePoolError
msg_gen_function += virLibStorageVolError msg_gen_function += virLibStorageVolError
msg_gen_function += virNWFilterReportError
msg_gen_function += virRaiseError msg_gen_function += virRaiseError
msg_gen_function += virReportError msg_gen_function += virReportError
msg_gen_function += virReportErrorHelper msg_gen_function += virReportErrorHelper

View File

@ -69,10 +69,6 @@
#define VIR_FROM_THIS VIR_FROM_NWFILTER #define VIR_FROM_THIS VIR_FROM_NWFILTER
#define virNWFilterReportError(code, fmt...) \
virReportErrorHelper(VIR_FROM_NWFILTER, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
#ifdef HAVE_LIBPCAP #ifdef HAVE_LIBPCAP
# define LEASEFILE LOCALSTATEDIR "/run/libvirt/network/nwfilter.leases" # define LEASEFILE LOCALSTATEDIR "/run/libvirt/network/nwfilter.leases"
@ -576,11 +572,11 @@ virNWFilterSnoopReqNew(const char *ifkey)
virNWFilterSnoopReqPtr req; virNWFilterSnoopReqPtr req;
if (ifkey == NULL || strlen(ifkey) != VIR_IFKEY_LEN - 1) { if (ifkey == NULL || strlen(ifkey) != VIR_IFKEY_LEN - 1) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterSnoopReqNew called with invalid " _("virNWFilterSnoopReqNew called with invalid "
"key \"%s\" (%zu)"), "key \"%s\" (%zu)"),
ifkey ? ifkey : "", ifkey ? ifkey : "",
strlen(ifkey)); strlen(ifkey));
return NULL; return NULL;
} }
@ -890,8 +886,8 @@ virNWFilterSnoopReqLeaseDel(virNWFilterSnoopReqPtr req,
if (req->techdriver && if (req->techdriver &&
req->techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr, req->techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr,
dhcpsrvrs, false) < 0) { dhcpsrvrs, false) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterSnoopListDel failed")); _("virNWFilterSnoopListDel failed"));
ret = -1; ret = -1;
} }
@ -1097,35 +1093,35 @@ virNWFilterSnoopDHCPOpen(const char *ifname, virMacAddr *mac,
handle = pcap_create(ifname, pcap_errbuf); handle = pcap_create(ifname, pcap_errbuf);
if (handle == NULL) { if (handle == NULL) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("pcap_create failed")); _("pcap_create failed"));
goto cleanup_nohandle; goto cleanup_nohandle;
} }
if (pcap_set_snaplen(handle, PCAP_PBUFSIZE) < 0 || if (pcap_set_snaplen(handle, PCAP_PBUFSIZE) < 0 ||
pcap_set_buffer_size(handle, PCAP_BUFFERSIZE) < 0 || pcap_set_buffer_size(handle, PCAP_BUFFERSIZE) < 0 ||
pcap_activate(handle) < 0) { pcap_activate(handle) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("setup of pcap handle failed")); _("setup of pcap handle failed"));
goto cleanup; goto cleanup;
} }
if (pcap_compile(handle, &fp, ext_filter, 1, PCAP_NETMASK_UNKNOWN) != 0) { if (pcap_compile(handle, &fp, ext_filter, 1, PCAP_NETMASK_UNKNOWN) != 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("pcap_compile: %s"), pcap_geterr(handle)); _("pcap_compile: %s"), pcap_geterr(handle));
goto cleanup; goto cleanup;
} }
if (pcap_setfilter(handle, &fp) != 0) { if (pcap_setfilter(handle, &fp) != 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("pcap_setfilter: %s"), pcap_geterr(handle)); _("pcap_setfilter: %s"), pcap_geterr(handle));
goto cleanup_freecode; goto cleanup_freecode;
} }
if (pcap_setdirection(handle, dir) < 0) { if (pcap_setdirection(handle, dir) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("pcap_setdirection: %s"), _("pcap_setdirection: %s"),
pcap_geterr(handle)); pcap_geterr(handle));
goto cleanup_freecode; goto cleanup_freecode;
} }
@ -1158,9 +1154,9 @@ static void virNWFilterDHCPDecodeWorker(void *jobdata, void *opaque)
job->caplen, job->fromVM) == -1) { job->caplen, job->fromVM) == -1) {
req->jobCompletionStatus = -1; req->jobCompletionStatus = -1;
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Instantiation of rules failed on " _("Instantiation of rules failed on "
"interface '%s'"), req->ifname); "interface '%s'"), req->ifname);
} }
virAtomicIntDec(job->qCtr); virAtomicIntDec(job->qCtr);
VIR_FREE(job); VIR_FREE(job);
@ -1465,10 +1461,10 @@ virNWFilterDHCPSnoopThread(void *req0)
/* protect req->ifname */ /* protect req->ifname */
virNWFilterSnoopReqLock(req); virNWFilterSnoopReqLock(req);
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("interface '%s' failing; " _("interface '%s' failing; "
"reopening"), "reopening"),
req->ifname); req->ifname);
if (req->ifname) if (req->ifname)
pcapConf[i].handle = pcapConf[i].handle =
virNWFilterSnoopDHCPOpen(req->ifname, &req->macaddr, virNWFilterSnoopDHCPOpen(req->ifname, &req->macaddr,
@ -1519,9 +1515,9 @@ virNWFilterDHCPSnoopThread(void *req0)
hdr->caplen, hdr->caplen,
pcapConf[i].dir, pcapConf[i].dir,
&pcapConf[i].qCtr) < 0) { &pcapConf[i].qCtr) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Job submission failed on " _("Job submission failed on "
"interface '%s'"), req->ifname); "interface '%s'"), req->ifname);
error = true; error = true;
break; break;
} }
@ -1625,10 +1621,10 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
/* check that all tools are available for applying the filters (late) */ /* check that all tools are available for applying the filters (late) */
if ( !techdriver->canApplyBasicRules()) { if ( !techdriver->canApplyBasicRules()) {
virNWFilterReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("IP parameter must be provided since " _("IP parameter must be provided since "
"snooping the IP address does not work " "snooping the IP address does not work "
"possibly due to missing tools")); "possibly due to missing tools"));
goto exit_snoopreqput; goto exit_snoopreqput;
} }
@ -1637,15 +1633,16 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
if (techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr, if (techdriver->applyDHCPOnlyRules(req->ifname, &req->macaddr,
dhcpsrvrs, false) < 0) { dhcpsrvrs, false) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, _("applyDHCPOnlyRules " virReportError(VIR_ERR_INTERNAL_ERROR,
"failed - spoofing not protected!")); _("applyDHCPOnlyRules "
"failed - spoofing not protected!"));
goto exit_snoopreqput; goto exit_snoopreqput;
} }
if (virNWFilterHashTablePutAll(filterparams, req->vars) < 0) { if (virNWFilterHashTablePutAll(filterparams, req->vars) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterDHCPSnoopReq: can't copy variables" _("virNWFilterDHCPSnoopReq: can't copy variables"
" on if %s"), ifkey); " on if %s"), ifkey);
goto exit_snoopreqput; goto exit_snoopreqput;
} }
@ -1653,19 +1650,19 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
if (virHashAddEntry(virNWFilterSnoopState.ifnameToKey, ifname, if (virHashAddEntry(virNWFilterSnoopState.ifnameToKey, ifname,
req->ifkey) < 0) { req->ifkey) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterDHCPSnoopReq ifname map failed" _("virNWFilterDHCPSnoopReq ifname map failed"
" on interface \"%s\" key \"%s\""), ifname, " on interface \"%s\" key \"%s\""), ifname,
ifkey); ifkey);
goto exit_snoopunlock; goto exit_snoopunlock;
} }
if (isnewreq && if (isnewreq &&
virHashAddEntry(virNWFilterSnoopState.snoopReqs, ifkey, req) < 0) { virHashAddEntry(virNWFilterSnoopState.snoopReqs, ifkey, req) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterDHCPSnoopReq req add failed on" _("virNWFilterDHCPSnoopReq req add failed on"
" interface \"%s\" ifkey \"%s\""), ifname, " interface \"%s\" ifkey \"%s\""), ifname,
ifkey); ifkey);
goto exit_rem_ifnametokey; goto exit_rem_ifnametokey;
} }
@ -1674,9 +1671,9 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
if (virThreadCreate(&thread, false, virNWFilterDHCPSnoopThread, if (virThreadCreate(&thread, false, virNWFilterDHCPSnoopThread,
req) != 0) { req) != 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterDHCPSnoopReq virThreadCreate " _("virNWFilterDHCPSnoopReq virThreadCreate "
"failed on interface '%s'"), ifname); "failed on interface '%s'"), ifname);
goto exit_snoopreq_unlock; goto exit_snoopreq_unlock;
} }
@ -1684,16 +1681,16 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver,
req->threadkey = virNWFilterSnoopActivate(req); req->threadkey = virNWFilterSnoopActivate(req);
if (!req->threadkey) { if (!req->threadkey) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Activation of snoop request failed on " _("Activation of snoop request failed on "
"interface '%s'"), req->ifname); "interface '%s'"), req->ifname);
goto exit_snoopreq_unlock; goto exit_snoopreq_unlock;
} }
if (virNWFilterSnoopReqRestore(req) < 0) { if (virNWFilterSnoopReqRestore(req) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Restoring of leases failed on " _("Restoring of leases failed on "
"interface '%s'"), req->ifname); "interface '%s'"), req->ifname);
goto exit_snoop_cancel; goto exit_snoop_cancel;
} }
@ -1932,18 +1929,18 @@ virNWFilterSnoopLeaseFileLoad(void)
time(&now); time(&now);
while (fp && fgets(line, sizeof(line), fp)) { while (fp && fgets(line, sizeof(line), fp)) {
if (line[strlen(line)-1] != '\n') { if (line[strlen(line)-1] != '\n') {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterSnoopLeaseFileLoad lease file " _("virNWFilterSnoopLeaseFileLoad lease file "
"line %d corrupt"), ln); "line %d corrupt"), ln);
break; break;
} }
ln++; ln++;
/* key len 55 = "VMUUID"+'-'+"MAC" */ /* key len 55 = "VMUUID"+'-'+"MAC" */
if (sscanf(line, "%u %55s %16s %16s", &ipl.timeout, if (sscanf(line, "%u %55s %16s %16s", &ipl.timeout,
ifkey, ipstr, srvstr) < 4) { ifkey, ipstr, srvstr) < 4) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterSnoopLeaseFileLoad lease file " _("virNWFilterSnoopLeaseFileLoad lease file "
"line %d corrupt"), ln); "line %d corrupt"), ln);
break; break;
} }
if (ipl.timeout && ipl.timeout < now) if (ipl.timeout && ipl.timeout < now)
@ -1958,17 +1955,17 @@ virNWFilterSnoopLeaseFileLoad(void)
if (tmp < 0) { if (tmp < 0) {
virNWFilterSnoopReqPut(req); virNWFilterSnoopReqPut(req);
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("virNWFilterSnoopLeaseFileLoad req add" _("virNWFilterSnoopLeaseFileLoad req add"
" failed on interface \"%s\""), ifkey); " failed on interface \"%s\""), ifkey);
continue; continue;
} }
} }
if (virSocketAddrParseIPv4(&ipl.ipAddress, ipstr) < 0) { if (virSocketAddrParseIPv4(&ipl.ipAddress, ipstr) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("line %d corrupt ipaddr \"%s\""), _("line %d corrupt ipaddr \"%s\""),
ln, ipstr); ln, ipstr);
virNWFilterSnoopReqPut(req); virNWFilterSnoopReqPut(req);
continue; continue;
} }
@ -2113,8 +2110,8 @@ virNWFilterDHCPSnoopEnd(const char *ifname)
ifkey = (char *)virHashLookup(virNWFilterSnoopState.ifnameToKey, ifkey = (char *)virHashLookup(virNWFilterSnoopState.ifnameToKey,
ifname); ifname);
if (!ifkey) { if (!ifkey) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("ifname \"%s\" not in key map"), ifname); _("ifname \"%s\" not in key map"), ifname);
goto cleanup; goto cleanup;
} }
@ -2127,8 +2124,8 @@ virNWFilterDHCPSnoopEnd(const char *ifname)
req = virNWFilterSnoopReqGetByIFKey(ifkey); req = virNWFilterSnoopReqGetByIFKey(ifkey);
if (!req) { if (!req) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("ifkey \"%s\" has no req"), ifkey); _("ifkey \"%s\" has no req"), ifkey);
goto cleanup; goto cleanup;
} }
@ -2209,10 +2206,10 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver ATTRIBUTE_UNUSED,
virNWFilterHashTablePtr filterparams ATTRIBUTE_UNUSED, virNWFilterHashTablePtr filterparams ATTRIBUTE_UNUSED,
virNWFilterDriverStatePtr driver ATTRIBUTE_UNUSED) virNWFilterDriverStatePtr driver ATTRIBUTE_UNUSED)
{ {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("libvirt was not compiled with libpcap and \"" _("libvirt was not compiled with libpcap and \""
NWFILTER_VARNAME_CTRL_IP_LEARNING NWFILTER_VARNAME_CTRL_IP_LEARNING
"='dhcp'\" requires it.")); "='dhcp'\" requires it."));
return -1; return -1;
} }
#endif /* HAVE_LIBPCAP */ #endif /* HAVE_LIBPCAP */

View File

@ -44,9 +44,6 @@
#include "nwfilter_learnipaddr.h" #include "nwfilter_learnipaddr.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER #define VIR_FROM_THIS VIR_FROM_NWFILTER
#define virNWFilterReportError(code, fmt...) \
virReportErrorHelper(VIR_FROM_NWFILTER, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
static virNWFilterDriverStatePtr driverState; static virNWFilterDriverStatePtr driverState;
@ -239,8 +236,8 @@ nwfilterLookupByUUID(virConnectPtr conn,
nwfilterDriverUnlock(driver); nwfilterDriverUnlock(driver);
if (!nwfilter) { if (!nwfilter) {
virNWFilterReportError(VIR_ERR_NO_NWFILTER, virReportError(VIR_ERR_NO_NWFILTER,
"%s", _("no nwfilter with matching uuid")); "%s", _("no nwfilter with matching uuid"));
goto cleanup; goto cleanup;
} }
@ -265,8 +262,8 @@ nwfilterLookupByName(virConnectPtr conn,
nwfilterDriverUnlock(driver); nwfilterDriverUnlock(driver);
if (!nwfilter) { if (!nwfilter) {
virNWFilterReportError(VIR_ERR_NO_NWFILTER, virReportError(VIR_ERR_NO_NWFILTER,
_("no nwfilter with matching name '%s'"), name); _("no nwfilter with matching name '%s'"), name);
goto cleanup; goto cleanup;
} }
@ -389,15 +386,15 @@ nwfilterUndefine(virNWFilterPtr obj) {
nwfilter = virNWFilterObjFindByUUID(&driver->nwfilters, obj->uuid); nwfilter = virNWFilterObjFindByUUID(&driver->nwfilters, obj->uuid);
if (!nwfilter) { if (!nwfilter) {
virNWFilterReportError(VIR_ERR_NO_NWFILTER, virReportError(VIR_ERR_NO_NWFILTER,
"%s", _("no nwfilter with matching uuid")); "%s", _("no nwfilter with matching uuid"));
goto cleanup; goto cleanup;
} }
if (virNWFilterTestUnassignDef(obj->conn, nwfilter) < 0) { if (virNWFilterTestUnassignDef(obj->conn, nwfilter) < 0) {
virNWFilterReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
"%s", "%s",
_("nwfilter is in use")); _("nwfilter is in use"));
goto cleanup; goto cleanup;
} }
@ -437,8 +434,8 @@ nwfilterGetXMLDesc(virNWFilterPtr obj,
nwfilterDriverUnlock(driver); nwfilterDriverUnlock(driver);
if (!nwfilter) { if (!nwfilter) {
virNWFilterReportError(VIR_ERR_NO_NWFILTER, virReportError(VIR_ERR_NO_NWFILTER,
"%s", _("no nwfilter with matching uuid")); "%s", _("no nwfilter with matching uuid"));
goto cleanup; goto cleanup;
} }

View File

@ -45,9 +45,6 @@
#define VIR_FROM_THIS VIR_FROM_NWFILTER #define VIR_FROM_THIS VIR_FROM_NWFILTER
#define virNWFilterReportError(code, fmt...) \
virReportErrorHelper(VIR_FROM_NWFILTER, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
#define EBTABLES_CHAIN_INCOMING "PREROUTING" #define EBTABLES_CHAIN_INCOMING "PREROUTING"
#define EBTABLES_CHAIN_OUTGOING "POSTROUTING" #define EBTABLES_CHAIN_OUTGOING "POSTROUTING"
@ -242,9 +239,9 @@ printVar(virNWFilterVarCombIterPtr vars,
const char *varName; const char *varName;
varName = virNWFilterVarAccessGetVarName(item->varAccess); varName = virNWFilterVarAccessGetVarName(item->varAccess);
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Buffer too small to print variable " _("Buffer too small to print variable "
"'%s' into"), varName); "'%s' into"), varName);
return -1; return -1;
} }
@ -278,8 +275,8 @@ _printDataType(virNWFilterVarCombIterPtr vars,
if (!data) if (!data)
return -1; return -1;
if (snprintf(buf, bufsize, "%s", data) >= bufsize) { if (snprintf(buf, bufsize, "%s", data) >= bufsize) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("buffer too small for IP address")); _("buffer too small for IP address"));
VIR_FREE(data); VIR_FREE(data);
return -1; return -1;
} }
@ -292,8 +289,8 @@ _printDataType(virNWFilterVarCombIterPtr vars,
return -1; return -1;
if (snprintf(buf, bufsize, "%s", data) >= bufsize) { if (snprintf(buf, bufsize, "%s", data) >= bufsize) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("buffer too small for IPv6 address")); _("buffer too small for IPv6 address"));
VIR_FREE(data); VIR_FREE(data);
return -1; return -1;
} }
@ -303,8 +300,8 @@ _printDataType(virNWFilterVarCombIterPtr vars,
case DATATYPE_MACADDR: case DATATYPE_MACADDR:
case DATATYPE_MACMASK: case DATATYPE_MACMASK:
if (bufsize < VIR_MAC_STRING_BUFLEN) { if (bufsize < VIR_MAC_STRING_BUFLEN) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Buffer too small for MAC address")); _("Buffer too small for MAC address"));
return -1; return -1;
} }
@ -315,8 +312,8 @@ _printDataType(virNWFilterVarCombIterPtr vars,
case DATATYPE_IPMASK: case DATATYPE_IPMASK:
if (snprintf(buf, bufsize, "%d", if (snprintf(buf, bufsize, "%d",
item->u.u8) >= bufsize) { item->u.u8) >= bufsize) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Buffer too small for uint8 type")); _("Buffer too small for uint8 type"));
return -1; return -1;
} }
break; break;
@ -325,8 +322,8 @@ _printDataType(virNWFilterVarCombIterPtr vars,
case DATATYPE_UINT32_HEX: case DATATYPE_UINT32_HEX:
if (snprintf(buf, bufsize, asHex ? "0x%x" : "%u", if (snprintf(buf, bufsize, asHex ? "0x%x" : "%u",
item->u.u32) >= bufsize) { item->u.u32) >= bufsize) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Buffer too small for uint32 type")); _("Buffer too small for uint32 type"));
return -1; return -1;
} }
break; break;
@ -335,8 +332,8 @@ _printDataType(virNWFilterVarCombIterPtr vars,
case DATATYPE_UINT16_HEX: case DATATYPE_UINT16_HEX:
if (snprintf(buf, bufsize, asHex ? "0x%x" : "%d", if (snprintf(buf, bufsize, asHex ? "0x%x" : "%d",
item->u.u16) >= bufsize) { item->u.u16) >= bufsize) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Buffer too small for uint16 type")); _("Buffer too small for uint16 type"));
return -1; return -1;
} }
break; break;
@ -345,16 +342,16 @@ _printDataType(virNWFilterVarCombIterPtr vars,
case DATATYPE_UINT8_HEX: case DATATYPE_UINT8_HEX:
if (snprintf(buf, bufsize, asHex ? "0x%x" : "%d", if (snprintf(buf, bufsize, asHex ? "0x%x" : "%d",
item->u.u8) >= bufsize) { item->u.u8) >= bufsize) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Buffer too small for uint8 type")); _("Buffer too small for uint8 type"));
return -1; return -1;
} }
break; break;
case DATATYPE_IPSETNAME: case DATATYPE_IPSETNAME:
if (virStrcpy(buf, item->u.ipset.setname, bufsize) == NULL) { if (virStrcpy(buf, item->u.ipset.setname, bufsize) == NULL) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Buffer to small for ipset name")); _("Buffer to small for ipset name"));
return -1; return -1;
} }
break; break;
@ -385,8 +382,8 @@ _printDataType(virNWFilterVarCombIterPtr vars,
flags = virBufferContentAndReset(&vb); flags = virBufferContentAndReset(&vb);
if (virStrcpy(buf, flags, bufsize) == NULL) { if (virStrcpy(buf, flags, bufsize) == NULL) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Buffer too small for IPSETFLAGS type")); _("Buffer too small for IPSETFLAGS type"));
VIR_FREE(flags); VIR_FREE(flags);
return -1; return -1;
} }
@ -394,8 +391,8 @@ _printDataType(virNWFilterVarCombIterPtr vars,
break; break;
default: default:
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unhandled datatype %x"), item->datatype); _("Unhandled datatype %x"), item->datatype);
return -1; return -1;
break; break;
} }
@ -1297,10 +1294,10 @@ _iptablesCreateRuleInstance(int directionIn,
bool hasICMPType = false; bool hasICMPType = false;
if (!iptables_cmd) { if (!iptables_cmd) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot create rule since %s tool is " _("cannot create rule since %s tool is "
"missing."), "missing."),
isIPv6 ? "ip6tables" : "iptables"); isIPv6 ? "ip6tables" : "iptables");
goto err_exit; goto err_exit;
} }
@ -2015,9 +2012,9 @@ ebtablesCreateRuleInstance(char chainPrefix,
const char *target; const char *target;
if (!ebtables_cmd_path) { if (!ebtables_cmd_path) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot create rule since ebtables tool is " _("cannot create rule since ebtables tool is "
"missing.")); "missing."));
goto err_exit; goto err_exit;
} }
@ -2116,11 +2113,11 @@ ebtablesCreateRuleInstance(char chainPrefix,
since this clashes with -d below... */ since this clashes with -d below... */
if (reverse && if (reverse &&
HAS_ENTRY_ITEM(&rule->p.stpHdrFilter.ethHdr.dataSrcMACAddr)) { HAS_ENTRY_ITEM(&rule->p.stpHdrFilter.ethHdr.dataSrcMACAddr)) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("STP filtering in %s direction with " _("STP filtering in %s direction with "
"source MAC address set is not supported"), "source MAC address set is not supported"),
virNWFilterRuleDirectionTypeToString( virNWFilterRuleDirectionTypeToString(
VIR_NWFILTER_RULE_DIRECTION_INOUT)); VIR_NWFILTER_RULE_DIRECTION_INOUT));
return -1; return -1;
} }
@ -2683,8 +2680,8 @@ ebiptablesCreateRuleInstance(enum virDomainNetType nettype ATTRIBUTE_UNUSED,
break; break;
case VIR_NWFILTER_RULE_PROTOCOL_LAST: case VIR_NWFILTER_RULE_PROTOCOL_LAST:
virNWFilterReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("illegal protocol type")); "%s", _("illegal protocol type"));
rc = -1; rc = -1;
break; break;
} }
@ -3199,9 +3196,9 @@ ebtablesApplyBasicRules(const char *ifname,
char macaddr_str[VIR_MAC_STRING_BUFLEN]; char macaddr_str[VIR_MAC_STRING_BUFLEN];
if (!ebtables_cmd_path) { if (!ebtables_cmd_path) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot create rules since ebtables tool is " _("cannot create rules since ebtables tool is "
"missing.")); "missing."));
return -1; return -1;
} }
@ -3257,9 +3254,9 @@ ebtablesApplyBasicRules(const char *ifname,
tear_down_tmpebchains: tear_down_tmpebchains:
ebtablesCleanAll(ifname); ebtablesCleanAll(ifname);
virNWFilterReportError(VIR_ERR_BUILD_FIREWALL, virReportError(VIR_ERR_BUILD_FIREWALL,
"%s", "%s",
_("Some rules could not be created.")); _("Some rules could not be created."));
return -1; return -1;
} }
@ -3296,9 +3293,9 @@ ebtablesApplyDHCPOnlyRules(const char *ifname,
unsigned int num_dhcpsrvrs; unsigned int num_dhcpsrvrs;
if (!ebtables_cmd_path) { if (!ebtables_cmd_path) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot create rules since ebtables tool is " _("cannot create rules since ebtables tool is "
"missing.")); "missing."));
return -1; return -1;
} }
@ -3400,9 +3397,9 @@ ebtablesApplyDHCPOnlyRules(const char *ifname,
tear_down_tmpebchains: tear_down_tmpebchains:
ebtablesCleanAll(ifname); ebtablesCleanAll(ifname);
virNWFilterReportError(VIR_ERR_BUILD_FIREWALL, virReportError(VIR_ERR_BUILD_FIREWALL,
"%s", "%s",
_("Some rules could not be created.")); _("Some rules could not be created."));
return -1; return -1;
} }
@ -3425,9 +3422,9 @@ ebtablesApplyDropAllRules(const char *ifname)
chain_out[MAX_CHAINNAME_LENGTH]; chain_out[MAX_CHAINNAME_LENGTH];
if (!ebtables_cmd_path) { if (!ebtables_cmd_path) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot create rules since ebtables tool is " _("cannot create rules since ebtables tool is "
"missing.")); "missing."));
return -1; return -1;
} }
@ -3470,9 +3467,9 @@ ebtablesApplyDropAllRules(const char *ifname)
tear_down_tmpebchains: tear_down_tmpebchains:
ebtablesCleanAll(ifname); ebtablesCleanAll(ifname);
virNWFilterReportError(VIR_ERR_BUILD_FIREWALL, virReportError(VIR_ERR_BUILD_FIREWALL,
"%s", "%s",
_("Some rules could not be created.")); _("Some rules could not be created."));
return -1; return -1;
} }
@ -3903,12 +3900,12 @@ tear_down_tmpebchains:
ebiptablesExecCLI(&buf, &cli_status, NULL); ebiptablesExecCLI(&buf, &cli_status, NULL);
virNWFilterReportError(VIR_ERR_BUILD_FIREWALL, virReportError(VIR_ERR_BUILD_FIREWALL,
_("Some rules could not be created for " _("Some rules could not be created for "
"interface %s%s%s"), "interface %s%s%s"),
ifname, ifname,
errmsg ? ": " : "", errmsg ? ": " : "",
errmsg ? errmsg : ""); errmsg ? errmsg : "");
exit_free_sets: exit_free_sets:
virHashFree(chains_in_set); virHashFree(chains_in_set);
@ -4042,9 +4039,9 @@ ebiptablesRemoveRules(const char *ifname ATTRIBUTE_UNUSED,
goto err_exit; goto err_exit;
if (cli_status) { if (cli_status) {
virNWFilterReportError(VIR_ERR_BUILD_FIREWALL, virReportError(VIR_ERR_BUILD_FIREWALL,
"%s", "%s",
_("error while executing CLI commands")); _("error while executing CLI commands"));
rc = -1; rc = -1;
} }

View File

@ -39,9 +39,6 @@
#include "datatypes.h" #include "datatypes.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER #define VIR_FROM_THIS VIR_FROM_NWFILTER
#define virNWFilterReportError(code, fmt...) \
virReportErrorHelper(VIR_FROM_NWFILTER, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
#define NWFILTER_STD_VAR_MAC NWFILTER_VARNAME_MAC #define NWFILTER_STD_VAR_MAC NWFILTER_VARNAME_MAC
@ -164,8 +161,8 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTablePtr table,
if (virHashAddEntry(table->hashTable, if (virHashAddEntry(table->hashTable,
NWFILTER_STD_VAR_MAC, NWFILTER_STD_VAR_MAC,
val) < 0) { val) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Could not add variable 'MAC' to hashmap")); "%s", _("Could not add variable 'MAC' to hashmap"));
return -1; return -1;
} }
} }
@ -178,8 +175,8 @@ virNWFilterVarHashmapAddStdValues(virNWFilterHashTablePtr table,
if (virHashAddEntry(table->hashTable, if (virHashAddEntry(table->hashTable,
NWFILTER_STD_VAR_IP, NWFILTER_STD_VAR_IP,
val) < 0) { val) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Could not add variable 'IP' to hashmap")); "%s", _("Could not add variable 'IP' to hashmap"));
return -1; return -1;
} }
} }
@ -430,9 +427,9 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver,
if (obj) { if (obj) {
if (obj->wantRemoved) { if (obj->wantRemoved) {
virNWFilterReportError(VIR_ERR_NO_NWFILTER, virReportError(VIR_ERR_NO_NWFILTER,
_("Filter '%s' is in use."), _("Filter '%s' is in use."),
inc->filterref); inc->filterref);
rc = -1; rc = -1;
virNWFilterObjUnlock(obj); virNWFilterObjUnlock(obj);
break; break;
@ -478,9 +475,9 @@ _virNWFilterInstantiateRec(virNWFilterTechDriverPtr techdriver,
if (rc < 0) if (rc < 0)
break; break;
} else { } else {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("referenced filter '%s' is missing"), _("referenced filter '%s' is missing"),
inc->filterref); inc->filterref);
rc = -1; rc = -1;
break; break;
} }
@ -542,9 +539,9 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
if (obj) { if (obj) {
if (obj->wantRemoved) { if (obj->wantRemoved) {
virNWFilterReportError(VIR_ERR_NO_NWFILTER, virReportError(VIR_ERR_NO_NWFILTER,
_("Filter '%s' is in use."), _("Filter '%s' is in use."),
inc->filterref); inc->filterref);
rc = -1; rc = -1;
virNWFilterObjUnlock(obj); virNWFilterObjUnlock(obj);
break; break;
@ -585,9 +582,9 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter,
if (rc < 0) if (rc < 0)
break; break;
} else { } else {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("referenced filter '%s' is missing"), _("referenced filter '%s' is missing"),
inc->filterref); inc->filterref);
rc = -1; rc = -1;
break; break;
} }
@ -724,9 +721,10 @@ virNWFilterInstantiate(const unsigned char *vmuuid ATTRIBUTE_UNUSED,
goto err_exit; goto err_exit;
} else { } else {
rc = -1; rc = -1;
virNWFilterReportError(VIR_ERR_PARSE_FAILED, _("filter '%s' " virReportError(VIR_ERR_PARSE_FAILED,
"learning value '%s' invalid."), _("filter '%s' "
filter->name, learning); "learning value '%s' invalid."),
filter->name, learning);
} }
} else } else
goto err_unresolvable_vars; goto err_unresolvable_vars;
@ -799,9 +797,9 @@ err_unresolvable_vars:
buf = virNWFilterPrintVars(missing_vars->hashTable, ", ", false, reportIP); buf = virNWFilterPrintVars(missing_vars->hashTable, ", ", false, reportIP);
if (buf) { if (buf) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Cannot instantiate filter due to unresolvable " _("Cannot instantiate filter due to unresolvable "
"variables or unavailable list elements: %s"), buf); "variables or unavailable list elements: %s"), buf);
VIR_FREE(buf); VIR_FREE(buf);
} }
@ -842,10 +840,10 @@ __virNWFilterInstantiateFilter(const unsigned char *vmuuid,
techdriver = virNWFilterTechDriverForName(drvname); techdriver = virNWFilterTechDriverForName(drvname);
if (!techdriver) { if (!techdriver) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get access to ACL tech " _("Could not get access to ACL tech "
"driver '%s'"), "driver '%s'"),
drvname); drvname);
return -1; return -1;
} }
@ -853,16 +851,16 @@ __virNWFilterInstantiateFilter(const unsigned char *vmuuid,
obj = virNWFilterObjFindByName(&driver->nwfilters, filtername); obj = virNWFilterObjFindByName(&driver->nwfilters, filtername);
if (!obj) { if (!obj) {
virNWFilterReportError(VIR_ERR_NO_NWFILTER, virReportError(VIR_ERR_NO_NWFILTER,
_("Could not find filter '%s'"), _("Could not find filter '%s'"),
filtername); filtername);
return -1; return -1;
} }
if (obj->wantRemoved) { if (obj->wantRemoved) {
virNWFilterReportError(VIR_ERR_NO_NWFILTER, virReportError(VIR_ERR_NO_NWFILTER,
_("Filter '%s' is in use."), _("Filter '%s' is in use."),
filtername); filtername);
rc = -1; rc = -1;
goto err_exit; goto err_exit;
} }
@ -1070,10 +1068,10 @@ virNWFilterRollbackUpdateFilter(const virDomainNetDefPtr net)
techdriver = virNWFilterTechDriverForName(drvname); techdriver = virNWFilterTechDriverForName(drvname);
if (!techdriver) { if (!techdriver) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get access to ACL tech " _("Could not get access to ACL tech "
"driver '%s'"), "driver '%s'"),
drvname); drvname);
return -1; return -1;
} }
@ -1096,10 +1094,10 @@ virNWFilterTearOldFilter(virDomainNetDefPtr net)
techdriver = virNWFilterTechDriverForName(drvname); techdriver = virNWFilterTechDriverForName(drvname);
if (!techdriver) { if (!techdriver) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get access to ACL tech " _("Could not get access to ACL tech "
"driver '%s'"), "driver '%s'"),
drvname); drvname);
return -1; return -1;
} }
@ -1121,10 +1119,10 @@ _virNWFilterTeardownFilter(const char *ifname)
techdriver = virNWFilterTechDriverForName(drvname); techdriver = virNWFilterTechDriverForName(drvname);
if (!techdriver) { if (!techdriver) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Could not get access to ACL tech " _("Could not get access to ACL tech "
"driver '%s'"), "driver '%s'"),
drvname); drvname);
return -1; return -1;
} }
@ -1200,9 +1198,9 @@ virNWFilterDomainFWUpdateCB(void *payload,
vm->uuid, vm->uuid,
net); net);
if (err) if (err)
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failure while applying current filter on " _("Failure while applying current filter on "
"VM %s"), vm->name); "VM %s"), vm->name);
break; break;
} }
if (cb->err) if (cb->err)

View File

@ -56,9 +56,6 @@
#include "nwfilter_learnipaddr.h" #include "nwfilter_learnipaddr.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER #define VIR_FROM_THIS VIR_FROM_NWFILTER
#define virNWFilterReportError(code, fmt...) \
virReportErrorHelper(VIR_FROM_NWFILTER, code, __FILE__, \
__FUNCTION__, __LINE__, fmt)
#define IFINDEX2STR(VARNAME, ifindex) \ #define IFINDEX2STR(VARNAME, ifindex) \
char VARNAME[INT_BUFSIZE_BOUND(ifindex)]; \ char VARNAME[INT_BUFSIZE_BOUND(ifindex)]; \
@ -151,17 +148,17 @@ virNWFilterLockIface(const char *ifname) {
} }
if (virMutexInitRecursive(&ifaceLock->lock) < 0) { if (virMutexInitRecursive(&ifaceLock->lock) < 0) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("mutex initialization failed")); _("mutex initialization failed"));
VIR_FREE(ifaceLock); VIR_FREE(ifaceLock);
goto err_exit; goto err_exit;
} }
if (virStrcpyStatic(ifaceLock->ifname, ifname) == NULL) { if (virStrcpyStatic(ifaceLock->ifname, ifname) == NULL) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("interface name %s does not fit into " _("interface name %s does not fit into "
"buffer "), "buffer "),
ifaceLock->ifname); ifaceLock->ifname);
VIR_FREE(ifaceLock); VIR_FREE(ifaceLock);
goto err_exit; goto err_exit;
} }
@ -675,10 +672,10 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
return -1; return -1;
if ( !techdriver->canApplyBasicRules()) { if ( !techdriver->canApplyBasicRules()) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("IP parameter must be provided since " _("IP parameter must be provided since "
"snooping the IP address does not work " "snooping the IP address does not work "
"possibly due to missing tools")); "possibly due to missing tools"));
return -1; return -1;
} }
@ -703,17 +700,17 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,
} }
if (virStrcpyStatic(req->ifname, ifname) == NULL) { if (virStrcpyStatic(req->ifname, ifname) == NULL) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Destination buffer for ifname ('%s') " _("Destination buffer for ifname ('%s') "
"not large enough"), ifname); "not large enough"), ifname);
goto err_free_ht; goto err_free_ht;
} }
if (linkdev) { if (linkdev) {
if (virStrcpyStatic(req->linkdev, linkdev) == NULL) { if (virStrcpyStatic(req->linkdev, linkdev) == NULL) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Destination buffer for linkdev ('%s') " _("Destination buffer for linkdev ('%s') "
"not large enough"), linkdev); "not large enough"), linkdev);
goto err_free_ht; goto err_free_ht;
} }
} }
@ -763,10 +760,10 @@ virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver ATTRIBUTE_UNUSED,
virNWFilterHashTablePtr filterparams ATTRIBUTE_UNUSED, virNWFilterHashTablePtr filterparams ATTRIBUTE_UNUSED,
virNWFilterDriverStatePtr driver ATTRIBUTE_UNUSED, virNWFilterDriverStatePtr driver ATTRIBUTE_UNUSED,
enum howDetect howDetect ATTRIBUTE_UNUSED) { enum howDetect howDetect ATTRIBUTE_UNUSED) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("IP parameter must be given since libvirt " _("IP parameter must be given since libvirt "
"was not compiled with IP address learning " "was not compiled with IP address learning "
"support")); "support"));
return -1; return -1;
} }
#endif /* HAVE_LIBPCAP */ #endif /* HAVE_LIBPCAP */