about summary refs log tree commit diff
path: root/src/nm-policy.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2011-05-04 21:35:57 +0200
committerMichael Biebl <biebl@debian.org>2011-05-04 21:35:57 +0200
commit3241555aff5c969104e492501097f4cb8837bcca (patch)
tree6d15a02d02a9f1bfcda6075ae2b8c71537d8038d /src/nm-policy.c
parente1b66c145e71e7bc6a06845dd17788fb7b8e158e (diff)
parent9f806e97a24bba61417ae312fcc0da40914266fb (diff)
Merge commit 'upstream/0.8.999' into experimental
Diffstat (limited to 'src/nm-policy.c')
-rw-r--r--src/nm-policy.c97
1 files changed, 57 insertions, 40 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c
index fcada545..5c30828b 100644
--- a/src/nm-policy.c
+++ b/src/nm-policy.c
@@ -238,7 +238,7 @@ _set_hostname (NMPolicy *policy,
 	}
 
 	if (nm_policy_set_system_hostname (policy->cur_hostname, msg))
-		nm_utils_call_dispatcher ("hostname", NULL, NULL, NULL);
+		nm_utils_call_dispatcher ("hostname", NULL, NULL, NULL, NULL, NULL);
 }
 
 static void
@@ -539,7 +539,7 @@ update_ip6_routing_and_dns (NMPolicy *policy, gboolean force_update)
 	NMActRequest *best_req = NULL;
 	NMDnsManager *dns_mgr;
 	GSList *devices = NULL, *iter;
-#if NOT_YET
+#if 0
 	GSList *vpns;
 #endif
 	NMIP6Config *ip6_config = NULL;
@@ -555,7 +555,7 @@ update_ip6_routing_and_dns (NMPolicy *policy, gboolean force_update)
 	if (!force_update && (best == policy->default_device6))
 		goto out;
 
-#if NOT_YET
+#if 0
 	/* If a VPN connection is active, it is preferred */
 	vpns = nm_vpn_manager_get_active_connections (policy->vpn_manager);
 	for (iter = vpns; iter; iter = g_slist_next (iter)) {
@@ -686,6 +686,16 @@ typedef struct {
 	guint id;
 } ActivateData;
 
+static void
+activate_data_free (ActivateData *data)
+{
+	if (data->id)
+		g_source_remove (data->id);
+	g_object_unref (data->device);
+	memset (data, 0, sizeof (*data));
+	g_free (data);
+}
+
 static gboolean
 auto_activate_device (gpointer user_data)
 {
@@ -698,6 +708,9 @@ auto_activate_device (gpointer user_data)
 	g_assert (data);
 	policy = data->policy;
 
+	data->id = 0;
+	policy->pending_activation_checks = g_slist_remove (policy->pending_activation_checks, data);
+
 	// FIXME: if a device is already activating (or activated) with a connection
 	// but another connection now overrides the current one for that device,
 	// deactivate the device and activate the new connection instead of just
@@ -741,14 +754,37 @@ auto_activate_device (gpointer user_data)
 	g_slist_free (connections);
 
  out:
-	/* Remove this call's handler ID */
-	policy->pending_activation_checks = g_slist_remove (policy->pending_activation_checks, data);
-	g_object_unref (data->device);
-	g_free (data);
-
+	activate_data_free (data);
 	return FALSE;
 }
 
+static ActivateData *
+activate_data_new (NMPolicy *policy, NMDevice *device, guint delay_seconds)
+{
+	ActivateData *data;
+
+	data = g_malloc0 (sizeof (ActivateData));
+	data->policy = policy;
+	data->device = g_object_ref (device);
+	if (delay_seconds > 0)
+		data->id = g_timeout_add_seconds (delay_seconds, auto_activate_device, data);
+	else
+		data->id = g_idle_add (auto_activate_device, data);
+	return data;
+}
+
+static ActivateData *
+find_pending_activation (GSList *list, NMDevice *device)
+{
+	GSList *iter;
+
+	for (iter = list; iter; iter = g_slist_next (iter)) {
+		if (((ActivateData *) iter->data)->device == device)
+			return iter->data;
+	}
+	return NULL;
+}
+
 /*****************************************************************************/
 
 static void
@@ -803,7 +839,6 @@ static void
 schedule_activate_check (NMPolicy *policy, NMDevice *device, guint delay_seconds)
 {
 	ActivateData *data;
-	GSList *iter;
 	NMDeviceState state;
 
 	if (nm_manager_get_state (policy->manager) == NM_STATE_ASLEEP)
@@ -816,19 +851,11 @@ schedule_activate_check (NMPolicy *policy, NMDevice *device, guint delay_seconds
 	if (!nm_device_autoconnect_allowed (device))
 		return;
 
-	for (iter = policy->pending_activation_checks; iter; iter = g_slist_next (iter)) {
-		/* Only one pending activation check at a time */
-		if (((ActivateData *) iter->data)->device == device)
-			return;
+	/* Schedule an auto-activation if there isn't one already for this device */
+	if (find_pending_activation (policy->pending_activation_checks, device) == NULL) {
+		data = activate_data_new (policy, device, delay_seconds);
+		policy->pending_activation_checks = g_slist_append (policy->pending_activation_checks, data);
 	}
-
-	data = g_malloc0 (sizeof (ActivateData));
-	g_return_if_fail (data != NULL);
-
-	data->policy = policy;
-	data->device = g_object_ref (device);
-	data->id = delay_seconds ? g_timeout_add_seconds (delay_seconds, auto_activate_device, data) : g_idle_add (auto_activate_device, data);
-	policy->pending_activation_checks = g_slist_append (policy->pending_activation_checks, data);
 }
 
 static NMConnection *
@@ -896,7 +923,10 @@ device_state_changed (NMDevice *device,
 		break;
 	case NM_DEVICE_STATE_UNMANAGED:
 	case NM_DEVICE_STATE_UNAVAILABLE:
+		update_routing_and_dns (policy, FALSE);
+		break;
 	case NM_DEVICE_STATE_DISCONNECTED:
+		/* Device is now available for auto-activation */
 		update_routing_and_dns (policy, FALSE);
 		schedule_activate_check (policy, device, 0);
 		break;
@@ -968,21 +998,14 @@ static void
 device_removed (NMManager *manager, NMDevice *device, gpointer user_data)
 {
 	NMPolicy *policy = (NMPolicy *) user_data;
+	ActivateData *tmp;
 	GSList *iter;
 
 	/* Clear any idle callbacks for this device */
-	iter = policy->pending_activation_checks;
-	while (iter) {
-		ActivateData *data = (ActivateData *) iter->data;
-		GSList *next = g_slist_next (iter);
-
-		if (data->device == device) {
-			g_source_remove (data->id);
-			g_object_unref (data->device);
-			g_free (data);
-			policy->pending_activation_checks = g_slist_delete_link (policy->pending_activation_checks, iter);
-		}
-		iter = next;
+	tmp = find_pending_activation (policy->pending_activation_checks, device);
+	if (tmp) {
+		policy->pending_activation_checks = g_slist_remove (policy->pending_activation_checks, tmp);
+		activate_data_free (tmp);
 	}
 
 	/* Clear any signal handlers for this device */
@@ -1171,13 +1194,7 @@ nm_policy_destroy (NMPolicy *policy)
 		policy->lookup = NULL;
 	}
 
-	for (iter = policy->pending_activation_checks; iter; iter = g_slist_next (iter)) {
-		ActivateData *data = (ActivateData *) iter->data;
-
-		g_source_remove (data->id);
-		g_object_unref (data->device);
-		g_free (data);
-	}
+	g_slist_foreach (policy->pending_activation_checks, (GFunc) activate_data_free, NULL);
 	g_slist_free (policy->pending_activation_checks);
 
 	g_signal_handler_disconnect (policy->vpn_manager, policy->vpn_activated_id);