Blame SOURCES/rh1029464-settings-convert-NMDefaultWiredConnection-into-a-pla.patch

2186fd
From 49983db85eb0c4737271b27e83e70c1216419096 Mon Sep 17 00:00:00 2001
2186fd
From: Dan Williams <dcbw@redhat.com>
2186fd
Date: Tue, 12 Nov 2013 14:26:20 -0600
2186fd
Subject: [PATCH] settings: convert NMDefaultWiredConnection into a plain
2186fd
 NMSettingsConnection (rh #1029464) (bgo #712188)
2186fd
2186fd
Changing the default wired connection has always deleted the connection
2186fd
(thus disconnecting the interface) and re-added it as a settings plugin
2186fd
connection.  That was always sub-optimal, but until the 'unsaved' connection
2186fd
stuff landed this summer, we couldn't do anything about that.  Clean
2186fd
that all up, adding the connection as an unsaved connection right from
2186fd
the start, which allows changes to the connection without having to
2186fd
delete and recreate it, thus preventing disconnection of any interface
2186fd
that is using the connection.
2186fd
2186fd
A new signal is added to NMSettingsConnection that is only emitted when
2186fd
the connection is changed from D-Bus (thus indicating an explicit user-
2186fd
requested change) since the connection may be modified internally by
2186fd
NetworkManager.  NM-triggered changes should not result in the connection
2186fd
no longer being a default-wired connection.
2186fd
2186fd
https://bugzilla.gnome.org/show_bug.cgi?id=712188
2186fd
https://bugzilla.redhat.com/show_bug.cgi?id=1029464
2186fd
---
2186fd
 src/Makefile.am                            |   2 -
2186fd
 src/settings/nm-default-wired-connection.c | 190 ---------------------------
2186fd
 src/settings/nm-default-wired-connection.h |  55 --------
2186fd
 src/settings/nm-settings-connection.c      |  14 ++
2186fd
 src/settings/nm-settings-connection.h      |   3 +
2186fd
 src/settings/nm-settings.c                 | 204 ++++++++++++++---------------
2186fd
 6 files changed, 119 insertions(+), 349 deletions(-)
2186fd
 delete mode 100644 src/settings/nm-default-wired-connection.c
2186fd
 delete mode 100644 src/settings/nm-default-wired-connection.h
2186fd
2186fd
diff --git a/src/Makefile.am b/src/Makefile.am
2186fd
index bcac9ac..34b7339 100644
2186fd
--- a/src/Makefile.am
2186fd
+++ b/src/Makefile.am
2186fd
@@ -159,16 +159,14 @@ nm_sources = \
2186fd
 	\
2186fd
 	ppp-manager/nm-ppp-manager.c \
2186fd
 	ppp-manager/nm-ppp-manager.h \
2186fd
 	ppp-manager/nm-ppp-status.h \
2186fd
 	\
2186fd
 	settings/nm-agent-manager.c \
2186fd
 	settings/nm-agent-manager.h \
2186fd
-	settings/nm-default-wired-connection.c \
2186fd
-	settings/nm-default-wired-connection.h \
2186fd
 	settings/nm-inotify-helper.c \
2186fd
 	settings/nm-inotify-helper.h \
2186fd
 	settings/nm-secret-agent.c \
2186fd
 	settings/nm-secret-agent.h \
2186fd
 	settings/nm-settings-connection.c \
2186fd
 	settings/nm-settings-connection.h \
2186fd
 	settings/nm-settings-error.c \
2186fd
diff --git a/src/settings/nm-default-wired-connection.c b/src/settings/nm-default-wired-connection.c
2186fd
deleted file mode 100644
2186fd
index 6c8ce41..0000000
2186fd
--- a/src/settings/nm-default-wired-connection.c
2186fd
+++ /dev/null
2186fd
@@ -1,190 +0,0 @@
2186fd
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2186fd
-/* NetworkManager system settings service
2186fd
- *
2186fd
- * This program is free software; you can redistribute it and/or modify
2186fd
- * it under the terms of the GNU General Public License as published by
2186fd
- * the Free Software Foundation; either version 2 of the License, or
2186fd
- * (at your option) any later version.
2186fd
- *
2186fd
- * This program is distributed in the hope that it will be useful,
2186fd
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2186fd
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2186fd
- * GNU General Public License for more details.
2186fd
- *
2186fd
- * You should have received a copy of the GNU General Public License along
2186fd
- * with this program; if not, write to the Free Software Foundation, Inc.,
2186fd
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2186fd
- *
2186fd
- * (C) Copyright 2008 Novell, Inc.
2186fd
- * (C) Copyright 2009 - 2011 Red Hat, Inc.
2186fd
- */
2186fd
-
2186fd
-#include "config.h"
2186fd
-
2186fd
-#include <netinet/ether.h>
2186fd
-
2186fd
-#include <NetworkManager.h>
2186fd
-#include <nm-setting-connection.h>
2186fd
-#include <nm-setting-wired.h>
2186fd
-#include <nm-utils.h>
2186fd
-
2186fd
-#include "nm-dbus-glib-types.h"
2186fd
-#include "nm-default-wired-connection.h"
2186fd
-#include "nm-device-ethernet.h"
2186fd
-
2186fd
-G_DEFINE_TYPE (NMDefaultWiredConnection, nm_default_wired_connection, NM_TYPE_SETTINGS_CONNECTION)
2186fd
-
2186fd
-#define NM_DEFAULT_WIRED_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEFAULT_WIRED_CONNECTION, NMDefaultWiredConnectionPrivate))
2186fd
-
2186fd
-typedef struct {
2186fd
-	NMDevice *device;
2186fd
-} NMDefaultWiredConnectionPrivate;
2186fd
-
2186fd
-enum {
2186fd
-	TRY_UPDATE,
2186fd
-	DELETED,
2186fd
-	LAST_SIGNAL
2186fd
-};
2186fd
-
2186fd
-static guint signals[LAST_SIGNAL] = { 0 };
2186fd
-
2186fd
-/****************************************************************/
2186fd
-
2186fd
-NMDevice *
2186fd
-nm_default_wired_connection_get_device (NMDefaultWiredConnection *wired)
2186fd
-{
2186fd
-	g_return_val_if_fail (NM_IS_DEFAULT_WIRED_CONNECTION (wired), NULL);
2186fd
-
2186fd
-	return NM_DEFAULT_WIRED_CONNECTION_GET_PRIVATE (wired)->device;
2186fd
-}
2186fd
-
2186fd
-static void
2186fd
-commit_changes (NMSettingsConnection *connection,
2186fd
-                NMSettingsConnectionCommitFunc callback,
2186fd
-                gpointer user_data)
2186fd
-{
2186fd
-	NMDefaultWiredConnection *self = NM_DEFAULT_WIRED_CONNECTION (connection);
2186fd
-
2186fd
-	/* Keep the object alive over try-update since it might get removed
2186fd
-	 * from the settings service there, but we still need it for the callback.
2186fd
-	 */
2186fd
-	g_object_ref (connection);
2186fd
-	g_signal_emit (self, signals[TRY_UPDATE], 0);
2186fd
-	callback (connection, NULL, user_data);
2186fd
-	g_object_unref (connection);
2186fd
-}
2186fd
-
2186fd
-static void 
2186fd
-do_delete (NMSettingsConnection *connection,
2186fd
-	       NMSettingsConnectionDeleteFunc callback,
2186fd
-	       gpointer user_data)
2186fd
-{
2186fd
-	g_signal_emit (connection, signals[DELETED], 0);
2186fd
-	NM_SETTINGS_CONNECTION_CLASS (nm_default_wired_connection_parent_class)->delete (connection,
2186fd
-	                                                                                 callback,
2186fd
-	                                                                                 user_data);
2186fd
-}
2186fd
-
2186fd
-/****************************************************************/
2186fd
-
2186fd
-NMDefaultWiredConnection *
2186fd
-nm_default_wired_connection_new (NMDevice *device,
2186fd
-                                 const char *defname,
2186fd
-                                 gboolean read_only)
2186fd
-{
2186fd
-	NMDefaultWiredConnection *self;
2186fd
-	NMDefaultWiredConnectionPrivate *priv;
2186fd
-	NMSetting *setting;
2186fd
-	char *uuid;
2186fd
-	const guint8 *hw_address;
2186fd
-	guint len = 0;
2186fd
-	GByteArray *mac;
2186fd
-
2186fd
-	g_return_val_if_fail (NM_IS_DEVICE_ETHERNET (device), NULL);
2186fd
-	g_return_val_if_fail (defname != NULL, NULL);
2186fd
-
2186fd
-	self = (NMDefaultWiredConnection *) g_object_new (NM_TYPE_DEFAULT_WIRED_CONNECTION, NULL);
2186fd
-
2186fd
-	priv = NM_DEFAULT_WIRED_CONNECTION_GET_PRIVATE (self);
2186fd
-	priv->device = g_object_ref (device);
2186fd
-
2186fd
-	setting = nm_setting_connection_new ();
2186fd
-
2186fd
-	uuid = nm_utils_uuid_generate ();
2186fd
-	g_object_set (setting,
2186fd
-	              NM_SETTING_CONNECTION_ID, defname,
2186fd
-	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
2186fd
-	              NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
2186fd
-	              NM_SETTING_CONNECTION_UUID, uuid,
2186fd
-	              NM_SETTING_CONNECTION_READ_ONLY, read_only,
2186fd
-	              NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL),
2186fd
-	              NULL);
2186fd
-	g_free (uuid);
2186fd
-
2186fd
-	nm_connection_add_setting (NM_CONNECTION (self), setting);
2186fd
-
2186fd
-	/* Lock the connection to the specific device */
2186fd
-	hw_address = nm_device_get_hw_address (device, &len;;
2186fd
-	mac = g_byte_array_sized_new (len);
2186fd
-	g_byte_array_append (mac, hw_address, len);
2186fd
-
2186fd
-	setting = nm_setting_wired_new ();
2186fd
-	g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
2186fd
-	nm_connection_add_setting (NM_CONNECTION (self), setting);
2186fd
-
2186fd
-	g_byte_array_unref (mac);
2186fd
-
2186fd
-	return self;
2186fd
-}
2186fd
-
2186fd
-static void
2186fd
-nm_default_wired_connection_init (NMDefaultWiredConnection *self)
2186fd
-{
2186fd
-}
2186fd
-
2186fd
-static void
2186fd
-dispose (GObject *object)
2186fd
-{
2186fd
-	NMDefaultWiredConnectionPrivate *priv = NM_DEFAULT_WIRED_CONNECTION_GET_PRIVATE (object);
2186fd
-
2186fd
-	g_clear_object (&priv->device);
2186fd
-
2186fd
-	G_OBJECT_CLASS (nm_default_wired_connection_parent_class)->dispose (object);
2186fd
-}
2186fd
-
2186fd
-static void
2186fd
-nm_default_wired_connection_class_init (NMDefaultWiredConnectionClass *klass)
2186fd
-{
2186fd
-	GObjectClass *object_class = G_OBJECT_CLASS (klass);
2186fd
-	NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (klass);
2186fd
-
2186fd
-	g_type_class_add_private (klass, sizeof (NMDefaultWiredConnectionPrivate));
2186fd
-
2186fd
-	/* Virtual methods */
2186fd
-	object_class->dispose = dispose;
2186fd
-	settings_class->commit_changes = commit_changes;
2186fd
-	settings_class->delete = do_delete;
2186fd
-
2186fd
-	/* Signals */
2186fd
-	signals[TRY_UPDATE] =
2186fd
-		g_signal_new ("try-update",
2186fd
-			      G_OBJECT_CLASS_TYPE (object_class),
2186fd
-			      G_SIGNAL_RUN_LAST,
2186fd
-			      0, NULL, NULL,
2186fd
-			      g_cclosure_marshal_VOID__VOID,
2186fd
-			      G_TYPE_NONE, 0);
2186fd
-
2186fd
-	/* The 'deleted' signal is used to signal intentional deletions (like
2186fd
-	 * updating or user-requested deletion) rather than using the
2186fd
-	 * superclass' 'removed' signal, since that signal doesn't have the
2186fd
-	 * semantics we want; it gets emitted as a side-effect of various operations
2186fd
-	 * and is meant more for D-Bus clients instead of in-service uses.
2186fd
-	 */
2186fd
-	signals[DELETED] =
2186fd
-		g_signal_new ("deleted",
2186fd
-			      G_OBJECT_CLASS_TYPE (object_class),
2186fd
-			      G_SIGNAL_RUN_LAST,
2186fd
-			      0, NULL, NULL,
2186fd
-			      g_cclosure_marshal_VOID__VOID,
2186fd
-			      G_TYPE_NONE, 0);
2186fd
-}
2186fd
diff --git a/src/settings/nm-default-wired-connection.h b/src/settings/nm-default-wired-connection.h
2186fd
deleted file mode 100644
2186fd
index 3661a7b..0000000
2186fd
--- a/src/settings/nm-default-wired-connection.h
2186fd
+++ /dev/null
2186fd
@@ -1,55 +0,0 @@
2186fd
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2186fd
-/* NetworkManager system settings service
2186fd
- *
2186fd
- * This program is free software; you can redistribute it and/or modify
2186fd
- * it under the terms of the GNU General Public License as published by
2186fd
- * the Free Software Foundation; either version 2 of the License, or
2186fd
- * (at your option) any later version.
2186fd
- *
2186fd
- * This program is distributed in the hope that it will be useful,
2186fd
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
2186fd
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2186fd
- * GNU General Public License for more details.
2186fd
- *
2186fd
- * You should have received a copy of the GNU General Public License along
2186fd
- * with this program; if not, write to the Free Software Foundation, Inc.,
2186fd
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2186fd
- *
2186fd
- * (C) Copyright 2008 Novell, Inc.
2186fd
- * (C) Copyright 2009 - 2011 Red Hat, Inc.
2186fd
- */
2186fd
-
2186fd
-#ifndef NM_DEFAULT_WIRED_CONNECTION_H
2186fd
-#define NM_DEFAULT_WIRED_CONNECTION_H
2186fd
-
2186fd
-#include "nm-settings-connection.h"
2186fd
-#include "nm-device.h"
2186fd
-
2186fd
-G_BEGIN_DECLS
2186fd
-
2186fd
-#define NM_TYPE_DEFAULT_WIRED_CONNECTION            (nm_default_wired_connection_get_type ())
2186fd
-#define NM_DEFAULT_WIRED_CONNECTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEFAULT_WIRED_CONNECTION, NMDefaultWiredConnection))
2186fd
-#define NM_DEFAULT_WIRED_CONNECTION_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEFAULT_WIRED_CONNECTION, NMDefaultWiredConnectionClass))
2186fd
-#define NM_IS_DEFAULT_WIRED_CONNECTION(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEFAULT_WIRED_CONNECTION))
2186fd
-#define NM_IS_DEFAULT_WIRED_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_DEFAULT_WIRED_CONNECTION))
2186fd
-#define NM_DEFAULT_WIRED_CONNECTION_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEFAULT_WIRED_CONNECTION, NMDefaultWiredConnectionClass))
2186fd
-
2186fd
-typedef struct {
2186fd
-	NMSettingsConnection parent;
2186fd
-} NMDefaultWiredConnection;
2186fd
-
2186fd
-typedef struct {
2186fd
-	NMSettingsConnectionClass parent;
2186fd
-} NMDefaultWiredConnectionClass;
2186fd
-
2186fd
-GType nm_default_wired_connection_get_type (void);
2186fd
-
2186fd
-NMDefaultWiredConnection *nm_default_wired_connection_new (NMDevice *device,
2186fd
-                                                           const char *defname,
2186fd
-                                                           gboolean read_only);
2186fd
-
2186fd
-NMDevice *nm_default_wired_connection_get_device (NMDefaultWiredConnection *wired);
2186fd
-
2186fd
-G_END_DECLS
2186fd
-
2186fd
-#endif /* NM_DEFAULT_WIRED_CONNECTION_H */
2186fd
diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c
2186fd
index f1bc3c3..53c606f 100644
2186fd
--- a/src/settings/nm-settings-connection.c
2186fd
+++ b/src/settings/nm-settings-connection.c
2186fd
@@ -79,14 +79,15 @@ enum {
2186fd
 	PROP_VISIBLE,
2186fd
 	PROP_UNSAVED,
2186fd
 };
2186fd
 
2186fd
 enum {
2186fd
 	UPDATED,
2186fd
 	REMOVED,
2186fd
+	DBUS_UPDATED,
2186fd
 	LAST_SIGNAL
2186fd
 };
2186fd
 static guint signals[LAST_SIGNAL] = { 0 };
2186fd
 
2186fd
 typedef struct {
2186fd
 	gboolean disposed;
2186fd
 
2186fd
@@ -1232,14 +1233,16 @@ con_update_cb (NMSettingsConnection *self,
2186fd
 		 */
2186fd
 		for_agent = nm_connection_duplicate (NM_CONNECTION (self));
2186fd
 		nm_connection_clear_secrets_with_flags (for_agent,
2186fd
 		                                        secrets_filter_cb,
2186fd
 		                                        GUINT_TO_POINTER (NM_SETTING_SECRET_FLAG_AGENT_OWNED));
2186fd
 		nm_agent_manager_save_secrets (info->agent_mgr, for_agent, TRUE, info->sender_uid);
2186fd
 		g_object_unref (for_agent);
2186fd
+
2186fd
+		g_signal_emit (self, signals[DBUS_UPDATED], 0);
2186fd
 	}
2186fd
 
2186fd
 	update_complete (self, info, error);
2186fd
 }
2186fd
 
2186fd
 static void
2186fd
 update_auth_cb (NMSettingsConnection *self,
2186fd
@@ -2031,23 +2034,34 @@ nm_settings_connection_class_init (NMSettingsConnectionClass *class)
2186fd
 		                       "TRUE when the connection has not yet been saved "
2186fd
 		                       "to permanent storage (eg disk) or when it "
2186fd
 		                       "has been changed but not yet saved.",
2186fd
 		                       FALSE,
2186fd
 		                       G_PARAM_READABLE));
2186fd
 
2186fd
 	/* Signals */
2186fd
+
2186fd
+	/* Emitted when the connection is changed for any reason */
2186fd
 	signals[UPDATED] = 
2186fd
 		g_signal_new (NM_SETTINGS_CONNECTION_UPDATED,
2186fd
 		              G_TYPE_FROM_CLASS (class),
2186fd
 		              G_SIGNAL_RUN_FIRST,
2186fd
 		              0,
2186fd
 		              NULL, NULL,
2186fd
 		              g_cclosure_marshal_VOID__VOID,
2186fd
 		              G_TYPE_NONE, 0);
2186fd
 
2186fd
+	/* Emitted when connection is changed from D-Bus */
2186fd
+	signals[DBUS_UPDATED] =
2186fd
+		g_signal_new (NM_SETTINGS_CONNECTION_DBUS_UPDATED,
2186fd
+		              G_TYPE_FROM_CLASS (class),
2186fd
+		              G_SIGNAL_RUN_FIRST,
2186fd
+		              0, NULL, NULL,
2186fd
+		              g_cclosure_marshal_VOID__VOID,
2186fd
+		              G_TYPE_NONE, 0);
2186fd
+
2186fd
 	signals[REMOVED] = 
2186fd
 		g_signal_new (NM_SETTINGS_CONNECTION_REMOVED,
2186fd
 		              G_TYPE_FROM_CLASS (class),
2186fd
 		              G_SIGNAL_RUN_FIRST,
2186fd
 		              0,
2186fd
 		              NULL, NULL,
2186fd
 		              g_cclosure_marshal_VOID__VOID,
2186fd
diff --git a/src/settings/nm-settings-connection.h b/src/settings/nm-settings-connection.h
2186fd
index 8b995ab..a687ddb 100644
2186fd
--- a/src/settings/nm-settings-connection.h
2186fd
+++ b/src/settings/nm-settings-connection.h
2186fd
@@ -37,14 +37,17 @@ G_BEGIN_DECLS
2186fd
 
2186fd
 /* Signals */
2186fd
 #define NM_SETTINGS_CONNECTION_UPDATED "updated"
2186fd
 #define NM_SETTINGS_CONNECTION_REMOVED "removed"
2186fd
 #define NM_SETTINGS_CONNECTION_GET_SECRETS "get-secrets"
2186fd
 #define NM_SETTINGS_CONNECTION_CANCEL_SECRETS "cancel-secrets"
2186fd
 
2186fd
+/* Emitted when connection is changed from D-Bus */
2186fd
+#define NM_SETTINGS_CONNECTION_DBUS_UPDATED "dbus-updated"
2186fd
+
2186fd
 /* Properties */
2186fd
 #define NM_SETTINGS_CONNECTION_VISIBLE "visible"
2186fd
 #define NM_SETTINGS_CONNECTION_UNSAVED "unsaved"
2186fd
 
2186fd
 typedef struct _NMSettingsConnection NMSettingsConnection;
2186fd
 typedef struct _NMSettingsConnectionClass NMSettingsConnectionClass;
2186fd
 
2186fd
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
2186fd
index 49d64d1..e384a17 100644
2186fd
--- a/src/settings/nm-settings.c
2186fd
+++ b/src/settings/nm-settings.c
2186fd
@@ -54,15 +54,14 @@
2186fd
 #include <nm-utils.h>
2186fd
 
2186fd
 #include "nm-device-ethernet.h"
2186fd
 #include "nm-dbus-glib-types.h"
2186fd
 #include "nm-settings.h"
2186fd
 #include "nm-settings-connection.h"
2186fd
 #include "nm-settings-error.h"
2186fd
-#include "nm-default-wired-connection.h"
2186fd
 #include "nm-logging.h"
2186fd
 #include "nm-dbus-manager.h"
2186fd
 #include "nm-manager-auth.h"
2186fd
 #include "nm-session-monitor.h"
2186fd
 #include "plugins/keyfile/plugin.h"
2186fd
 #include "nm-agent-manager.h"
2186fd
 #include "nm-settings-utils.h"
2186fd
@@ -874,29 +873,14 @@ claim_connection (NMSettings *self,
2186fd
 		g_signal_emit_by_name (self, NM_CP_SIGNAL_CONNECTION_ADDED, connection);
2186fd
 
2186fd
 		/* Exported D-Bus signal */
2186fd
 		g_signal_emit (self, signals[NEW_CONNECTION], 0, connection);
2186fd
 	}
2186fd
 }
2186fd
 
2186fd
-static void
2186fd
-remove_default_wired_connection (NMSettings *self,
2186fd
-                                 NMSettingsConnection *connection,
2186fd
-                                 gboolean do_signal)
2186fd
-{
2186fd
-	NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
2186fd
-	const char *path = nm_connection_get_path (NM_CONNECTION (connection));
2186fd
-
2186fd
-	if (g_hash_table_lookup (priv->connections, path)) {
2186fd
-		if (do_signal)
2186fd
-			g_signal_emit_by_name (G_OBJECT (connection), NM_SETTINGS_CONNECTION_REMOVED);
2186fd
-		g_hash_table_remove (priv->connections, path);
2186fd
-	}
2186fd
-}
2186fd
-
2186fd
 /**
2186fd
  * nm_settings_add_connection:
2186fd
  * @self: the #NMSettings object
2186fd
  * @connection: the source connection to create a new #NMSettingsConnection from
2186fd
  * @save_to_disk: %TRUE to save the connection to disk immediately, %FALSE to
2186fd
  * not save to disk
2186fd
  * @error: on return, a location to store any errors that may occur
2186fd
@@ -1483,148 +1467,164 @@ have_connection_for_device (NMSettings *self, NMDevice *device)
2186fd
 	/* See if there's a known non-NetworkManager configuration for the device */
2186fd
 	if (nm_device_spec_match_list (device, priv->unrecognized_specs))
2186fd
 		return TRUE;
2186fd
 
2186fd
 	return FALSE;
2186fd
 }
2186fd
 
2186fd
-#define DEFAULT_WIRED_TAG "default-wired"
2186fd
+#define DEFAULT_WIRED_CONNECTION_TAG "default-wired-connection"
2186fd
+#define DEFAULT_WIRED_DEVICE_TAG     "default-wired-device"
2186fd
+
2186fd
+static void default_wired_clear_tag (NMSettings *self,
2186fd
+                                     NMDevice *device,
2186fd
+                                     NMSettingsConnection *connection,
2186fd
+                                     gboolean add_to_no_auto_default);
2186fd
 
2186fd
 static void
2186fd
-default_wired_deleted (NMDefaultWiredConnection *wired,
2186fd
-                       NMSettings *self)
2186fd
+default_wired_connection_removed_cb (NMSettingsConnection *connection, NMSettings *self)
2186fd
 {
2186fd
-	NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
2186fd
 	NMDevice *device;
2186fd
-	NMSettingConnection *s_con;
2186fd
 
2186fd
-	device = nm_default_wired_connection_get_device (wired);
2186fd
-	g_object_set_data (G_OBJECT (device), DEFAULT_WIRED_TAG, NULL);
2186fd
-
2186fd
-	s_con = nm_connection_get_setting_connection (NM_CONNECTION (wired));
2186fd
-	g_assert (s_con);
2186fd
-
2186fd
-	/* Ignore removals of read-only connections, since they couldn't have
2186fd
-	 * been removed by the user.
2186fd
-	 */
2186fd
-	if (nm_setting_connection_get_read_only (s_con))
2186fd
-		return;
2186fd
-
2186fd
-	/* When the default wired connection is removed (either deleted or saved
2186fd
-	 * to a new persistent connection by a plugin), write the MAC address of
2186fd
-	 * the wired device to the config file and don't create a new default wired
2186fd
+	/* When the default wired connection is removed (either deleted or saved to
2186fd
+	 * a new persistent connection by a plugin), write the MAC address of the
2186fd
+	 * wired device to the config file and don't create a new default wired
2186fd
 	 * connection for that device again.
2186fd
 	 */
2186fd
-	nm_config_set_ethernet_no_auto_default (priv->config, NM_CONFIG_DEVICE (device));
2186fd
+	device = g_object_get_data (G_OBJECT (connection), DEFAULT_WIRED_DEVICE_TAG);
2186fd
+	if (device)
2186fd
+		default_wired_clear_tag (self, device, connection, TRUE);
2186fd
 }
2186fd
 
2186fd
 static void
2186fd
-delete_cb (NMSettingsConnection *connection, GError *error, gpointer user_data)
2186fd
+default_wired_connection_dbus_updated_cb (NMSettingsConnection *connection, NMSettings *self)
2186fd
 {
2186fd
-}
2186fd
-
2186fd
-static void
2186fd
-default_wired_try_update (NMDefaultWiredConnection *wired,
2186fd
-                          NMSettings *self)
2186fd
-{
2186fd
-	GError *error = NULL;
2186fd
-	const char *id;
2186fd
-	NMSettingsConnection *added;
2186fd
+	NMDevice *device;
2186fd
 
2186fd
-	/* Try to move this default wired conneciton to a plugin so that it has
2186fd
-	 * persistent storage.
2186fd
+	/* The connection has been changed by the user, it should no longer be
2186fd
+	 * considered a default wired connection, and should no longer affect
2186fd
+	 * the no-auto-default configuration option.
2186fd
 	 */
2186fd
+	device = g_object_get_data (G_OBJECT (connection), DEFAULT_WIRED_DEVICE_TAG);
2186fd
+	if (device)
2186fd
+		default_wired_clear_tag (self, device, connection, FALSE);
2186fd
+}
2186fd
 
2186fd
-	/* Keep it alive over removal so we can re-add it if we need to */
2186fd
-	g_object_ref (wired);
2186fd
+static void
2186fd
+default_wired_clear_tag (NMSettings *self,
2186fd
+                         NMDevice *device,
2186fd
+                         NMSettingsConnection *connection,
2186fd
+                         gboolean add_to_no_auto_default)
2186fd
+{
2186fd
+	g_return_if_fail (NM_IS_SETTINGS (self));
2186fd
+	g_return_if_fail (NM_IS_DEVICE (device));
2186fd
+	g_return_if_fail (NM_IS_CONNECTION (connection));
2186fd
+	g_return_if_fail (device == g_object_get_data (G_OBJECT (connection), DEFAULT_WIRED_DEVICE_TAG));
2186fd
+	g_return_if_fail (connection == g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG));
2186fd
 
2186fd
-	id = nm_connection_get_id (NM_CONNECTION (wired));
2186fd
-	g_assert (id);
2186fd
+	g_object_set_data (G_OBJECT (connection), DEFAULT_WIRED_DEVICE_TAG, NULL);
2186fd
+	g_object_set_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG, NULL);
2186fd
 
2186fd
-	remove_default_wired_connection (self, NM_SETTINGS_CONNECTION (wired), FALSE);
2186fd
-	added = nm_settings_add_connection (self, NM_CONNECTION (wired), TRUE, &error);
2186fd
-	if (added) {
2186fd
-		nm_settings_connection_delete (NM_SETTINGS_CONNECTION (wired), delete_cb, NULL);
2186fd
+	g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (default_wired_connection_removed_cb), self);
2186fd
+	g_signal_handlers_disconnect_by_func (connection, G_CALLBACK (default_wired_connection_dbus_updated_cb), self);
2186fd
 
2186fd
-		g_object_set_data (G_OBJECT (nm_default_wired_connection_get_device (wired)),
2186fd
-		                   DEFAULT_WIRED_TAG,
2186fd
-		                   NULL);
2186fd
-		nm_log_info (LOGD_SETTINGS, "Saved default wired connection '%s' to persistent storage", id);
2186fd
-	} else {
2186fd
-		nm_log_warn (LOGD_SETTINGS, "couldn't save default wired connection '%s': %d / %s",
2186fd
-			         id,
2186fd
-			         error ? error->code : -1,
2186fd
-			         (error && error->message) ? error->message : "(unknown)");
2186fd
-		g_clear_error (&error);
2186fd
-
2186fd
-		/* If there was an error, don't destroy the default wired connection,
2186fd
-		 * but add it back to the system settings service. Connection is already
2186fd
-		 * exported on the bus, don't export it again, thus do_export == FALSE.
2186fd
-		 */
2186fd
-		claim_connection (self, NM_SETTINGS_CONNECTION (wired), FALSE);
2186fd
-	}
2186fd
-
2186fd
-	g_object_unref (wired);
2186fd
+	if (add_to_no_auto_default)
2186fd
+		nm_config_set_ethernet_no_auto_default (NM_SETTINGS_GET_PRIVATE (self)->config, NM_CONFIG_DEVICE (device));
2186fd
 }
2186fd
 
2186fd
 void
2186fd
 nm_settings_device_added (NMSettings *self, NMDevice *device)
2186fd
 {
2186fd
 	NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
2186fd
-	NMDefaultWiredConnection *wired;
2186fd
-	gboolean read_only = TRUE;
2186fd
-	const char *id;
2186fd
-	char *defname;
2186fd
+	NMConnection *connection;
2186fd
+	NMSettingsConnection *added;
2186fd
+	NMSetting *setting;
2186fd
+	GError *error = NULL;
2186fd
+	const guint8 *hw_address;
2186fd
+	char *defname, *uuid;
2186fd
+	guint len = 0;
2186fd
+	GByteArray *mac;
2186fd
 
2186fd
 	if (!NM_IS_DEVICE_ETHERNET (device))
2186fd
 		return;
2186fd
 
2186fd
 	/* If the device isn't managed or it already has a default wired connection,
2186fd
 	 * ignore it.
2186fd
 	 */
2186fd
 	if (   !nm_device_get_managed (device)
2186fd
-	    || g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_TAG)
2186fd
+	    || g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG)
2186fd
 	    || have_connection_for_device (self, device)
2186fd
 	    || !nm_config_get_ethernet_can_auto_default (priv->config, NM_CONFIG_DEVICE (device)))
2186fd
 		return;
2186fd
 
2186fd
-	if (get_plugin (self, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_CONNECTIONS))
2186fd
-		read_only = FALSE;
2186fd
+	hw_address = nm_device_get_hw_address (device, &len;;
2186fd
+	if (!hw_address)
2186fd
+		return;
2186fd
+
2186fd
+	connection = nm_connection_new ();
2186fd
+	g_assert (connection);
2186fd
+	setting = nm_setting_connection_new ();
2186fd
+	g_assert (setting);
2186fd
+	nm_connection_add_setting (connection, setting);
2186fd
 
2186fd
 	defname = nm_settings_utils_get_default_wired_name (priv->connections);
2186fd
-	wired = nm_default_wired_connection_new (device, defname, read_only);
2186fd
+	uuid = nm_utils_uuid_generate ();
2186fd
+	g_object_set (setting,
2186fd
+	              NM_SETTING_CONNECTION_ID, defname,
2186fd
+	              NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
2186fd
+	              NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
2186fd
+	              NM_SETTING_CONNECTION_UUID, uuid,
2186fd
+	              NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL),
2186fd
+	              NULL);
2186fd
+	g_free (uuid);
2186fd
 	g_free (defname);
2186fd
-	if (!wired)
2186fd
+
2186fd
+	/* Lock the connection to the device */
2186fd
+	setting = nm_setting_wired_new ();
2186fd
+	nm_connection_add_setting (connection, setting);
2186fd
+
2186fd
+	mac = g_byte_array_sized_new (len);
2186fd
+	g_byte_array_append (mac, hw_address, len);
2186fd
+	g_object_set (setting, NM_SETTING_WIRED_MAC_ADDRESS, mac, NULL);
2186fd
+	g_byte_array_unref (mac);
2186fd
+
2186fd
+	/* Add the connection */
2186fd
+	added = nm_settings_add_connection (self, connection, FALSE, &error);
2186fd
+	g_object_unref (connection);
2186fd
+
2186fd
+	if (!added) {
2186fd
+		nm_log_warn (LOGD_SETTINGS, "(%s) couldn't create default wired connection: %s",
2186fd
+		             nm_device_get_iface (device),
2186fd
+		             (error && error->message) ? error->message : "(unknown)");
2186fd
+		g_clear_error (&error);
2186fd
 		return;
2186fd
+	}
2186fd
 
2186fd
-	id = nm_connection_get_id (NM_CONNECTION (wired));
2186fd
-	g_assert (id);
2186fd
+	g_object_set_data (G_OBJECT (added), DEFAULT_WIRED_DEVICE_TAG, device);
2186fd
+	g_object_set_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG, added);
2186fd
 
2186fd
-	nm_log_info (LOGD_SETTINGS, "Added default wired connection '%s' for %s",
2186fd
-	             id, nm_device_get_udi (device));
2186fd
+	g_signal_connect (added, NM_SETTINGS_CONNECTION_DBUS_UPDATED,
2186fd
+	                  G_CALLBACK (default_wired_connection_dbus_updated_cb), self);
2186fd
+	g_signal_connect (added, NM_SETTINGS_CONNECTION_REMOVED,
2186fd
+	                  G_CALLBACK (default_wired_connection_removed_cb), self);
2186fd
 
2186fd
-	g_signal_connect (wired, "try-update", (GCallback) default_wired_try_update, self);
2186fd
-	g_signal_connect (wired, "deleted", (GCallback) default_wired_deleted, self);
2186fd
-	claim_connection (self, NM_SETTINGS_CONNECTION (wired), TRUE);
2186fd
-	g_object_unref (wired);
2186fd
-
2186fd
-	g_object_set_data (G_OBJECT (device), DEFAULT_WIRED_TAG, wired);
2186fd
+	nm_log_info (LOGD_SETTINGS, "(%s): created default wired connection '%s'",
2186fd
+	             nm_device_get_iface (device),
2186fd
+	             nm_connection_get_id (NM_CONNECTION (added)));
2186fd
 }
2186fd
 
2186fd
 void
2186fd
 nm_settings_device_removed (NMSettings *self, NMDevice *device)
2186fd
 {
2186fd
-	NMDefaultWiredConnection *connection;
2186fd
+	NMSettingsConnection *connection;
2186fd
 
2186fd
-	if (!NM_IS_DEVICE_ETHERNET (device))
2186fd
-		return;
2186fd
-
2186fd
-	connection = (NMDefaultWiredConnection *) g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_TAG);
2186fd
-	if (connection)
2186fd
-		remove_default_wired_connection (self, NM_SETTINGS_CONNECTION (connection), TRUE);
2186fd
+	connection = g_object_get_data (G_OBJECT (device), DEFAULT_WIRED_CONNECTION_TAG);
2186fd
+	if (connection) {
2186fd
+		default_wired_clear_tag (self, device, connection, FALSE);
2186fd
+		nm_settings_connection_delete (connection, NULL, NULL);
2186fd
+	}
2186fd
 }
2186fd
 
2186fd
 /***************************************************************/
2186fd
 
2186fd
 static gint
2186fd
 best_connection_sort (gconstpointer a, gconstpointer b, gpointer user_data)
2186fd
 {
2186fd
-- 
2186fd
1.8.3.1
2186fd