From: Alvaro Polo Date: Tue, 4 Jun 2013 07:44:32 +0000 (+0200) Subject: Fix a invalid usage of virDomainNetDef in OpenVZ driver X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=7a5ac8352073bd9babbec76d2ef74df7ab8e61eb;p=libvirt.git Fix a invalid usage of virDomainNetDef in OpenVZ driver OpenVZ was accessing ethernet data to obtain the guest iface name regardless the domain is configured to use ethernet or bridged networking. This prevented the guest network interface to be rightly named for bridged networking. --- diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index c8081ce4b3..db738a455a 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -815,6 +815,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, char host_macaddr[VIR_MAC_STRING_BUFLEN]; struct openvz_driver *driver = conn->privateData; virCommandPtr cmd = NULL; + char *guest_ifname = NULL; if (net == NULL) return 0; @@ -840,11 +841,15 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, virBuffer buf = VIR_BUFFER_INITIALIZER; int veid = openvzGetVEID(vpsid); - /* if user doesn't specify guest interface name, - * then we need to generate it */ - if (net->data.ethernet.dev == NULL) { - net->data.ethernet.dev = openvzGenerateContainerVethName(veid); - if (net->data.ethernet.dev == NULL) { + /* if net is ethernet and the user has specified guest interface name, + * let's use it; otherwise generate a new one */ + if (net->type == VIR_DOMAIN_NET_TYPE_ETHERNET && + net->data.ethernet.dev != NULL) { + if (VIR_STRDUP(guest_ifname, net->data.ethernet.dev) == -1) + goto cleanup; + } else { + guest_ifname = openvzGenerateContainerVethName(veid); + if (guest_ifname == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not generate eth name for container")); goto cleanup; @@ -862,7 +867,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, } } - virBufferAdd(&buf, net->data.ethernet.dev, -1); /* Guest dev */ + virBufferAdd(&buf, guest_ifname, -1); /* Guest dev */ virBufferAsprintf(&buf, ",%s", macaddr); /* Guest dev mac */ virBufferAsprintf(&buf, ",%s", net->ifname); /* Host dev */ virBufferAsprintf(&buf, ",%s", host_macaddr); /* Host dev mac */ @@ -871,7 +876,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) { virBufferAsprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */ } else { - virBufferAsprintf(configBuf, "ifname=%s", net->data.ethernet.dev); + virBufferAsprintf(configBuf, "ifname=%s", guest_ifname); virBufferAsprintf(configBuf, ",mac=%s", macaddr); /* Guest dev mac */ virBufferAsprintf(configBuf, ",host_ifname=%s", net->ifname); /* Host dev */ virBufferAsprintf(configBuf, ",host_mac=%s", host_macaddr); /* Host dev mac */ @@ -895,6 +900,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, cleanup: virCommandFree(cmd); + VIR_FREE(guest_ifname); return rc; }