Add support for VETH devices in Network Manager (required to run NetworkManager in LXC containers)


I'm using LXC containers to run our network test suites in Ubuntu and
while adding Network Manager support to my tests, I noticed that Network
Manager doesn't know what a veth device is and was simply ignoring my
ethX devices.

The attached patch adds an extra interface type for veth devices and
updates the logic in the udev event code so that if a veth device is
detected and that its name doesn't start by "veth" it'll be considered
as a regular network interface with "veth" as the driver.

The veth devices behave like a regular physical device, support the
ethtool calls and any regular call you might do, but they aren't tied to
physical device.

These devices are used by containers as the point to point link between
the host and the container. The container side of it is usually called
"ethX" in the container network namespace, the host side of it is
usually called "vethXXXXX" (randomly generated suffix) and is bridged on
the host side.

The patch ignores the host side of the veth pairs as these are usually
bridged or used by some other tool that won't like NM interfering with
them. Doing that string check isn't particularly pretty but it's the
easiest way I found to deal with the problem.

I tested the patch on an Ubuntu 12.10 system
( + Ubuntu patches) running the same NM
in both the host and the container. As expected, the container side
properly started handling the interface and the host side ignored it

Please keep me Cced on any reply as I'm not subscribed to this mailing-list.

Stéphane Graber
Ubuntu developer

Index: network-manager-
--- network-manager-	2012-07-16 10:30:54.003182512 -0400
+++ network-manager-	2012-07-16 11:41:55.696204385 -0400
@@ -392,6 +392,11 @@
 			driver = "8021q";
+			// In a veth pair, the host side is called veth*. Don't try to manage these.
+			if (!g_str_has_prefix (ifname, "veth"))
+				driver = "veth";
+			break;
 			if (g_str_has_prefix (ifname, "easytether"))
 				driver = "easytether";
Index: network-manager-
--- network-manager-	2012-07-16 10:30:54.019182597 -0400
+++ network-manager-	2012-07-16 10:30:45.163138675 -0400
@@ -1769,6 +1769,8 @@
 	else if (!g_strcmp0 (type, "dummy"))
+	else if (!g_strcmp0 (type, "veth"))
 	rtnl_link_put (result);
Index: network-manager-
--- network-manager-	2012-07-16 10:30:54.023182612 -0400
+++ network-manager-	2012-07-16 10:30:49.551160436 -0400
@@ -116,6 +116,7 @@
 int             nm_system_get_iface_type      (int ifindex, const char *name);
Index: network-manager-
--- network-manager-	2012-07-16 10:30:54.047182731 -0400
+++ network-manager-	2012-07-16 10:30:53.227178661 -0400
@@ -252,7 +252,7 @@
 		// FIXME: Convert this into a no-export property so type can be specified
 		//        when the device is created.
 		itype = nm_system_get_iface_type (nm_device_get_ifindex (self), nm_device_get_iface (self));
-		g_assert (itype == NM_IFACE_TYPE_UNSPEC);
+		g_assert (itype == NM_IFACE_TYPE_UNSPEC || itype == NM_IFACE_TYPE_VETH);
 		nm_log_dbg (LOGD_HW | LOGD_ETHER, "(%s): kernel ifindex %d",
 			        nm_device_get_iface (NM_DEVICE (self)),

Attachment: signature.asc
Description: OpenPGP digital signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]