summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-05-02 14:19:14 +0200
committerThomas Haller <thaller@redhat.com>2023-05-04 10:34:12 +0200
commitfc624b8de838fcacd18429bee981949b18f6a9a8 (patch)
tree3c21cbac348eff152623d522c8574386c5647d2c
parent2e3fabae50be1429e451c85f32ef9b7011b8feae (diff)
downloadNetworkManager-fc624b8de838fcacd18429bee981949b18f6a9a8.tar.gz
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.
-rw-r--r--src/core/nm-manager.c26
-rw-r--r--src/core/nm-policy.c2
-rw-r--r--src/core/settings/nm-settings-connection.c5
3 files changed, 18 insertions, 15 deletions
diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c
index 02dabaf6fe..8773ce47fe 100644
--- a/src/core/nm-manager.c
+++ b/src/core/nm-manager.c
@@ -1252,7 +1252,7 @@ _autoconnect_retries_initial(NMSettingsConnection *sett_conn)
if (retries == -1)
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)
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 */
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
- && nm_manager_devcon_autoconnect_blocked_reason_set(
- self,
- device,
- sett_conn,
- NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED
- | NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_USER_REQUEST,
- FALSE))
- changed = TRUE;
+ if (device) {
+ if (nm_manager_devcon_autoconnect_blocked_reason_set(
+ self,
+ device,
+ sett_conn,
+ NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
+ FALSE))
+ changed = TRUE;
+ }
/* we remove all the blocked reason from the connection, if something
* happened, then it means the status changed */
@@ -1487,8 +1486,9 @@ nm_manager_devcon_autoconnect_blocked_reason_set(NMManager
gboolean changed = FALSE;
char buf[100];
- nm_assert(value);
- nm_assert(sett_conn);
+ nm_assert(NM_IS_SETTINGS_CONNECTION(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) {
data = _devcon_lookup_data(self, device, sett_conn, TRUE);
diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c
index 9309026e56..2e7f9c605b 100644
--- a/src/core/nm-policy.c
+++ b/src/core/nm-policy.c
@@ -2158,7 +2158,7 @@ device_state_changed(NMDevice *device,
priv->manager,
device,
sett_conn,
- NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_ALL,
+ NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
FALSE);
break;
case NM_DEVICE_STATE_SECONDARIES:
diff --git a/src/core/settings/nm-settings-connection.c b/src/core/settings/nm-settings-connection.c
index 8d9ee08a99..8b18812255 100644
--- a/src/core/settings/nm-settings-connection.c
+++ b/src/core/settings/nm-settings-connection.c
@@ -2526,7 +2526,10 @@ nm_settings_connection_autoconnect_blocked_reason_set(NMSettingsConnection
char buf1[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 = NM_FLAGS_ASSIGN(v, reason, set);