summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-05-16 21:41:33 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2022-10-14 11:29:58 +0200
commit3453bf09e8e5bd1b3b20e229b7d3de5dd89e1940 (patch)
tree9a846943a21b8bb130417b0f94fc81fb8b95e46e
parent1cd5276952661ffd13440ec02c1e884495167c56 (diff)
downloadNetworkManager-3453bf09e8e5bd1b3b20e229b7d3de5dd89e1940.tar.gz
dhcp: replace switch in l3_cfg_notify_cb() with if blocks
The l3_cfg_notify_cb() handler is used for different purposes, and different events will be considered. Usually a switch statement is very nice for enums, especially if all enum values should be handled (because the compiler can warn about unhandled cases). In this case, not all events are supposed to be handled. At this point, it seems nicer to just use an if block. It better composes. The compiler should be able to optimize both variants to the same result. In any case, checking some integers for equality is in any case going to be efficient. (cherry picked from commit 7db07faa5e31c077dd9a817cac52cc1e04a6e28b) (cherry picked from commit 9acb6f90825c6d8fc6c702176027b0807a97947f)
-rw-r--r--src/core/dhcp/nm-dhcp-client.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c
index e30b137d68..ca1361e71c 100644
--- a/src/core/dhcp/nm-dhcp-client.c
+++ b/src/core/dhcp/nm-dhcp-client.c
@@ -589,15 +589,11 @@ l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDhcp
nm_assert(l3cfg == priv->config.l3cfg);
- switch (notify_data->notify_type) {
- case NM_L3_CONFIG_NOTIFY_TYPE_PLATFORM_CHANGE_ON_IDLE:
- {
+ if (notify_data->notify_type == NM_L3_CONFIG_NOTIFY_TYPE_PLATFORM_CHANGE_ON_IDLE
+ && priv->l3cfg_notify.wait_ll_address) {
const NMPlatformIP6Address *addr;
gs_free_error GError *error = NULL;
- if (!priv->l3cfg_notify.wait_ll_address)
- return;
-
addr = ipv6_lladdr_find(self);
if (addr) {
_LOGD("got IPv6LL address, starting transaction");
@@ -615,11 +611,10 @@ l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDhcp
}));
}
}
-
- break;
}
- case NM_L3_CONFIG_NOTIFY_TYPE_POST_COMMIT:
- {
+
+ if (notify_data->notify_type == NM_L3_CONFIG_NOTIFY_TYPE_POST_COMMIT
+ && priv->l3cfg_notify.wait_dhcp_commit) {
const NML3ConfigData *committed_l3cd;
NMDedupMultiIter ipconf_iter;
const NMPlatformIPAddress *lease_address;
@@ -630,9 +625,6 @@ l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDhcp
* configured. If the address was added, we can proceed accepting the
* lease and notifying NMDevice. */
- if (!priv->l3cfg_notify.wait_dhcp_commit)
- return;
-
nm_l3_config_data_iter_ip_address_for_each (&ipconf_iter,
priv->l3cd,
priv->config.addr_family,
@@ -648,12 +640,12 @@ l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDhcp
address4->address,
address4->plen,
address4->peer_address))
- return;
+ goto wait_dhcp_commit_done;
} else {
const NMPlatformIP6Address *address6 = (const NMPlatformIP6Address *) lease_address;
if (!nm_l3_config_data_lookup_address_6(committed_l3cd, &address6->address))
- return;
+ goto wait_dhcp_commit_done;
}
priv->l3cfg_notify.wait_dhcp_commit = FALSE;
@@ -669,7 +661,7 @@ l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDhcp
.notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_IT_LOOKS_BAD,
.it_looks_bad.reason = reason,
}));
- return;
+ goto wait_dhcp_commit_done;
}
_emit_notify(
@@ -679,11 +671,8 @@ l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, NMDhcp
.l3cd = priv->l3cd,
.accepted = TRUE,
}}));
- break;
- };
- default:
- /* ignore */;
}
+wait_dhcp_commit_done:;
}
gboolean