1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

OpenVZ: add ethernet interface type support

This patch adds support for ethernet interface type to OpenVZ domains
as stated in this previous message: http://www.redhat.com/archives/libvir-
list/2010-July/msg00658.html
This commit is contained in:
Jean-Baptiste Rouault 2010-08-18 17:05:02 +02:00 committed by Eric Blake
parent 2ce55fe77e
commit 9a4b705f74

View File

@ -740,53 +740,56 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
virCapabilitiesGenerateMac(driver->caps, host_mac); virCapabilitiesGenerateMac(driver->caps, host_mac);
virFormatMacAddr(host_mac, host_macaddr); virFormatMacAddr(host_mac, host_macaddr);
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) { if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
(net->type == VIR_DOMAIN_NET_TYPE_ETHERNET &&
net->data.ethernet.ipaddr == NULL)) {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
char *dev_name_ve;
int veid = openvzGetVEID(vpsid); int veid = openvzGetVEID(vpsid);
//--netif_add ifname[,mac,host_ifname,host_mac] //--netif_add ifname[,mac,host_ifname,host_mac]
ADD_ARG_LIT("--netif_add") ; ADD_ARG_LIT("--netif_add") ;
/* generate interface name in ve and copy it to options */ /* if user doesn't specify guest interface name,
dev_name_ve = openvzGenerateContainerVethName(veid); * then we need to generate it */
if (dev_name_ve == NULL) { if (net->data.ethernet.dev == NULL) {
openvzError(VIR_ERR_INTERNAL_ERROR, "%s", net->data.ethernet.dev = openvzGenerateContainerVethName(veid);
_("Could not generate eth name for container")); if (net->data.ethernet.dev == NULL) {
rc = -1; openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
goto exit; _("Could not generate eth name for container"));
rc = -1;
goto exit;
}
} }
/* if user doesn't specified host interface name, /* if user doesn't specified host interface name,
* than we need to generate it */ * than we need to generate it */
if (net->ifname == NULL) { if (net->ifname == NULL) {
net->ifname = openvzGenerateVethName(veid, dev_name_ve); net->ifname = openvzGenerateVethName(veid, net->data.ethernet.dev);
if (net->ifname == NULL) { if (net->ifname == NULL) {
openvzError(VIR_ERR_INTERNAL_ERROR, "%s", openvzError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not generate veth name")); _("Could not generate veth name"));
rc = -1; rc = -1;
VIR_FREE(dev_name_ve);
goto exit; goto exit;
} }
} }
virBufferAdd(&buf, dev_name_ve, -1); /* Guest dev */ virBufferAdd(&buf, net->data.ethernet.dev, -1); /* Guest dev */
virBufferVSprintf(&buf, ",%s", macaddr); /* Guest dev mac */ virBufferVSprintf(&buf, ",%s", macaddr); /* Guest dev mac */
virBufferVSprintf(&buf, ",%s", net->ifname); /* Host dev */ virBufferVSprintf(&buf, ",%s", net->ifname); /* Host dev */
virBufferVSprintf(&buf, ",%s", host_macaddr); /* Host dev mac */ virBufferVSprintf(&buf, ",%s", host_macaddr); /* Host dev mac */
if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) { if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
virBufferVSprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */ if (driver->version >= VZCTL_BRIDGE_MIN_VERSION) {
} else { virBufferVSprintf(&buf, ",%s", net->data.bridge.brname); /* Host bridge */
virBufferVSprintf(configBuf, "ifname=%s", dev_name_ve); } else {
virBufferVSprintf(configBuf, ",mac=%s", macaddr); /* Guest dev mac */ virBufferVSprintf(configBuf, "ifname=%s", net->data.ethernet.dev);
virBufferVSprintf(configBuf, ",host_ifname=%s", net->ifname); /* Host dev */ virBufferVSprintf(configBuf, ",mac=%s", macaddr); /* Guest dev mac */
virBufferVSprintf(configBuf, ",host_mac=%s", host_macaddr); /* Host dev mac */ virBufferVSprintf(configBuf, ",host_ifname=%s", net->ifname); /* Host dev */
virBufferVSprintf(configBuf, ",bridge=%s", net->data.bridge.brname); /* Host bridge */ virBufferVSprintf(configBuf, ",host_mac=%s", host_macaddr); /* Host dev mac */
virBufferVSprintf(configBuf, ",bridge=%s", net->data.bridge.brname); /* Host bridge */
}
} }
VIR_FREE(dev_name_ve);
if (!(opt = virBufferContentAndReset(&buf))) if (!(opt = virBufferContentAndReset(&buf)))
goto no_memory; goto no_memory;