---
src/lxc/lxc_native.c | 47 +++++++++++++++++-----
.../lxcconf2xml-macvlannetwork.config | 13 ++++++
.../lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml | 26 ++++++++++++
tests/lxcconf2xmltest.c | 1 +
4 files changed, 77 insertions(+), 10 deletions(-)
create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.config
create mode 100644 tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 9d9ccb1..9ddbcc7 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -323,9 +323,11 @@ static virDomainNetDefPtr
lxcCreateNetDef(const char *type,
const char *link,
const char *mac,
- const char *flag)
+ const char *flag,
+ const char *macvlanmode)
{
virDomainNetDefPtr net = NULL;
+ virMacAddr macAddr;
if (VIR_ALLOC(net) < 0)
goto error;
@@ -337,9 +339,11 @@ lxcCreateNetDef(const char *type,
net->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN;
}
- if (STREQ(type, "veth")) {
- virMacAddr macAddr;
+ if (mac && virMacAddrParse(mac, &macAddr) == 0)
+ net->mac = macAddr;
+
+ if (STREQ(type, "veth")) {
if (!link)
goto error;
@@ -348,9 +352,20 @@ lxcCreateNetDef(const char *type,
if (VIR_STRDUP(net->data.bridge.brname, link) < 0)
goto error;
- if (mac && virMacAddrParse(mac, &macAddr) == 0)
- net->mac = macAddr;
+ } else if (STREQ(type, "macvlan")) {
+ net->type = VIR_DOMAIN_NET_TYPE_DIRECT;
+ if (!link || VIR_STRDUP(net->data.direct.linkdev, link) < 0)
+ goto error;
+
+ if (!macvlanmode || STREQ(macvlanmode, "private"))
+ net->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_PRIVATE;
+ else if (STREQ(macvlanmode, "vepa"))
+ net->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_VEPA;
+ else if (STREQ(macvlanmode, "bridge"))
+ net->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_BRIDGE;
+ else
+ VIR_WARN("Unknown macvlan type: %s", macvlanmode);
}
return net;
@@ -385,7 +400,8 @@ lxcAddNetworkDefinition(virDomainDefPtr def,
const char *type,
const char *link,
const char *mac,
- const char *flag)
+ const char *flag,
+ const char *macvlanmode)
{
virDomainNetDefPtr net = NULL;
virDomainHostdevDefPtr hostdev = NULL;
@@ -405,7 +421,7 @@ lxcAddNetworkDefinition(virDomainDefPtr def,
goto error;
def->hostdevs[def->nhostdevs - 1] = hostdev;
} else {
- if (!(net = lxcCreateNetDef(type, link, mac, flag)))
+ if (!(net = lxcCreateNetDef(type, link, mac, flag, macvlanmode)))
goto error;
if (VIR_EXPAND_N(def->nets, def->nnets, 1) < 0)
@@ -427,6 +443,7 @@ typedef struct {
char *link;
char *mac;
char *flag;
+ char *macvlanmode;
bool privnet;
size_t networks;
} lxcNetworkParseData;
@@ -441,7 +458,9 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void
*data)
/* Store the previous NIC */
status = lxcAddNetworkDefinition(parseData->def, parseData->type,
parseData->link, parseData->mac,
- parseData->flag);
+ parseData->flag,
+ parseData->macvlanmode);
+
if (status < 0)
return -1;
else if (status > 0)
@@ -454,6 +473,7 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void
*data)
parseData->link = NULL;
parseData->mac = NULL;
parseData->flag = NULL;
+ parseData->macvlanmode = NULL;
/* Keep the new value */
parseData->type = value->str;
@@ -464,6 +484,12 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void
*data)
parseData->mac = value->str;
else if (STREQ(name, "lxc.network.flags"))
parseData->flag = value->str;
+ else if (STREQ(name, "lxc.network.macvlan.mode"))
+ parseData->macvlanmode = value->str;
+ else if (STRPREFIX(name, "lxc.network"))
+ VIR_WARN("Unhandled network property: %s = %s",
+ name,
+ value->str);
return 0;
}
@@ -472,13 +498,14 @@ static int
lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
{
int status;
- lxcNetworkParseData data = {def, NULL, NULL, NULL, NULL, true, 0};
+ lxcNetworkParseData data = {def, 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.mac, data.flag,
+ data.macvlanmode);
if (status < 0)
return -1;
else if (status > 0)
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.config
b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.config
new file mode 100644
index 0000000..7c96bfa
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.config
@@ -0,0 +1,13 @@
+# Template used to create this container: opensuse
+# Template script checksum (SHA-1): 27307e0a95bd81b2c0bd82d6f87fdbe83be075ef
+
+lxc.network.type = macvlan
+lxc.network.flags = up
+lxc.network.link = eth0
+lxc.network.hwaddr = 02:00:15:8f:05:c1
+lxc.network.macvlan.mode = vepa
+
+#remove next line if host DNS configuration should not be available to container
+lxc.rootfs = /var/lib/lxc/migrate_test/rootfs
+lxc.utsname = migrate_test
+lxc.autodev=1
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
new file mode 100644
index 0000000..aa0683a
--- /dev/null
+++ b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
@@ -0,0 +1,26 @@
+<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>
+ <interface type='direct'>
+ <mac address='02:00:15:8f:05:c1'/>
+ <source dev='eth0' mode='vepa'/>
+ <link state='up'/>
+ </interface>
+ </devices>
+</domain>
diff --git a/tests/lxcconf2xmltest.c b/tests/lxcconf2xmltest.c
index c888b42..4e7dd58 100644
--- a/tests/lxcconf2xmltest.c
+++ b/tests/lxcconf2xmltest.c
@@ -107,6 +107,7 @@ mymain(void)
DO_TEST("nonetwork", false);
DO_TEST("nonenetwork", false);
DO_TEST("physnetwork", false);
+ DO_TEST("macvlannetwork", false);
return ret;
}
--
1.8.5.2