Commit f73d0663 authored by Dan Williams's avatar Dan Williams

ifnet: don't require a conn_name when creating an ifnet connection

If the connection doesn't yet have a conn_name, that means it's not
yet saved to disk.
parent 689dadaf
...@@ -37,11 +37,6 @@ ...@@ -37,11 +37,6 @@
G_DEFINE_TYPE (NMIfnetConnection, nm_ifnet_connection, NM_TYPE_SETTINGS_CONNECTION) G_DEFINE_TYPE (NMIfnetConnection, nm_ifnet_connection, NM_TYPE_SETTINGS_CONNECTION)
#define NM_IFNET_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IFNET_CONNECTION, NMIfnetConnectionPrivate)) #define NM_IFNET_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_IFNET_CONNECTION, NMIfnetConnectionPrivate))
enum {
PROP_ZERO,
PROP_CONN_NAME,
_PROP_END,
};
enum { enum {
IFNET_SETUP_MONITORS, IFNET_SETUP_MONITORS,
...@@ -57,20 +52,20 @@ typedef struct { ...@@ -57,20 +52,20 @@ typedef struct {
} NMIfnetConnectionPrivate; } NMIfnetConnectionPrivate;
NMIfnetConnection * NMIfnetConnection *
nm_ifnet_connection_new (const char *conn_name, NMConnection *source) nm_ifnet_connection_new (NMConnection *source, const char *conn_name)
{ {
NMConnection *tmp; NMConnection *tmp;
GObject *object; GObject *object;
GError *error = NULL; GError *error = NULL;
gboolean update_unsaved = TRUE; gboolean update_unsaved = TRUE;
g_return_val_if_fail (conn_name != NULL, NULL); g_return_val_if_fail (source || conn_name, NULL);
if (source) if (source)
tmp = g_object_ref (source); tmp = g_object_ref (source);
else { else {
tmp = ifnet_update_connection_from_config_block (conn_name, NULL, &error); tmp = ifnet_update_connection_from_config_block (conn_name, NULL, &error);
if (!tmp){ if (!tmp) {
g_error_free (error); g_error_free (error);
return NULL; return NULL;
} }
...@@ -80,6 +75,7 @@ nm_ifnet_connection_new (const char *conn_name, NMConnection *source) ...@@ -80,6 +75,7 @@ nm_ifnet_connection_new (const char *conn_name, NMConnection *source)
} }
object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION, NULL); object = (GObject *) g_object_new (NM_TYPE_IFNET_CONNECTION, NULL);
g_assert (object);
NM_IFNET_CONNECTION_GET_PRIVATE (object)->conn_name = g_strdup (conn_name); NM_IFNET_CONNECTION_GET_PRIVATE (object)->conn_name = g_strdup (conn_name);
nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object), nm_settings_connection_replace_settings (NM_SETTINGS_CONNECTION (object),
tmp, tmp,
...@@ -109,29 +105,48 @@ commit_changes (NMSettingsConnection *connection, ...@@ -109,29 +105,48 @@ commit_changes (NMSettingsConnection *connection,
GError *error = NULL; GError *error = NULL;
NMIfnetConnectionPrivate *priv = NM_IFNET_CONNECTION_GET_PRIVATE (connection); NMIfnetConnectionPrivate *priv = NM_IFNET_CONNECTION_GET_PRIVATE (connection);
gchar *new_name = NULL; gchar *new_name = NULL;
gboolean success = FALSE;
g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0); g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0);
if (!ifnet_update_parsers_by_connection (NM_CONNECTION (connection),
priv->conn_name, if (priv->conn_name) {
CONF_NET_FILE, /* Existing connection; update it */
WPA_SUPPLICANT_CONF, success = ifnet_update_parsers_by_connection (NM_CONNECTION (connection),
&new_name, priv->conn_name,
NULL, CONF_NET_FILE,
&error)) { WPA_SUPPLICANT_CONF,
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Failed to update %s", priv->conn_name); &new_name,
NULL,
&error);
} else {
/* New connection, add it */
success = ifnet_add_new_connection (NM_CONNECTION (connection),
CONF_NET_FILE,
WPA_SUPPLICANT_CONF,
&new_name,
NULL,
&error);
if (success)
reload_parsers ();
}
if (success) {
/* update connection name */
g_assert (new_name);
g_free (priv->conn_name);
priv->conn_name = new_name;
NM_SETTINGS_CONNECTION_CLASS (nm_ifnet_connection_parent_class)->commit_changes (connection, callback, user_data);
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Successfully updated %s", priv->conn_name);
} else {
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Failed to update %s",
priv->conn_name ? priv->conn_name :
nm_connection_get_id (NM_CONNECTION (connection)));
reload_parsers (); reload_parsers ();
callback (connection, error, user_data); callback (connection, error, user_data);
g_error_free (error); g_error_free (error);
g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0);
return;
} }
g_free (priv->conn_name);
priv->conn_name = new_name;
NM_SETTINGS_CONNECTION_CLASS (nm_ifnet_connection_parent_class)->commit_changes (connection, callback, user_data);
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Successfully updated %s", priv->conn_name);
g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0); g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0);
} }
...@@ -144,31 +159,32 @@ do_delete (NMSettingsConnection *connection, ...@@ -144,31 +159,32 @@ do_delete (NMSettingsConnection *connection,
NMIfnetConnectionPrivate *priv = NM_IFNET_CONNECTION_GET_PRIVATE (connection); NMIfnetConnectionPrivate *priv = NM_IFNET_CONNECTION_GET_PRIVATE (connection);
g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0); g_signal_emit (connection, signals[IFNET_CANCEL_MONITORS], 0);
if (!ifnet_delete_connection_in_parsers (priv->conn_name, CONF_NET_FILE, WPA_SUPPLICANT_CONF, NULL)) {
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Failed to delete %s", /* Only connections which exist in /etc/conf.d/net will have a conn_name */
priv->conn_name); if (priv->conn_name) {
reload_parsers (); if (!ifnet_delete_connection_in_parsers (priv->conn_name, CONF_NET_FILE, WPA_SUPPLICANT_CONF, NULL)) {
callback (connection, error, user_data); PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Failed to delete %s", priv->conn_name);
g_error_free (error); reload_parsers ();
g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0); callback (connection, error, user_data);
return; g_error_free (error);
g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0);
return;
}
} }
NM_SETTINGS_CONNECTION_CLASS (nm_ifnet_connection_parent_class)->delete (connection, callback, user_data); NM_SETTINGS_CONNECTION_CLASS (nm_ifnet_connection_parent_class)->delete (connection, callback, user_data);
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Successfully deleted %s",
priv->conn_name);
g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0); g_signal_emit (connection, signals[IFNET_SETUP_MONITORS], 0);
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "Successfully deleted %s",
priv->conn_name ? priv->conn_name :
nm_connection_get_id (NM_CONNECTION (connection)));
} }
static void static void
finalize (GObject * object) finalize (GObject * object)
{ {
NMIfnetConnectionPrivate *priv = g_free (NM_IFNET_CONNECTION_GET_PRIVATE (object)->conn_name);
NM_IFNET_CONNECTION_GET_PRIVATE (object);
g_return_if_fail (priv);
g_free (priv->conn_name);
G_OBJECT_CLASS (nm_ifnet_connection_parent_class)->finalize (object); G_OBJECT_CLASS (nm_ifnet_connection_parent_class)->finalize (object);
} }
...@@ -178,8 +194,7 @@ nm_ifnet_connection_class_init (NMIfnetConnectionClass * ifnet_connection_class) ...@@ -178,8 +194,7 @@ nm_ifnet_connection_class_init (NMIfnetConnectionClass * ifnet_connection_class)
GObjectClass *object_class = G_OBJECT_CLASS (ifnet_connection_class); GObjectClass *object_class = G_OBJECT_CLASS (ifnet_connection_class);
NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (ifnet_connection_class); NMSettingsConnectionClass *settings_class = NM_SETTINGS_CONNECTION_CLASS (ifnet_connection_class);
g_type_class_add_private (ifnet_connection_class, g_type_class_add_private (ifnet_connection_class, sizeof (NMIfnetConnectionPrivate));
sizeof (NMIfnetConnectionPrivate));
object_class->finalize = finalize; object_class->finalize = finalize;
settings_class->delete = do_delete; settings_class->delete = do_delete;
......
...@@ -44,8 +44,8 @@ typedef struct { ...@@ -44,8 +44,8 @@ typedef struct {
GType nm_ifnet_connection_get_type (void); GType nm_ifnet_connection_get_type (void);
NMIfnetConnection *nm_ifnet_connection_new (const char *conn_name, NMIfnetConnection *nm_ifnet_connection_new (NMConnection *source,
NMConnection *source); const char *conn_name);
const char *nm_ifnet_connection_get_conn_name (NMIfnetConnection *connection); const char *nm_ifnet_connection_get_conn_name (NMIfnetConnection *connection);
......
...@@ -260,7 +260,7 @@ reload_connections (gpointer config) ...@@ -260,7 +260,7 @@ reload_connections (gpointer config)
const char *conn_name = n_iter->data; const char *conn_name = n_iter->data;
/* read the new connection */ /* read the new connection */
new = nm_ifnet_connection_new (conn_name, NULL); new = nm_ifnet_connection_new (NULL, conn_name);
if (!new) if (!new)
continue; continue;
...@@ -321,7 +321,12 @@ reload_connections (gpointer config) ...@@ -321,7 +321,12 @@ reload_connections (gpointer config)
/* remove deleted/unused connections */ /* remove deleted/unused connections */
g_hash_table_iter_init (&iter, priv->connections); g_hash_table_iter_init (&iter, priv->connections);
while (g_hash_table_iter_next (&iter, (gpointer) &uuid, (gpointer) &candidate)) { while (g_hash_table_iter_next (&iter, (gpointer) &uuid, (gpointer) &candidate)) {
if (!g_hash_table_lookup (new_connections, uuid)) { /* only saved connections (which have a conn_name) get removed; unsaved
* ones obviously don't exist in /etc/conf.d/net yet and shouldn't get
* blown away by net file changes.
*/
if ( nm_ifnet_connection_get_conn_name (NM_IFNET_CONNECTION (candidate))
&& !g_hash_table_lookup (new_connections, uuid)) {
nm_settings_connection_signal_remove (candidate); nm_settings_connection_signal_remove (candidate);
g_hash_table_iter_remove (&iter); g_hash_table_iter_remove (&iter);
} }
...@@ -453,16 +458,12 @@ get_connections (NMSystemConfigInterface *config) ...@@ -453,16 +458,12 @@ get_connections (NMSystemConfigInterface *config)
NMIfnetConnection *connection; NMIfnetConnection *connection;
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%p) ... get_connections.", config); PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%p) ... get_connections.", config);
if (priv->unmanaged_well_known) {
PLUGIN_PRINT (IFNET_PLUGIN_NAME,
"(%p) ... get_connections (managed=false): return empty list.",
config);
return NULL;
}
g_hash_table_iter_init (&iter, priv->connections); g_hash_table_iter_init (&iter, priv->connections);
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) { while (g_hash_table_iter_next (&iter, NULL, (gpointer) &connection)) {
if (is_managed (nm_ifnet_connection_get_conn_name (connection))) const char *conn_name = nm_ifnet_connection_get_conn_name (connection);
if (!conn_name || (!priv->unmanaged_well_known && is_managed (conn_name)))
connections = g_slist_prepend (connections, connection); connections = g_slist_prepend (connections, connection);
} }
PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%p) connections count: %d", PLUGIN_PRINT (IFNET_PLUGIN_NAME, "(%p) connections count: %d",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment