const char *link,
const char *mac,
const char *flag,
- const char *macvlanmode)
+ const char *macvlanmode,
+ const char *vlanid)
{
virDomainNetDefPtr net = NULL;
virDomainHostdevDefPtr hostdev = NULL;
+ bool isPhys, isVlan = false;
if ((type == NULL) || STREQ(type, "empty") || STREQ(type, "") ||
STREQ(type, "none"))
return 0;
- if (type != NULL && STREQ(type, "phys")) {
- if (!link ||
- !(hostdev = lxcCreateHostdevDef(VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES,
+ isPhys = STREQ(type, "phys");
+ isVlan = STREQ(type, "vlan");
+ if (type != NULL && (isPhys || isVlan)) {
+ if (!link) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Missing 'link' attribute for NIC"));
+ goto error;
+ }
+ if (!(hostdev = lxcCreateHostdevDef(VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES,
VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET,
link)))
goto error;
+ /* This still requires the user to manually setup the vlan interface
+ * on the host */
+ if (isVlan && vlanid) {
+ VIR_FREE(hostdev->source.caps.u.net.iface);
+ if (virAsprintf(&hostdev->source.caps.u.net.iface,
+ "%s.%s", link, vlanid) < 0)
+ goto error;
+ }
+
if (VIR_EXPAND_N(def->hostdevs, def->nhostdevs, 1) < 0)
goto error;
def->hostdevs[def->nhostdevs - 1] = hostdev;
char *mac;
char *flag;
char *macvlanmode;
+ char *vlanid;
bool privnet;
size_t networks;
} lxcNetworkParseData;
status = lxcAddNetworkDefinition(parseData->def, parseData->type,
parseData->link, parseData->mac,
parseData->flag,
- parseData->macvlanmode);
+ parseData->macvlanmode,
+ parseData->vlanid);
if (status < 0)
return -1;
parseData->mac = NULL;
parseData->flag = NULL;
parseData->macvlanmode = NULL;
+ parseData->vlanid = NULL;
/* Keep the new value */
parseData->type = value->str;
parseData->flag = value->str;
else if (STREQ(name, "lxc.network.macvlan.mode"))
parseData->macvlanmode = value->str;
+ else if (STREQ(name, "lxc.network.vlan.id"))
+ parseData->vlanid = value->str;
else if (STRPREFIX(name, "lxc.network"))
VIR_WARN("Unhandled network property: %s = %s",
name,
lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
{
int status;
- lxcNetworkParseData data = {def, NULL, NULL, NULL, NULL, NULL, true, 0};
+ lxcNetworkParseData data = {def, NULL, NULL, NULL, NULL,
+ NULL, NULL, true, 0};
virConfWalk(properties, lxcNetworkWalkCallback, &data);
/* Add the last network definition found */
status = lxcAddNetworkDefinition(def, data.type, data.link,
data.mac, data.flag,
- data.macvlanmode);
+ data.macvlanmode,
+ data.vlanid);
if (status < 0)
return -1;
else if (status > 0)
--- /dev/null
+<domain type='lxc'>
+ <name>migrate_test</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>65536</memory>
+ <currentMemory unit='KiB'>0</currentMemory>
+ <vcpu placement='static' current='0'>1</vcpu>
+ <os>
+ <type>exe</type>
+ <init>/sbin/init</init>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <filesystem type='mount' accessmode='passthrough'>
+ <source dir='/var/lib/lxc/migrate_test/rootfs'/>
+ <target dir='/'/>
+ </filesystem>
+ <hostdev mode='capabilities' type='net'>
+ <source>
+ <interface>eth0.2</interface>
+ </source>
+ </hostdev>
+ </devices>
+</domain>