From c0d5b58332840939f93bb5d4053422dbd42ec4f7 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 8 Apr 2019 09:26:05 +0200 Subject: [PATCH] core: don't realize unmanaged software devices Currently, if user configuration or settings specify that a software device is unmanaged, for example: [device-bond-unmanaged] match-device=interface-name:bond* managed=0 or [keyfile] unmanaged-devices=interface-name:bond* and there is a connection for the device with autoconnect=yes, NM creates the platform link and a realized device in unmanaged state. Fix this, the device should not be realized if it is unmanaged. https://bugzilla.redhat.com/show_bug.cgi?id=1679230 --- src/devices/nm-device.c | 29 ++++++++++++++++++++++++++++- src/devices/nm-device.h | 2 ++ src/nm-manager.c | 7 +++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 9e68dae22c..957455204c 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -5315,7 +5315,8 @@ nm_device_autoconnect_allowed (NMDevice *self) if (priv->state < NM_DEVICE_STATE_DISCONNECTED) return FALSE; } else { - /* Unrealized devices can always autoconnect. */ + if (!nm_device_check_unrealized_device_managed (self)) + return FALSE; } /* The 'autoconnect-allowed' signal is emitted on a device to allow @@ -13517,6 +13518,32 @@ nm_device_set_unmanaged_by_flags_queue (NMDevice *self, _set_unmanaged_flags (self, flags, set_op, TRUE, FALSE, reason); } +/** + * nm_device_check_unrealized_device_managed: + * + * Checks if a unrealized device is managed from user settings + * or user configuration. + */ +gboolean +nm_device_check_unrealized_device_managed (NMDevice *self) +{ + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + + nm_assert (!nm_device_is_real (self)); + + if (!nm_config_data_get_device_config_boolean (NM_CONFIG_GET_DATA, + NM_CONFIG_KEYFILE_KEY_DEVICE_MANAGED, + self, + TRUE, + TRUE)) + return FALSE; + + if (nm_device_spec_match_list (self, nm_settings_get_unmanaged_specs (priv->settings))) + return FALSE; + + return TRUE; +} + void nm_device_set_unmanaged_by_user_settings (NMDevice *self) { diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 45c9dda00c..d11c33ab46 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -691,6 +691,8 @@ void nm_device_set_unmanaged_by_user_udev (NMDevice *self); void nm_device_set_unmanaged_by_user_conf (NMDevice *self); void nm_device_set_unmanaged_by_quitting (NMDevice *device); +gboolean nm_device_check_unrealized_device_managed (NMDevice *self); + gboolean nm_device_is_nm_owned (NMDevice *device); gboolean nm_device_has_capability (NMDevice *self, NMDeviceCapabilities caps); diff --git a/src/nm-manager.c b/src/nm-manager.c index d82f671a6b..1c396939ca 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -1995,6 +1995,13 @@ system_create_virtual_device (NMManager *self, NMConnection *connection) g_object_unref (device); } + if (!nm_device_check_unrealized_device_managed (device)) { + _LOG3D (LOGD_DEVICE, connection, + "skip activation because virtual device '%s' is unmanaged", + nm_device_get_iface (device)); + return device; + } + /* Create backing resources if the device has any autoconnect connections */ connections = nm_settings_get_connections_clone (priv->settings, NULL, NULL, NULL,