From a861054fc7999ccb41fcbe9592c1df80456cca94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 7 Dec 2017 03:27:46 +0100 Subject: [PATCH] xenconfig: add support for multiple IP addresses Xen's xl config format has long supported specifying multiple IP addresses for virtual interfaces. E.g. vif = [ "ip=10.0.0.1 10.1.1.1 2000::1, ..." ] Add support for converting multiple IP addresses to/from domXML. Reviewed-by: Jim Fehlig --- src/xenconfig/xen_common.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 7f838b65e9..40b1483215 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -847,7 +847,7 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename) while (list) { char model[10]; char type[10]; - char ip[16]; + char ip[128]; char mac[18]; char bridge[50]; char vifname[50]; @@ -964,8 +964,18 @@ xenParseVif(virConfPtr conf, virDomainDefPtr def, const char *vif_typename) if (bridge[0] && VIR_STRDUP(net->data.bridge.brname, bridge) < 0) goto cleanup; } - if (ip[0] && virDomainNetAppendIPAddress(net, ip, AF_INET, 0) < 0) - goto cleanup; + if (ip[0]) { + char **ip_list = virStringSplit(ip, " ", 0); + size_t i; + + for (i = 0; ip_list[i]; i++) { + if (virDomainNetAppendIPAddress(net, ip_list[i], 0, 0) < 0) { + virStringListFree(ip_list); + goto cleanup; + } + } + virStringListFree(ip_list); + } if (script && script[0] && VIR_STRDUP(net->script, script) < 0) @@ -1207,14 +1217,10 @@ xenFormatNet(virConnectPtr conn, switch (net->type) { case VIR_DOMAIN_NET_TYPE_BRIDGE: virBufferAsprintf(&buf, ",bridge=%s", net->data.bridge.brname); - if (net->guestIP.nips == 1) { - char *ipStr = virSocketAddrFormat(&net->guestIP.ips[0]->address); + if (net->guestIP.nips > 0) { + char *ipStr = xenMakeIPList(&net->guestIP); virBufferAsprintf(&buf, ",ip=%s", ipStr); VIR_FREE(ipStr); - } else if (net->guestIP.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; @@ -1222,14 +1228,10 @@ xenFormatNet(virConnectPtr conn, case VIR_DOMAIN_NET_TYPE_ETHERNET: if (net->script) virBufferAsprintf(&buf, ",script=%s", net->script); - if (net->guestIP.nips == 1) { - char *ipStr = virSocketAddrFormat(&net->guestIP.ips[0]->address); + if (net->guestIP.nips > 0) { + char *ipStr = xenMakeIPList(&net->guestIP); virBufferAsprintf(&buf, ",ip=%s", ipStr); VIR_FREE(ipStr); - } else if (net->guestIP.nips > 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Driver does not support setting multiple IP addresses")); - goto cleanup; } break; -- GitLab