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.
This commit is contained in:
Thomas Haller 2017-10-25 21:29:45 +02:00
parent 3828ba3b0e
commit cb2aa6bd4c
2 changed files with 23 additions and 25 deletions

View file

@ -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

View file

@ -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