core: assert for valid blocked reasons in autoconnect code

We only have a few blocked reasons. Some of them can be only set on the
devcon data, and some only on the settings connection. Assert that we
don't mix that up.
This commit is contained in:
Thomas Haller
2023-05-02 14:19:14 +02:00
parent 2e3fabae50
commit fc624b8de8
3 changed files with 18 additions and 15 deletions

View File

@@ -1252,7 +1252,7 @@ _autoconnect_retries_initial(NMSettingsConnection *sett_conn)
if (retries == -1) if (retries == -1)
retries = nm_config_data_get_autoconnect_retries_default(NM_CONFIG_GET_DATA); retries = nm_config_data_get_autoconnect_retries_default(NM_CONFIG_GET_DATA);
nm_assert(retries >= 0 && ((guint) retries) <= ((guint) G_MAXINT32)); nm_assert(retries >= 0 && retries <= G_MAXINT32);
if (retries == 0) if (retries == 0)
return NM_AUTOCONNECT_RETRIES_FOREVER; return NM_AUTOCONNECT_RETRIES_FOREVER;
@@ -1401,16 +1401,15 @@ nm_manager_devcon_autoconnect_reset_reconnect_all(NMManager *self,
/* we reset the tries-count and any blocked-reason */ /* we reset the tries-count and any blocked-reason */
nm_manager_devcon_autoconnect_retries_reset(self, NULL, sett_conn); nm_manager_devcon_autoconnect_retries_reset(self, NULL, sett_conn);
/* if there is a device and we changed the state, then something changed. */ if (device) {
if (device if (nm_manager_devcon_autoconnect_blocked_reason_set(
&& nm_manager_devcon_autoconnect_blocked_reason_set( self,
self, device,
device, sett_conn,
sett_conn, NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED FALSE))
| NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_USER_REQUEST, changed = TRUE;
FALSE)) }
changed = TRUE;
/* we remove all the blocked reason from the connection, if something /* we remove all the blocked reason from the connection, if something
* happened, then it means the status changed */ * happened, then it means the status changed */
@@ -1487,8 +1486,9 @@ nm_manager_devcon_autoconnect_blocked_reason_set(NMManager
gboolean changed = FALSE; gboolean changed = FALSE;
char buf[100]; char buf[100];
nm_assert(value); nm_assert(NM_IS_SETTINGS_CONNECTION(sett_conn));
nm_assert(sett_conn); nm_assert(value != NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_NONE);
nm_assert(!NM_FLAGS_ANY(value, ~(NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED)));
if (device) { if (device) {
data = _devcon_lookup_data(self, device, sett_conn, TRUE); data = _devcon_lookup_data(self, device, sett_conn, TRUE);

View File

@@ -2158,7 +2158,7 @@ device_state_changed(NMDevice *device,
priv->manager, priv->manager,
device, device,
sett_conn, sett_conn,
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_ALL, NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
FALSE); FALSE);
break; break;
case NM_DEVICE_STATE_SECONDARIES: case NM_DEVICE_STATE_SECONDARIES:

View File

@@ -2526,7 +2526,10 @@ nm_settings_connection_autoconnect_blocked_reason_set(NMSettingsConnection
char buf1[100]; char buf1[100];
char buf2[100]; char buf2[100];
nm_assert(reason); nm_assert(reason != NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_NONE);
nm_assert(!NM_FLAGS_ANY(reason,
~(NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_USER_REQUEST
| NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_NO_SECRETS)));
v = priv->autoconnect_blocked_reason; v = priv->autoconnect_blocked_reason;
v = NM_FLAGS_ASSIGN(v, reason, set); v = NM_FLAGS_ASSIGN(v, reason, set);