[PATCH v4 17/17] Report error if a driver can't handle multiple IP addresses

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

 



Drivers supporting one and only one IP address raise an error if more IP
addresses are configured.
---
 src/vbox/vbox_common.c     | 12 +++++++++---
 src/xenconfig/xen_common.c | 12 ++++++++++--
 src/xenconfig/xen_sxpr.c   | 12 ++++++++++--
 3 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index fa1e12d..96d09f6 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1255,7 +1255,7 @@ vboxAttachSound(virDomainDefPtr def, IMachine *machine)
     VBOX_RELEASE(audioAdapter);
 }
 
-static void
+static int
 vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
 {
     ISystemProperties *systemProperties = NULL;
@@ -1307,10 +1307,14 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
         } else if (def->nets[i]->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
             VIR_DEBUG("NIC(%zu): brname: %s", i, def->nets[i]->data.bridge.brname);
             VIR_DEBUG("NIC(%zu): script: %s", i, def->nets[i]->script);
-            if (def->nets[i]->nips > 0) {
+            if (def->nets[i]->nips == 1) {
                 char *ipStr = virSocketAddrFormat(&def->nets[i]->ips[0]->address);
                 VIR_DEBUG("NIC(%zu): ipaddr: %s", i, ipStr);
                 VIR_FREE(ipStr);
+            } else if (def->nets[i]->nips > 1) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                               _("Driver does not support setting multiple IP addresses"));
+                return -1;
             }
         }
 
@@ -1394,6 +1398,7 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
         gVBoxAPI.UINetworkAdapter.SetMACAddress(adapter, MACAddress);
         VBOX_UTF16_FREE(MACAddress);
     }
+    return 0;
 }
 
 static void
@@ -1939,7 +1944,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml)
     vboxSetBootDeviceOrder(def, data, machine);
     vboxAttachDrives(def, data, machine);
     vboxAttachSound(def, machine);
-    vboxAttachNetwork(def, data, machine);
+    if (vboxAttachNetwork(def, data, machine) < 0)
+        goto cleanup;
     vboxAttachSerial(def, data, machine);
     vboxAttachParallel(def, data, machine);
     vboxAttachVideo(def, machine);
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index bcb3bd3..77915eb 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1222,10 +1222,14 @@ xenFormatNet(virConnectPtr conn,
     switch (net->type) {
     case VIR_DOMAIN_NET_TYPE_BRIDGE:
         virBufferAsprintf(&buf, ",bridge=%s", net->data.bridge.brname);
-        if (net->nips > 0) {
+        if (net->nips == 1) {
             char *ipStr = virSocketAddrFormat(&net->ips[0]->address);
             virBufferAsprintf(&buf, ",ip=%s", ipStr);
             VIR_FREE(ipStr);
+        } else if (net->nips > 1) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Driver does not support setting multiple IP addresses"));
+            goto cleanup;
         }
         virBufferAsprintf(&buf, ",script=%s", DEFAULT_VIF_SCRIPT);
         break;
@@ -1233,10 +1237,14 @@ xenFormatNet(virConnectPtr conn,
     case VIR_DOMAIN_NET_TYPE_ETHERNET:
         if (net->script)
             virBufferAsprintf(&buf, ",script=%s", net->script);
-        if (net->nips > 0) {
+        if (net->nips == 1) {
             char *ipStr = virSocketAddrFormat(&net->ips[0]->address);
             virBufferAsprintf(&buf, ",ip=%s", ipStr);
             VIR_FREE(ipStr);
+        } else if (net->nips > 1) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Driver does not support setting multiple IP addresses"));
+            goto cleanup;
         }
         break;
 
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index caeb464..d3c1d9b 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -1898,10 +1898,14 @@ xenFormatSxprNet(virConnectPtr conn,
             script = def->script;
 
         virBufferEscapeSexpr(buf, "(script '%s')", script);
-        if (def->nips > 0) {
+        if (def->nips == 1) {
             char *ipStr = virSocketAddrFormat(&def->ips[0]->address);
             virBufferEscapeSexpr(buf, "(ip '%s')", ipStr);
             VIR_FREE(ipStr);
+        } else if (def->nips > 1) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Driver does not support setting multiple IP addresses"));
+            return -1;
         }
         break;
 
@@ -1935,10 +1939,14 @@ xenFormatSxprNet(virConnectPtr conn,
         if (def->script)
             virBufferEscapeSexpr(buf, "(script '%s')",
                                  def->script);
-        if (def->nips > 0) {
+        if (def->nips == 1) {
             char *ipStr = virSocketAddrFormat(&def->ips[0]->address);
             virBufferEscapeSexpr(buf, "(ip '%s')", ipStr);
             VIR_FREE(ipStr);
+        } else if (def->nips > 1) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Driver does not support setting multiple IP addresses"));
+            return -1;
         }
         break;
 
-- 
2.1.2

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