diff --git a/ChangeLog b/ChangeLog index 9cb94c5ba3..8eb9ecf7db 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2008-10-11 Dan Williams + + * include/NetworkManager.h + introspection/nm-device.xml + include/NetworkManagerVPN.h + - Add a few more state reasons for the device deactivated state + + * src/nm-device-interface.c + src/nm-device-interface.h + - (nm_device_interface_deactivate): add a 'reason' argument + + * src/nm-device.c + src/nm-device.h + - (nm_device_deactivate, nm_device_take_down): add a 'reason' argument + - (nm_device_state_changed): pass the state change reason to + nm_device_take_down() + - (nm_device_set_managed): take a 'reason' argument, and pass it along + to the state change function + + * src/nm-manager.c + src/nm-manager.h + - (remove_one_device, handle_unmanaged_devices, sync_devices, + impl_manager_sleep): pass a reason code to nm_device_set_managed() + - (nm_manager_deactivate_connection): add a 'reason' argument and pass + something reasonable along to VPN deactivation + + * src/vpn-manager/nm-vpn-manager.c + src/vpn-manager/nm-vpn-manager.h + - (nm_vpn_manager_deactivate_connection): add a 'reason' argument and + pass that along to nm_vpn_connection_disconnect() + 2008-10-11 Dan Williams * src/nm-device-wifi.c diff --git a/include/NetworkManager.h b/include/NetworkManager.h index 39358ed623..05f717ccd8 100644 --- a/include/NetworkManager.h +++ b/include/NetworkManager.h @@ -325,6 +325,18 @@ typedef enum { /* Necessary firmware for the device may be missing */ NM_DEVICE_STATE_REASON_FIRMWARE_MISSING, + /* The device was removed */ + NM_DEVICE_STATE_REASON_REMOVED, + + /* NetworkManager went to sleep */ + NM_DEVICE_STATE_REASON_SLEEPING, + + /* The device's active connection disappeared */ + NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, + + /* Device disconnected by user or client */ + NM_DEVICE_STATE_REASON_USER_REQUESTED, + /* Unused */ NM_DEVICE_STATE_REASON_LAST = 0xFFFF } NMDeviceStateReason; diff --git a/include/NetworkManagerVPN.h b/include/NetworkManagerVPN.h index 952d08aeaf..c33c9b3edb 100644 --- a/include/NetworkManagerVPN.h +++ b/include/NetworkManagerVPN.h @@ -103,7 +103,8 @@ typedef enum NMVPNConnectionStateReason NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED, NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS, - NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED + NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED, + NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED } NMVPNConnectionStateReason; typedef enum { diff --git a/introspection/nm-device.xml b/introspection/nm-device.xml index 6c3cc1b412..ec7b0606d2 100644 --- a/introspection/nm-device.xml +++ b/introspection/nm-device.xml @@ -319,6 +319,26 @@ Necessary firmware for the device may be missing. + + + + The device was removed. + + + + + NetworkManager went to sleep. + + + + + The device's active connection was removed or disappeared. + + + + + A user or client requested the disconnection. + diff --git a/src/NetworkManagerPolicy.c b/src/NetworkManagerPolicy.c index b4063ebb97..bfa3540941 100644 --- a/src/NetworkManagerPolicy.c +++ b/src/NetworkManagerPolicy.c @@ -921,7 +921,7 @@ connection_removed (NMManager *manager, char *path = g_ptr_array_index (list, i); GError *error = NULL; - if (!nm_manager_deactivate_connection (manager, path, &error)) { + if (!nm_manager_deactivate_connection (manager, path, NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, &error)) { nm_warning ("Connection '%s' disappeared, but error deactivating it: (%d) %s", s_con->id, error->code, error->message); g_error_free (error); diff --git a/src/nm-device-interface.c b/src/nm-device-interface.c index 499dd86d0b..88bb14a9f2 100644 --- a/src/nm-device-interface.c +++ b/src/nm-device-interface.c @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ #include "nm-marshal.h" #include "nm-setting-connection.h" @@ -234,11 +234,11 @@ nm_device_interface_activate (NMDeviceInterface *device, } void -nm_device_interface_deactivate (NMDeviceInterface *device) +nm_device_interface_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason) { g_return_if_fail (NM_IS_DEVICE_INTERFACE (device)); - NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device); + NM_DEVICE_INTERFACE_GET_INTERFACE (device)->deactivate (device, reason); } NMDeviceState diff --git a/src/nm-device-interface.h b/src/nm-device-interface.h index ac9972fa63..f18a11d2ac 100644 --- a/src/nm-device-interface.h +++ b/src/nm-device-interface.h @@ -1,3 +1,4 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ #ifndef NM_DEVICE_INTERFACE_H #define NM_DEVICE_INTERFACE_H @@ -62,7 +63,7 @@ struct _NMDeviceInterface { NMActRequest *req, GError **error); - void (*deactivate) (NMDeviceInterface *device); + void (*deactivate) (NMDeviceInterface *device, NMDeviceStateReason reason); /* Signals */ void (*state_changed) (NMDeviceInterface *device, @@ -84,7 +85,7 @@ gboolean nm_device_interface_activate (NMDeviceInterface *device, NMActRequest *req, GError **error); -void nm_device_interface_deactivate (NMDeviceInterface *device); +void nm_device_interface_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason); NMDeviceState nm_device_interface_get_state (NMDeviceInterface *device); diff --git a/src/nm-device.c b/src/nm-device.c index 1d5772e456..d9ae0ab496 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -114,7 +114,9 @@ static gboolean nm_device_activate (NMDeviceInterface *device, GError **error); static void nm_device_activate_schedule_stage5_ip_config_commit (NMDevice *self); -static void nm_device_deactivate (NMDeviceInterface *device); +static void nm_device_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason); + +static void nm_device_take_down (NMDevice *dev, gboolean wait, NMDeviceStateReason reason); static gboolean nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware); static gboolean nm_device_is_up (NMDevice *self); @@ -1527,19 +1529,21 @@ nm_device_deactivate_quickly (NMDevice *self) * */ static void -nm_device_deactivate (NMDeviceInterface *device) +nm_device_deactivate (NMDeviceInterface *device, NMDeviceStateReason reason) { NMDevice *self = NM_DEVICE (device); - NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; + NMDeviceStateReason ignored = NM_DEVICE_STATE_REASON_NONE; g_return_if_fail (self != NULL); - nm_info ("(%s): deactivating device.", nm_device_get_iface (self)); + nm_info ("(%s): deactivating device (reason: %d).", + nm_device_get_iface (self), + reason); nm_device_deactivate_quickly (self); /* Clean up nameservers and addresses */ - nm_device_set_ip4_config (self, NULL, &reason); + nm_device_set_ip4_config (self, NULL, &ignored); /* Take out any entries in the routing table and any IP address the device had. */ nm_system_device_flush_ip4_routes (self); @@ -2061,13 +2065,13 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) return success; } -void -nm_device_take_down (NMDevice *self, gboolean block) +static void +nm_device_take_down (NMDevice *self, gboolean block, NMDeviceStateReason reason) { g_return_if_fail (NM_IS_DEVICE (self)); if (nm_device_get_act_request (self)) - nm_device_interface_deactivate (NM_DEVICE_INTERFACE (self)); + nm_device_interface_deactivate (NM_DEVICE_INTERFACE (self), reason); if (nm_device_is_up (self)) { nm_info ("(%s): cleaning up...", nm_device_get_iface (self)); @@ -2107,10 +2111,10 @@ nm_device_dispose (GObject *object) */ if (self->priv->managed) { - NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE; + NMDeviceStateReason ignored = NM_DEVICE_STATE_REASON_NONE; - nm_device_take_down (self, FALSE); - nm_device_set_ip4_config (self, NULL, &reason); + nm_device_take_down (self, FALSE, NM_DEVICE_STATE_REASON_REMOVED); + nm_device_set_ip4_config (self, NULL, &ignored); } clear_act_request (self); @@ -2348,7 +2352,7 @@ nm_info ("(%s): device state change: %d -> %d", nm_device_get_iface (device), ol switch (state) { case NM_DEVICE_STATE_UNMANAGED: if (old_state > NM_DEVICE_STATE_UNMANAGED) - nm_device_take_down (device, TRUE); + nm_device_take_down (device, TRUE, reason); break; case NM_DEVICE_STATE_UNAVAILABLE: if (old_state == NM_DEVICE_STATE_UNMANAGED) { @@ -2359,7 +2363,7 @@ nm_info ("(%s): device state change: %d -> %d", nm_device_get_iface (device), ol * eg carrier changes we actually deactivate it */ case NM_DEVICE_STATE_DISCONNECTED: if (old_state != NM_DEVICE_STATE_UNAVAILABLE) - nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device)); + nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device), reason); break; default: break; @@ -2408,7 +2412,9 @@ nm_device_get_managed (NMDevice *device) } void -nm_device_set_managed (NMDevice *device, gboolean managed) +nm_device_set_managed (NMDevice *device, + gboolean managed, + NMDeviceStateReason reason) { NMDevicePrivate *priv; @@ -2430,8 +2436,8 @@ nm_device_set_managed (NMDevice *device, gboolean managed) /* If now managed, jump to unavailable */ if (managed) - nm_device_state_changed (device, NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_REASON_NOW_MANAGED); + nm_device_state_changed (device, NM_DEVICE_STATE_UNAVAILABLE, reason); else - nm_device_state_changed (device, NM_DEVICE_STATE_UNMANAGED, NM_DEVICE_STATE_REASON_NOW_UNMANAGED); + nm_device_state_changed (device, NM_DEVICE_STATE_UNMANAGED, reason); } diff --git a/src/nm-device.h b/src/nm-device.h index 9ca0d7ef6c..99fdb86557 100644 --- a/src/nm-device.h +++ b/src/nm-device.h @@ -143,8 +143,6 @@ gboolean nm_device_set_ip4_config (NMDevice *dev, NMIP4Config *config, NMDeviceStateReason *reason); -void nm_device_take_down (NMDevice *dev, gboolean wait); - void * nm_device_get_system_config_data (NMDevice *dev); NMActRequest * nm_device_get_act_request (NMDevice *dev); @@ -166,7 +164,9 @@ gboolean nm_device_can_interrupt_activation (NMDevice *self); NMDeviceState nm_device_get_state (NMDevice *device); gboolean nm_device_get_managed (NMDevice *device); -void nm_device_set_managed (NMDevice *device, gboolean managed); +void nm_device_set_managed (NMDevice *device, + gboolean managed, + NMDeviceStateReason reason); G_END_DECLS diff --git a/src/nm-manager.c b/src/nm-manager.c index b7559027bb..403327aa8d 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -420,7 +420,7 @@ static void remove_one_device (NMManager *manager, NMDevice *device) { if (nm_device_get_managed (device)) - nm_device_set_managed (device, FALSE); + nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_REMOVED); g_signal_handlers_disconnect_by_func (device, manager_device_state_changed, manager); @@ -1153,7 +1153,7 @@ handle_unmanaged_devices (NMManager *manager, GPtrArray *ops) device = nm_manager_get_device_by_udi (manager, udi); if (device) { unmanaged = g_slist_prepend (unmanaged, device); - nm_device_set_managed (device, FALSE); + nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_NOW_UNMANAGED); } } @@ -1162,7 +1162,7 @@ handle_unmanaged_devices (NMManager *manager, GPtrArray *ops) NMDevice *device = NM_DEVICE (iter->data); if (!g_slist_find (unmanaged, device)) - nm_device_set_managed (device, TRUE); + nm_device_set_managed (device, TRUE, NM_DEVICE_STATE_REASON_NOW_MANAGED); } g_slist_free (unmanaged); @@ -1394,7 +1394,10 @@ sync_devices (NMManager *self) const char *udi = nm_device_get_udi (device); if (nm_hal_manager_udi_exists (priv->hal_mgr, udi)) { - nm_device_set_managed (device, nm_manager_udi_is_managed (self, udi)); + if (nm_manager_udi_is_managed (self, udi)) + nm_device_set_managed (device, TRUE, NM_DEVICE_STATE_REASON_NOW_MANAGED); + else + nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_NOW_UNMANAGED); } else { priv->devices = g_slist_delete_link (priv->devices, iter); remove_one_device (self, device); @@ -2006,12 +2009,14 @@ impl_manager_activate_connection (NMManager *manager, gboolean nm_manager_deactivate_connection (NMManager *manager, const char *connection_path, + NMDeviceStateReason reason, GError **error) { NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); NMVPNManager *vpn_manager; GSList *iter; gboolean success = FALSE; + NMVPNConnectionStateReason vpn_reason = NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED; /* Check for device connections first */ for (iter = priv->devices; iter; iter = g_slist_next (iter)) { @@ -2025,7 +2030,7 @@ nm_manager_deactivate_connection (NMManager *manager, if (!strcmp (connection_path, nm_act_request_get_active_connection_path (req))) { nm_device_state_changed (device, NM_DEVICE_STATE_DISCONNECTED, - NM_DEVICE_STATE_REASON_NONE); + reason); success = TRUE; goto done; } @@ -2033,7 +2038,9 @@ nm_manager_deactivate_connection (NMManager *manager, /* Check for VPN connections next */ vpn_manager = nm_vpn_manager_get (); - if (nm_vpn_manager_deactivate_connection (vpn_manager, connection_path)) { + if (reason == NM_DEVICE_STATE_REASON_CONNECTION_REMOVED) + vpn_reason = NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED; + if (nm_vpn_manager_deactivate_connection (vpn_manager, connection_path, vpn_reason)) { success = TRUE; } else { g_set_error (error, @@ -2052,7 +2059,10 @@ impl_manager_deactivate_connection (NMManager *manager, const char *connection_path, GError **error) { - return nm_manager_deactivate_connection (manager, connection_path, error); + return nm_manager_deactivate_connection (manager, + connection_path, + NM_DEVICE_STATE_REASON_USER_REQUESTED, + error); } static gboolean @@ -2082,7 +2092,7 @@ impl_manager_sleep (NMManager *manager, gboolean sleep, GError **error) * we'll remove them in 'wake' for speed's sake. */ for (iter = priv->devices; iter; iter = iter->next) - nm_device_set_managed (NM_DEVICE (iter->data), FALSE); + nm_device_set_managed (NM_DEVICE (iter->data), FALSE, NM_DEVICE_STATE_REASON_SLEEPING); } else { nm_info ("Waking up..."); diff --git a/src/nm-manager.h b/src/nm-manager.h index ae6b9a4f52..84dd13ee52 100644 --- a/src/nm-manager.h +++ b/src/nm-manager.h @@ -70,6 +70,7 @@ const char * nm_manager_activate_connection (NMManager *manager, gboolean nm_manager_deactivate_connection (NMManager *manager, const char *connection_path, + NMDeviceStateReason reason, GError **error); /* State handling */ diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c index e8e47c3a6d..65b524787e 100644 --- a/src/vpn-manager/nm-vpn-manager.c +++ b/src/vpn-manager/nm-vpn-manager.c @@ -206,7 +206,9 @@ nm_vpn_manager_activate_connection (NMVPNManager *manager, } gboolean -nm_vpn_manager_deactivate_connection (NMVPNManager *manager, const char *path) +nm_vpn_manager_deactivate_connection (NMVPNManager *manager, + const char *path, + NMVPNConnectionStateReason reason) { NMVPNManagerPrivate *priv; GSList *iter; @@ -226,7 +228,7 @@ nm_vpn_manager_deactivate_connection (NMVPNManager *manager, const char *path) vpn_path = nm_vpn_connection_get_active_connection_path (vpn); if (!strcmp (path, vpn_path)) { - nm_vpn_connection_disconnect (vpn, NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED); + nm_vpn_connection_disconnect (vpn, reason); found = TRUE; } } diff --git a/src/vpn-manager/nm-vpn-manager.h b/src/vpn-manager/nm-vpn-manager.h index 9d3bf4850a..13b5e2e89a 100644 --- a/src/vpn-manager/nm-vpn-manager.h +++ b/src/vpn-manager/nm-vpn-manager.h @@ -55,7 +55,8 @@ const char *nm_vpn_manager_activate_connection (NMVPNManager *manager, GError **error); gboolean nm_vpn_manager_deactivate_connection (NMVPNManager *manager, - const char *path); + const char *path, + NMVPNConnectionStateReason reason); void nm_vpn_manager_add_active_connections (NMVPNManager *manager, NMConnection *filter,