device: improve tracking autoconnect-blocked flags of NMDevice

- split NM_DEVICE_AUTOCONNECT_BLOCKED_INTERN in two parts:
  "wrong-pin" and "manual-disconnect". Setting/unsetting them
  should be tracked differently, as their reason differs.

- no longer initialize/clear the autoconnect-blocked reasons
  during realize/unrealize of the device. Instead, initialize
  it once when the object gets created (nm_device_init()), and
  keep the settings beyond unrealize/realize cycles. This only
  matters for software devices, as regular devices get deleted
  after unrealizing once. But for software devices it is essential,
  because we don't want to forget the autoconnect settings of
  the device instance.

- drop verbose logging about blocking autoconnect due to failed
  pin. We already log changes to autoconnect-blocked flags with
  TRACE level. An additional message about this particular issue
  seems not necessary at INFO level.

- in NMManager's do_sleep_wake(), no longer block autoconnect
  for devices during sleep. We already unmanage the device, which
  is a far more effective measure to prevent activation. We should
  not also block autoconnect.
This commit is contained in:
Thomas Haller 2017-11-07 12:36:17 +01:00
parent 5279ab5be6
commit 3c2b9485a7
5 changed files with 20 additions and 23 deletions

View file

@ -491,8 +491,7 @@ modem_prepare_result (NMModem *modem,
* the device to be auto-activated anymore, which would risk locking
* the SIM if the incorrect PIN continues to be used.
*/
_LOGI (LOGD_MB, "disabling autoconnect due to failed SIM PIN");
nm_device_autoconnect_blocked_set (device, NM_DEVICE_AUTOCONNECT_BLOCKED_INTERN);
nm_device_autoconnect_blocked_set (device, NM_DEVICE_AUTOCONNECT_BLOCKED_WRONG_PIN);
}
nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, reason);

View file

@ -3275,7 +3275,6 @@ realize_start_setup (NMDevice *self,
NMDeviceCapabilities capabilities = 0;
NMConfig *config;
guint real_rate;
NMDeviceAutoconnectBlockedFlags autoconnect_blocked_flags;
/* plink is a NMPlatformLink type, however, we require it to come from the platform
* cache (where else would it come from?). */
@ -3388,13 +3387,6 @@ realize_start_setup (NMDevice *self,
if (real_rate)
priv->stats.timeout_id = g_timeout_add (real_rate, _stats_timeout_cb, self);
autoconnect_blocked_flags = NM_DEVICE_AUTOCONNECT_BLOCKED_NONE;
if (!DEFAULT_AUTOCONNECT)
autoconnect_blocked_flags |= NM_DEVICE_AUTOCONNECT_BLOCKED_INTERN;
nm_device_autoconnect_blocked_set_full (self,
NM_DEVICE_AUTOCONNECT_BLOCKED_ALL,
autoconnect_blocked_flags);
klass->realize_start_notify (self, plink);
nm_assert (!nm_device_get_unmanaged_mask (self, NM_UNMANAGED_USER_EXPLICIT));
@ -3594,8 +3586,6 @@ nm_device_unrealize (NMDevice *self, gboolean remove_resources, GError **error)
priv->real = FALSE;
_notify (self, PROP_REAL);
nm_device_autoconnect_blocked_set (self, NM_DEVICE_AUTOCONNECT_BLOCKED_ALL);
g_object_thaw_notify (G_OBJECT (self));
nm_device_set_unmanaged_flags (self,
@ -4221,9 +4211,10 @@ nm_device_set_enabled (NMDevice *self, gboolean enabled)
}
NM_UTILS_FLAGS2STR_DEFINE_STATIC (_autoconnect_blocked_flags_to_string, NMDeviceAutoconnectBlockedFlags,
NM_UTILS_FLAGS2STR (NM_DEVICE_AUTOCONNECT_BLOCKED_NONE, "none"),
NM_UTILS_FLAGS2STR (NM_DEVICE_AUTOCONNECT_BLOCKED_USER, "user"),
NM_UTILS_FLAGS2STR (NM_DEVICE_AUTOCONNECT_BLOCKED_INTERN, "intern"),
NM_UTILS_FLAGS2STR (NM_DEVICE_AUTOCONNECT_BLOCKED_NONE, "none"),
NM_UTILS_FLAGS2STR (NM_DEVICE_AUTOCONNECT_BLOCKED_USER, "user"),
NM_UTILS_FLAGS2STR (NM_DEVICE_AUTOCONNECT_BLOCKED_WRONG_PIN, "wrong-pin"),
NM_UTILS_FLAGS2STR (NM_DEVICE_AUTOCONNECT_BLOCKED_MANUAL_DISCONNECT, "manual-disconnect"),
);
NMDeviceAutoconnectBlockedFlags
@ -9740,7 +9731,7 @@ disconnect_cb (NMDevice *self,
nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, FALSE, NULL, subject, local->message);
g_dbus_method_invocation_take_error (context, local);
} else {
nm_device_autoconnect_blocked_set (self, NM_DEVICE_AUTOCONNECT_BLOCKED_INTERN);
nm_device_autoconnect_blocked_set (self, NM_DEVICE_AUTOCONNECT_BLOCKED_MANUAL_DISCONNECT);
nm_device_state_changed (self,
NM_DEVICE_STATE_DEACTIVATING,
@ -12996,10 +12987,10 @@ _set_state_full (NMDevice *self,
break;
}
/* Reset autoconnect flag when the device is activating or connected. */
/* Reset intern autoconnect flags when the device is activating or connected. */
if ( state >= NM_DEVICE_STATE_PREPARE
&& state <= NM_DEVICE_STATE_ACTIVATED)
nm_device_autoconnect_blocked_unset (self, NM_DEVICE_AUTOCONNECT_BLOCKED_INTERN);
nm_device_autoconnect_blocked_unset (self, NM_DEVICE_AUTOCONNECT_BLOCKED_INTERNAL);
_notify (self, PROP_STATE);
_notify (self, PROP_STATE_REASON);
@ -14124,6 +14115,10 @@ nm_device_init (NMDevice *self)
priv->netns = g_object_ref (NM_NETNS_GET);
priv->autoconnect_blocked_flags = DEFAULT_AUTOCONNECT
? NM_DEVICE_AUTOCONNECT_BLOCKED_NONE
: NM_DEVICE_AUTOCONNECT_BLOCKED_USER;
priv->auth_retries = NM_DEVICE_AUTH_RETRIES_UNSET;
priv->type = NM_DEVICE_TYPE_UNKNOWN;
priv->capabilities = NM_DEVICE_CAP_NM_SUPPORTED;

View file

@ -665,11 +665,17 @@ void nm_device_update_from_platform_link (NMDevice *self,
typedef enum {
NM_DEVICE_AUTOCONNECT_BLOCKED_NONE = 0,
NM_DEVICE_AUTOCONNECT_BLOCKED_USER = (1LL << 0),
NM_DEVICE_AUTOCONNECT_BLOCKED_INTERN = (1LL << 1),
NM_DEVICE_AUTOCONNECT_BLOCKED_WRONG_PIN = (1LL << 1),
NM_DEVICE_AUTOCONNECT_BLOCKED_MANUAL_DISCONNECT = (1LL << 2),
_NM_DEVICE_AUTOCONNECT_BLOCKED_LAST,
NM_DEVICE_AUTOCONNECT_BLOCKED_ALL = (((_NM_DEVICE_AUTOCONNECT_BLOCKED_LAST - 1) << 1) - 1),
NM_DEVICE_AUTOCONNECT_BLOCKED_INTERNAL = NM_DEVICE_AUTOCONNECT_BLOCKED_ALL & ~NM_DEVICE_AUTOCONNECT_BLOCKED_USER,
} NMDeviceAutoconnectBlockedFlags;
NMDeviceAutoconnectBlockedFlags nm_device_autoconnect_blocked_get (NMDevice *device, NMDeviceAutoconnectBlockedFlags mask);

View file

@ -132,8 +132,7 @@ modem_prepare_result (NMModem *modem,
* the device to be auto-activated anymore, which would risk locking
* the SIM if the incorrect PIN continues to be used.
*/
nm_device_autoconnect_blocked_set (device, NM_DEVICE_AUTOCONNECT_BLOCKED_INTERN);
_LOGI (LOGD_MB, "disabling autoconnect due to failed SIM PIN");
nm_device_autoconnect_blocked_set (device, NM_DEVICE_AUTOCONNECT_BLOCKED_WRONG_PIN);
}
nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, reason);

View file

@ -4623,8 +4623,6 @@ do_sleep_wake (NMManager *self, gboolean sleeping_changed)
nm_device_set_enabled (device, enabled);
}
nm_device_autoconnect_blocked_unset (device, NM_DEVICE_AUTOCONNECT_BLOCKED_INTERN);
nm_device_set_unmanaged_by_flags (device, NM_UNMANAGED_SLEEPING, FALSE, NM_DEVICE_STATE_REASON_NOW_MANAGED);
}
}