summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2014-07-29 15:38:39 +0200
committerThomas Haller <thaller@redhat.com>2014-07-30 01:26:13 +0200
commit45b0f0bfd6cc8d87261d2f5432dae82be7e5c83e (patch)
treebe123dd9d9b9a870f7043ec7fc3e2b94b3d156ea
parentbf028d48ed174e44b8d6cff0d7c08668a0533f9b (diff)
downloadNetworkManager-th/bgo731937_delete_nm_generated_connection-1.tar.gz
PATCH: https://bugzilla.gnome.org/show_bug.cgi?id=731937#c15th/bgo731937_delete_nm_generated_connection-1
-rw-r--r--src/devices/nm-device.c8
-rw-r--r--src/nm-manager.c84
2 files changed, 38 insertions, 54 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 78ba819bba..f593d0ca61 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -733,12 +733,10 @@ nm_device_get_physical_port_id (NMDevice *device)
static gboolean
nm_device_uses_assumed_connection (NMDevice *self)
{
- NMConnection *connection;
+ NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
- connection = nm_device_get_connection (self);
- if (!connection)
- return FALSE;
- return !!(nm_connection_get_flags (connection) & NM_CONNECTION_FLAGS_NM_ASSUMED);
+ return priv->act_request ?
+ nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (priv->act_request)) : FALSE;
}
static SlaveInfo *
diff --git a/src/nm-manager.c b/src/nm-manager.c
index 6a2b3ec73c..6cd829aa6a 100644
--- a/src/nm-manager.c
+++ b/src/nm-manager.c
@@ -1637,10 +1637,7 @@ get_existing_connection (NMManager *manager, NMDevice *device)
added = nm_settings_add_connection (priv->settings, connection, FALSE, &error);
if (added)
- nm_connection_set_flags (NM_CONNECTION (added),
- NM_CONNECTION_FLAGS_NM_GENERATED |
- NM_CONNECTION_FLAGS_NM_ASSUMED,
- TRUE);
+ nm_connection_set_flags (NM_CONNECTION (added), NM_CONNECTION_FLAGS_NM_GENERATED, TRUE);
else {
nm_log_warn (LOGD_SETTINGS, "(%s) Couldn't save generated connection '%s': %s",
nm_device_get_iface (device),
@@ -1654,15 +1651,11 @@ get_existing_connection (NMManager *manager, NMDevice *device)
}
static gboolean
-assume_connection (NMManager *self, NMDevice *device, NMConnection **inout_connection)
+assume_connection (NMManager *self, NMDevice *device, NMConnection *connection)
{
NMActiveConnection *active, *master_ac;
NMAuthSubject *subject;
GError *error = NULL;
- NMConnection *connection;
-
- g_return_val_if_fail (inout_connection && *inout_connection, FALSE);
- connection = *inout_connection;
nm_log_dbg (LOGD_DEVICE, "(%s): will attempt to assume connection",
nm_device_get_iface (device));
@@ -1685,12 +1678,6 @@ assume_connection (NMManager *self, NMDevice *device, NMConnection **inout_conne
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
g_error_free (error);
- if (nm_connection_get_flags (connection) & NM_CONNECTION_FLAGS_NM_ASSUMED) {
- nm_log_dbg (LOGD_DEVICE, "(%s): connection assumption failed. Deleting generated connection",
- nm_device_get_iface (device));
- nm_settings_connection_delete (NM_SETTINGS_CONNECTION (connection), NULL, NULL);
- *inout_connection = NULL;
- }
return FALSE;
}
@@ -1708,23 +1695,23 @@ assume_connection (NMManager *self, NMDevice *device, NMConnection **inout_conne
return TRUE;
}
-static void
+static gboolean
recheck_assume_connection (NMDevice *device, gpointer user_data)
{
- NMManager *self = user_data;
+ NMManager *self = NM_MANAGER (user_data);
NMConnection *connection;
- gboolean was_unmanaged = FALSE;
+ gboolean was_unmanaged = FALSE, success;
if (manager_sleeping (self))
- return;
+ return FALSE;
if (nm_device_get_unmanaged_flag (device, NM_UNMANAGED_USER))
- return;
+ return FALSE;
connection = get_existing_connection (self, device);
if (!connection) {
nm_log_dbg (LOGD_DEVICE, "(%s): can't assume; no connection",
nm_device_get_iface (device));
- return;
+ return FALSE;
}
if (nm_device_get_state (device) == NM_DEVICE_STATE_UNMANAGED) {
@@ -1734,16 +1721,29 @@ recheck_assume_connection (NMDevice *device, gpointer user_data)
NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED);
}
- if (!assume_connection (self, device, &connection)) {
+ success = assume_connection (self, device, connection);
+ if (!success) {
+ nm_log_dbg (LOGD_DEVICE, "(%s): connection assumption failed. Deleting generated connection",
+ nm_device_get_iface (device));
+
if (was_unmanaged) {
nm_device_state_changed (device,
NM_DEVICE_STATE_UNAVAILABLE,
NM_DEVICE_STATE_REASON_CONFIG_FAILED);
- nm_device_state_changed (device,
- NM_DEVICE_STATE_UNMANAGED,
- NM_DEVICE_STATE_REASON_CONFIG_FAILED);
+
+ /* Return default-unmanaged devices to their original state */
+ if (nm_device_get_unmanaged_flag (device, NM_UNMANAGED_DEFAULT)) {
+ nm_device_state_changed (device,
+ NM_DEVICE_STATE_UNMANAGED,
+ NM_DEVICE_STATE_REASON_CONFIG_FAILED);
+ }
}
+
+ if (nm_connection_get_flags (connection) & NM_CONNECTION_FLAGS_NM_GENERATED)
+ nm_settings_connection_delete (NM_SETTINGS_CONNECTION (connection), NULL, NULL);
}
+
+ return success;
}
static void
@@ -1774,19 +1774,18 @@ device_ip_iface_changed (NMDevice *device,
* add_device:
* @self: the #NMManager
* @device: the #NMDevice to add
- * @generate_con: %TRUE if existing connection (if any) should be assumed
+ * @try_assume: %TRUE if existing connection (if any) should be assumed
*
* If successful, this function will increase the references count of @device.
* Callers should decrease the reference count.
*/
static void
-add_device (NMManager *self, NMDevice *device, gboolean generate_con)
+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;
- NMConnection *connection = NULL;
gboolean enabled = FALSE;
RfKillType rtype;
GSList *iter, *remove = NULL;
@@ -1866,19 +1865,16 @@ add_device (NMManager *self, NMDevice *device, gboolean generate_con)
nm_device_dbus_export (device);
- /* Don't generate a connection e.g. for devices NM just created, or
- * for the loopback, or when we're sleeping. */
- if (generate_con && !user_unmanaged && !sleeping)
- connection = get_existing_connection (self, device);
+ if (try_assume) {
+ try_assume = recheck_assume_connection (device, self);
+ g_signal_connect (device, NM_DEVICE_RECHECK_ASSUME,
+ G_CALLBACK (recheck_assume_connection), self);
+ }
- /* Start the device if it's supposed to be managed. Note that this will
- * manage default-unmanaged devices if they have a generated connection.
- */
- if (nm_device_get_managed (device) || connection) {
+ if (!try_assume && nm_device_get_managed (device)) {
nm_device_state_changed (device,
- NM_DEVICE_STATE_UNAVAILABLE,
- connection ? NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED :
- NM_DEVICE_STATE_REASON_NOW_MANAGED);
+ NM_DEVICE_STATE_UNAVAILABLE,
+ NM_DEVICE_STATE_REASON_NOW_MANAGED);
}
nm_settings_device_added (priv->settings, device);
@@ -1889,16 +1885,6 @@ add_device (NMManager *self, NMDevice *device, gboolean generate_con)
* need to create new virtual interfaces now.
*/
system_create_virtual_devices (self);
-
- /* If the device has a connection it can assume, do that now. If it's a
- * device that we might ever want to assume a connection on, then set that up.
- */
- if (connection)
- assume_connection (self, device, &connection);
- if (generate_con) {
- g_signal_connect (device, NM_DEVICE_RECHECK_ASSUME,
- G_CALLBACK (recheck_assume_connection), self);
- }
}
static NMDevice *