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 07efe3d..7887a8b 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1254,7 +1254,7 @@ vboxAttachSound(virDomainDefPtr def, IMachine *machine)
VBOX_RELEASE(audioAdapter);
}
-static void
+static int
vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
ISystemProperties *systemProperties = NULL;
@@ -1306,10 +1306,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;
}
}
@@ -1393,6 +1397,7 @@ vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
gVBoxAPI.UINetworkAdapter.SetMACAddress(adapter, MACAddress);
VBOX_UTF16_FREE(MACAddress);
}
+ return 0;
}
static void
@@ -1938,7 +1943,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 e8ae5fa..e622cb1 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1220,10 +1220,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;
@@ -1231,10 +1235,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 a1c342b..554d28f 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