summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2015-01-22 16:41:15 +0100
committerLubomir Rintel <lkundrak@v3.sk>2015-03-23 15:13:02 +0100
commit85ee1f4a9c04cad8f2486f858efd5ca10cb09077 (patch)
tree84ce066514d52c1de663a87c3297a04a0a5ba418
parent4a0586955767537b7494f931ccaa93bbf59c36f9 (diff)
downloadNetworkManager-85ee1f4a9c04cad8f2486f858efd5ca10cb09077.tar.gz
platform: give the platform an opportunity to override default-unmanaged
Some out of tree drivers add Ethernet devices that are supposed to be managed by other their tooling, e.g. VirtualBox or VMWare. Rather than hardcoding their drivers (at least VirtualBox doesn't even set a "driver" property in sysfs) or hardcoding a logic that identifies such devices let's just add a possibility to blacklist them in udev. This makes it possible for whoever who ships such a driver to ship rules that prevent NetworkManager from managing the device itself. Furthermore it makes it possible for the user with special needs leverage the flexibility of udev rules to override the defaults. In the end the user can decide to let NetworkManager manage default-unmanaged interfaces such as VEth or turn on default-unmanaged for devices on a particular bus. An udev rule for VirtualBox would look like this: SUBSYSTEM=="net", ENV{INTERFACE}=="vboxnet[0-9]*", ENV{NM_UNMANAGED}="1"
-rw-r--r--man/NetworkManager.xml28
-rw-r--r--src/nm-manager.c5
-rw-r--r--src/platform/nm-fake-platform.c7
-rw-r--r--src/platform/nm-linux-platform.c15
-rw-r--r--src/platform/nm-platform.c19
-rw-r--r--src/platform/nm-platform.h2
6 files changed, 75 insertions, 1 deletions
diff --git a/man/NetworkManager.xml b/man/NetworkManager.xml
index aa54fe1524..ceb810e3b4 100644
--- a/man/NetworkManager.xml
+++ b/man/NetworkManager.xml
@@ -359,6 +359,33 @@
</refsect1>
<refsect1>
+ <title>UDEV PROPERTIES</title>
+
+ <para>
+ <citerefentry><refentrytitle>udev</refentrytitle><manvolnum>7</manvolnum></citerefentry>
+ device manager is used for the network device discovery. The following
+ property influences how NetworkManager manages the devices:
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term><varname>NM_UNMANAGED</varname></term>
+ <listitem><para>
+ No default connection will be created and automatic activation
+ will not be attempted when this property of a device is set to a
+ true value ("1" or "true"). You will still be able to attach a
+ connection to the device manually or observe externally added
+ configuration such as addresses or routes.
+ </para><para>
+ Create an udev rule that sets this property to prevent NetworkManager
+ from interfering with virtual Ethernet device interfaces that are
+ managed by virtualization tools.
+ </para></listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
<title>DEBUGGING</title>
<para>
The following environment variables are supported to help
@@ -386,6 +413,7 @@
<citerefentry><refentrytitle>nm-settings</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
<citerefentry><refentrytitle>nm-applet</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
<citerefentry><refentrytitle>nm-connection-editor</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+ <citerefentry><refentrytitle>udev</refentrytitle><manvolnum>7</manvolnum></citerefentry>
</para>
</refsect1>
</refentry>
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 4da0f315f6..9ccb7e44d2 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -1795,7 +1795,7 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume)
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
const char *iface, *driver, *type_desc;
const GSList *unmanaged_specs;
- gboolean user_unmanaged, sleeping;
+ gboolean user_unmanaged, sleeping, platform_unmanaged;
gboolean enabled = FALSE;
RfKillType rtype;
GSList *iter, *remove = NULL;
@@ -1871,6 +1871,9 @@ add_device (NMManager *self, NMDevice *device, gboolean try_assume)
user_unmanaged = nm_device_spec_match_list (device, unmanaged_specs);
nm_device_set_initial_unmanaged_flag (device, NM_UNMANAGED_USER, user_unmanaged);
+ if (nm_platform_link_get_unmanaged (nm_device_get_ifindex (device), &platform_unmanaged))
+ nm_device_set_initial_unmanaged_flag (device, NM_UNMANAGED_DEFAULT, platform_unmanaged);
+
sleeping = manager_sleeping (self);
nm_device_set_initial_unmanaged_flag (device, NM_UNMANAGED_INTERNAL, sleeping);
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 941d742a11..7194707b29 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -299,6 +299,12 @@ link_get_type_name (NMPlatform *platform, int ifindex)
return type_to_type_name (link_get_type (platform, ifindex));
}
+static gboolean
+link_get_unmanaged (NMPlatform *platform, int ifindex, gboolean *managed)
+{
+ return FALSE;
+}
+
static void
link_changed (NMPlatform *platform, NMFakePlatformLink *device)
{
@@ -1384,6 +1390,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
platform_class->link_get_name = link_get_name;
platform_class->link_get_type = link_get_type;
platform_class->link_get_type_name = link_get_type_name;
+ platform_class->link_get_unmanaged = link_get_unmanaged;
platform_class->link_set_up = link_set_up;
platform_class->link_set_down = link_set_down;
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index f219898d87..3a0bbe4d1c 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -2395,6 +2395,20 @@ link_get_type_name (NMPlatform *platform, int ifindex)
return type;
}
+static gboolean
+link_get_unmanaged (NMPlatform *platform, int ifindex, gboolean *managed)
+{
+ NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
+ GUdevDevice *udev_device = g_hash_table_lookup (priv->udev_devices, GINT_TO_POINTER (ifindex));
+
+ if (g_udev_device_get_property (udev_device, "NM_UNMANAGED")) {
+ *managed = g_udev_device_get_property_as_boolean (udev_device, "NM_UNMANAGED");
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static guint32
link_get_flags (NMPlatform *platform, int ifindex)
{
@@ -4571,6 +4585,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_get_name = link_get_name;
platform_class->link_get_type = link_get_type;
platform_class->link_get_type_name = link_get_type_name;
+ platform_class->link_get_unmanaged = link_get_unmanaged;
platform_class->link_refresh = link_refresh;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 9500a75424..d51c142e04 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -653,6 +653,25 @@ nm_platform_link_get_type_name (int ifindex)
}
/**
+ * nm_platform_link_get_unmanaged:
+ * @ifindex: Interface index.
+ * @managed: Management status in case %TRUE is returned
+ *
+ * Returns: %TRUE if platform overrides whether the device ought
+ * to be managed by default. %FALSE with @managed unmodified
+ * otherwise.
+ */
+gboolean
+nm_platform_link_get_unmanaged (int ifindex, gboolean *managed)
+{
+ reset_error ();
+
+ g_return_val_if_fail (klass->link_get_unmanaged, FALSE);
+
+ return klass->link_get_unmanaged (platform, ifindex, managed);
+}
+
+/**
* nm_platform_link_is_software:
* @ifindex: Interface index.
*
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index c2dca4e585..bc7b84c9ff 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -351,6 +351,7 @@ typedef struct {
const char *(*link_get_name) (NMPlatform *, int ifindex);
NMLinkType (*link_get_type) (NMPlatform *, int ifindex);
const char *(*link_get_type_name) (NMPlatform *, int ifindex);
+ gboolean (*link_get_unmanaged) (NMPlatform *, int ifindex, gboolean *managed);
gboolean (*link_refresh) (NMPlatform *, int ifindex);
@@ -498,6 +499,7 @@ int nm_platform_link_get_ifindex (const char *name);
const char *nm_platform_link_get_name (int ifindex);
NMLinkType nm_platform_link_get_type (int ifindex);
const char *nm_platform_link_get_type_name (int ifindex);
+gboolean nm_platform_link_get_unmanaged (int ifindex, gboolean *managed);
gboolean nm_platform_link_is_software (int ifindex);
gboolean nm_platform_link_supports_slaves (int ifindex);