diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 66be361f3f..3b7bfaed9b 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -328,6 +328,57 @@ lxcFstabWalkCallback(const char* name, virConfValuePtr value, void * data)
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)
{
@@ -388,6 +439,10 @@ lxcParseConfigString(const char *config)
if (virConfWalk(properties, lxcFstabWalkCallback, vmdef) < 0)
goto error;
+ /* Network configuration */
+ if (lxcConvertNetworkSettings(vmdef, properties) < 0)
+ goto error;
+
goto cleanup;
error:
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.config b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.config
new file mode 100644
index 0000000000..c1bb9a697f
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.config
@@ -0,0 +1,4 @@
+lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
+lxc.utsname = migrate_test
+lxc.autodev=1
+lxc.network.type = none
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml
new file mode 100644
index 0000000000..eebcb4ed58
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml
@@ -0,0 +1,21 @@
+
+ migrate_test
+ c7a5fdbd-edaf-9455-926a-d65c16db1809
+ 65536
+ 0
+ 1
+
+ exe
+ /sbin/init
+
+
+ destroy
+ restart
+ destroy
+
+
+
+
+
+
+
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-nonetwork.config b/tests/lxcconf2xmldata/lxcconf2xml-nonetwork.config
new file mode 100644
index 0000000000..b6fbe1d5c8
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-nonetwork.config
@@ -0,0 +1,3 @@
+lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
+lxc.utsname = migrate_test
+lxc.autodev=1
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml b/tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml
new file mode 100644
index 0000000000..511e3dd7ac
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml
@@ -0,0 +1,24 @@
+
+ migrate_test
+ c7a5fdbd-edaf-9455-926a-d65c16db1809
+ 65536
+ 0
+ 1
+
+ exe
+ /sbin/init
+
+
+
+
+
+ destroy
+ restart
+ destroy
+
+
+
+
+
+
+
diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c
index c4b21ecb04..50041a591d 100644
--- a/tests/lxcconf2xmltest.c
+++ b/tests/lxcconf2xmltest.c
@@ -104,6 +104,8 @@ mymain(void)
DO_TEST("simple", false);
DO_TEST("fstab", true);
+ DO_TEST("nonetwork", false);
+ DO_TEST("nonenetwork", false);
return ret;
}