diff options
author | Thomas Haller <thaller@redhat.com> | 2023-03-21 16:55:29 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-03-22 17:15:54 +0100 |
commit | 07c6f933d1b4ba20be43bb5f5d6f977572411750 (patch) | |
tree | 451c7bfefb503e2dca1d885d3031636274add23c | |
parent | d8b8a888b2f9abb9756093fb812e77318d54ee87 (diff) |
wifi: fix aggressively roaming (background Wi-Fi scanning) based on seen-bssids
"wifi.seen-bssids" looks like a regular property, but it is not. Unlike
almost all other properties, it does not contain user configuration,
rather it gets filled by the daemon.
The values are thus stored in "/var/lib/NetworkManager/seen-bssids"
file, and the daemon maintains the values separately from the profile.
Only before exporting the profile on D-Bus, the value gets merged (see
NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->>getsettings_cached and
nm_connection_to_dbus_full().
Hence, looking at nm_setting_wireless_get_num_seen_bssids() is not
working. Fix that.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/1253
Fixes: 0f3203338c85 ('wifi: roam aggressively if we on a multi-AP network')
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1577
-rw-r--r-- | src/core/devices/wifi/nm-device-wifi.c | 20 | ||||
-rw-r--r-- | src/core/settings/nm-settings-connection.c | 8 | ||||
-rw-r--r-- | src/core/settings/nm-settings-connection.h | 2 | ||||
-rw-r--r-- | src/core/supplicant/nm-supplicant-config.c | 7 | ||||
-rw-r--r-- | src/core/supplicant/nm-supplicant-config.h | 6 | ||||
-rw-r--r-- | src/core/supplicant/tests/test-supplicant-config.c | 2 |
6 files changed, 34 insertions, 11 deletions
diff --git a/src/core/devices/wifi/nm-device-wifi.c b/src/core/devices/wifi/nm-device-wifi.c index b598cde2b5..aad512ca9e 100644 --- a/src/core/devices/wifi/nm-device-wifi.c +++ b/src/core/devices/wifi/nm-device-wifi.c @@ -2915,10 +2915,11 @@ supplicant_connection_timeout_cb(gpointer user_data) } static NMSupplicantConfig * -build_supplicant_config(NMDeviceWifi *self, - NMConnection *connection, - guint32 fixed_freq, - GError **error) +build_supplicant_config(NMDeviceWifi *self, + NMSettingsConnection *sett_conn, + NMConnection *connection, + guint32 fixed_freq, + GError **error) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); NMSupplicantConfig *config = NULL; @@ -2947,7 +2948,10 @@ build_supplicant_config(NMDeviceWifi *self, goto error; } - if (!nm_supplicant_config_add_bgscan(config, connection, error)) { + if (!nm_supplicant_config_add_bgscan(config, + connection, + nm_settings_connection_get_num_seen_bssids(sett_conn), + error)) { g_prefix_error(error, "bgscan: "); goto error; } @@ -3281,6 +3285,7 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) NMActRequest *req; NMWifiAP *ap; NMConnection *connection; + NMSettingsConnection *sett_conn; const char *setting_name; NMSettingWireless *s_wireless; GError *error = NULL; @@ -3304,6 +3309,9 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) ap_mode = nm_wifi_ap_get_mode(ap); + sett_conn = nm_act_request_get_settings_connection(req); + nm_assert(sett_conn); + connection = nm_act_request_get_applied_connection(req); s_wireless = nm_connection_get_setting_wireless(connection); nm_assert(s_wireless); @@ -3352,7 +3360,7 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) set_powersave(device); /* Build up the supplicant configuration */ - config = build_supplicant_config(self, connection, nm_wifi_ap_get_freq(ap), &error); + config = build_supplicant_config(self, sett_conn, connection, nm_wifi_ap_get_freq(ap), &error); if (!config) { _LOGE(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) couldn't build wireless configuration: %s", diff --git a/src/core/settings/nm-settings-connection.c b/src/core/settings/nm-settings-connection.c index b80af551ce..b8cf0b5833 100644 --- a/src/core/settings/nm-settings-connection.c +++ b/src/core/settings/nm-settings-connection.c @@ -2500,6 +2500,14 @@ nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *se nm_key_file_db_set_string_list(priv->kf_db_seen_bssids, connection_uuid, seen_bssids_strv, i); } +guint +nm_settings_connection_get_num_seen_bssids(NMSettingsConnection *self) +{ + g_return_val_if_fail(NM_IS_SETTINGS_CONNECTION(self), 0); + + return nm_g_hash_table_size(NM_SETTINGS_CONNECTION_GET_PRIVATE(self)->seen_bssids_hash); +} + /*****************************************************************************/ NMSettingsAutoconnectBlockedReason diff --git a/src/core/settings/nm-settings-connection.h b/src/core/settings/nm-settings-connection.h index 546e4efb14..54abcf45b7 100644 --- a/src/core/settings/nm-settings-connection.h +++ b/src/core/settings/nm-settings-connection.h @@ -338,6 +338,8 @@ gboolean nm_settings_connection_has_seen_bssid(NMSettingsConnection *self, const void nm_settings_connection_add_seen_bssid(NMSettingsConnection *self, const char *seen_bssid); +guint nm_settings_connection_get_num_seen_bssids(NMSettingsConnection *self); + gboolean nm_settings_connection_autoconnect_is_blocked(NMSettingsConnection *self); NMSettingsAutoconnectBlockedReason diff --git a/src/core/supplicant/nm-supplicant-config.c b/src/core/supplicant/nm-supplicant-config.c index c63a00585a..1d9372e09f 100644 --- a/src/core/supplicant/nm-supplicant-config.c +++ b/src/core/supplicant/nm-supplicant-config.c @@ -592,7 +592,10 @@ nm_supplicant_config_add_setting_wireless(NMSupplicantConfig *self, } gboolean -nm_supplicant_config_add_bgscan(NMSupplicantConfig *self, NMConnection *connection, GError **error) +nm_supplicant_config_add_bgscan(NMSupplicantConfig *self, + NMConnection *connection, + guint num_seen_bssids, + GError **error) { NMSettingWireless *s_wifi; NMSettingWirelessSecurity *s_wsec; @@ -629,7 +632,7 @@ nm_supplicant_config_add_bgscan(NMSupplicantConfig *self, NMConnection *connecti * when the signal is still somewhat OK so we have an up-to-date roam * candidate list when the signal gets bad. */ - if (nm_setting_wireless_get_num_seen_bssids(s_wifi) > 1 + if (num_seen_bssids > 1u || ((s_wsec = nm_connection_get_setting_wireless_security(connection)) && NM_IN_STRSET(nm_setting_wireless_security_get_key_mgmt(s_wsec), "ieee8021x", diff --git a/src/core/supplicant/nm-supplicant-config.h b/src/core/supplicant/nm-supplicant-config.h index 063f7f5580..585cf9588d 100644 --- a/src/core/supplicant/nm-supplicant-config.h +++ b/src/core/supplicant/nm-supplicant-config.h @@ -44,8 +44,10 @@ gboolean nm_supplicant_config_add_setting_wireless(NMSupplicantConfig *self, guint32 fixed_freq, GError **error); -gboolean -nm_supplicant_config_add_bgscan(NMSupplicantConfig *self, NMConnection *connection, GError **error); +gboolean nm_supplicant_config_add_bgscan(NMSupplicantConfig *self, + NMConnection *connection, + guint num_seen_bssids, + GError **error); gboolean nm_supplicant_config_add_setting_wireless_security(NMSupplicantConfig *self, NMSettingWirelessSecurity *setting, diff --git a/src/core/supplicant/tests/test-supplicant-config.c b/src/core/supplicant/tests/test-supplicant-config.c index 237b1a9671..1ca5b26e56 100644 --- a/src/core/supplicant/tests/test-supplicant-config.c +++ b/src/core/supplicant/tests/test-supplicant-config.c @@ -127,7 +127,7 @@ build_supplicant_config(NMConnection *connection, g_assert_no_error(error); g_assert(success); - success = nm_supplicant_config_add_bgscan(config, connection, &error); + success = nm_supplicant_config_add_bgscan(config, connection, 0, &error); g_assert_no_error(error); g_assert(success); |