Re: [PATCHv2 3/4] network: rework networkGetNetworkAddress to make it can get IPv6 address

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 03/09/2015 07:50 AM, John Ferlan wrote:

$SUBJ:

network: Allow networkGetNetworkAddress to return IPv6 address

On 02/28/2015 04:08 AM, Luyao Huang wrote:
Export the required helpers and rework networkGetNetworkAddress to
make it can get IPv6 address.

Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx>
---
v2: rework the code and make networkGetNetworkAddress
call virNetDevGetIPAddress instead of virNetDevGetIPv4Address.

  src/network/bridge_driver.c | 15 ++++++++-------
  src/network/bridge_driver.h |  6 ++++--
  src/qemu/qemu_command.c     |  8 ++++++--
  3 files changed, 18 insertions(+), 11 deletions(-)

This one I believe had some merge conflicts with recent upstream changes..

Yes..

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 1209609..5aeb168 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -4524,6 +4524,7 @@ 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
s/(v4)/(v4 or v6)

   * network. If a libvirt virtual network, that will be provided in the
@@ -4540,12 +4541,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;
This is unecessary since virNetworkDefGetIpByIndex returns NULL if not
found.

Other than that the rest seems OK.

Thanks for your review.
John

      virSocketAddr addr;
      virSocketAddrPtr addrptr = NULL;
      char *dev_name = NULL;
@@ -4566,12 +4567,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");
              break;
          }
          addrptr = &ipdef->address;
@@ -4599,7 +4600,7 @@ networkGetNetworkAddress(const char *netname, char **netaddr)
      }
if (dev_name) {
-        if (virNetDevGetIPv4Address(dev_name, &addr) < 0)
+        if (virNetDevGetIPAddress(dev_name, want_ipv6, &addr) < 0)
              goto error;
          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 24b2ad9..82a4ce3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7286,7 +7286,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, "
@@ -7450,7 +7452,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, "


Luyao

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]