mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-11 09:18:38 +02:00
settings: expose nm_settings_connection_get_seen_bssids()
The seen-BSSID list lives in NMSettingsConnection's private LRU
hash, not in the NMSettingWireless property of the same name. As
documented in commit 07c6f933d1 ('wifi: fix aggressively roaming
(background Wi-Fi scanning) based on seen-bssids'), the setting
field is only populated for D-Bus export via _get_seen_bssids() in
the GetSettings handler; reading it from an applied connection
during activation returns stale/empty data.
Promote the existing static _get_seen_bssids() helper to a public
nm_settings_connection_get_seen_bssids() accessor and expose
SEEN_BSSIDS_MAX as NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX so that
callers needing the actual BSSID list during activation (rather
than just the count, already available via
nm_settings_connection_get_num_seen_bssids()) can stack-allocate
a fixed-size strv buffer without leaking the constant.
No functional change. Existing internal callers in
nm-settings-connection.c switch from the static name to the new
public name.
Signed-off-by: Louis Kotze <loukot@gmail.com>
This commit is contained in:
parent
19b065bc4a
commit
fbfbd7f8e4
2 changed files with 23 additions and 16 deletions
|
|
@ -28,8 +28,6 @@
|
|||
#include "nm-dbus-manager.h"
|
||||
#include "settings/plugins/keyfile/nms-keyfile-storage.h"
|
||||
|
||||
#define SEEN_BSSIDS_MAX 30
|
||||
|
||||
#define _NM_SETTINGS_UPDATE2_FLAG_ALL_PERSIST_MODES \
|
||||
((NMSettingsUpdate2Flags) (NM_SETTINGS_UPDATE2_FLAG_TO_DISK \
|
||||
| NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY \
|
||||
|
|
@ -220,9 +218,7 @@ static const GDBusSignalInfo signal_info_updated;
|
|||
static const GDBusSignalInfo signal_info_removed;
|
||||
static const NMDBusInterfaceInfoExtended interface_info_settings_connection;
|
||||
|
||||
static void update_agent_secrets_cache(NMSettingsConnection *self, NMConnection *new);
|
||||
static guint _get_seen_bssids(NMSettingsConnection *self,
|
||||
const char *strv_buf[static(SEEN_BSSIDS_MAX + 1)]);
|
||||
static void update_agent_secrets_cache(NMSettingsConnection *self, NMConnection *new);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -1405,7 +1401,7 @@ get_settings_auth_cb(NMSettingsConnection *self,
|
|||
GError *error,
|
||||
gpointer data)
|
||||
{
|
||||
const char *seen_bssids_strv[SEEN_BSSIDS_MAX + 1];
|
||||
const char *seen_bssids_strv[NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX + 1];
|
||||
NMConnectionSerializationOptions options = {};
|
||||
|
||||
if (error) {
|
||||
|
|
@ -1426,7 +1422,7 @@ get_settings_auth_cb(NMSettingsConnection *self,
|
|||
* from the same reason as timestamp. Thus we put it here to GetSettings()
|
||||
* return settings too.
|
||||
*/
|
||||
_get_seen_bssids(self, seen_bssids_strv);
|
||||
nm_settings_connection_get_seen_bssids(self, seen_bssids_strv);
|
||||
options.seen_bssids = seen_bssids_strv;
|
||||
|
||||
/* Secrets should *never* be returned by the GetSettings method, they
|
||||
|
|
@ -2434,7 +2430,7 @@ _nm_settings_connection_register_kf_dbs(NMSettingsConnection *self,
|
|||
SeenBssidEntry *entry;
|
||||
|
||||
nm_assert(result_len == nm_g_hash_table_size(priv->seen_bssids_hash));
|
||||
if (result_len >= SEEN_BSSIDS_MAX)
|
||||
if (result_len >= NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX)
|
||||
break;
|
||||
|
||||
if (!_nm_utils_hwaddr_aton_exact(tmp_strv[i], &addr_bin, sizeof(addr_bin)))
|
||||
|
|
@ -2459,12 +2455,14 @@ _nm_settings_connection_register_kf_dbs(NMSettingsConnection *self,
|
|||
nm_clear_pointer(&priv->seen_bssids_hash, g_hash_table_destroy);
|
||||
|
||||
nm_assert(nm_g_hash_table_size(priv->seen_bssids_hash) == result_len);
|
||||
nm_assert(result_len <= SEEN_BSSIDS_MAX);
|
||||
nm_assert(result_len <= NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
static guint
|
||||
_get_seen_bssids(NMSettingsConnection *self, const char *strv_buf[static(SEEN_BSSIDS_MAX + 1)])
|
||||
guint
|
||||
nm_settings_connection_get_seen_bssids(
|
||||
NMSettingsConnection *self,
|
||||
const char *strv_buf[static(NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX + 1)])
|
||||
{
|
||||
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self);
|
||||
SeenBssidEntry *entry;
|
||||
|
|
@ -2472,7 +2470,7 @@ _get_seen_bssids(NMSettingsConnection *self, const char *strv_buf[static(SEEN_BS
|
|||
|
||||
i = 0;
|
||||
c_list_for_each_entry (entry, &priv->seen_bssids_lst_head, seen_bssids_lst) {
|
||||
nm_assert(i <= SEEN_BSSIDS_MAX);
|
||||
nm_assert(i <= NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX);
|
||||
strv_buf[i++] = entry->bssid;
|
||||
}
|
||||
strv_buf[i] = NULL;
|
||||
|
|
@ -2515,7 +2513,7 @@ void
|
|||
nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *seen_bssid)
|
||||
{
|
||||
NMSettingsConnectionPrivate *priv = NM_SETTINGS_CONNECTION_GET_PRIVATE(self);
|
||||
const char *seen_bssids_strv[SEEN_BSSIDS_MAX + 1];
|
||||
const char *seen_bssids_strv[NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX + 1];
|
||||
NMEtherAddr addr_bin;
|
||||
const char *connection_uuid;
|
||||
SeenBssidEntry entry_stack;
|
||||
|
|
@ -2546,14 +2544,14 @@ nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *se
|
|||
if (!g_hash_table_add(priv->seen_bssids_hash, entry))
|
||||
nm_assert_not_reached();
|
||||
|
||||
if (g_hash_table_size(priv->seen_bssids_hash) > SEEN_BSSIDS_MAX) {
|
||||
if (g_hash_table_size(priv->seen_bssids_hash) > NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX) {
|
||||
g_hash_table_remove(
|
||||
priv->seen_bssids_hash,
|
||||
c_list_last_entry(&priv->seen_bssids_lst_head, SeenBssidEntry, seen_bssids_lst));
|
||||
}
|
||||
}
|
||||
|
||||
nm_assert(g_hash_table_size(priv->seen_bssids_hash) <= SEEN_BSSIDS_MAX);
|
||||
nm_assert(g_hash_table_size(priv->seen_bssids_hash) <= NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX);
|
||||
nm_assert(g_hash_table_size(priv->seen_bssids_hash)
|
||||
== c_list_length(&priv->seen_bssids_lst_head));
|
||||
|
||||
|
|
@ -2564,7 +2562,7 @@ nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *se
|
|||
if (!connection_uuid)
|
||||
return;
|
||||
|
||||
i = _get_seen_bssids(self, seen_bssids_strv);
|
||||
i = nm_settings_connection_get_seen_bssids(self, seen_bssids_strv);
|
||||
nm_key_file_db_set_string_list(priv->kf_db_seen_bssids, connection_uuid, seen_bssids_strv, i);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -348,6 +348,15 @@ void nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const cha
|
|||
|
||||
guint nm_settings_connection_get_num_seen_bssids(NMSettingsConnection *self);
|
||||
|
||||
/* Maximum number of BSSIDs tracked per connection. Public so that callers
|
||||
* needing the full list can stack-allocate a fixed-size strv buffer for
|
||||
* nm_settings_connection_get_seen_bssids(). */
|
||||
#define NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX 30u
|
||||
|
||||
guint nm_settings_connection_get_seen_bssids(
|
||||
NMSettingsConnection *self,
|
||||
const char *strv_buf[static(NM_SETTINGS_CONNECTION_SEEN_BSSIDS_MAX + 1)]);
|
||||
|
||||
gboolean nm_settings_connection_autoconnect_is_blocked(NMSettingsConnection *self);
|
||||
|
||||
NMSettingsAutoconnectBlockedReason
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue