diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2017-03-17 10:21:57 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2017-03-17 10:21:57 +0100 |
commit | 1e4f1892e052c69983245b14e17a88dec6e5d138 (patch) | |
tree | 0058b257df78a0752db770ec3702ce1b46cf1032 | |
parent | 6da6318e8839df3d5d5b5cab65c1ac75ab76bb5f (diff) | |
parent | d190ca487f4dfcdf0482f36d45636f2a33b63aa1 (diff) | |
download | NetworkManager-1e4f1892e052c69983245b14e17a88dec6e5d138.tar.gz |
merge: branch 'lr/active-connection-state-changed'
https://bugzilla.gnome.org/show_bug.cgi?id=779627
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | clients/cli/connections.c | 277 | ||||
-rw-r--r-- | introspection/org.freedesktop.NetworkManager.Connection.Active.xml | 14 | ||||
-rw-r--r-- | introspection/org.freedesktop.NetworkManager.VPN.Connection.xml | 2 | ||||
-rw-r--r-- | libnm-core/nm-dbus-interface.h | 58 | ||||
-rw-r--r-- | libnm-core/nm-vpn-dbus-interface.h | 37 | ||||
-rw-r--r-- | libnm/libnm.ver | 2 | ||||
-rw-r--r-- | libnm/nm-active-connection.c | 71 | ||||
-rw-r--r-- | libnm/nm-active-connection.h | 32 | ||||
-rw-r--r-- | libnm/nm-client.c | 3 | ||||
-rw-r--r-- | libnm/nm-object.c | 7 | ||||
-rw-r--r-- | libnm/nm-vpn-connection.c | 6 | ||||
-rw-r--r-- | libnm/nm-vpn-connection.h | 5 | ||||
-rw-r--r-- | src/devices/nm-device.c | 6 | ||||
-rw-r--r-- | src/nm-act-request.c | 8 | ||||
-rw-r--r-- | src/nm-active-connection.c | 12 | ||||
-rw-r--r-- | src/nm-active-connection.h | 6 | ||||
-rw-r--r-- | src/nm-manager.c | 20 | ||||
-rw-r--r-- | src/nm-policy.c | 2 | ||||
-rw-r--r-- | src/vpn/nm-vpn-connection.c | 96 | ||||
-rw-r--r-- | src/vpn/nm-vpn-connection.h | 4 |
21 files changed, 408 insertions, 262 deletions
diff --git a/Makefile.am b/Makefile.am index fac53d5cc6..8ee15b5be5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -512,6 +512,8 @@ GLIB_GENERATED += \ $(libnm_core_lib_c_mkenums) nm_core_enum_types_sources = $(libnm_core_lib_h_pub_real) +nm_core_enum_types_MKENUMS_C_FLAGS = --identifier-prefix NM --fhead '\#include "nm-default.h"\n' + $(libnm_core_lib_h_pub_mkenums): libnm-core/.dirstamp $(libnm_core_lib_c_mkenums): libnm-core/.dirstamp diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 84cde2b78c..fecec0d403 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -2124,104 +2124,90 @@ typedef struct { static void activate_connection_info_finish (ActivateConnectionInfo *info); static const char * -vpn_connection_state_reason_to_string (NMVpnConnectionStateReason reason) +active_connection_state_reason_to_string (NMActiveConnectionStateReason reason) { switch (reason) { - case NM_VPN_CONNECTION_STATE_REASON_UNKNOWN: - return _("unknown reason"); - case NM_VPN_CONNECTION_STATE_REASON_NONE: - return _("none"); - case NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED: - return _("the user was disconnected"); - case NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED: - return _("the base network connection was interrupted"); - case NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED: - return _("the VPN service stopped unexpectedly"); - case NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID: - return _("the VPN service returned invalid configuration"); - case NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT: - return _("the connection attempt timed out"); - case NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT: - return _("the VPN service did not start in time"); - case NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED: - return _("the VPN service failed to start"); - case NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS: - return _("no valid VPN secrets"); - case NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED: - return _("invalid VPN secrets"); - case NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED: - return _("the connection was removed"); - default: - return _("unknown"); - } + case NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN: + return _("Unknown reason"); + case NM_ACTIVE_CONNECTION_STATE_REASON_NONE: + return _("The connection was disconnected"); + case NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED: + return _("Disconnected by user"); + case NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED: + return _("The base network connection was interrupted"); + case NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED: + return _("The VPN service stopped unexpectedly"); + case NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID: + return _("The VPN service returned invalid configuration"); + case NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT: + return _("The connection attempt timed out"); + case NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT: + return _("The VPN service did not start in time"); + case NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED: + return _("The VPN service failed to start"); + case NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS: + return _("No valid secrets"); + case NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED: + return _("Invalid secrets"); + case NM_ACTIVE_CONNECTION_STATE_REASON_CONNECTION_REMOVED: + return _("The connection was removed"); + case NM_ACTIVE_CONNECTION_STATE_REASON_DEPENDENCY_FAILED: + return _("Master connection failed"); + case NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REALIZE_FAILED: + return _("Could not create a software link"); + case NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REMOVED: + return _("The device disappeared"); + } + + g_return_val_if_reached (_("Invalid reason")); } static void -device_state_cb (NMDevice *device, GParamSpec *pspec, ActivateConnectionInfo *info) +check_activated (ActivateConnectionInfo *info) { NmCli *nmc = info->nmc; - NMActiveConnection *active; - NMDeviceState state; + NMDevice *device = info->device; + NMActiveConnection *active = info->active; NMActiveConnectionState ac_state; + NMActiveConnectionStateReason ac_reason; + NMDeviceState dev_state; + NMDeviceStateReason dev_reason; - active = nm_device_get_active_connection (device); - state = nm_device_get_state (device); - - ac_state = active ? nm_active_connection_get_state (active) : NM_ACTIVE_CONNECTION_STATE_UNKNOWN; + ac_state = nm_active_connection_get_state (active); + ac_reason = nm_active_connection_get_state_reason (active); - if (ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { - if (nmc->print_output == NMC_PRINT_PRETTY) - nmc_terminal_erase_line (); - g_print (_("Connection successfully activated (D-Bus active path: %s)\n"), - nm_object_get_path (NM_OBJECT (active))); - activate_connection_info_finish (info); - } else if ( ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING - && state >= NM_DEVICE_STATE_IP_CONFIG - && state <= NM_DEVICE_STATE_ACTIVATED) { - if (nmc->print_output == NMC_PRINT_PRETTY) - nmc_terminal_erase_line (); - g_print (_("Connection successfully activated (master waiting for slaves) (D-Bus active path: %s)\n"), - nm_object_get_path (NM_OBJECT (active))); - activate_connection_info_finish (info); + if (device) { + dev_state = nm_device_get_state (device); + dev_reason = nm_device_get_state_reason (device); } -} - -static void -active_connection_removed_cb (NMClient *client, NMActiveConnection *active, ActivateConnectionInfo *info) -{ - NmCli *nmc = info->nmc; - if (active == info->active) { - g_string_printf (nmc->return_text, _("Error: Connection activation failed.")); - nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; - activate_connection_info_finish (info); - } -} - -static void -active_connection_state_cb (NMActiveConnection *active, GParamSpec *pspec, ActivateConnectionInfo *info) -{ - NmCli *nmc = info->nmc; - NMActiveConnectionState state; - - state = nm_active_connection_get_state (active); - - if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { + if (ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { if (nmc->print_output == NMC_PRINT_PRETTY) nmc_terminal_erase_line (); g_print (_("Connection successfully activated (D-Bus active path: %s)\n"), nm_object_get_path (NM_OBJECT (active))); activate_connection_info_finish (info); - } else if (state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { - g_string_printf (nmc->return_text, _("Error: Connection activation failed.")); - nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; - activate_connection_info_finish (info); - } else if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) { + } else if (ac_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { + if (device && ac_reason == NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED) { + if (dev_state == NM_DEVICE_STATE_FAILED || dev_state == NM_DEVICE_STATE_DISCONNECTED) { + g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"), + nmc_device_reason_to_string (dev_reason)); + nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; + activate_connection_info_finish (info); + } else { + /* Just wait for the device to go failed. We'll get a better error message. */ + return; + } + } else { + g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"), + active_connection_state_reason_to_string (ac_reason)); + nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; + activate_connection_info_finish (info); + } + } else if (ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) { /* activating master connection does not automatically activate any slaves, so their * active connection state will not progress beyond ACTIVATING state. * Monitor the device instead. */ - const GPtrArray *devices; - NMDevice *device; if (nmc->secret_agent) { NMRemoteConnection *connection = nm_active_connection_get_connection (active); @@ -2230,53 +2216,34 @@ active_connection_state_cb (NMActiveConnection *active, GParamSpec *pspec, Activ nm_connection_get_path (NM_CONNECTION (connection))); } - devices = nm_active_connection_get_devices (active); - device = devices->len ? g_ptr_array_index (devices, 0) : NULL; if ( device && ( NM_IS_DEVICE_BOND (device) || NM_IS_DEVICE_TEAM (device) - || NM_IS_DEVICE_BRIDGE (device))) { - g_signal_connect (device, "notify::" NM_DEVICE_STATE, G_CALLBACK (device_state_cb), info); - device_state_cb (device, NULL, info); + || NM_IS_DEVICE_BRIDGE (device)) + && dev_state >= NM_DEVICE_STATE_IP_CONFIG + && dev_state <= NM_DEVICE_STATE_ACTIVATED) { + if (nmc->print_output == NMC_PRINT_PRETTY) + nmc_terminal_erase_line (); + g_print (_("Connection successfully activated (master waiting for slaves) (D-Bus active path: %s)\n"), + nm_object_get_path (NM_OBJECT (active))); + activate_connection_info_finish (info); } } } static void -vpn_connection_state_cb (NMVpnConnection *vpn, - NMVpnConnectionState state, - NMVpnConnectionStateReason reason, - ActivateConnectionInfo *info) +device_state_cb (NMDevice *device, GParamSpec *pspec, ActivateConnectionInfo *info) { - NmCli *nmc = info->nmc; - - switch (state) { - case NM_VPN_CONNECTION_STATE_PREPARE: - case NM_VPN_CONNECTION_STATE_NEED_AUTH: - case NM_VPN_CONNECTION_STATE_CONNECT: - case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET: - /* no operation */ - break; - - case NM_VPN_CONNECTION_STATE_ACTIVATED: - if (nmc->print_output == NMC_PRINT_PRETTY) - nmc_terminal_erase_line (); - g_print (_("VPN connection successfully activated (D-Bus active path: %s)\n"), - nm_object_get_path (NM_OBJECT (vpn))); - activate_connection_info_finish (info); - break; - - case NM_VPN_CONNECTION_STATE_FAILED: - case NM_VPN_CONNECTION_STATE_DISCONNECTED: - g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s."), - vpn_connection_state_reason_to_string (reason)); - nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; - activate_connection_info_finish (info); - break; + check_activated (info); +} - default: - break; - } +static void +active_connection_state_cb (NMActiveConnection *active, + NMActiveConnectionState state, + NMActiveConnectionStateReason reason, + ActivateConnectionInfo *info) +{ + check_activated (info); } static void @@ -2308,24 +2275,28 @@ progress_cb (gpointer user_data) } static gboolean -progress_device_cb (gpointer user_data) +progress_active_connection_cb (gpointer user_data) { - NMDevice *device = (NMDevice *) user_data; - - nmc_terminal_show_progress (device ? nmc_device_state_to_string (nm_device_get_state (device)) : ""); + NMActiveConnection *active = user_data; + const char *str; + NMDevice *device; + NMActiveConnectionState ac_state; + const GPtrArray *ac_devs; - return TRUE; -} + ac_state = nm_active_connection_get_state (active); -static gboolean -progress_vpn_cb (gpointer user_data) -{ - NMVpnConnection *vpn = (NMVpnConnection *) user_data; - const char *str; + if (ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) { + /* If the connection is activating, the device state + * is more interesting. */ + ac_devs = nm_active_connection_get_devices (active); + device = ac_devs->len > 0 ? g_ptr_array_index (ac_devs, 0) : NULL; + } else { + device = NULL; + } - str = NM_IS_VPN_CONNECTION (vpn) ? - vpn_connection_state_to_string (nm_vpn_connection_get_vpn_state (vpn)) : - ""; + str = device + ? nmc_device_state_to_string (nm_device_get_state (device)) + : active_connection_state_to_string (ac_state); nmc_terminal_show_progress (str); @@ -2341,14 +2312,9 @@ activate_connection_info_finish (ActivateConnectionInfo *info) } if (info->active) { - if (NM_IS_VPN_CONNECTION (info->active)) - g_signal_handlers_disconnect_by_func (info->active, G_CALLBACK (vpn_connection_state_cb), info); - else - g_signal_handlers_disconnect_by_func (info->active, G_CALLBACK (active_connection_state_cb), info); + g_signal_handlers_disconnect_by_func (info->active, G_CALLBACK (active_connection_state_cb), info); g_object_unref (info->active); - } - g_signal_handlers_disconnect_by_func (info->nmc->client, G_CALLBACK (active_connection_removed_cb), info); g_free (info); quit (); @@ -2393,34 +2359,27 @@ activate_connection_cb (GObject *client, GAsyncResult *result, gpointer user_dat } activate_connection_info_finish (info); } else { - if (NM_IS_VPN_CONNECTION (active)) { - /* Monitor VPN state */ - g_signal_connect (G_OBJECT (active), "vpn-state-changed", G_CALLBACK (vpn_connection_state_cb), info); - - /* Start progress indication showing VPN states */ - if (nmc->print_output == NMC_PRINT_PRETTY) { - if (progress_id) - g_source_remove (progress_id); - progress_id = g_timeout_add (120, progress_vpn_cb, NM_VPN_CONNECTION (active)); - } - } else { - g_signal_connect (active, "notify::state", G_CALLBACK (active_connection_state_cb), info); - active_connection_state_cb (active, NULL, info); - - /* Start progress indication showing device states */ - if (nmc->print_output == NMC_PRINT_PRETTY) { - if (progress_id) - g_source_remove (progress_id); - progress_id = g_timeout_add (120, progress_device_cb, device); - } + /* Monitor the active connection state state */ + g_signal_connect (G_OBJECT (active), "state-changed", G_CALLBACK (active_connection_state_cb), info); + active_connection_state_cb (active, + nm_active_connection_get_state (active), + nm_active_connection_get_state_reason (active), + info); + + if (device) { + g_signal_connect (device, "notify::" NM_DEVICE_STATE, G_CALLBACK (device_state_cb), info); + device_state_cb (device, NULL, info); + } + + /* Start progress indication showing VPN states */ + if (nmc->print_output == NMC_PRINT_PRETTY) { + if (progress_id) + g_source_remove (progress_id); + progress_id = g_timeout_add (120, progress_active_connection_cb, active); } /* Start timer not to loop forever when signals are not emitted */ g_timeout_add_seconds (nmc->timeout, activate_connection_timeout_cb, info); - - /* Fail when the active connection goes away. */ - g_signal_connect (nmc->client, NM_CLIENT_ACTIVE_CONNECTION_REMOVED, - G_CALLBACK (active_connection_removed_cb), info); } } } diff --git a/introspection/org.freedesktop.NetworkManager.Connection.Active.xml b/introspection/org.freedesktop.NetworkManager.Connection.Active.xml index 3ffa4cd67a..31a485c9ff 100644 --- a/introspection/org.freedesktop.NetworkManager.Connection.Active.xml +++ b/introspection/org.freedesktop.NetworkManager.Connection.Active.xml @@ -81,6 +81,20 @@ <property name="State" type="u" access="read"/> <!-- + StateChanged: + @state: (<link linkend="NMActiveConnectionState">NMActiveConnectionState</link>) The new state of the active connection. + @reason: (<link linkend="NMActiveConnectionStateReason">NMActiveConnectionStateReason</link>) Reason code describing the change to the new state. + + Emitted when the state of the active connection has changed. + + Since: 1.8 + --> + <signal name="StateChanged"> + <arg name="state" type="u"/> + <arg name="reason" type="u"/> + </signal> + + <!-- Default: Whether this active connection is the default IPv4 connection, i.e. diff --git a/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml b/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml index 5d57908665..1dc1cc435c 100644 --- a/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml +++ b/introspection/org.freedesktop.NetworkManager.VPN.Connection.xml @@ -39,7 +39,7 @@ <!-- VpnStateChanged: @state: (<link linkend="NMVpnConnectionState">NMVpnConnectionState</link>) The new state of the VPN connection. - @reason: (<link linkend="NMVpnConnectionStateReason">NMVpnConnectionStateReason</link>) Reason code describing the change to the new state. + @reason: (<link linkend="NMActiveConnectionStateReason">NMActiveConnectionStateReason</link>) Reason code describing the change to the new state. Emitted when the state of the VPN connection has changed. --> diff --git a/libnm-core/nm-dbus-interface.h b/libnm-core/nm-dbus-interface.h index 89c2ab1628..16318b78bc 100644 --- a/libnm-core/nm-dbus-interface.h +++ b/libnm-core/nm-dbus-interface.h @@ -30,6 +30,7 @@ #ifndef NM_VERSION_H #define NM_AVAILABLE_IN_1_2 +#define NM_AVAILABLE_IN_1_8 #endif /* @@ -641,6 +642,62 @@ typedef enum { } NMActiveConnectionState; /** + * NMActiveConnectionStateReason: + * @NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN: The reason for the active connection + * state change is unknown. + * @NM_ACTIVE_CONNECTION_STATE_REASON_NONE: No reason was given for the active + * connection state change. + * @NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED: The active connection changed + * state because the user disconnected it. + * @NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED: The active connection + * changed state because the device it was using was disconnected. + * @NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED: The service providing the + * VPN connection was stopped. + * @NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID: The IP config of the active + * connection was invalid. + * @NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT: The connection attempt to + * the VPN service timed out. + * @NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT: A timeout occurred + * while starting the service providing the VPN connection. + * @NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED: Starting the service + * providing the VPN connection failed. + * @NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS: Necessary secrets for the + * connection were not provided. + * @NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED: Authentication to the + * server failed. + * @NM_ACTIVE_CONNECTION_STATE_REASON_CONNECTION_REMOVED: The connection was + * deleted from settings. + * @NM_ACTIVE_CONNECTION_STATE_REASON_DEPENDENCY_FAILED: Master connection of this + * connection failed to activate. + * @NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REALIZE_FAILED: Could not create the + * software device link. + * @NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REMOVED: The device this connection + * depended on disappeared. + * + * Active connection state reasons. + * + * Since: 1.8 + */ +NM_AVAILABLE_IN_1_8 +typedef enum { + NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN = 0, + NM_ACTIVE_CONNECTION_STATE_REASON_NONE = 1, + NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED = 2, + NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED = 3, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED = 4, + NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID = 5, + NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT = 6, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT = 7, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED = 8, + NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS = 9, + NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED = 10, + NM_ACTIVE_CONNECTION_STATE_REASON_CONNECTION_REMOVED = 11, + NM_ACTIVE_CONNECTION_STATE_REASON_DEPENDENCY_FAILED = 12, + NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REALIZE_FAILED = 13, + NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REMOVED = 14, +} NMActiveConnectionStateReason; + +/** * NMSecretAgentGetSecretsFlags: * @NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE: no special behavior; by default no * user interaction is allowed and requests for secrets are fulfilled from @@ -693,6 +750,7 @@ typedef enum /*< flags >*/ { #ifndef NM_VERSION_H #undef NM_AVAILABLE_IN_1_2 +#undef NM_AVAILABLE_IN_1_8 #endif #define NM_LLDP_ATTR_DESTINATION "destination" diff --git a/libnm-core/nm-vpn-dbus-interface.h b/libnm-core/nm-vpn-dbus-interface.h index 1495c95526..964abb555a 100644 --- a/libnm-core/nm-vpn-dbus-interface.h +++ b/libnm-core/nm-vpn-dbus-interface.h @@ -26,6 +26,12 @@ #ifndef __NM_VPN_DBUS_INTERFACE_H__ #define __NM_VPN_DBUS_INTERFACE_H__ +#include "nm-dbus-interface.h" + +#ifndef NM_VERSION_H +#define NM_DEPRECATED_IN_1_8_FOR(n) +#endif + /* * dbus services details */ @@ -147,20 +153,22 @@ typedef enum { * * VPN connection state reasons */ -typedef enum { - NM_VPN_CONNECTION_STATE_REASON_UNKNOWN = 0, - NM_VPN_CONNECTION_STATE_REASON_NONE, - NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED, - NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, - NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED, - NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, - NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, - 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_CONNECTION_REMOVED +NM_DEPRECATED_IN_1_8_FOR(NMActiveConnectionStateReason) +typedef enum { /*< skip >*/ + NM_VPN_CONNECTION_STATE_REASON_UNKNOWN = NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN, + NM_VPN_CONNECTION_STATE_REASON_NONE = NM_ACTIVE_CONNECTION_STATE_REASON_NONE, + NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED = NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED, + NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED = NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, + NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED = NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED, + NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID = NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, + NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT = NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, + NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT = NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, + NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED = NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, + NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS = NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, + NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED = NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED, + NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED = NM_ACTIVE_CONNECTION_STATE_REASON_CONNECTION_REMOVED, } NMVpnConnectionStateReason; +#define NMVpnConnectionStateReason NMActiveConnectionStateReason /** * NMVpnPluginFailure: @@ -177,6 +185,9 @@ typedef enum { NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG } NMVpnPluginFailure; +#ifndef NM_VERSION_H +#undef NM_DEPRECATED_IN_1_8_FOR +#endif /*** Generic config ***/ diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 4b3d02fdfa..96b77d4dc9 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1146,6 +1146,8 @@ global: libnm_1_8_0 { global: + nm_active_connection_state_reason_get_type; + nm_active_connection_get_state_reason; nm_connection_get_setting_dummy; nm_device_dummy_get_type; nm_ip_route_get_variant_attribute_spec; diff --git a/libnm/nm-active-connection.c b/libnm/nm-active-connection.c index 6a823403c4..f21fd10495 100644 --- a/libnm/nm-active-connection.c +++ b/libnm/nm-active-connection.c @@ -37,6 +37,8 @@ #include "nm-ip6-config.h" #include "nm-remote-connection.h" +#include "introspection/org.freedesktop.NetworkManager.Connection.Active.h" + G_DEFINE_TYPE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT); #define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate)) @@ -57,6 +59,7 @@ typedef struct { NMDhcpConfig *dhcp6_config; gboolean is_vpn; NMDevice *master; + NMActiveConnectionStateReason reason; } NMActiveConnectionPrivate; enum { @@ -80,6 +83,14 @@ enum { LAST_PROP }; +enum { + STATE_CHANGED, + + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + /** * nm_active_connection_get_connection: * @connection: a #NMActiveConnection @@ -205,6 +216,24 @@ nm_active_connection_get_state (NMActiveConnection *connection) } /** + * nm_active_connection_get_state_reason: + * @connection: a #NMActiveConnection + * + * Gets the reason for active connection's state. + * + * Returns: the reason + * + * Since: 1.8 + **/ +NMActiveConnectionStateReason +nm_active_connection_get_state_reason (NMActiveConnection *connection) +{ + g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN); + + return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->reason; +} + +/** * nm_active_connection_get_default: * @connection: a #NMActiveConnection * @@ -351,9 +380,35 @@ nm_active_connection_init (NMActiveConnection *connection) } static void +state_changed_proxy (NMDBusActiveConnectionProxy *proxy, + NMActiveConnectionState state, + NMActiveConnectionStateReason reason, + gpointer user_data) +{ + NMActiveConnection *connection = NM_ACTIVE_CONNECTION (user_data); + NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection); + + priv->state = state; + priv->reason = reason; + g_signal_emit (connection, signals[STATE_CHANGED], 0, state, reason); +} + +static void +constructed (GObject *object) +{ + GDBusProxy *proxy; + + proxy = _nm_object_get_proxy (NM_OBJECT (object), NM_DBUS_INTERFACE_ACTIVE_CONNECTION); + g_signal_connect (proxy, "state-changed", + G_CALLBACK (state_changed_proxy), object); + g_object_unref (proxy); +} + +static void dispose (GObject *object) { NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object); + GDBusProxy *proxy; g_clear_pointer (&priv->devices, g_ptr_array_unref); @@ -364,6 +419,12 @@ dispose (GObject *object) g_clear_object (&priv->ip6_config); g_clear_object (&priv->dhcp6_config); + proxy = _nm_object_get_proxy (NM_OBJECT (object), NM_DBUS_INTERFACE_ACTIVE_CONNECTION); + if (proxy) { + g_signal_handlers_disconnect_by_data (proxy, object); + g_object_unref (proxy); + } + G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object); } @@ -503,6 +564,7 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class) /* virtual methods */ object_class->get_property = get_property; + object_class->constructed = constructed; object_class->dispose = dispose; object_class->finalize = finalize; @@ -693,4 +755,13 @@ nm_active_connection_class_init (NMActiveConnectionClass *ap_class) NM_TYPE_DEVICE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + + /* signals */ + signals[STATE_CHANGED] = + g_signal_new ("state-changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 2, + G_TYPE_UINT, G_TYPE_UINT); } diff --git a/libnm/nm-active-connection.h b/libnm/nm-active-connection.h index 8478b3dd7c..23cd737246 100644 --- a/libnm/nm-active-connection.h +++ b/libnm/nm-active-connection.h @@ -69,21 +69,23 @@ typedef struct { GType nm_active_connection_get_type (void); -NMRemoteConnection *nm_active_connection_get_connection (NMActiveConnection *connection); -const char *nm_active_connection_get_id (NMActiveConnection *connection); -const char *nm_active_connection_get_uuid (NMActiveConnection *connection); -const char *nm_active_connection_get_connection_type (NMActiveConnection *connection); -const char *nm_active_connection_get_specific_object_path (NMActiveConnection *connection); -const GPtrArray *nm_active_connection_get_devices (NMActiveConnection *connection); -NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *connection); -NMDevice *nm_active_connection_get_master (NMActiveConnection *connection); -gboolean nm_active_connection_get_default (NMActiveConnection *connection); -NMIPConfig *nm_active_connection_get_ip4_config (NMActiveConnection *connection); -NMDhcpConfig *nm_active_connection_get_dhcp4_config (NMActiveConnection *connection); -gboolean nm_active_connection_get_default6 (NMActiveConnection *connection); -NMIPConfig *nm_active_connection_get_ip6_config (NMActiveConnection *connection); -NMDhcpConfig *nm_active_connection_get_dhcp6_config (NMActiveConnection *connection); -gboolean nm_active_connection_get_vpn (NMActiveConnection *connection); +NMRemoteConnection *nm_active_connection_get_connection (NMActiveConnection *connection); +const char *nm_active_connection_get_id (NMActiveConnection *connection); +const char *nm_active_connection_get_uuid (NMActiveConnection *connection); +const char *nm_active_connection_get_connection_type (NMActiveConnection *connection); +const char *nm_active_connection_get_specific_object_path (NMActiveConnection *connection); +const GPtrArray *nm_active_connection_get_devices (NMActiveConnection *connection); +NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *connection); +NM_AVAILABLE_IN_1_8 +NMActiveConnectionStateReason nm_active_connection_get_state_reason (NMActiveConnection *connection); +NMDevice *nm_active_connection_get_master (NMActiveConnection *connection); +gboolean nm_active_connection_get_default (NMActiveConnection *connection); +NMIPConfig *nm_active_connection_get_ip4_config (NMActiveConnection *connection); +NMDhcpConfig *nm_active_connection_get_dhcp4_config (NMActiveConnection *connection); +gboolean nm_active_connection_get_default6 (NMActiveConnection *connection); +NMIPConfig *nm_active_connection_get_ip6_config (NMActiveConnection *connection); +NMDhcpConfig *nm_active_connection_get_dhcp6_config (NMActiveConnection *connection); +gboolean nm_active_connection_get_vpn (NMActiveConnection *connection); G_END_DECLS diff --git a/libnm/nm-client.c b/libnm/nm-client.c index ccc96e947e..308402ee51 100644 --- a/libnm/nm-client.c +++ b/libnm/nm-client.c @@ -45,6 +45,7 @@ #include "introspection/org.freedesktop.NetworkManager.Settings.h" #include "introspection/org.freedesktop.NetworkManager.Settings.Connection.h" #include "introspection/org.freedesktop.NetworkManager.VPN.Connection.h" +#include "introspection/org.freedesktop.NetworkManager.Connection.Active.h" #include "nm-access-point.h" #include "nm-active-connection.h" @@ -2008,6 +2009,8 @@ proxy_type (GDBusObjectManagerClient *manager, return NMDBUS_TYPE_DNS_MANAGER_PROXY; else if (strcmp (interface_name, NM_DBUS_INTERFACE_VPN_CONNECTION) == 0) return NMDBUS_TYPE_VPN_CONNECTION_PROXY; + else if (strcmp (interface_name, NM_DBUS_INTERFACE_ACTIVE_CONNECTION) == 0) + return NMDBUS_TYPE_ACTIVE_CONNECTION_PROXY; /* Use a generic D-Bus Proxy whenever we can. The typed GDBusProxy * subclasses actually use quite some memory, so they're better avoided. */ diff --git a/libnm/nm-object.c b/libnm/nm-object.c index 048905fd69..95346e06e9 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -129,11 +129,16 @@ GDBusProxy * _nm_object_get_proxy (NMObject *object, const char *interface) { + NMObjectPrivate *priv; GDBusInterface *proxy; g_return_val_if_fail (NM_IS_OBJECT (object), NULL); - proxy = g_dbus_object_get_interface (NM_OBJECT_GET_PRIVATE (object)->object, interface); + priv = NM_OBJECT_GET_PRIVATE (object); + if (priv->object == NULL) + return NULL; + + proxy = g_dbus_object_get_interface (priv->object, interface); g_return_val_if_fail (proxy != NULL, NULL); return G_DBUS_PROXY (proxy); diff --git a/libnm/nm-vpn-connection.c b/libnm/nm-vpn-connection.c index a91a6f6952..b773096eb8 100644 --- a/libnm/nm-vpn-connection.c +++ b/libnm/nm-vpn-connection.c @@ -229,3 +229,9 @@ nm_vpn_connection_class_init (NMVpnConnectionClass *connection_class) G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); } + +GType +nm_vpn_connection_state_reason_get_type (void) +{ + return nm_active_connection_state_reason_get_type (); +} diff --git a/libnm/nm-vpn-connection.h b/libnm/nm-vpn-connection.h index 0857035a5f..23b17d963a 100644 --- a/libnm/nm-vpn-connection.h +++ b/libnm/nm-vpn-connection.h @@ -41,6 +41,9 @@ G_BEGIN_DECLS #define NM_VPN_CONNECTION_VPN_STATE "vpn-state" #define NM_VPN_CONNECTION_BANNER "banner" +GType nm_vpn_connection_state_reason_get_type (void) G_GNUC_CONST; +#define NM_TYPE_VPN_CONNECTION_STATE_REASON (nm_vpn_connection_state_reason_get_type ()) + /** * NMVpnConnection: */ @@ -54,7 +57,7 @@ typedef struct { /* Signals */ void (*vpn_state_changed) (NMVpnConnection *connection, NMVpnConnectionState state, - NMVpnConnectionStateReason reason); + NMActiveConnectionStateReason reason); /*< private >*/ gpointer padding[4]; diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 802900f5bc..10f870f3ff 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -9029,7 +9029,9 @@ static void _clear_queued_act_request (NMDevicePrivate *priv) { if (priv->queued_act_request) { - nm_active_connection_set_state ((NMActiveConnection *) priv->queued_act_request, NM_ACTIVE_CONNECTION_STATE_DEACTIVATED); + nm_active_connection_set_state ((NMActiveConnection *) priv->queued_act_request, + NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, + NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED); g_clear_object (&priv->queued_act_request); } } @@ -12192,7 +12194,7 @@ _set_state_full (NMDevice *self, _notify (self, PROP_STATE); _notify (self, PROP_STATE_REASON); - g_signal_emit (self, signals[STATE_CHANGED], 0, state, old_state, reason); + g_signal_emit (self, signals[STATE_CHANGED], 0, (guint) state, (guint) old_state, (guint) reason); /* Post-process the event after internal notification */ diff --git a/src/nm-act-request.c b/src/nm-act-request.c index e4f6492365..6d8bb0652e 100644 --- a/src/nm-act-request.c +++ b/src/nm-act-request.c @@ -397,6 +397,7 @@ device_state_changed (NMActiveConnection *active, { NMActiveConnectionState cur_ac_state = nm_active_connection_get_state (active); NMActiveConnectionState ac_state = NM_ACTIVE_CONNECTION_STATE_UNKNOWN; + NMActiveConnectionStateReason ac_state_reason = NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN; /* Decide which device state changes to handle when this active connection * is not the device's current request. Two cases here: (a) the AC is @@ -451,6 +452,7 @@ device_state_changed (NMActiveConnection *active, case NM_DEVICE_STATE_UNMANAGED: case NM_DEVICE_STATE_UNAVAILABLE: ac_state = NM_ACTIVE_CONNECTION_STATE_DEACTIVATED; + ac_state_reason = NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED; g_signal_handlers_disconnect_by_func (device, G_CALLBACK (device_notify), active); break; @@ -464,7 +466,7 @@ device_state_changed (NMActiveConnection *active, nm_active_connection_set_default6 (active, FALSE); } - nm_active_connection_set_state (active, ac_state); + nm_active_connection_set_state (active, ac_state, ac_state_reason); } static void @@ -486,7 +488,9 @@ master_failed (NMActiveConnection *self) } /* If no device, or the device wasn't active, just move to deactivated state */ - nm_active_connection_set_state (self, NM_ACTIVE_CONNECTION_STATE_DEACTIVATED); + nm_active_connection_set_state (self, + NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, + NM_ACTIVE_CONNECTION_STATE_REASON_DEPENDENCY_FAILED); } /*****************************************************************************/ diff --git a/src/nm-active-connection.c b/src/nm-active-connection.c index 320ba45828..ee28f0f255 100644 --- a/src/nm-active-connection.c +++ b/src/nm-active-connection.c @@ -95,6 +95,7 @@ enum { DEVICE_CHANGED, DEVICE_METERED_CHANGED, PARENT_ACTIVE, + STATE_CHANGED, LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -209,7 +210,8 @@ nm_active_connection_get_state (NMActiveConnection *self) void nm_active_connection_set_state (NMActiveConnection *self, - NMActiveConnectionState new_state) + NMActiveConnectionState new_state, + NMActiveConnectionStateReason reason) { NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); NMActiveConnectionState old_state; @@ -236,6 +238,7 @@ nm_active_connection_set_state (NMActiveConnection *self, old_state = priv->state; priv->state = new_state; priv->state_set = TRUE; + g_signal_emit (self, signals[STATE_CHANGED], 0, (guint) new_state, (guint) reason); _notify (self, PROP_STATE); check_master_ready (self); @@ -1418,6 +1421,13 @@ nm_active_connection_class_init (NMActiveConnectionClass *ac_class) NULL, NULL, NULL, G_TYPE_NONE, 1, NM_TYPE_ACTIVE_CONNECTION); + signals[STATE_CHANGED] = + g_signal_new (NM_ACTIVE_CONNECTION_STATE_CHANGED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); + nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (ac_class), NMDBUS_TYPE_ACTIVE_CONNECTION_SKELETON, NULL); diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h index ba231c3077..8d3478c79d 100644 --- a/src/nm-active-connection.h +++ b/src/nm-active-connection.h @@ -57,6 +57,9 @@ #define NM_ACTIVE_CONNECTION_INT_MASTER_READY "int-master-ready" #define NM_ACTIVE_CONNECTION_INT_ACTIVATION_TYPE "int-activation-type" +/* Signals */ +#define NM_ACTIVE_CONNECTION_STATE_CHANGED "state-changed" + /* Internal signals*/ #define NM_ACTIVE_CONNECTION_DEVICE_CHANGED "device-changed" #define NM_ACTIVE_CONNECTION_DEVICE_METERED_CHANGED "device-metered-changed" @@ -139,7 +142,8 @@ gboolean nm_active_connection_get_default6 (NMActiveConnection *self); NMActiveConnectionState nm_active_connection_get_state (NMActiveConnection *self); void nm_active_connection_set_state (NMActiveConnection *self, - NMActiveConnectionState state); + NMActiveConnectionState state, + NMActiveConnectionStateReason reason); NMDevice * nm_active_connection_get_device (NMActiveConnection *self); diff --git a/src/nm-manager.c b/src/nm-manager.c index 649f8464fd..1003ebbb99 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -3061,12 +3061,16 @@ active_connection_parent_active (NMActiveConnection *active, } else { _LOGW (LOGD_CORE, "Could not realize device '%s': %s", nm_device_get_iface (device), error->message); - nm_active_connection_set_state (active, NM_ACTIVE_CONNECTION_STATE_DEACTIVATED); + nm_active_connection_set_state (active, + NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, + NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REALIZE_FAILED); } } else { _LOGW (LOGD_CORE, "The parent connection device '%s' depended on disappeared.", nm_device_get_iface (device)); - nm_active_connection_set_state (active, NM_ACTIVE_CONNECTION_STATE_DEACTIVATED); + nm_active_connection_set_state (active, + NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, + NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_REMOVED); } } @@ -3396,8 +3400,12 @@ _internal_activation_failed (NMManager *self, error_desc); if (nm_active_connection_get_state (active) <= NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { - nm_active_connection_set_state (active, NM_ACTIVE_CONNECTION_STATE_DEACTIVATING); - nm_active_connection_set_state (active, NM_ACTIVE_CONNECTION_STATE_DEACTIVATED); + nm_active_connection_set_state (active, + NM_ACTIVE_CONNECTION_STATE_DEACTIVATING, + NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN); + nm_active_connection_set_state (active, + NM_ACTIVE_CONNECTION_STATE_DEACTIVATED, + NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN); } } @@ -4003,10 +4011,10 @@ nm_manager_deactivate_connection (NMManager *manager, gboolean success = FALSE; if (NM_IS_VPN_CONNECTION (active)) { - NMVpnConnectionStateReason vpn_reason = NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED; + NMActiveConnectionStateReason vpn_reason = NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED; if (nm_device_state_reason_check (reason) == NM_DEVICE_STATE_REASON_CONNECTION_REMOVED) - vpn_reason = NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED; + vpn_reason = NM_ACTIVE_CONNECTION_STATE_REASON_CONNECTION_REMOVED; if (nm_vpn_connection_deactivate (NM_VPN_CONNECTION (active), vpn_reason, FALSE)) success = TRUE; diff --git a/src/nm-policy.c b/src/nm-policy.c index 66c9895c8d..fc791db6b3 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1820,7 +1820,7 @@ static void vpn_connection_state_changed (NMVpnConnection *vpn, NMVpnConnectionState new_state, NMVpnConnectionState old_state, - NMVpnConnectionStateReason reason, + NMActiveConnectionStateReason reason, NMPolicy *self) { if (new_state == NM_VPN_CONNECTION_STATE_ACTIVATED) diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c index 912972cb90..223974ca4c 100644 --- a/src/vpn/nm-vpn-connection.c +++ b/src/vpn/nm-vpn-connection.c @@ -109,7 +109,7 @@ typedef struct { VpnState vpn_state; guint dispatcher_id; - NMVpnConnectionStateReason failure_reason; + NMActiveConnectionStateReason failure_reason; NMVpnServiceState service_state; guint start_timeout; @@ -159,13 +159,13 @@ struct _NMVpnConnectionClass { /* Signals */ void (*vpn_state_changed) (NMVpnConnection *self, NMVpnConnectionState new_state, - NMVpnConnectionStateReason reason); + NMActiveConnectionStateReason reason); /* not exported over D-Bus */ void (*internal_state_changed) (NMVpnConnection *self, NMVpnConnectionState new_state, NMVpnConnectionState old_state, - NMVpnConnectionStateReason reason); + NMActiveConnectionStateReason reason); void (*internal_failed_retry) (NMVpnConnection *self); }; @@ -189,7 +189,7 @@ static void plugin_interactive_secrets_required (NMVpnConnection *self, static void _set_vpn_state (NMVpnConnection *self, VpnState vpn_state, - NMVpnConnectionStateReason reason, + NMActiveConnectionStateReason reason, gboolean quitting); /*****************************************************************************/ @@ -447,7 +447,7 @@ dispatcher_pre_down_done (guint call_id, gpointer user_data) NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); priv->dispatcher_id = 0; - _set_vpn_state (self, STATE_DISCONNECTED, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_DISCONNECTED, NM_ACTIVE_CONNECTION_STATE_REASON_USER_DISCONNECTED, FALSE); } static void @@ -457,7 +457,7 @@ dispatcher_pre_up_done (guint call_id, gpointer user_data) NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); priv->dispatcher_id = 0; - _set_vpn_state (self, STATE_ACTIVATED, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_ACTIVATED, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); } static void @@ -474,7 +474,7 @@ dispatcher_cleanup (NMVpnConnection *self) static void _set_vpn_state (NMVpnConnection *self, VpnState vpn_state, - NMVpnConnectionStateReason reason, + NMActiveConnectionStateReason reason, gboolean quitting) { NMVpnConnectionPrivate *priv; @@ -500,7 +500,8 @@ _set_vpn_state (NMVpnConnection *self, /* Update active connection base class state */ nm_active_connection_set_state (NM_ACTIVE_CONNECTION (self), - _state_to_ac_state (vpn_state)); + _state_to_ac_state (vpn_state), + reason); /* Clear any in-progress secrets request */ cancel_get_secrets (self); @@ -679,12 +680,12 @@ device_state_changed (NMActiveConnection *active, if (new_state <= NM_DEVICE_STATE_DISCONNECTED) { _set_vpn_state (NM_VPN_CONNECTION (active), STATE_DISCONNECTED, - NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, + NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, FALSE); } else if (new_state == NM_DEVICE_STATE_FAILED) { _set_vpn_state (NM_VPN_CONNECTION (active), STATE_FAILED, - NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, + NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, FALSE); } @@ -845,13 +846,13 @@ plugin_failed (NMVpnConnection *self, guint reason) switch (reason) { case NM_VPN_PLUGIN_FAILURE_LOGIN_FAILED: - priv->failure_reason = NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED; + priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_LOGIN_FAILED; break; case NM_VPN_PLUGIN_FAILURE_BAD_IP_CONFIG: - priv->failure_reason = NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID; + priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID; break; default: - priv->failure_reason = NM_VPN_CONNECTION_STATE_REASON_UNKNOWN; + priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN; break; } } @@ -884,23 +885,6 @@ NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_vpn_state_to_string, VpnState, ); #define vpn_state_to_string(state) NM_UTILS_LOOKUP_STR (_vpn_state_to_string, state) -NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_vpn_reason_to_string, NMVpnConnectionStateReason, - NM_UTILS_LOOKUP_DEFAULT (NULL), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_UNKNOWN, "unknown"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_NONE, "none"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED, "user-disconnected"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED, "device-disconnected"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED, "service-stopped"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, "ip-config-invalid"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, "connect-timeout"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, "service-start-timeout"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED, "service-start-failed"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS, "no-secrets"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_LOGIN_FAILED, "login-failed"), - NM_UTILS_LOOKUP_STR_ITEM (NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED, "connection-removed"), -); -#define vpn_reason_to_string(reason) NM_UTILS_LOOKUP_STR (_vpn_reason_to_string, reason) - static void plugin_state_changed (NMVpnConnection *self, NMVpnServiceState new_service_state) { @@ -920,12 +904,10 @@ plugin_state_changed (NMVpnConnection *self, NMVpnServiceState new_service_state if ((priv->vpn_state >= STATE_WAITING) && (priv->vpn_state <= STATE_ACTIVATED)) { VpnState old_state = priv->vpn_state; - _LOGI ("VPN plugin: state change reason: %s (%d)", - vpn_reason_to_string (priv->failure_reason), priv->failure_reason); _set_vpn_state (self, STATE_FAILED, priv->failure_reason, FALSE); /* Reset the failure reason */ - priv->failure_reason = NM_VPN_CONNECTION_STATE_REASON_UNKNOWN; + priv->failure_reason = NM_ACTIVE_CONNECTION_STATE_REASON_UNKNOWN; /* If the connection failed, the service cannot persist, but the * connection can persist, ask listeners to re-activate the connection. @@ -938,7 +920,7 @@ plugin_state_changed (NMVpnConnection *self, NMVpnServiceState new_service_state } else if (new_service_state == NM_VPN_SERVICE_STATE_STARTING && old_service_state == NM_VPN_SERVICE_STATE_STARTED) { /* The VPN service got disconnected and is attempting to reconnect */ - _set_vpn_state (self, STATE_CONNECT, NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, FALSE); + _set_vpn_state (self, STATE_CONNECT, NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, FALSE); } } @@ -1130,7 +1112,7 @@ nm_vpn_connection_apply_config (NMVpnConnection *self) _LOGI ("VPN connection: (IP Config Get) complete"); if (priv->vpn_state < STATE_PRE_UP) - _set_vpn_state (self, STATE_PRE_UP, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_PRE_UP, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); return TRUE; } @@ -1143,7 +1125,7 @@ _cleanup_failed_config (NMVpnConnection *self) nm_exported_object_clear_and_unexport (&priv->ip6_config); _LOGW ("VPN connection: did not receive valid IP config information"); - _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, FALSE); + _set_vpn_state (self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_IP_CONFIG_INVALID, FALSE); } static void @@ -1348,7 +1330,7 @@ nm_vpn_connection_config_get (NMVpnConnection *self, GVariant *dict) _LOGI ("VPN connection: (IP Config Get) reply received."); if (priv->vpn_state == STATE_CONNECT) - _set_vpn_state (self, STATE_IP_CONFIG_GET, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_IP_CONFIG_GET, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); if (!process_generic_config (self, dict)) return; @@ -1408,7 +1390,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) g_return_if_fail (dict && g_variant_is_of_type (dict, G_VARIANT_TYPE_VARDICT)); if (priv->vpn_state == STATE_CONNECT) - _set_vpn_state (self, STATE_IP_CONFIG_GET, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_IP_CONFIG_GET, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); if (priv->vpn_state > STATE_ACTIVATED) { _LOGI ("VPN connection: (IP4 Config Get) ignoring, the connection is no longer active"); @@ -1582,7 +1564,7 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict) _LOGI ("VPN connection: (IP6 Config Get) reply received"); if (priv->vpn_state == STATE_CONNECT) - _set_vpn_state (self, STATE_IP_CONFIG_GET, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_IP_CONFIG_GET, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); if (priv->vpn_state > STATE_ACTIVATED) { _LOGI ("VPN connection: (IP6 Config Get) ignoring, the connection is no longer active"); @@ -1735,7 +1717,7 @@ connect_timeout_cb (gpointer user_data) if (priv->vpn_state == STATE_CONNECT || priv->vpn_state == STATE_IP_CONFIG_GET) { _LOGW ("VPN connection: connect timeout exceeded."); - _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, FALSE); + _set_vpn_state (self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_CONNECT_TIMEOUT, FALSE); } return FALSE; @@ -1785,7 +1767,7 @@ connect_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_data) g_dbus_error_strip_remote_error (error); _LOGW ("VPN connection: failed to connect: '%s'", error->message); - _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED, FALSE); + _set_vpn_state (self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, FALSE); } else connect_success (self); } @@ -1823,7 +1805,7 @@ connect_interactive_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_d g_dbus_error_strip_remote_error (error); _LOGW ("VPN connection: failed to connect interactively: '%s'", error->message); - _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED, FALSE); + _set_vpn_state (self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, FALSE); } else connect_success (self); } @@ -1898,7 +1880,7 @@ really_activate (NMVpnConnection *self, const char *username) self); } - _set_vpn_state (self, STATE_CONNECT, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_CONNECT, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); } static void @@ -2004,7 +1986,7 @@ _name_owner_changed (GObject *object, _nm_dbus_signal_connect (priv->proxy, "Ip6Config", G_VARIANT_TYPE ("(a{sv})"), G_CALLBACK (ip6_config_cb), self); - _set_vpn_state (self, STATE_NEED_AUTH, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_NEED_AUTH, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); /* Kick off the secrets requests; first we get existing system secrets * and ask the plugin if these are sufficient, next we get all existing @@ -2016,7 +1998,7 @@ _name_owner_changed (GObject *object, /* service went away */ priv->service_running = FALSE; _LOGI ("VPN service disappeared"); - nm_vpn_connection_disconnect (self, NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED, FALSE); + nm_vpn_connection_disconnect (self, NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_STOPPED, FALSE); } g_free (owner); @@ -2031,7 +2013,7 @@ _daemon_exec_timeout (gpointer data) _LOGW ("Timed out waiting for the service to start"); priv->start_timeout = 0; - nm_vpn_connection_disconnect (self, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, FALSE); + nm_vpn_connection_disconnect (self, NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_TIMEOUT, FALSE); return G_SOURCE_REMOVE; } @@ -2158,7 +2140,7 @@ on_proxy_acquired (GObject *object, GAsyncResult *result, gpointer user_data) error->message); _set_vpn_state (self, STATE_FAILED, - NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED, + NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, FALSE); return; } @@ -2176,7 +2158,7 @@ on_proxy_acquired (GObject *object, GAsyncResult *result, gpointer user_data) _LOGW ("Could not launch the VPN service. error: %s.", error->message); - nm_vpn_connection_disconnect (self, NM_VPN_CONNECTION_STATE_REASON_SERVICE_START_FAILED, FALSE); + nm_vpn_connection_disconnect (self, NM_ACTIVE_CONNECTION_STATE_REASON_SERVICE_START_FAILED, FALSE); } } @@ -2226,7 +2208,7 @@ nm_vpn_connection_activate (NMVpnConnection *self, (GAsyncReadyCallback) on_proxy_acquired, self); - _set_vpn_state (self, STATE_PREPARE, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_PREPARE, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); } NMVpnConnectionState @@ -2350,7 +2332,7 @@ nm_vpn_connection_get_ip6_internal_gateway (NMVpnConnection *self) void nm_vpn_connection_disconnect (NMVpnConnection *self, - NMVpnConnectionStateReason reason, + NMActiveConnectionStateReason reason, gboolean quitting) { g_return_if_fail (NM_IS_VPN_CONNECTION (self)); @@ -2360,7 +2342,7 @@ nm_vpn_connection_disconnect (NMVpnConnection *self, gboolean nm_vpn_connection_deactivate (NMVpnConnection *self, - NMVpnConnectionStateReason reason, + NMActiveConnectionStateReason reason, gboolean quitting) { NMVpnConnectionPrivate *priv; @@ -2399,7 +2381,7 @@ plugin_need_secrets_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_d _LOGE ("plugin NeedSecrets request #%d failed: %s", priv->secrets_idx + 1, error->message); - _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); + _set_vpn_state (self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); return; } @@ -2415,7 +2397,7 @@ plugin_need_secrets_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_d /* More secrets required */ if (priv->secrets_idx == SECRETS_REQ_NEW) { _LOGE ("final secrets request failed to provide sufficient secrets"); - _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); + _set_vpn_state (self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); } else { _LOGD ("service indicated additional secrets required"); get_secrets (self, priv->secrets_idx + 1, NULL); @@ -2441,9 +2423,9 @@ plugin_new_secrets_cb (GDBusProxy *proxy, GAsyncResult *result, gpointer user_da g_dbus_error_strip_remote_error (error); _LOGE ("sending new secrets to the plugin failed: %s", error->message); - _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); + _set_vpn_state (self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); } else - _set_vpn_state (self, STATE_CONNECT, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_CONNECT, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); } static void @@ -2473,7 +2455,7 @@ get_secrets_cb (NMSettingsConnection *connection, if (error && priv->secrets_idx >= SECRETS_REQ_NEW) { _LOGE ("Failed to request VPN secrets #%d: %s", priv->secrets_idx + 1, error->message); - _set_vpn_state (self, STATE_FAILED, NM_VPN_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); + _set_vpn_state (self, STATE_FAILED, NM_ACTIVE_CONNECTION_STATE_REASON_NO_SECRETS, FALSE); return; } @@ -2574,7 +2556,7 @@ plugin_interactive_secrets_required (NMVpnConnection *self, priv->vpn_state == STATE_NEED_AUTH); priv->secrets_idx = SECRETS_REQ_INTERACTIVE; - _set_vpn_state (self, STATE_NEED_AUTH, NM_VPN_CONNECTION_STATE_REASON_NONE, FALSE); + _set_vpn_state (self, STATE_NEED_AUTH, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); /* Copy hints and add message to the end */ hints = g_malloc0 (sizeof (char *) * (secrets_len + 2)); diff --git a/src/vpn/nm-vpn-connection.h b/src/vpn/nm-vpn-connection.h index 8393f08125..038d0efded 100644 --- a/src/vpn/nm-vpn-connection.h +++ b/src/vpn/nm-vpn-connection.h @@ -62,10 +62,10 @@ const char * nm_vpn_connection_get_banner (NMVpnConnection *self); const gchar * nm_vpn_connection_get_service (NMVpnConnection *self); gboolean nm_vpn_connection_deactivate (NMVpnConnection *self, - NMVpnConnectionStateReason reason, + NMActiveConnectionStateReason reason, gboolean quitting); void nm_vpn_connection_disconnect (NMVpnConnection *self, - NMVpnConnectionStateReason reason, + NMActiveConnectionStateReason reason, gboolean quitting); NMProxyConfig * nm_vpn_connection_get_proxy_config (NMVpnConnection *self); |