summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-04-28 12:12:21 +0200
committerThomas Haller <thaller@redhat.com>2023-05-04 10:34:12 +0200
commit5492945fdcab7027b0f7f5791e303d2a22249f9e (patch)
treec8a694dfa0c8e0c38a0bc070f3326355d0ba3178
parenta019d965f72e1f8d59413f2df9e8d94cdfff84db (diff)
downloadNetworkManager-5492945fdcab7027b0f7f5791e303d2a22249f9e.tar.gz
core: use switch statement in device_state_changed()
It seems better for readability, because reacting based on the state-reason is ugly already. This way, we access nm_device_state_reason_check(reason) only at once place. With the if, it's not immediately obvious that both if/else parts only switch on the reason too.
-rw-r--r--src/core/nm-policy.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c
index 7a4cab1d21..5b64c86951 100644
--- a/src/core/nm-policy.c
+++ b/src/core/nm-policy.c
@@ -1983,7 +1983,8 @@ device_state_changed(NMDevice *device,
gboolean blocked = FALSE;
guint64 con_v;
- if (nm_device_state_reason_check(reason) == NM_DEVICE_STATE_REASON_NO_SECRETS) {
+ switch (nm_device_state_reason_check(reason)) {
+ case NM_DEVICE_STATE_REASON_NO_SECRETS:
/* we want to block the connection from auto-connect if it failed due to no-secrets.
* However, if a secret-agent registered, since the connection made the last
* secret-request, we do not block it. The new secret-agent might not yet
@@ -2009,8 +2010,8 @@ device_state_changed(NMDevice *device,
TRUE);
blocked = TRUE;
}
- } else if (nm_device_state_reason_check(reason)
- == NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED) {
+ break;
+ case NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED:
/* A connection that fails due to dependency-failed is not
* able to reconnect until the master connection activates
* again; when this happens, the master clears the blocked
@@ -2032,6 +2033,9 @@ device_state_changed(NMDevice *device,
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
TRUE);
blocked = TRUE;
+ break;
+ default:
+ break;
}
if (!blocked) {