NetworkManager r3425 - in trunk: . src



Author: dcbw
Date: Tue Mar 11 22:26:46 2008
New Revision: 3425
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3425&view=rev

Log:
2008-03-11  Dan Williams  <dcbw redhat com>

	* src/nm-device.c
		- (nm_device_deactivate): don't need to munge DNS here; that gets done
			already in nm_device_set_ip4_config()
		- (handle_dhcp_lease_change): fail the device if setting the IP4Config
			due to a DHCP rebind fails
		- (nm_device_set_ip4_config): send property notifications when the
			ip4 config changes
		- (get_property): only report IP4Config property during valid states

	* src/NetworkManagerPolicy.c
		- (update_routing_and_dns): ignore devices that don't have an ip4
			config; add parameter 'force_update' to allow callers to specify
			that changes should be made even if the default device doesn't change
		- (device_ip4_config_changed): update DNS and routing when the device's
			IP4Config changes, like for DHCP updates
		- (device_added): listen for ip4-config property changes



Modified:
   trunk/ChangeLog
   trunk/src/NetworkManagerPolicy.c
   trunk/src/nm-device.c

Modified: trunk/src/NetworkManagerPolicy.c
==============================================================================
--- trunk/src/NetworkManagerPolicy.c	(original)
+++ trunk/src/NetworkManagerPolicy.c	Tue Mar 11 22:26:46 2008
@@ -110,7 +110,7 @@
 }
 
 static void
-update_routing_and_dns (NMPolicy *policy)
+update_routing_and_dns (NMPolicy *policy, gboolean force_update)
 {
 	NMDevice *best = NULL;
 	guint32 best_prio = 0;
@@ -123,7 +123,8 @@
 		NMDevice *dev = NM_DEVICE (iter->data);
 		guint32 prio;
 		
-		if (nm_device_get_state (dev) != NM_DEVICE_STATE_ACTIVATED)
+		if (   (nm_device_get_state (dev) != NM_DEVICE_STATE_ACTIVATED)
+		    || !nm_device_get_ip4_config (dev))
 			continue;
 
 		prio = get_device_priority (dev);
@@ -133,11 +134,10 @@
 		}
 	}
 
-	if (!best || (best == policy->default_device))
+	if (!best)
+		goto out;
+	if (!force_update && (best == policy->default_device))
 		goto out;
-
-	nm_info ("Policy (%s) now the default device for routing and DNS.",
-	         nm_device_get_iface (best));
 
 	update_default_route (policy, best);
 
@@ -146,6 +146,9 @@
 	nm_named_manager_add_ip4_config (named_mgr, config, NM_NAMED_IP_CONFIG_TYPE_BEST_DEVICE);
 	g_object_unref (named_mgr);
 
+	nm_info ("Policy set (%s) as default device for routing and DNS.",
+	         nm_device_get_iface (best));
+
 out:
 	policy->default_device = best;	
 }
@@ -296,9 +299,9 @@
 		if (connection)
 			g_object_set_data (G_OBJECT (connection), INVALID_TAG, NULL);
 
-		update_routing_and_dns (policy);
+		update_routing_and_dns (policy, FALSE);
 	} else if (state == NM_DEVICE_STATE_DISCONNECTED) {
-		update_routing_and_dns (policy);
+		update_routing_and_dns (policy, FALSE);
 
 		schedule_activate_check (policy, device);
 	}
@@ -316,6 +319,12 @@
 }
 
 static void
+device_ip4_config_changed (NMDevice *device, NMIP4Config *config, gpointer user_data)
+{
+	update_routing_and_dns ((NMPolicy *) user_data, TRUE);
+}
+
+static void
 wireless_networks_changed (NMDevice80211Wireless *device, NMAccessPoint *ap, gpointer user_data)
 {
 	schedule_activate_check ((NMPolicy *) user_data, NM_DEVICE (device));
@@ -356,6 +365,11 @@
 	                       policy);
 	policy->dev_signal_ids = add_device_signal_id (policy->dev_signal_ids, id, device);
 
+	id = g_signal_connect (device, "notify::" NM_DEVICE_INTERFACE_IP4_CONFIG,
+	                       G_CALLBACK (device_ip4_config_changed),
+	                       policy);
+	policy->dev_signal_ids = add_device_signal_id (policy->dev_signal_ids, id, device);
+
 	if (NM_IS_DEVICE_802_11_WIRELESS (device)) {
 		id = g_signal_connect (device, "access-point-added",
 		                       G_CALLBACK (wireless_networks_changed),
@@ -392,7 +406,7 @@
 		iter = next;
 	}
 
-	update_routing_and_dns (policy);
+	update_routing_and_dns (policy, FALSE);
 }
 
 static void

Modified: trunk/src/nm-device.c
==============================================================================
--- trunk/src/nm-device.c	(original)
+++ trunk/src/nm-device.c	Tue Mar 11 22:26:46 2008
@@ -1075,8 +1075,6 @@
 nm_device_deactivate (NMDeviceInterface *device)
 {
 	NMDevice *self = NM_DEVICE (device);
-	NMIP4Config *	config;
-	NMNamedManager * named_mgr;
 
 	g_return_if_fail (self != NULL);
 
@@ -1084,13 +1082,8 @@
 
 	nm_device_deactivate_quickly (self);
 
-	/* Remove any device nameservers and domains */
-	if ((config = nm_device_get_ip4_config (self))) {
-		named_mgr = nm_named_manager_get ();
-		nm_named_manager_remove_ip4_config (named_mgr, config);
-		nm_device_set_ip4_config (self, NULL);
-		g_object_unref (named_mgr);
-	}
+	/* Clean up nameservers and addresses */
+	nm_device_set_ip4_config (self, NULL);
 
 	/* Take out any entries in the routing table and any IP address the device had. */
 	nm_system_device_flush_routes (self);
@@ -1288,6 +1281,7 @@
 			NM_DEVICE_GET_CLASS (device)->update_link (device);
 	} else {
 		nm_warning ("Failed to update IP4 config in response to DHCP event.");
+		nm_device_state_changed (device, NM_DEVICE_STATE_FAILED);
 	}
 }
 
@@ -1399,7 +1393,7 @@
 {
 	g_return_val_if_fail (self != NULL, NULL);
 
-	return self->priv->ip4_config;
+	return NM_DEVICE_GET_PRIVATE (self)->ip4_config;
 }
 
 
@@ -1427,8 +1421,11 @@
 		priv->ip4_config = NULL;
 	}
 
-	if (!config)
+	if (!config) {
+		if (nm_device_get_state (self) == NM_DEVICE_STATE_ACTIVATED)
+			g_object_notify (G_OBJECT (self), NM_DEVICE_INTERFACE_IP4_CONFIG);
 		return TRUE;
+	}
 
 	priv->ip4_config = g_object_ref (config);
 
@@ -1451,6 +1448,8 @@
 		nm_system_activate_nis (config);
 	}
 
+	g_object_notify (G_OBJECT (self), NM_DEVICE_INTERFACE_IP4_CONFIG);
+
 	return success;
 }
 
@@ -1693,6 +1692,7 @@
 			  GValue *value, GParamSpec *pspec)
 {
 	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (object);
+	NMDeviceState state;
 
 	switch (prop_id) {
 	case NM_DEVICE_INTERFACE_PROP_UDI:
@@ -1711,7 +1711,12 @@
 		g_value_set_uint (value, priv->ip4_address);
 		break;
 	case NM_DEVICE_INTERFACE_PROP_IP4_CONFIG:
-		g_value_set_object (value, priv->ip4_config);
+		state = nm_device_get_state (NM_DEVICE (object));
+		if (   (state == NM_DEVICE_STATE_ACTIVATED)
+		    || (state == NM_DEVICE_STATE_IP_CONFIG))
+			g_value_set_object (value, priv->ip4_config);
+		else
+			g_value_set_object (value, NULL);
 		break;
 	case NM_DEVICE_INTERFACE_PROP_STATE:
 		g_value_set_uint (value, priv->state);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]