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 familys 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.
---
src/conf/domain_conf.c | 2 +-
src/conf/network_conf.c | 4 ++--
src/network/bridge_driver.c | 4 ++--
src/util/network.c | 7 ++++---
4 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index bd9f425..53c8d09 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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);
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index ddef790..f209dad 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -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);
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 6323fa5..ac91c57 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -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);
diff --git a/src/util/network.c b/src/util/network.c
index b8107f7..4cb6bfe 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -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);
}
--
1.7.2.3