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



Hello,

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
(0.9.4.0+git201206081144.2efeac8 + 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
completely.


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

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com

Index: network-manager-0.9.4.0+git201206081144.2efeac8/src/nm-udev-manager.c
===================================================================
--- network-manager-0.9.4.0+git201206081144.2efeac8.orig/src/nm-udev-manager.c	2012-07-16 10:30:54.003182512 -0400
+++ network-manager-0.9.4.0+git201206081144.2efeac8/src/nm-udev-manager.c	2012-07-16 11:41:55.696204385 -0400
@@ -392,6 +392,11 @@
 		case NM_IFACE_TYPE_VLAN:
 			driver = "8021q";
 			break;
+		case NM_IFACE_TYPE_VETH:
+			// 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;
 		default:
 			if (g_str_has_prefix (ifname, "easytether"))
 				driver = "easytether";
Index: network-manager-0.9.4.0+git201206081144.2efeac8/src/nm-system.c
===================================================================
--- network-manager-0.9.4.0+git201206081144.2efeac8.orig/src/nm-system.c	2012-07-16 10:30:54.019182597 -0400
+++ network-manager-0.9.4.0+git201206081144.2efeac8/src/nm-system.c	2012-07-16 10:30:45.163138675 -0400
@@ -1769,6 +1769,8 @@
 		res = NM_IFACE_TYPE_VLAN;
 	else if (!g_strcmp0 (type, "dummy"))
 		res = NM_IFACE_TYPE_DUMMY;
+	else if (!g_strcmp0 (type, "veth"))
+		res = NM_IFACE_TYPE_VETH;
 
 	rtnl_link_put (result);
 out:
Index: network-manager-0.9.4.0+git201206081144.2efeac8/src/nm-system.h
===================================================================
--- network-manager-0.9.4.0+git201206081144.2efeac8.orig/src/nm-system.h	2012-07-16 10:30:54.023182612 -0400
+++ network-manager-0.9.4.0+git201206081144.2efeac8/src/nm-system.h	2012-07-16 10:30:49.551160436 -0400
@@ -116,6 +116,7 @@
 		NM_IFACE_TYPE_BOND,
 		NM_IFACE_TYPE_VLAN,
 		NM_IFACE_TYPE_DUMMY,
+		NM_IFACE_TYPE_VETH,
 };
 
 int             nm_system_get_iface_type      (int ifindex, const char *name);
Index: network-manager-0.9.4.0+git201206081144.2efeac8/src/nm-device-ethernet.c
===================================================================
--- network-manager-0.9.4.0+git201206081144.2efeac8.orig/src/nm-device-ethernet.c	2012-07-16 10:30:54.047182731 -0400
+++ network-manager-0.9.4.0+git201206081144.2efeac8/src/nm-device-ethernet.c	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]