diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2017-10-16 19:51:16 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2017-10-16 19:51:16 +0200 |
commit | 1c7281c77129f5e23bd20d8c88964c3fccd4353c (patch) | |
tree | 6a49b2b9bf96542eda78fcfa67f23d141ad7f939 | |
parent | 802116db43381f67b873e7e0283485c4ff035fc9 (diff) | |
parent | 90aa8a8b7bf8d23cc9f45e886f7377663f47c6ff (diff) | |
download | NetworkManager-1c7281c77129f5e23bd20d8c88964c3fccd4353c.tar.gz |
clients: merge branch 'bg/tui-activation-rh1500651'
https://bugzilla.redhat.com/show_bug.cgi?id=1500651
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | clients/cli/common.c | 249 | ||||
-rw-r--r-- | clients/cli/common.h | 4 | ||||
-rw-r--r-- | clients/cli/connections.c | 125 | ||||
-rw-r--r-- | clients/common/nm-client-utils.c | 297 | ||||
-rw-r--r-- | clients/common/nm-client-utils.h | 12 | ||||
-rw-r--r-- | clients/tui/nmt-connect-connection-list.c | 2 | ||||
-rw-r--r-- | clients/tui/nmtui-connect.c | 74 |
8 files changed, 384 insertions, 385 deletions
diff --git a/Makefile.am b/Makefile.am index 7bce597e99..06cceb344e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3191,7 +3191,9 @@ clients_common_libnmc_base_la_SOURCES = \ clients/common/nm-secret-agent-simple.c \ clients/common/nm-secret-agent-simple.h \ clients/common/nm-vpn-helpers.c \ - clients/common/nm-vpn-helpers.h + clients/common/nm-vpn-helpers.h \ + clients/common/nm-client-utils.c \ + clients/common/nm-client-utils.h clients_common_libnmc_base_la_CPPFLAGS = \ $(clients_cppflags) \ @@ -3242,8 +3244,6 @@ clients_common_libnmc_la_SOURCES = \ shared/nm-meta-setting.c \ shared/nm-meta-setting.h \ \ - clients/common/nm-client-utils.c \ - clients/common/nm-client-utils.h \ clients/common/nm-meta-setting-desc.c \ clients/common/nm-meta-setting-desc.h \ clients/common/nm-meta-setting-access.c \ diff --git a/clients/cli/common.c b/clients/cli/common.c index 5d942e4637..0f5dff4baf 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -438,255 +438,6 @@ print_dhcp6_config (NMDhcpConfig *dhcp6, return FALSE; } -const char * -nmc_device_state_to_string (NMDeviceState state) -{ - switch (state) { - case NM_DEVICE_STATE_UNMANAGED: - return _("unmanaged"); - case NM_DEVICE_STATE_UNAVAILABLE: - return _("unavailable"); - case NM_DEVICE_STATE_DISCONNECTED: - return _("disconnected"); - case NM_DEVICE_STATE_PREPARE: - return _("connecting (prepare)"); - case NM_DEVICE_STATE_CONFIG: - return _("connecting (configuring)"); - case NM_DEVICE_STATE_NEED_AUTH: - return _("connecting (need authentication)"); - case NM_DEVICE_STATE_IP_CONFIG: - return _("connecting (getting IP configuration)"); - case NM_DEVICE_STATE_IP_CHECK: - return _("connecting (checking IP connectivity)"); - case NM_DEVICE_STATE_SECONDARIES: - return _("connecting (starting secondary connections)"); - case NM_DEVICE_STATE_ACTIVATED: - return _("connected"); - case NM_DEVICE_STATE_DEACTIVATING: - return _("deactivating"); - case NM_DEVICE_STATE_FAILED: - return _("connection failed"); - default: - return _("unknown"); - } -} - -const char * -nmc_device_metered_to_string (NMMetered value) -{ - switch (value) { - case NM_METERED_YES: - return _("yes"); - case NM_METERED_NO: - return _("no"); - case NM_METERED_GUESS_YES: - return _("yes (guessed)"); - case NM_METERED_GUESS_NO: - return _("no (guessed)"); - default: - return _("unknown"); - } -} - -const char * -nmc_device_reason_to_string (NMDeviceStateReason reason) -{ - switch (reason) { - case NM_DEVICE_STATE_REASON_NONE: - return _("No reason given"); - - case NM_DEVICE_STATE_REASON_UNKNOWN: - return _("Unknown error"); - - case NM_DEVICE_STATE_REASON_NOW_MANAGED: - return _("Device is now managed"); - - case NM_DEVICE_STATE_REASON_NOW_UNMANAGED: - return _("Device is now unmanaged"); - - case NM_DEVICE_STATE_REASON_CONFIG_FAILED: - return _("The device could not be readied for configuration"); - - case NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE: - return _("IP configuration could not be reserved (no available address, timeout, etc.)"); - - case NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED: - return _("The IP configuration is no longer valid"); - - case NM_DEVICE_STATE_REASON_NO_SECRETS: - return _("Secrets were required, but not provided"); - - case NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT: - return _("802.1X supplicant disconnected"); - - case NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED: - return _("802.1X supplicant configuration failed"); - - case NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED: - return _("802.1X supplicant failed"); - - case NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT: - return _("802.1X supplicant took too long to authenticate"); - - case NM_DEVICE_STATE_REASON_PPP_START_FAILED: - return _("PPP service failed to start"); - - case NM_DEVICE_STATE_REASON_PPP_DISCONNECT: - return _("PPP service disconnected"); - - case NM_DEVICE_STATE_REASON_PPP_FAILED: - return _("PPP failed"); - - case NM_DEVICE_STATE_REASON_DHCP_START_FAILED: - return _("DHCP client failed to start"); - - case NM_DEVICE_STATE_REASON_DHCP_ERROR: - return _("DHCP client error"); - - case NM_DEVICE_STATE_REASON_DHCP_FAILED: - return _("DHCP client failed"); - - case NM_DEVICE_STATE_REASON_SHARED_START_FAILED: - return _("Shared connection service failed to start"); - - case NM_DEVICE_STATE_REASON_SHARED_FAILED: - return _("Shared connection service failed"); - - case NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED: - return _("AutoIP service failed to start"); - - case NM_DEVICE_STATE_REASON_AUTOIP_ERROR: - return _("AutoIP service error"); - - case NM_DEVICE_STATE_REASON_AUTOIP_FAILED: - return _("AutoIP service failed"); - - case NM_DEVICE_STATE_REASON_MODEM_BUSY: - return _("The line is busy"); - - case NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE: - return _("No dial tone"); - - case NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER: - return _("No carrier could be established"); - - case NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT: - return _("The dialing request timed out"); - - case NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED: - return _("The dialing attempt failed"); - - case NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED: - return _("Modem initialization failed"); - - case NM_DEVICE_STATE_REASON_GSM_APN_FAILED: - return _("Failed to select the specified APN"); - - case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING: - return _("Not searching for networks"); - - case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED: - return _("Network registration denied"); - - case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT: - return _("Network registration timed out"); - - case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED: - return _("Failed to register with the requested network"); - - case NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED: - return _("PIN check failed"); - - case NM_DEVICE_STATE_REASON_FIRMWARE_MISSING: - return _("Necessary firmware for the device may be missing"); - - case NM_DEVICE_STATE_REASON_REMOVED: - return _("The device was removed"); - - case NM_DEVICE_STATE_REASON_SLEEPING: - return _("NetworkManager went to sleep"); - - case NM_DEVICE_STATE_REASON_CONNECTION_REMOVED: - return _("The device's active connection disappeared"); - - case NM_DEVICE_STATE_REASON_USER_REQUESTED: - return _("Device disconnected by user or client"); - - case NM_DEVICE_STATE_REASON_CARRIER: - return _("Carrier/link changed"); - - case NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED: - return _("The device's existing connection was assumed"); - - case NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE: - return _("The supplicant is now available"); - - case NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND: - return _("The modem could not be found"); - - case NM_DEVICE_STATE_REASON_BT_FAILED: - return _("The Bluetooth connection failed or timed out"); - - case NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED: - return _("GSM Modem's SIM card not inserted"); - - case NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED: - return _("GSM Modem's SIM PIN required"); - - case NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED: - return _("GSM Modem's SIM PUK required"); - - case NM_DEVICE_STATE_REASON_GSM_SIM_WRONG: - return _("GSM Modem's SIM wrong"); - - case NM_DEVICE_STATE_REASON_INFINIBAND_MODE: - return _("InfiniBand device does not support connected mode"); - - case NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED: - return _("A dependency of the connection failed"); - - case NM_DEVICE_STATE_REASON_BR2684_FAILED: - return _("A problem with the RFC 2684 Ethernet over ADSL bridge"); - - case NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE: - return _("ModemManager is unavailable"); - - case NM_DEVICE_STATE_REASON_SSID_NOT_FOUND: - return _("The Wi-Fi network could not be found"); - - case NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED: - return _("A secondary connection of the base connection failed"); - - case NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED: - return _("DCB or FCoE setup failed"); - - case NM_DEVICE_STATE_REASON_TEAMD_CONTROL_FAILED: - return _("teamd control failed"); - - case NM_DEVICE_STATE_REASON_MODEM_FAILED: - return _("Modem failed or no longer available"); - - case NM_DEVICE_STATE_REASON_MODEM_AVAILABLE: - return _("Modem now ready and available"); - - case NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT: - return _("SIM PIN was incorrect"); - - case NM_DEVICE_STATE_REASON_NEW_ACTIVATION: - return _("New connection activation was enqueued"); - - case NM_DEVICE_STATE_REASON_PARENT_CHANGED: - return _("The device's parent changed"); - - case NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED: - return _("The device parent's management changed"); - - default: - /* TRANSLATORS: Unknown reason for a device state change (NMDeviceStateReason) */ - return _("Unknown"); - } -} - /* * nmc_find_connection: * @connections: array of NMConnections to search in diff --git a/clients/cli/common.h b/clients/cli/common.h index b7057e462f..354b2a5f1e 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -30,10 +30,6 @@ gboolean print_ip6_config (NMIPConfig *cfg6, const NmcConfig *nmc_config, const gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field); gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, const NmcConfig *nmc_config, const char *group_prefix, const char *one_field); -const char * nmc_device_state_to_string (NMDeviceState state); -const char * nmc_device_reason_to_string (NMDeviceStateReason reason); -const char * nmc_device_metered_to_string (NMMetered value); - NMConnection *nmc_find_connection (const GPtrArray *connections, const char *filter_type, const char *filter_val, diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 55e0275cda..e518c9aa7c 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -2050,132 +2050,43 @@ typedef struct { static void activate_connection_info_finish (ActivateConnectionInfo *info); -static const char * -active_connection_state_reason_to_string (NMActiveConnectionStateReason reason) -{ - switch (reason) { - 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 check_activated (ActivateConnectionInfo *info) { + NMActiveConnectionState ac_state; NmCli *nmc = info->nmc; - NMDevice *device = info->device; - NMActiveConnection *active = info->active; - NMActiveConnectionStateReason ac_reason; - NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN; - NMDeviceStateReason dev_reason = NM_DEVICE_STATE_REASON_UNKNOWN; - const char *reason; - - ac_reason = nm_active_connection_get_state_reason (active); - - if (device) { - dev_state = nm_device_get_state (device); - dev_reason = nm_device_get_state_reason (device); - } - - switch (nm_active_connection_get_state (active)) { + const char *reason = NULL; + ac_state = nmc_activation_get_effective_state (info->active, info->device, &reason); + switch (ac_state) { case NM_ACTIVE_CONNECTION_STATE_ACTIVATED: if (nmc->nmc_config.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))); + if (reason) { + g_print (_("Connection successfully activated (%s) (D-Bus active path: %s)\n"), + reason, + nm_object_get_path (NM_OBJECT (info->active))); + } else { + g_print (_("Connection successfully activated (D-Bus active path: %s)\n"), + nm_object_get_path (NM_OBJECT (info->active))); + } activate_connection_info_finish (info); break; - case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: - - if ( !device - || ac_reason != NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED - || nm_device_get_active_connection (device) != active) { - /* (1) - * - we have no device, - * - or, @ac_reason is specific - * - or, @device no longer references the current @active - * >> we complete with @ac_reason. */ - reason = active_connection_state_reason_to_string (ac_reason); - } else if ( dev_state <= NM_DEVICE_STATE_DISCONNECTED - || dev_state >= NM_DEVICE_STATE_FAILED) { - /* (2) - * - not (1) - * - and, the device is no longer in an activated state, - * >> we complete with @dev_reason. */ - reason = nmc_device_reason_to_string (dev_reason); - } else { - /* (3) - * we wait for the device go disconnect. We will get a better - * failure reason from the device (2). */ - reason = NULL; - } - - if (reason) { - g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"), - reason); - nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; - activate_connection_info_finish (info); - } + nm_assert (reason); + g_string_printf (nmc->return_text, _("Error: Connection activation failed: %s"), + reason); + nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION; + activate_connection_info_finish (info); break; - case 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. */ - if (nmc->secret_agent) { - NMRemoteConnection *connection = nm_active_connection_get_connection (active); + NMRemoteConnection *connection = nm_active_connection_get_connection (info->active); nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent), nm_connection_get_path (NM_CONNECTION (connection))); } - - if ( device - && ( NM_IS_DEVICE_BOND (device) - || NM_IS_DEVICE_TEAM (device) - || NM_IS_DEVICE_BRIDGE (device)) - && dev_state >= NM_DEVICE_STATE_IP_CONFIG - && dev_state <= NM_DEVICE_STATE_ACTIVATED) { - if (nmc->nmc_config.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); - } break; - default: break; } diff --git a/clients/common/nm-client-utils.c b/clients/common/nm-client-utils.c index a15a10b3bc..9423202ca7 100644 --- a/clients/common/nm-client-utils.c +++ b/clients/common/nm-client-utils.c @@ -21,6 +21,10 @@ #include "nm-client-utils.h" +#include "nm-device-bond.h" +#include "nm-device-bridge.h" +#include "nm-device-team.h" + /* * Convert string to unsigned integer. * If required, the resulting number is checked to be in the <min,max> range. @@ -211,3 +215,296 @@ nmc_bond_validate_mode (const char *mode, GError **error) return nmc_string_is_valid (mode, valid_modes, error); } +const char * +nmc_device_state_to_string (NMDeviceState state) +{ + switch (state) { + case NM_DEVICE_STATE_UNMANAGED: + return _("unmanaged"); + case NM_DEVICE_STATE_UNAVAILABLE: + return _("unavailable"); + case NM_DEVICE_STATE_DISCONNECTED: + return _("disconnected"); + case NM_DEVICE_STATE_PREPARE: + return _("connecting (prepare)"); + case NM_DEVICE_STATE_CONFIG: + return _("connecting (configuring)"); + case NM_DEVICE_STATE_NEED_AUTH: + return _("connecting (need authentication)"); + case NM_DEVICE_STATE_IP_CONFIG: + return _("connecting (getting IP configuration)"); + case NM_DEVICE_STATE_IP_CHECK: + return _("connecting (checking IP connectivity)"); + case NM_DEVICE_STATE_SECONDARIES: + return _("connecting (starting secondary connections)"); + case NM_DEVICE_STATE_ACTIVATED: + return _("connected"); + case NM_DEVICE_STATE_DEACTIVATING: + return _("deactivating"); + case NM_DEVICE_STATE_FAILED: + return _("connection failed"); + default: + return _("unknown"); + } +} + +const char * +nmc_device_metered_to_string (NMMetered value) +{ + switch (value) { + case NM_METERED_YES: + return _("yes"); + case NM_METERED_NO: + return _("no"); + case NM_METERED_GUESS_YES: + return _("yes (guessed)"); + case NM_METERED_GUESS_NO: + return _("no (guessed)"); + default: + return _("unknown"); + } +} + +const char * +nmc_device_reason_to_string (NMDeviceStateReason reason) +{ + switch (reason) { + case NM_DEVICE_STATE_REASON_NONE: + return _("No reason given"); + case NM_DEVICE_STATE_REASON_UNKNOWN: + return _("Unknown error"); + case NM_DEVICE_STATE_REASON_NOW_MANAGED: + return _("Device is now managed"); + case NM_DEVICE_STATE_REASON_NOW_UNMANAGED: + return _("Device is now unmanaged"); + case NM_DEVICE_STATE_REASON_CONFIG_FAILED: + return _("The device could not be readied for configuration"); + case NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE: + return _("IP configuration could not be reserved (no available address, timeout, etc.)"); + case NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED: + return _("The IP configuration is no longer valid"); + case NM_DEVICE_STATE_REASON_NO_SECRETS: + return _("Secrets were required, but not provided"); + case NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT: + return _("802.1X supplicant disconnected"); + case NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED: + return _("802.1X supplicant configuration failed"); + case NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED: + return _("802.1X supplicant failed"); + case NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT: + return _("802.1X supplicant took too long to authenticate"); + case NM_DEVICE_STATE_REASON_PPP_START_FAILED: + return _("PPP service failed to start"); + case NM_DEVICE_STATE_REASON_PPP_DISCONNECT: + return _("PPP service disconnected"); + case NM_DEVICE_STATE_REASON_PPP_FAILED: + return _("PPP failed"); + case NM_DEVICE_STATE_REASON_DHCP_START_FAILED: + return _("DHCP client failed to start"); + case NM_DEVICE_STATE_REASON_DHCP_ERROR: + return _("DHCP client error"); + case NM_DEVICE_STATE_REASON_DHCP_FAILED: + return _("DHCP client failed"); + case NM_DEVICE_STATE_REASON_SHARED_START_FAILED: + return _("Shared connection service failed to start"); + case NM_DEVICE_STATE_REASON_SHARED_FAILED: + return _("Shared connection service failed"); + case NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED: + return _("AutoIP service failed to start"); + case NM_DEVICE_STATE_REASON_AUTOIP_ERROR: + return _("AutoIP service error"); + case NM_DEVICE_STATE_REASON_AUTOIP_FAILED: + return _("AutoIP service failed"); + case NM_DEVICE_STATE_REASON_MODEM_BUSY: + return _("The line is busy"); + case NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE: + return _("No dial tone"); + case NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER: + return _("No carrier could be established"); + case NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT: + return _("The dialing request timed out"); + case NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED: + return _("The dialing attempt failed"); + case NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED: + return _("Modem initialization failed"); + case NM_DEVICE_STATE_REASON_GSM_APN_FAILED: + return _("Failed to select the specified APN"); + case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING: + return _("Not searching for networks"); + case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED: + return _("Network registration denied"); + case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT: + return _("Network registration timed out"); + case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED: + return _("Failed to register with the requested network"); + case NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED: + return _("PIN check failed"); + case NM_DEVICE_STATE_REASON_FIRMWARE_MISSING: + return _("Necessary firmware for the device may be missing"); + case NM_DEVICE_STATE_REASON_REMOVED: + return _("The device was removed"); + case NM_DEVICE_STATE_REASON_SLEEPING: + return _("NetworkManager went to sleep"); + case NM_DEVICE_STATE_REASON_CONNECTION_REMOVED: + return _("The device's active connection disappeared"); + case NM_DEVICE_STATE_REASON_USER_REQUESTED: + return _("Device disconnected by user or client"); + case NM_DEVICE_STATE_REASON_CARRIER: + return _("Carrier/link changed"); + case NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED: + return _("The device's existing connection was assumed"); + case NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE: + return _("The supplicant is now available"); + case NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND: + return _("The modem could not be found"); + case NM_DEVICE_STATE_REASON_BT_FAILED: + return _("The Bluetooth connection failed or timed out"); + case NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED: + return _("GSM Modem's SIM card not inserted"); + case NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED: + return _("GSM Modem's SIM PIN required"); + case NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED: + return _("GSM Modem's SIM PUK required"); + case NM_DEVICE_STATE_REASON_GSM_SIM_WRONG: + return _("GSM Modem's SIM wrong"); + case NM_DEVICE_STATE_REASON_INFINIBAND_MODE: + return _("InfiniBand device does not support connected mode"); + case NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED: + return _("A dependency of the connection failed"); + case NM_DEVICE_STATE_REASON_BR2684_FAILED: + return _("A problem with the RFC 2684 Ethernet over ADSL bridge"); + case NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE: + return _("ModemManager is unavailable"); + case NM_DEVICE_STATE_REASON_SSID_NOT_FOUND: + return _("The Wi-Fi network could not be found"); + case NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED: + return _("A secondary connection of the base connection failed"); + case NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED: + return _("DCB or FCoE setup failed"); + case NM_DEVICE_STATE_REASON_TEAMD_CONTROL_FAILED: + return _("teamd control failed"); + case NM_DEVICE_STATE_REASON_MODEM_FAILED: + return _("Modem failed or no longer available"); + case NM_DEVICE_STATE_REASON_MODEM_AVAILABLE: + return _("Modem now ready and available"); + case NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT: + return _("SIM PIN was incorrect"); + case NM_DEVICE_STATE_REASON_NEW_ACTIVATION: + return _("New connection activation was enqueued"); + case NM_DEVICE_STATE_REASON_PARENT_CHANGED: + return _("The device's parent changed"); + case NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED: + return _("The device parent's management changed"); + default: + /* TRANSLATORS: Unknown reason for a device state change (NMDeviceStateReason) */ + return _("Unknown"); + } +} + +const char * +nm_active_connection_state_reason_to_string (NMActiveConnectionStateReason reason) +{ + switch (reason) { + 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"); + default: + /* TRANSLATORS: Unknown reason for a connection state change (NMActiveConnectionStateReason) */ + return _("Unknown"); + } +} + +NMActiveConnectionState +nmc_activation_get_effective_state (NMActiveConnection *active, + NMDevice *device, + const char **reason) +{ + NMActiveConnectionState ac_state; + NMActiveConnectionStateReason ac_reason; + NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN; + NMDeviceStateReason dev_reason = NM_DEVICE_STATE_REASON_UNKNOWN; + + g_return_val_if_fail (active, NM_ACTIVE_CONNECTION_STATE_UNKNOWN); + g_return_val_if_fail (reason, NM_ACTIVE_CONNECTION_STATE_UNKNOWN); + + *reason = NULL; + ac_reason = nm_active_connection_get_state_reason (active); + + if (device) { + dev_state = nm_device_get_state (device); + dev_reason = nm_device_get_state_reason (device); + } + + ac_state = nm_active_connection_get_state (active); + switch (ac_state) { + case NM_ACTIVE_CONNECTION_STATE_DEACTIVATED: + if ( !device + || ac_reason != NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED + || nm_device_get_active_connection (device) != active) { + /* (1) + * - we have no device, + * - or, @ac_reason is specific + * - or, @device no longer references the current @active + * >> we complete with @ac_reason. */ + *reason = nm_active_connection_state_reason_to_string (ac_reason); + } else if ( dev_state <= NM_DEVICE_STATE_DISCONNECTED + || dev_state >= NM_DEVICE_STATE_FAILED) { + /* (2) + * - not (1) + * - and, the device is no longer in an activated state, + * >> we complete with @dev_reason. */ + *reason = nmc_device_reason_to_string (dev_reason); + } else { + /* (3) + * we wait for the device go disconnect. We will get a better + * failure reason from the device (2). */ + return NM_ACTIVE_CONNECTION_STATE_UNKNOWN; + } + break; + case 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. */ + if ( device + && ( NM_IS_DEVICE_BOND (device) + || NM_IS_DEVICE_TEAM (device) + || NM_IS_DEVICE_BRIDGE (device)) + && dev_state >= NM_DEVICE_STATE_IP_CONFIG + && dev_state <= NM_DEVICE_STATE_ACTIVATED) { + *reason = "master waiting for slaves"; + return NM_ACTIVE_CONNECTION_STATE_ACTIVATED; + } + break; + default: + break; + } + + return ac_state; +} diff --git a/clients/common/nm-client-utils.h b/clients/common/nm-client-utils.h index aea29e6360..ac18fe9475 100644 --- a/clients/common/nm-client-utils.h +++ b/clients/common/nm-client-utils.h @@ -21,7 +21,8 @@ #define __NM_CLIENT_UTILS_H__ #include "nm-meta-setting.h" - +#include "nm-active-connection.h" +#include "nm-device.h" typedef enum { NMC_TRI_STATE_NO, @@ -46,4 +47,13 @@ gboolean matches (const char *cmd, const char *pattern); /* FIXME: don't expose this function on it's own, at least not from this file. */ const char *nmc_bond_validate_mode (const char *mode, GError **error); +const char *nm_active_connection_state_reason_to_string (NMActiveConnectionStateReason reason); +const char *nmc_device_state_to_string (NMDeviceState state); +const char *nmc_device_reason_to_string (NMDeviceStateReason reason); +const char *nmc_device_metered_to_string (NMMetered value); + +NMActiveConnectionState nmc_activation_get_effective_state (NMActiveConnection *active, + NMDevice *device, + const char **reason); + #endif /* __NM_CLIENT_UTILS_H__ */ diff --git a/clients/tui/nmt-connect-connection-list.c b/clients/tui/nmt-connect-connection-list.c index 862861292d..afcbd35ebd 100644 --- a/clients/tui/nmt-connect-connection-list.c +++ b/clients/tui/nmt-connect-connection-list.c @@ -88,6 +88,7 @@ nmt_connect_connection_free (NmtConnectConnection *nmtconn) g_clear_object (&nmtconn->ap); g_clear_object (&nmtconn->active); g_free (nmtconn->ssid); + g_slice_free (NmtConnectConnection, nmtconn); } static void @@ -97,6 +98,7 @@ nmt_connect_device_free (NmtConnectDevice *nmtdev) g_clear_object (&nmtdev->device); g_slist_free_full (nmtdev->conns, (GDestroyNotify) nmt_connect_connection_free); + g_slice_free (NmtConnectDevice, nmtdev); } static const char *device_sort_order[] = { diff --git a/clients/tui/nmtui-connect.c b/clients/tui/nmtui-connect.c index ddabcd72ac..086e4bd3fb 100644 --- a/clients/tui/nmtui-connect.c +++ b/clients/tui/nmtui-connect.c @@ -36,6 +36,7 @@ #include "nmt-password-dialog.h" #include "nm-secret-agent-simple.h" #include "nm-vpn-helpers.h" +#include "nm-client-utils.h" #include "nmt-utils.h" /** @@ -148,38 +149,60 @@ secrets_requested (NMSecretAgentSimple *agent, g_object_unref (form); } +typedef struct { + NMDevice *device; + NMActiveConnection *active; + NmtSyncOp *op; +} ActivateConnectionInfo; + static void connect_cancelled (NmtNewtForm *form, gpointer user_data) { - NmtSyncOp *op = user_data; + ActivateConnectionInfo *info = user_data; GError *error = NULL; error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_CANCELLED, "Cancelled"); - nmt_sync_op_complete_boolean (op, FALSE, error); + nmt_sync_op_complete_boolean (info->op, FALSE, error); g_clear_error (&error); } static void -activate_ac_state_changed (GObject *object, - GParamSpec *pspec, - gpointer user_data) +check_activated (ActivateConnectionInfo *info) { - NmtSyncOp *op = user_data; - NMActiveConnectionState state; - GError *error = NULL; - - state = nm_active_connection_get_state (NM_ACTIVE_CONNECTION (object)); - if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING) + NMActiveConnectionState ac_state; + const char *reason = NULL; + gs_free_error GError *error = NULL; + + ac_state = nmc_activation_get_effective_state (info->active, info->device, &reason); + if (!NM_IN_SET (ac_state, + NM_ACTIVE_CONNECTION_STATE_ACTIVATED, + NM_ACTIVE_CONNECTION_STATE_DEACTIVATED)) return; - if (state != NM_ACTIVE_CONNECTION_STATE_ACTIVATED) { - error = g_error_new_literal (NM_CLIENT_ERROR, NM_CLIENT_ERROR_FAILED, - _("Activation failed")); + if (ac_state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) { + nm_assert (reason); + error = g_error_new (NM_CLIENT_ERROR, NM_CLIENT_ERROR_FAILED, + _("Activation failed: %s"), reason); } - nmt_sync_op_complete_boolean (op, error == NULL, error); - g_clear_error (&error); + nmt_sync_op_complete_boolean (info->op, error == NULL, error); +} + +static void +activate_ac_state_changed (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + check_activated (user_data); +} + +static void +activate_device_state_changed (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + check_activated (user_data); } static void @@ -226,6 +249,7 @@ activate_connection (NMConnection *connection, const char *specific_object_path; NMActiveConnection *ac; GError *error = NULL; + ActivateConnectionInfo info = { }; form = g_object_new (NMT_TYPE_NEWT_FORM, "escape-exits", TRUE, @@ -290,12 +314,18 @@ activate_connection (NMConnection *connection, /* Now wait for the connection to actually reach the ACTIVATED state, * allowing the user to cancel if it takes too long. */ - nmt_sync_op_init (&op); + info.active = ac; + info.device = device; + info.op = &op; - g_signal_connect (form, "quit", G_CALLBACK (connect_cancelled), &op); + g_signal_connect (form, "quit", G_CALLBACK (connect_cancelled), &info); g_signal_connect (ac, "notify::" NM_ACTIVE_CONNECTION_STATE, - G_CALLBACK (activate_ac_state_changed), &op); + G_CALLBACK (activate_ac_state_changed), &info); + if (device) { + g_signal_connect (device, "notify::" NM_DEVICE_STATE, + G_CALLBACK (activate_device_state_changed), &info); + } if (!nmt_sync_op_wait_boolean (&op, &error)) { if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) @@ -303,8 +333,10 @@ activate_connection (NMConnection *connection, g_clear_error (&error); } - g_signal_handlers_disconnect_by_func (form, G_CALLBACK (connect_cancelled), &op); - g_signal_handlers_disconnect_by_func (ac, G_CALLBACK (activate_ac_state_changed), &op); + g_signal_handlers_disconnect_by_func (form, G_CALLBACK (connect_cancelled), &info); + g_signal_handlers_disconnect_by_func (ac, G_CALLBACK (activate_ac_state_changed), &info); + if (device) + g_signal_handlers_disconnect_by_func (device, G_CALLBACK (activate_device_state_changed), &info); done: if (nmt_newt_widget_get_realized (NMT_NEWT_WIDGET (form))) |