[PATCH 22/28] util: provide default destination IP in alternate virNetDevIPRouteAdd()

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

 



The version of virNetDevIPRouteAdd() has a bit of code to create the
appropriate "0.0.0.0" or "::" virSocketAddr when the addr passed in is
NULL or invalid, but the alternate implementation (used on platforms
that don't support libnl) had no such code, making the two
implementations semantically diferent. This patch corrects that
oversight.
---
 src/util/virnetdevip.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index dad2a78..6889f81 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -618,9 +618,27 @@ virNetDevIPRouteAdd(const char *ifname,
 {
     virCommandPtr cmd = NULL;
     char *addrstr = NULL, *gatewaystr = NULL;
+    virSocketAddr defaultAddr;
+    virSocketAddrPtr actualAddr;
     int ret = -1;
 
-    if (!(addrstr = virSocketAddrFormat(addr)))
+    actualAddr = addr;
+
+    /* If we have no valid network address, then use the default one */
+    if (!addr || !VIR_SOCKET_ADDR_VALID(addr)) {
+        int family = VIR_SOCKET_ADDR_FAMILY(gateway);
+        if (family == AF_INET) {
+            if (virSocketAddrParseIPv4(&defaultAddr, VIR_SOCKET_ADDR_IPV4_ALL) < 0)
+                goto cleanup;
+        } else {
+            if (virSocketAddrParseIPv6(&defaultAddr, VIR_SOCKET_ADDR_IPV6_ALL) < 0)
+                goto cleanup;
+        }
+
+        actualAddr = &defaultAddr;
+    }
+
+    if (!(addrstr = virSocketAddrFormat(actualAddr)))
         goto cleanup;
     if (!(gatewaystr = virSocketAddrFormat(gateway)))
         goto cleanup;
-- 
2.5.5

--
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]