Fix passing of address family to virSocketParseAddr

The virSocketParseAddr function was accepting any AF_* constant
and using that to set the ai_flags field in struct addrinfo.
This is invalid, since address families must go in the ai_family
field of the struct.

* src/util/network.c: Fix handling of address family
* src/conf/network_conf.c, src/network/bridge_driver.c: Pass
  AF_UNSPEC instead of relying on it being 0.
This commit is contained in:
Daniel P. Berrange 2010-10-20 14:26:30 +01:00
parent af3d4eec0d
commit 746c336495
4 changed files with 9 additions and 8 deletions

View File

@ -2515,7 +2515,7 @@ virDomainChrDefParseTargetXML(virCapsPtr caps,
goto error; goto error;
} }
if (virSocketParseAddr(addrStr, def->target.addr, 0) < 0) { if (virSocketParseAddr(addrStr, def->target.addr, AF_UNSPEC) < 0) {
virDomainReportError(VIR_ERR_XML_ERROR, virDomainReportError(VIR_ERR_XML_ERROR,
_("%s is not a valid address"), _("%s is not a valid address"),
addrStr); addrStr);

View File

@ -243,7 +243,7 @@ virNetworkDHCPRangeDefParseXML(virNetworkDefPtr def,
continue; continue;
} }
if (virSocketParseAddr(start, &saddr, 0) < 0) { if (virSocketParseAddr(start, &saddr, AF_UNSPEC) < 0) {
virNetworkReportError(VIR_ERR_XML_ERROR, virNetworkReportError(VIR_ERR_XML_ERROR,
_("cannot parse dhcp start address '%s'"), _("cannot parse dhcp start address '%s'"),
start); start);
@ -252,7 +252,7 @@ virNetworkDHCPRangeDefParseXML(virNetworkDefPtr def,
cur = cur->next; cur = cur->next;
continue; continue;
} }
if (virSocketParseAddr(end, &eaddr, 0) < 0) { if (virSocketParseAddr(end, &eaddr, AF_UNSPEC) < 0) {
virNetworkReportError(VIR_ERR_XML_ERROR, virNetworkReportError(VIR_ERR_XML_ERROR,
_("cannot parse dhcp end address '%s'"), _("cannot parse dhcp end address '%s'"),
end); end);

View File

@ -1046,14 +1046,14 @@ static int networkCheckRouteCollision(virNetworkObjPtr network)
if (!network->def->ipAddress || !network->def->netmask) if (!network->def->ipAddress || !network->def->netmask)
return 0; return 0;
if (virSocketParseAddr(network->def->ipAddress, &inaddress, 0) < 0) { if (virSocketParseAddr(network->def->ipAddress, &inaddress, AF_UNSPEC) < 0) {
networkReportError(VIR_ERR_INTERNAL_ERROR, networkReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse IP address '%s'"), _("cannot parse IP address '%s'"),
network->def->ipAddress); network->def->ipAddress);
goto error; goto error;
} }
if (virSocketParseAddr(network->def->netmask, &innetmask, 0) < 0) { if (virSocketParseAddr(network->def->netmask, &innetmask, AF_UNSPEC) < 0) {
networkReportError(VIR_ERR_INTERNAL_ERROR, networkReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot parse netmask '%s'"), _("cannot parse netmask '%s'"),
network->def->netmask); network->def->netmask);

View File

@ -58,7 +58,7 @@ static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
* virSocketParseAddr: * virSocketParseAddr:
* @val: a numeric network address IPv4 or IPv6 * @val: a numeric network address IPv4 or IPv6
* @addr: where to store the return value, optional. * @addr: where to store the return value, optional.
* @hint: optional hint to pass down to getaddrinfo * @family: address family to pass down to getaddrinfo
* *
* Mostly a wrapper for getaddrinfo() extracting the address storage * Mostly a wrapper for getaddrinfo() extracting the address storage
* from the numeric string like 1.2.3.4 or 2001:db8:85a3:0:0:8a2e:370:7334 * from the numeric string like 1.2.3.4 or 2001:db8:85a3:0:0:8a2e:370:7334
@ -66,7 +66,7 @@ static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
* Returns the length of the network address or -1 in case of error. * Returns the length of the network address or -1 in case of error.
*/ */
int int
virSocketParseAddr(const char *val, virSocketAddrPtr addr, int hint) { virSocketParseAddr(const char *val, virSocketAddrPtr addr, int family) {
int len; int len;
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *res = NULL; struct addrinfo *res = NULL;
@ -75,7 +75,8 @@ virSocketParseAddr(const char *val, virSocketAddrPtr addr, int hint) {
return(-1); return(-1);
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_NUMERICHOST | hint; hints.ai_family = family;
hints.ai_flags = AI_NUMERICHOST;
if ((getaddrinfo(val, NULL, &hints, &res) != 0) || (res == NULL)) { if ((getaddrinfo(val, NULL, &hints, &res) != 0) || (res == NULL)) {
return(-1); return(-1);
} }