On Tue, Jun 04, 2013 at 09:44:32AM +0200, Alvaro Polo wrote:
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.
Ooh, nasty one!
---
src/openvz/openvz_driver.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index c8081ce..db738a4 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;
ACK
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|