From 3c0df723521dcb9a6c8632748616bf030c21e4ef Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 11 Mar 2008 22:26:46 +0000 Subject: [PATCH] 2008-03-11 Dan Williams * 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 git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3425 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 19 +++++++++++++++++++ src/NetworkManagerPolicy.c | 32 +++++++++++++++++++++++--------- src/nm-device.c | 29 +++++++++++++++++------------ 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 427ccad49f..83b0b2d1f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2008-03-11 Dan Williams + + * 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 + 2008-03-11 Dan Williams Fix address handling as a result of DHCP rebind/renew/reboot. diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index e5d6f13b4f..f17e921aa5 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -110,7 +110,7 @@ get_device_priority (NMDevice *dev) } 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 @@ update_routing_and_dns (NMPolicy *policy) 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 @@ update_routing_and_dns (NMPolicy *policy) } } - 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 @@ update_routing_and_dns (NMPolicy *policy) 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 @@ device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data) 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); } @@ -315,6 +318,12 @@ device_carrier_changed (NMDevice *device, gboolean carrier, gpointer user_data) } } +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) { @@ -356,6 +365,11 @@ device_added (NMManager *manager, NMDevice *device, gpointer user_data) 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 @@ device_removed (NMManager *manager, NMDevice *device, gpointer user_data) iter = next; } - update_routing_and_dns (policy); + update_routing_and_dns (policy, FALSE); } static void diff --git a/src/nm-device.c b/src/nm-device.c index e32bb9a5af..3b0d93a82c 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -1075,8 +1075,6 @@ static void 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 (NMDeviceInterface *device) 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 @@ handle_dhcp_lease_change (NMDevice *device) 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 @@ nm_device_get_ip4_config (NMDevice *self) { 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 @@ nm_device_set_ip4_config (NMDevice *self, NMIP4Config *config) 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_device_set_ip4_config (NMDevice *self, NMIP4Config *config) nm_system_activate_nis (config); } + g_object_notify (G_OBJECT (self), NM_DEVICE_INTERFACE_IP4_CONFIG); + return success; } @@ -1693,6 +1692,7 @@ get_property (GObject *object, guint prop_id, 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 @@ get_property (GObject *object, guint prop_id, 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);