for exmple,the xml is:
<domain type = 'lxc'>
...
<devices>
<interface type ="ethernet">
<mac address="02:36:1d:18:2a:e4"/>
<ip address='192.168.112.105' family='ipv4' prefix='24'/>
<target dev="tap361d182e-14"/>
</interface>
<devices>
</domian>
when i start lxc with that xml file,system will report error and start lxc failed
Now i create the veth pair and set mac address in lxc if the network type is ethernet
Signed-off-by: mark zhong <zhongguocheng1(a)163.com>
---
src/lxc/lxc_process.c | 36 ++++++++++++++++++++++++++++++++++++
src/lxc/lxc_process.h | 3 +++
2 files changed, 39 insertions(+)
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 57e3880..913fe36 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -359,6 +359,39 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
return ret;
}
+char *virLXCProcessSetupInterfaceEthernet(virDomainDefPtr vm,
+ virDomainNetDefPtr net)
+{
+ char *ret = NULL;
+ char *parentVeth;
+ char *containerVeth = NULL;
+
+ VIR_DEBUG("calling vethCreate()");
+ parentVeth = net->ifname;
+ if (virNetDevVethCreate(&parentVeth, &containerVeth) < 0)
+ goto cleanup;
+ VIR_DEBUG("parentVeth: %s, containerVeth: %s", parentVeth, containerVeth);
+
+ if (net->ifname == NULL)
+ net->ifname = parentVeth;
+
+ if (virNetDevSetMAC(containerVeth, &net->mac) < 0)
+ goto cleanup;
+
+ if (virNetDevSetOnline(parentVeth, true) < 0)
+ goto cleanup;
+
+ if (net->filter &&
+ virDomainConfNWFilterInstantiate(vm->uuid, net) < 0)
+ goto cleanup;
+
+ ret = containerVeth;
+
+ cleanup:
+ return ret;
+}
+
+
static const char *nsInfoLocal[VIR_LXC_DOMAIN_NAMESPACE_LAST] = {
[VIR_LXC_DOMAIN_NAMESPACE_SHARENET] = "net",
[VIR_LXC_DOMAIN_NAMESPACE_SHAREIPC] = "ipc",
@@ -559,6 +592,9 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
break;
case VIR_DOMAIN_NET_TYPE_ETHERNET:
+ if (!(veth = virLXCProcessSetupInterfaceEthernet(def,
+ net)))
+ goto cleanup;
break;
case VIR_DOMAIN_NET_TYPE_USER:
diff --git a/src/lxc/lxc_process.h b/src/lxc/lxc_process.h
index b6c8083..3b4ade3 100644
--- a/src/lxc/lxc_process.h
+++ b/src/lxc/lxc_process.h
@@ -53,5 +53,8 @@ char *virLXCProcessSetupInterfaceBridged(virDomainDefPtr vm,
char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
virDomainDefPtr def,
virDomainNetDefPtr net);
+char *virLXCProcessSetupInterfaceEthernet(virDomainDefPtr vm,
+ virDomainNetDefPtr net);
+
#endif /* __LXC_PROCESS_H__ */
--
2.5.1.windows.1