return ret;
}
+typedef struct {
+ char *type;
+ bool privnet;
+ size_t networks;
+} lxcNetworkParseData;
+
+static int
+lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void *data)
+{
+ lxcNetworkParseData *parseData = data;
+
+ if (STREQ(name, "lxc.network.type")) {
+ if (parseData->type != NULL && STREQ(parseData->type, "none"))
+ parseData->privnet = false;
+ else if ((parseData->type != NULL) &&
+ STRNEQ(parseData->type, "empty") &&
+ STRNEQ(parseData->type, "")) {
+ parseData->networks++;
+ }
+
+ /* Start a new network interface config */
+ parseData->type = NULL;
+
+ /* Keep the new value */
+ parseData->type = value->str;
+ }
+ return 0;
+}
+
+static int
+lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
+{
+ lxcNetworkParseData data = {NULL, true, 0};
+
+ virConfWalk(properties, lxcNetworkWalkCallback, &data);
+
+ if ((data.type != NULL) && STREQ(data.type, "none"))
+ data.privnet = false;
+ else if ((data.type != NULL) && STRNEQ(data.type, "empty") &&
+ STRNEQ(data.type, "")) {
+ data.networks++;
+ }
+
+ if (data.networks == 0 && data.privnet) {
+ /* When no network type is provided LXC only adds loopback */
+ def->features[VIR_DOMAIN_FEATURE_PRIVNET] = VIR_DOMAIN_FEATURE_STATE_ON;
+ }
+
+ return 0;
+}
+
virDomainDefPtr
lxcParseConfigString(const char *config)
{
if (virConfWalk(properties, lxcFstabWalkCallback, vmdef) < 0)
goto error;
+ /* Network configuration */
+ if (lxcConvertNetworkSettings(vmdef, properties) < 0)
+ goto error;
+
goto cleanup;
error:
--- /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>
+ </devices>
+</domain>
--- /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>
+ <features>
+ <privnet/>
+ </features>
+ <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>
+ </devices>
+</domain>