From cb2aa6bd4c75234bfb1faf1a3a2bb3ab64a0ccf8 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 25 Oct 2017 21:29:45 +0200 Subject: [PATCH] policy: move blocking autoconnect from NMDeviceModem to NMPolicy Only NMPolicy should be concerned with handling autoconnect, and blocking it. Move the code. Note that there is a slight possible change in behavior, as the order of when the connection is blocked changes, based on the different times when the device changed signal gets executed. But that shouldn't be a problem. --- src/devices/wwan/nm-device-modem.c | 26 +------------------------- src/nm-policy.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 7f2bb9389a..22fb8c673d 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -364,9 +364,8 @@ device_state_changed (NMDevice *device, { NMDeviceModem *self = NM_DEVICE_MODEM (device); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (self); - NMSettingsConnection *connection = nm_device_get_settings_connection (device); - g_assert (priv->modem); + g_return_if_fail (priv->modem); if (new_state == NM_DEVICE_STATE_UNAVAILABLE && old_state < NM_DEVICE_STATE_UNAVAILABLE) { @@ -374,30 +373,7 @@ device_state_changed (NMDevice *device, _LOGI (LOGD_MB, "modem state '%s'", nm_modem_state_to_string (nm_modem_get_state (priv->modem))); } - nm_modem_device_state_changed (priv->modem, new_state, old_state); - - switch (nm_device_state_reason_check (reason)) { - case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED: - case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING: - case NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED: - case NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED: - case NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED: - case NM_DEVICE_STATE_REASON_GSM_SIM_WRONG: - case NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT: - case NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED: - case NM_DEVICE_STATE_REASON_GSM_APN_FAILED: - /* Block autoconnect of the just-failed connection for situations - * where a retry attempt would just fail again. - */ - if (connection) { - nm_settings_connection_autoconnect_blocked_reason_set (connection, - NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED); - } - break; - default: - break; - } } static NMDeviceCapabilities diff --git a/src/nm-policy.c b/src/nm-policy.c index 7472dd54f7..3cfb1f7c4a 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -1748,6 +1748,28 @@ device_state_changed (NMDevice *device, NMIP6Config *ip6_config; NMSettingConnection *s_con = NULL; + switch (nm_device_state_reason_check (reason)) { + case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED: + case NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING: + case NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED: + case NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED: + case NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED: + case NM_DEVICE_STATE_REASON_GSM_SIM_WRONG: + case NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT: + case NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED: + case NM_DEVICE_STATE_REASON_GSM_APN_FAILED: + /* Block autoconnect of the just-failed connection for situations + * where a retry attempt would just fail again. + */ + if (connection) { + nm_settings_connection_autoconnect_blocked_reason_set (connection, + NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED); + } + break; + default: + break; + } + switch (new_state) { case NM_DEVICE_STATE_FAILED: /* Mark the connection invalid if it failed during activation so that