From: Luyao Huang <lhuang(a)redhat.com>
Export the required helpers and rework networkGetNetworkAddress to
make it can get IPv6 address.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/network/bridge_driver.c | 17 +++++++++--------
src/network/bridge_driver.h | 6 ++++--
src/qemu/qemu_command.c | 8 ++++++--
3 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 5186be8..c00c656 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -4493,8 +4493,9 @@ networkReleaseActualDevice(virDomainDefPtr dom,
* networkGetNetworkAddress:
* @netname: the name of a network
* @netaddr: string representation of IP address for that network.
+ * @want_ipv6: if true will get IPv6 address, false for IPv4.
*
- * Attempt to return an IP (v4) address associated with the named
+ * Attempt to return an IP (v4 or v6) address associated with the named
* network. If a libvirt virtual network, that will be provided in the
* configuration. For host bridge and direct (macvtap) networks, we
* must do an ioctl to learn the address.
@@ -4509,12 +4510,12 @@ networkReleaseActualDevice(virDomainDefPtr dom,
* completely unsupported.
*/
int
-networkGetNetworkAddress(const char *netname, char **netaddr)
+networkGetNetworkAddress(const char *netname, char **netaddr, bool want_ipv6)
{
int ret = -1;
virNetworkObjPtr network;
virNetworkDefPtr netdef;
- virNetworkIpDefPtr ipdef;
+ virNetworkIpDefPtr ipdef = NULL;
virSocketAddr addr;
virSocketAddrPtr addrptr = NULL;
char *dev_name = NULL;
@@ -4535,12 +4536,12 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
case VIR_NETWORK_FORWARD_NONE:
case VIR_NETWORK_FORWARD_NAT:
case VIR_NETWORK_FORWARD_ROUTE:
- /* if there's an ipv4def, get it's address */
- ipdef = virNetworkDefGetIpByIndex(netdef, AF_INET, 0);
+ /* if there's an ipdef, get it's IPv4 or IPv6 address */
+ ipdef = virNetworkDefGetIpByIndex(netdef, want_ipv6 ? AF_INET6 : AF_INET, 0);
if (!ipdef) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("network '%s' doesn't have an IPv4
address"),
- netdef->name);
+ _("network '%s' doesn't have an '%s'
address"),
+ netdef->name, want_ipv6 ? "IPv6" :
"IPv4");
goto cleanup;
}
addrptr = &ipdef->address;
@@ -4569,7 +4570,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
}
if (dev_name) {
- if (virNetDevGetIPAddress(dev_name, false, &addr) < 0)
+ if (virNetDevGetIPAddress(dev_name, want_ipv6, &addr) < 0)
goto cleanup;
addrptr = &addr;
}
diff --git a/src/network/bridge_driver.h b/src/network/bridge_driver.h
index 2f801ee..465ab18 100644
--- a/src/network/bridge_driver.h
+++ b/src/network/bridge_driver.h
@@ -44,7 +44,9 @@ int networkReleaseActualDevice(virDomainDefPtr dom,
virDomainNetDefPtr iface)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-int networkGetNetworkAddress(const char *netname, char **netaddr)
+int networkGetNetworkAddress(const char *netname,
+ char **netaddr,
+ bool want_ipv6)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int networkDnsmasqConfContents(virNetworkObjPtr network,
@@ -57,7 +59,7 @@ int networkDnsmasqConfContents(virNetworkObjPtr network,
# define networkAllocateActualDevice(dom, iface) 0
# define networkNotifyActualDevice(dom, iface) (dom=dom, iface=iface, 0)
# define networkReleaseActualDevice(dom, iface) (dom=dom, iface=iface, 0)
-# define networkGetNetworkAddress(netname, netaddr) (-2)
+# define networkGetNetworkAddress(netname, netaddr, want_ipv6) (-2)
# define networkDnsmasqConfContents(network, pidfile, configstr, \
dctx, caps) 0
# endif
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 1510797..466c0cf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7381,7 +7381,9 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
listenNetwork = virDomainGraphicsListenGetNetwork(graphics, 0);
if (!listenNetwork)
break;
- ret = networkGetNetworkAddress(listenNetwork, &netAddr);
+ ret = networkGetNetworkAddress(listenNetwork, &netAddr,
+ graphics->listens->family ==
+ VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_IPV6);
if (ret <= -2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("network-based listen not possible,
"
@@ -7545,7 +7547,9 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
listenNetwork = virDomainGraphicsListenGetNetwork(graphics, 0);
if (!listenNetwork)
break;
- ret = networkGetNetworkAddress(listenNetwork, &netAddr);
+ ret = networkGetNetworkAddress(listenNetwork, &netAddr,
+ graphics->listens->family ==
+ VIR_DOMAIN_GRAPHICS_LISTEN_FAMILY_IPV6);
if (ret <= -2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
"%s", _("network-based listen not possible,
"
--
2.1.0