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;
}
if (virSocketParseAddr(addrStr, def->target.addr, 0) < 0) {
if (virSocketParseAddr(addrStr, def->target.addr, AF_UNSPEC) < 0) {
virDomainReportError(VIR_ERR_XML_ERROR,
_("%s is not a valid address"),
addrStr);

View File

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

View File

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

View File

@ -58,7 +58,7 @@ static int getIPv6Addr(virSocketAddrPtr addr, virIPv6AddrPtr tab) {
* virSocketParseAddr:
* @val: a numeric network address IPv4 or IPv6
* @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
* 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.
*/
int
virSocketParseAddr(const char *val, virSocketAddrPtr addr, int hint) {
virSocketParseAddr(const char *val, virSocketAddrPtr addr, int family) {
int len;
struct addrinfo hints;
struct addrinfo *res = NULL;
@ -75,7 +75,8 @@ virSocketParseAddr(const char *val, virSocketAddrPtr addr, int hint) {
return(-1);
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)) {
return(-1);
}