mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 13:20:08 +01:00
device: move tracking auth_retry to NMDevice
It will be also used by NMDeviceWifi. It might waste a 4 bytes for device types that don't require authentication. But it deduplicates code.
This commit is contained in:
parent
6705c71263
commit
32acaccf2a
4 changed files with 24 additions and 42 deletions
|
|
@ -115,8 +115,6 @@ typedef struct _NMDeviceEthernetPrivate {
|
|||
DcbWait dcb_wait;
|
||||
guint dcb_timeout_id;
|
||||
|
||||
int auth_retries;
|
||||
|
||||
bool dcb_handle_carrier_changes:1;
|
||||
} NMDeviceEthernetPrivate;
|
||||
|
||||
|
|
@ -262,18 +260,8 @@ device_state_changed (NMDevice *device,
|
|||
NMDeviceState old_state,
|
||||
NMDeviceStateReason reason)
|
||||
{
|
||||
NMDeviceEthernetPrivate *priv;
|
||||
|
||||
if (new_state > NM_DEVICE_STATE_ACTIVATED)
|
||||
wired_secrets_cancel (NM_DEVICE_ETHERNET (device));
|
||||
|
||||
if (NM_IN_SET (new_state,
|
||||
NM_DEVICE_STATE_ACTIVATED,
|
||||
NM_DEVICE_STATE_FAILED,
|
||||
NM_DEVICE_STATE_DISCONNECTED)) {
|
||||
priv = NM_DEVICE_ETHERNET_GET_PRIVATE (NM_DEVICE_ETHERNET (device));
|
||||
priv->auth_retries = NM_DEVICE_AUTH_RETRIES_UNSET;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -284,7 +272,6 @@ nm_device_ethernet_init (NMDeviceEthernet *self)
|
|||
priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_DEVICE_ETHERNET, NMDeviceEthernetPrivate);
|
||||
self->_priv = priv;
|
||||
|
||||
priv->auth_retries = NM_DEVICE_AUTH_RETRIES_UNSET;
|
||||
priv->s390_options = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free);
|
||||
}
|
||||
|
||||
|
|
@ -677,8 +664,7 @@ handle_auth_or_fail (NMDeviceEthernet *self,
|
|||
|
||||
priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
|
||||
|
||||
if (!nm_device_auth_retries_try_next (NM_DEVICE (self),
|
||||
&priv->auth_retries))
|
||||
if (!nm_device_auth_retries_try_next (NM_DEVICE (self)))
|
||||
return NM_ACT_STAGE_RETURN_FAILURE;
|
||||
|
||||
nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
|
||||
|
|
@ -1343,9 +1329,6 @@ deactivate (NMDevice *device)
|
|||
NMSettingDcb *s_dcb;
|
||||
GError *error = NULL;
|
||||
|
||||
/* Clear wired secrets tries when deactivating */
|
||||
priv->auth_retries = NM_DEVICE_AUTH_RETRIES_UNSET;
|
||||
|
||||
nm_clear_g_source (&priv->pppoe_wait_id);
|
||||
|
||||
if (priv->ppp_manager) {
|
||||
|
|
|
|||
|
|
@ -72,7 +72,6 @@ typedef struct {
|
|||
Supplicant supplicant;
|
||||
guint supplicant_timeout_id;
|
||||
NMActRequestGetSecretsCallId macsec_secrets_id;
|
||||
int auth_retries;
|
||||
} NMDeviceMacsecPrivate;
|
||||
|
||||
struct _NMDeviceMacsec {
|
||||
|
|
@ -484,8 +483,7 @@ handle_auth_or_fail (NMDeviceMacsec *self,
|
|||
|
||||
priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
||||
|
||||
if (!nm_device_auth_retries_try_next (NM_DEVICE (self),
|
||||
&priv->auth_retries))
|
||||
if (!nm_device_auth_retries_try_next (NM_DEVICE (self)))
|
||||
return NM_ACT_STAGE_RETURN_FAILURE;
|
||||
|
||||
nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE);
|
||||
|
|
@ -741,17 +739,8 @@ device_state_changed (NMDevice *device,
|
|||
NMDeviceState old_state,
|
||||
NMDeviceStateReason reason)
|
||||
{
|
||||
NMDeviceMacsecPrivate *priv;
|
||||
|
||||
if (new_state > NM_DEVICE_STATE_ACTIVATED)
|
||||
macsec_secrets_cancel (NM_DEVICE_MACSEC (device));
|
||||
|
||||
if (NM_IN_SET (new_state, NM_DEVICE_STATE_ACTIVATED,
|
||||
NM_DEVICE_STATE_FAILED,
|
||||
NM_DEVICE_STATE_DISCONNECTED)) {
|
||||
priv = NM_DEVICE_MACSEC_GET_PRIVATE (NM_DEVICE_MACSEC (device));
|
||||
priv->auth_retries = NM_DEVICE_AUTH_RETRIES_UNSET;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
|
@ -810,9 +799,6 @@ get_property (GObject *object, guint prop_id,
|
|||
static void
|
||||
nm_device_macsec_init (NMDeviceMacsec *self)
|
||||
{
|
||||
NMDeviceMacsecPrivate *priv = NM_DEVICE_MACSEC_GET_PRIVATE (self);
|
||||
|
||||
priv->auth_retries = NM_DEVICE_AUTH_RETRIES_UNSET;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -89,6 +89,10 @@ _LOG_DECLARE_SELF (NMDevice);
|
|||
#define CARRIER_WAIT_TIME_MS 5000
|
||||
#define CARRIER_WAIT_TIME_AFTER_MTU_MS 10000
|
||||
|
||||
#define NM_DEVICE_AUTH_RETRIES_UNSET -1
|
||||
#define NM_DEVICE_AUTH_RETRIES_INFINITY -2
|
||||
#define NM_DEVICE_AUTH_RETRIES_DEFAULT 3
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef void (*ActivationHandleFunc) (NMDevice *self);
|
||||
|
|
@ -238,6 +242,8 @@ typedef struct _NMDevicePrivate {
|
|||
|
||||
int parent_ifindex;
|
||||
|
||||
int auth_retries;
|
||||
|
||||
union {
|
||||
const guint8 hw_addr_len; /* read-only */
|
||||
guint8 hw_addr_len_;
|
||||
|
|
@ -12877,6 +12883,10 @@ _set_state_full (NMDevice *self,
|
|||
NM_DEVICE_SYS_IFACE_STATE_ASSUME))
|
||||
nm_device_sys_iface_state_set (self, NM_DEVICE_SYS_IFACE_STATE_MANAGED);
|
||||
|
||||
if ( state <= NM_DEVICE_STATE_DISCONNECTED
|
||||
|| state >= NM_DEVICE_STATE_ACTIVATED)
|
||||
priv->auth_retries = NM_DEVICE_AUTH_RETRIES_UNSET;
|
||||
|
||||
if (state > NM_DEVICE_STATE_DISCONNECTED)
|
||||
nm_device_assume_state_reset (self);
|
||||
|
||||
|
|
@ -14024,10 +14034,16 @@ nm_device_get_supplicant_timeout (NMDevice *self)
|
|||
}
|
||||
|
||||
gboolean
|
||||
nm_device_auth_retries_try_next (NMDevice *self, int *p_auth_retries)
|
||||
nm_device_auth_retries_try_next (NMDevice *self)
|
||||
{
|
||||
NMDevicePrivate *priv;
|
||||
NMSettingConnection *s_con;
|
||||
int auth_retries = *p_auth_retries;
|
||||
int auth_retries;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
|
||||
|
||||
priv = NM_DEVICE_GET_PRIVATE (self);
|
||||
auth_retries = priv->auth_retries;
|
||||
|
||||
if (G_UNLIKELY (auth_retries == NM_DEVICE_AUTH_RETRIES_UNSET)) {
|
||||
auth_retries = -1;
|
||||
|
|
@ -14052,7 +14068,7 @@ nm_device_auth_retries_try_next (NMDevice *self, int *p_auth_retries)
|
|||
else
|
||||
nm_assert (auth_retries > 0);
|
||||
|
||||
*p_auth_retries = auth_retries;
|
||||
priv->auth_retries = auth_retries;
|
||||
}
|
||||
|
||||
if (auth_retries == NM_DEVICE_AUTH_RETRIES_INFINITY)
|
||||
|
|
@ -14061,7 +14077,7 @@ nm_device_auth_retries_try_next (NMDevice *self, int *p_auth_retries)
|
|||
nm_assert (auth_retries == 0);
|
||||
return FALSE;
|
||||
}
|
||||
(*p_auth_retries)--;
|
||||
priv->auth_retries--;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -14100,6 +14116,7 @@ nm_device_init (NMDevice *self)
|
|||
|
||||
priv->netns = g_object_ref (NM_NETNS_GET);
|
||||
|
||||
priv->auth_retries = NM_DEVICE_AUTH_RETRIES_UNSET;
|
||||
priv->type = NM_DEVICE_TYPE_UNKNOWN;
|
||||
priv->capabilities = NM_DEVICE_CAP_NM_SUPPORTED;
|
||||
priv->state = NM_DEVICE_STATE_UNMANAGED;
|
||||
|
|
|
|||
|
|
@ -736,11 +736,7 @@ void nm_device_update_permanent_hw_address (NMDevice *self, gboolean force_freez
|
|||
void nm_device_update_dynamic_ip_setup (NMDevice *self);
|
||||
guint nm_device_get_supplicant_timeout (NMDevice *self);
|
||||
|
||||
#define NM_DEVICE_AUTH_RETRIES_UNSET -1
|
||||
#define NM_DEVICE_AUTH_RETRIES_INFINITY -2
|
||||
#define NM_DEVICE_AUTH_RETRIES_DEFAULT 3
|
||||
|
||||
gboolean nm_device_auth_retries_try_next (NMDevice *self, int *p_auth_retry);
|
||||
gboolean nm_device_auth_retries_try_next (NMDevice *self);
|
||||
|
||||
gboolean nm_device_hw_addr_get_cloned (NMDevice *self,
|
||||
NMConnection *connection,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue