The virSocketParse method was not doing any error reporting which meant the true cause of the problem was lost. Remove all error reporting from callers, and push it into virSocketParse * src/util/network.c: Add error reporting to virSocketParse * src/conf/domain_conf.c, src/conf/network_conf.c, src/network/bridge_driver.c: Remove error reporting in callers of virSocketParse --- src/conf/domain_conf.c | 6 +----- src/conf/network_conf.c | 15 +++------------ src/network/bridge_driver.c | 12 ++---------- src/util/network.c | 21 +++++++++++++++++---- 4 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 945c1f4..fe93711 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2515,12 +2515,8 @@ virDomainChrDefParseTargetXML(virCapsPtr caps, goto error; } - if (virSocketParseAddr(addrStr, def->target.addr, AF_UNSPEC) < 0) { - virDomainReportError(VIR_ERR_XML_ERROR, - _("%s is not a valid address"), - addrStr); + if (virSocketParseAddr(addrStr, def->target.addr, AF_UNSPEC) < 0) goto error; - } if (def->target.addr->data.stor.ss_family != AF_INET) { virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED, diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index f209dad..fe52f95 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -244,22 +244,14 @@ virNetworkDHCPRangeDefParseXML(virNetworkDefPtr def, } if (virSocketParseAddr(start, &saddr, AF_UNSPEC) < 0) { - virNetworkReportError(VIR_ERR_XML_ERROR, - _("cannot parse dhcp start address '%s'"), - start); xmlFree(start); xmlFree(end); - cur = cur->next; - continue; + return -1; } if (virSocketParseAddr(end, &eaddr, AF_UNSPEC) < 0) { - virNetworkReportError(VIR_ERR_XML_ERROR, - _("cannot parse dhcp end address '%s'"), - end); xmlFree(start); xmlFree(end); - cur = cur->next; - continue; + return -1; } range = virSocketGetRange(&saddr, &eaddr); @@ -269,8 +261,7 @@ virNetworkDHCPRangeDefParseXML(virNetworkDefPtr def, start, end); xmlFree(start); xmlFree(end); - cur = cur->next; - continue; + return -1; } if (VIR_REALLOC_N(def->ranges, def->nranges + 1) < 0) { diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index ac91c57..37ed32e 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1046,19 +1046,11 @@ static int networkCheckRouteCollision(virNetworkObjPtr network) if (!network->def->ipAddress || !network->def->netmask) return 0; - if (virSocketParseAddr(network->def->ipAddress, &inaddress, AF_UNSPEC) < 0) { - networkReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse IP address '%s'"), - network->def->ipAddress); + if (virSocketParseAddr(network->def->ipAddress, &inaddress, AF_UNSPEC) < 0) goto error; - } - if (virSocketParseAddr(network->def->netmask, &innetmask, AF_UNSPEC) < 0) { - networkReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse netmask '%s'"), - network->def->netmask); + if (virSocketParseAddr(network->def->netmask, &innetmask, AF_UNSPEC) < 0) goto error; - } if (inaddress.data.stor.ss_family != AF_INET || innetmask.data.stor.ss_family != AF_INET) { diff --git a/src/util/network.c b/src/util/network.c index 7c6ced9..4ee4532 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -77,15 +77,28 @@ virSocketParseAddr(const char *val, virSocketAddrPtr addr, int family) { int len; struct addrinfo hints; struct addrinfo *res = NULL; + int err; - if (val == NULL) - return(-1); + if (val == NULL) { + virSocketError(VIR_ERR_INVALID_ARG, _("Missing address")); + return -1; + } memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = AI_NUMERICHOST; - if ((getaddrinfo(val, NULL, &hints, &res) != 0) || (res == NULL)) { - return(-1); + if ((err = getaddrinfo(val, NULL, &hints, &res)) != 0) { + virSocketError(VIR_ERR_SYSTEM_ERROR, + _("Cannot parse socket address '%s': %s"), + val, gai_strerror(err)); + return -1; + } + + if (res == NULL) { + virSocketError(VIR_ERR_SYSTEM_ERROR, + _("No socket addresses found for '%s'"), + val); + return -1; } len = res->ai_addrlen; -- 1.7.2.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list