mirror of https://gitee.com/openkylin/libvirt.git
Fix error reporting for virSocketParse
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
This commit is contained in:
parent
497adba2d4
commit
179c4be0e1
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue