---
 src/lxc/lxc_container.c   | 23 ++++++++++++++++++-----
 src/qemu/qemu_interface.c | 24 ++++++++++++++++--------
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 15dacf1..7f4ce72 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -494,6 +494,7 @@ static int 
lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
     char *toStr = NULL;
     char *viaStr = NULL;
     virDomainNetDefPtr netDef;
+    char *ipStr = NULL, *peerStr = NULL;
     bool privNet = vmDef->features[VIR_DOMAIN_FEATURE_PRIVNET] ==
                    VIR_TRISTATE_SWITCH_ON;
 
@@ -515,7 +516,16 @@ static int 
lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
         for (j = 0; j < netDef->nips; j++) {
             virDomainNetIpDefPtr ip = netDef->ips[j];
             int prefix;
-            char *ipStr = virSocketAddrFormat(&ip->address);
+
+            VIR_FREE(ipStr);
+            VIR_FREE(peerStr);
+
+
+            ipStr = virSocketAddrFormat(&ip->address);
+            if (VIR_SOCKET_ADDR_VALID(&ip->peer))
+                peerStr = virSocketAddrFormat(&ip->peer);
+            else if (VIR_STRDUP(peerStr, "[none]") < 0)
+                goto error_out;
 
             if ((prefix = virSocketAddrGetIpPrefix(&ip->address,
                                                    NULL, ip->prefix)) < 0) {
@@ -525,12 +535,13 @@ static int 
lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
                 goto error_out;
             }
 
-            VIR_DEBUG("Adding IP address '%s/%d' to '%s'",
-                      ipStr, ip->prefix, newname);
+            VIR_DEBUG("Adding IP address '%s/%d' (peer %s) to '%s'",
+                      ipStr, prefix, peerStr, newname);
+
             if (virNetDevSetIPAddress(newname, &ip->address, &ip->peer, 
prefix) < 0) {
                 virReportError(VIR_ERR_SYSTEM_ERROR,
-                               _("Failed to set IP address '%s' on %s"),
-                               ipStr, newname);
+                               _("Failed to set IP address '%s/%d' (peer %s) 
on %s"),
+                               ipStr, prefix, peerStr, newname);
                 VIR_FREE(ipStr);
                 goto error_out;
             }
@@ -568,6 +579,8 @@ static int 
lxcContainerRenameAndEnableInterfaces(virDomainDefPtr vmDef,
         rc = virNetDevSetOnline("lo", true);
 
  error_out:
+    VIR_FREE(ipStr);
+    VIR_FREE(peerStr);
     VIR_FREE(toStr);
     VIR_FREE(viaStr);
     VIR_FREE(newname);
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index 34fe30e..58bbe71 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -411,6 +411,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
     bool template_ifname = false;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     const char *tunpath = "/dev/net/tun";
+    char *ipStr = NULL, *peerStr = NULL;
     size_t i;
 
     if (net->backend.tap) {
@@ -451,7 +452,15 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
     for (i = 0; i < net->nips; i++) {
         virDomainNetIpDefPtr ip = net->ips[i];
         int prefix;
-        char *ipStr = virSocketAddrFormat(&ip->address);
+
+        VIR_FREE(ipStr);
+        VIR_FREE(peerStr);
+
+        ipStr = virSocketAddrFormat(&ip->address);
+        if (VIR_SOCKET_ADDR_VALID(&ip->peer))
+            peerStr = virSocketAddrFormat(&ip->peer);
+        else if (VIR_STRDUP(peerStr, "[none]") < 0)
+            goto cleanup;
 
         if ((prefix = virSocketAddrGetIpPrefix(&ip->address,
                                                NULL, ip->prefix)) < 0) {
@@ -461,17 +470,15 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
             goto cleanup;
         }
 
-        VIR_DEBUG("Adding IP address '%s/%d' to '%s'",
-                  ipStr, ip->prefix, net->ifname);
+        VIR_DEBUG("Adding IP address '%s/%d' (peer %s) to '%s'",
+                  ipStr, prefix, peerStr, net->ifname);
 
         if (virNetDevSetIPAddress(net->ifname, &ip->address, &ip->peer, 
prefix) < 0) {
             virReportError(VIR_ERR_SYSTEM_ERROR,
-                           _("Failed to set IP address '%s' on %s"),
-                           ipStr, net->ifname);
-            VIR_FREE(ipStr);
+                           _("Failed to set IP address '%s/%u' (peer %s) on 
%s"),
+                           ipStr, prefix, peerStr, net->ifname);
             goto cleanup;
         }
-        VIR_FREE(ipStr);
     }
 
     if (net->linkstate == VIR_DOMAIN_NET_INTERFACE_LINK_STATE_UP ||
@@ -519,7 +526,8 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
             VIR_FREE(net->ifname);
     }
     virObjectUnref(cfg);
-
+    VIR_FREE(ipStr);
+    VIR_FREE(peerStr);
     return ret;
 }
 
-- 
2.5.5

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

Reply via email to