mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 23:40:16 +01:00
policy: track autoconnect-blocked-reasons as flags
Extend the enum and API to use flags for the blocked reasons.
A connection is blocked from autoconnect if it has any reason
set.
There is no behavioral change in this patch beyond that, because
where we previously would set blocked-reason NONE, we would still
clear all flags, and not only a particular one.
Later of course, we want to set and clear individual flags
independently.
(cherry picked from commit 8d2d9b0748)
This commit is contained in:
parent
c8de52e281
commit
78d619fc9d
3 changed files with 65 additions and 35 deletions
|
|
@ -1170,7 +1170,7 @@ pending_ac_state_changed (NMActiveConnection *ac, guint state, guint reason, NMP
|
|||
* loop.
|
||||
*/
|
||||
con = nm_active_connection_get_settings_connection (ac);
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (con, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED);
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (con, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED, TRUE);
|
||||
schedule_activate_check (self, nm_active_connection_get_device (ac));
|
||||
|
||||
/* Cleanup */
|
||||
|
|
@ -1223,7 +1223,7 @@ auto_activate_device (NMPolicy *self,
|
|||
|
||||
if ( !nm_settings_connection_is_visible (candidate)
|
||||
|| nm_settings_connection_autoconnect_retries_get (candidate) == 0
|
||||
|| nm_settings_connection_autoconnect_blocked_reason_get (candidate) != NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE)
|
||||
|| nm_settings_connection_autoconnect_blocked_reason_get (candidate, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL))
|
||||
continue;
|
||||
|
||||
s_con = nm_connection_get_setting_connection (NM_CONNECTION (candidate));
|
||||
|
|
@ -1260,7 +1260,8 @@ auto_activate_device (NMPolicy *self,
|
|||
nm_settings_connection_get_id (best_connection),
|
||||
error->message);
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (best_connection,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED);
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED,
|
||||
TRUE);
|
||||
schedule_activate_check (self, device);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1419,7 +1420,8 @@ reset_autoconnect_all (NMPolicy *self,
|
|||
NMSettingsConnection *connection = connections[i];
|
||||
|
||||
if ( only_for_failed_secrets
|
||||
&& nm_settings_connection_autoconnect_blocked_reason_get (connection) != NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS)
|
||||
&& !nm_settings_connection_autoconnect_blocked_reason_get (connection,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS))
|
||||
continue;
|
||||
|
||||
if ( device
|
||||
|
|
@ -1430,11 +1432,10 @@ reset_autoconnect_all (NMPolicy *self,
|
|||
changed = TRUE;
|
||||
nm_settings_connection_autoconnect_retries_reset (connection);
|
||||
|
||||
if (nm_settings_connection_autoconnect_blocked_reason_get (connection) != NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE) {
|
||||
if (nm_settings_connection_autoconnect_blocked_reason_set (connection,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL,
|
||||
FALSE))
|
||||
changed = TRUE;
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (connection,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE);
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
|
@ -1599,9 +1600,11 @@ activate_slave_connections (NMPolicy *self, NMDevice *device)
|
|||
|
||||
if (!internal_activation)
|
||||
nm_settings_connection_autoconnect_retries_reset (connection);
|
||||
if (nm_settings_connection_autoconnect_blocked_reason_get (connection) == NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED) {
|
||||
if (nm_settings_connection_autoconnect_blocked_reason_get (connection,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED)) {
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (connection,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE);
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL,
|
||||
FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1711,7 +1714,8 @@ device_state_changed (NMDevice *device,
|
|||
*/
|
||||
if (connection) {
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (connection,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED);
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED,
|
||||
TRUE);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
@ -1733,7 +1737,7 @@ device_state_changed (NMDevice *device,
|
|||
_LOGD (LOGD_DEVICE, "connection '%s' now blocked from autoconnect due to no secrets",
|
||||
nm_settings_connection_get_id (connection));
|
||||
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS);
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS, TRUE);
|
||||
} else if (tries != 0) {
|
||||
if (tries > 0) {
|
||||
_LOGD (LOGD_DEVICE, "connection '%s' failed to autoconnect; %d tries left",
|
||||
|
|
@ -1799,7 +1803,7 @@ device_state_changed (NMDevice *device,
|
|||
nm_settings_connection_get_id (connection),
|
||||
NM_UTILS_LOOKUP_STR (nm_device_state_reason_to_str,
|
||||
nm_device_state_reason_check (reason)));
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (connection, blocked_reason);
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (connection, blocked_reason, TRUE);
|
||||
}
|
||||
}
|
||||
ip6_remove_device_prefix_delegations (self, device);
|
||||
|
|
@ -1836,7 +1840,7 @@ device_state_changed (NMDevice *device,
|
|||
case NM_DEVICE_STATE_IP_CONFIG:
|
||||
/* We must have secrets if we got here. */
|
||||
if (connection)
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE);
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (connection, NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL, FALSE);
|
||||
break;
|
||||
case NM_DEVICE_STATE_SECONDARIES:
|
||||
if (connection)
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ typedef struct _NMSettingsConnectionPrivate {
|
|||
|
||||
bool timestamp_set:1;
|
||||
|
||||
NMSettingsAutoconnectBlockedReason autoconnect_blocked_reason:3;
|
||||
NMSettingsAutoconnectBlockedReason autoconnect_blocked_reason:4;
|
||||
|
||||
GSList *pending_auths; /* List of pending authentication requests */
|
||||
|
||||
|
|
@ -2610,29 +2610,40 @@ nm_settings_connection_autoconnect_retries_blocked_until (NMSettingsConnection *
|
|||
return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_retries_blocked_until;
|
||||
}
|
||||
|
||||
NM_UTILS_FLAGS2STR_DEFINE_STATIC (_autoconnect_blocked_reason_to_string, NMSettingsAutoconnectBlockedReason,
|
||||
NM_UTILS_FLAGS2STR (NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE, "none"),
|
||||
NM_UTILS_FLAGS2STR (NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST, "user-request"),
|
||||
NM_UTILS_FLAGS2STR (NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED, "failed"),
|
||||
NM_UTILS_FLAGS2STR (NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS, "no-secrets"),
|
||||
);
|
||||
|
||||
NMSettingsAutoconnectBlockedReason
|
||||
nm_settings_connection_autoconnect_blocked_reason_get (NMSettingsConnection *self)
|
||||
nm_settings_connection_autoconnect_blocked_reason_get (NMSettingsConnection *self, NMSettingsAutoconnectBlockedReason mask)
|
||||
{
|
||||
return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_blocked_reason;
|
||||
return NM_SETTINGS_CONNECTION_GET_PRIVATE (self)->autoconnect_blocked_reason & (mask ?: NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL);
|
||||
}
|
||||
|
||||
void
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (NMSettingsConnection *self,
|
||||
NMSettingsAutoconnectBlockedReason reason)
|
||||
gboolean
|
||||
nm_settings_connection_autoconnect_blocked_reason_set_full (NMSettingsConnection *self,
|
||||
NMSettingsAutoconnectBlockedReason mask,
|
||||
NMSettingsAutoconnectBlockedReason value)
|
||||
{
|
||||
NMSettingsAutoconnectBlockedReason v;
|
||||
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE (self);
|
||||
char buf[100];
|
||||
|
||||
nm_assert (NM_IN_SET (reason,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS));
|
||||
nm_assert (mask);
|
||||
nm_assert (!NM_FLAGS_ANY (value, ~mask));
|
||||
|
||||
if (priv->autoconnect_blocked_reason == reason)
|
||||
return;
|
||||
v = priv->autoconnect_blocked_reason;
|
||||
v = (v & ~mask) | (value & mask);
|
||||
|
||||
_LOGT ("autoconnect: blocked reason: %d", (int) reason);
|
||||
priv->autoconnect_blocked_reason = reason;
|
||||
if (priv->autoconnect_blocked_reason == v)
|
||||
return FALSE;
|
||||
|
||||
_LOGT ("autoconnect: blocked reason: %s", _autoconnect_blocked_reason_to_string (v, buf, sizeof (buf)));
|
||||
priv->autoconnect_blocked_reason = v;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -84,9 +84,14 @@ typedef enum { /*< skip >*/
|
|||
|
||||
typedef enum {
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE = 0,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST = 1,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED = 2,
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS = 3,
|
||||
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST = (1LL << 0),
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED = (1LL << 1),
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS = (1LL << 2),
|
||||
|
||||
NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_ALL = ( NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_USER_REQUEST
|
||||
| NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_FAILED
|
||||
| NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NO_SECRETS),
|
||||
} NMSettingsAutoconnectBlockedReason;
|
||||
|
||||
struct _NMSettingsConnectionCallId;
|
||||
|
|
@ -220,9 +225,19 @@ void nm_settings_connection_autoconnect_retries_reset (NMSettingsConnection *sel
|
|||
|
||||
gint32 nm_settings_connection_autoconnect_retries_blocked_until (NMSettingsConnection *self);
|
||||
|
||||
NMSettingsAutoconnectBlockedReason nm_settings_connection_autoconnect_blocked_reason_get (NMSettingsConnection *self);
|
||||
void nm_settings_connection_autoconnect_blocked_reason_set (NMSettingsConnection *self,
|
||||
NMSettingsAutoconnectBlockedReason reason);
|
||||
NMSettingsAutoconnectBlockedReason nm_settings_connection_autoconnect_blocked_reason_get (NMSettingsConnection *self,
|
||||
NMSettingsAutoconnectBlockedReason mask);
|
||||
gboolean nm_settings_connection_autoconnect_blocked_reason_set_full (NMSettingsConnection *self,
|
||||
NMSettingsAutoconnectBlockedReason mask,
|
||||
NMSettingsAutoconnectBlockedReason value);
|
||||
|
||||
static inline gboolean
|
||||
nm_settings_connection_autoconnect_blocked_reason_set (NMSettingsConnection *self,
|
||||
NMSettingsAutoconnectBlockedReason mask,
|
||||
gboolean set)
|
||||
{
|
||||
return nm_settings_connection_autoconnect_blocked_reason_set_full (self, mask, set ? mask : NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE);
|
||||
}
|
||||
|
||||
gboolean nm_settings_connection_get_nm_generated (NMSettingsConnection *self);
|
||||
gboolean nm_settings_connection_get_volatile (NMSettingsConnection *self);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue