summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-03-21 16:55:29 +0100
committerThomas Haller <thaller@redhat.com>2023-03-29 14:22:57 +0200
commit3ddc17700ddc2f13b2d635e6fade075a69d6a3cf (patch)
tree4386f47cb1e0b1fdb54b3ea4c556e4bad9895b24
parentf71cd2eb72d97ee9119e812bba7bbd581c587114 (diff)
downloadNetworkManager-3ddc17700ddc2f13b2d635e6fade075a69d6a3cf.tar.gz
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 (cherry picked from commit 07c6f933d1b4ba20be43bb5f5d6f977572411750)
-rw-r--r--src/core/devices/wifi/nm-device-wifi.c20
-rw-r--r--src/core/settings/nm-settings-connection.c8
-rw-r--r--src/core/settings/nm-settings-connection.h2
-rw-r--r--src/core/supplicant/nm-supplicant-config.c7
-rw-r--r--src/core/supplicant/nm-supplicant-config.h6
-rw-r--r--src/core/supplicant/tests/test-supplicant-config.c2
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 7b632f2792..03625f8d6d 100644
--- a/src/core/devices/wifi/nm-device-wifi.c
+++ b/src/core/devices/wifi/nm-device-wifi.c
@@ -2912,10 +2912,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;
@@ -2944,7 +2945,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;
}
@@ -3279,6 +3283,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;
@@ -3302,6 +3307,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);
@@ -3350,7 +3358,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 1638efcd7e..024c000996 100644
--- a/src/core/settings/nm-settings-connection.c
+++ b/src/core/settings/nm-settings-connection.c
@@ -2532,6 +2532,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);
+}
+
/*****************************************************************************/
/**
diff --git a/src/core/settings/nm-settings-connection.h b/src/core/settings/nm-settings-connection.h
index 47599c3d6e..fce7497c4c 100644
--- a/src/core/settings/nm-settings-connection.h
+++ b/src/core/settings/nm-settings-connection.h
@@ -345,6 +345,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);
+
int nm_settings_connection_autoconnect_retries_get(NMSettingsConnection *self);
void nm_settings_connection_autoconnect_retries_set(NMSettingsConnection *self, int retries);
void nm_settings_connection_autoconnect_retries_reset(NMSettingsConnection *self);
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);