From 13ebb5fc12aab3bf41d7e6c700b2bc7d1c64bbef Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 21 Feb 2023 13:43:57 +0100 Subject: [PATCH] fixup! policy: track autoconnect retries per Device x Connection The "set-full(value, mask)" variants allow to set and clear flags at the same time. Granted, that flexibility is totally unused and unnecessary. The current patch does right to drop nm_settings_connection_autoconnect_blocked_reason_set_full() and only have a (simplified) nm_settings_connection_autoconnect_blocked_reason_set(). If we already recognize that the set-full() variant is overkill, let's not introduce it here either. While at it, don't do: if (...) { ... return ...; } else { ... If a branch can always return early from a function, don't have an else branch. Unindent the code. --- src/core/nm-manager.c | 41 ++++++++++++++++++++--------------------- src/core/nm-manager.h | 26 +++++--------------------- 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index 7cd07475b9..14943a4ce0 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -1411,25 +1411,24 @@ nm_manager_devcon_autoconnect_is_blocked(NMManager *self, } gboolean -nm_manager_devcon_autoconnect_blocked_reason_set_full(NMManager *self, - NMDevice *device, - NMSettingsConnection *sett_conn, - NMSettingsAutoconnectBlockedReason mask, - NMSettingsAutoconnectBlockedReason value) +nm_manager_devcon_autoconnect_blocked_reason_set(NMManager *self, + NMDevice *device, + NMSettingsConnection *sett_conn, + NMSettingsAutoconnectBlockedReason value, + gboolean set) { NMSettingsAutoconnectBlockedReason v; DevConData *data; gboolean changed = FALSE; char buf[100]; - nm_assert(mask); + nm_assert(value); nm_assert(sett_conn); - nm_assert(!NM_FLAGS_ANY(value, ~mask)); if (device) { data = _devcon_lookup_data(self, device, sett_conn, TRUE); v = data->autoconnect.blocked_reason; - v = (v & ~mask) | (value & mask); + v = set ? NM_FLAGS_SET(v, value) : NM_FLAGS_UNSET(v, value); if (data->autoconnect.blocked_reason == v) return FALSE; @@ -1440,20 +1439,20 @@ nm_manager_devcon_autoconnect_blocked_reason_set_full(NMManager nm_device_get_ip_iface(device)); data->autoconnect.blocked_reason = v; return TRUE; - } else { - c_list_for_each_entry (data, &sett_conn->devcon_con_lst_head, con_lst) { - v = data->autoconnect.blocked_reason; - v = (v & ~mask) | (value & mask); + } - if (data->autoconnect.blocked_reason == v) - continue; - _LOGT(LOGD_SETTINGS, - "autoconnect: blocked reason: %s for device %s", - nm_settings_autoconnect_blocked_reason_to_string(v, buf, sizeof(buf)), - nm_device_get_ip_iface(data->device)); - data->autoconnect.blocked_reason = v; - changed = TRUE; - } + c_list_for_each_entry (data, &sett_conn->devcon_con_lst_head, con_lst) { + v = data->autoconnect.blocked_reason; + v = set ? NM_FLAGS_SET(v, value) : NM_FLAGS_UNSET(v, value); + + if (data->autoconnect.blocked_reason == v) + continue; + _LOGT(LOGD_SETTINGS, + "autoconnect: blocked reason: %s for device %s", + nm_settings_autoconnect_blocked_reason_to_string(v, buf, sizeof(buf)), + nm_device_get_ip_iface(data->device)); + data->autoconnect.blocked_reason = v; + changed = TRUE; } return changed; diff --git a/src/core/nm-manager.h b/src/core/nm-manager.h index b177b60b36..bc8b537485 100644 --- a/src/core/nm-manager.h +++ b/src/core/nm-manager.h @@ -249,26 +249,10 @@ gboolean nm_manager_devcon_autoconnect_is_blocked(NMManager *self, NMDevice *device, NMSettingsConnection *sett_conn); -gboolean -nm_manager_devcon_autoconnect_blocked_reason_set_full(NMManager *self, - NMDevice *device, - NMSettingsConnection *sett_conn, - NMSettingsAutoconnectBlockedReason mask, - NMSettingsAutoconnectBlockedReason value); - -static inline gboolean -nm_manager_devcon_autoconnect_blocked_reason_set(NMManager *self, - NMDevice *device, - NMSettingsConnection *sett_conn, - NMSettingsAutoconnectBlockedReason mask, - gboolean set) -{ - return nm_manager_devcon_autoconnect_blocked_reason_set_full( - self, - device, - sett_conn, - mask, - set ? mask : NM_SETTINGS_AUTO_CONNECT_BLOCKED_REASON_NONE); -} +gboolean nm_manager_devcon_autoconnect_blocked_reason_set(NMManager *self, + NMDevice *device, + NMSettingsConnection *sett_conn, + NMSettingsAutoconnectBlockedReason value, + gboolean set); #endif /* __NETWORKMANAGER_MANAGER_H__ */