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;
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;
}
}
- 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 */
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 */
cleanup:
virCommandFree(cmd);
+ VIR_FREE(guest_ifname);
return rc;
}