diff mbox series

[v2,3/4] station: knownnetworks: limit quick scans to 5 freqs per network

Message ID 20240124134001.20453-3-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [v2,1/4] knownnetworks: pass scan_bss to known_network_add_frequency | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood Jan. 24, 2024, 1:40 p.m. UTC
In very large network deployments there could be a vast amount of APs
which could create a large known frequency list after some time once
all the APs are seen in scan results. This then increases the quick
scan time significantly, in the very worst case (but unlikely) just
as long as a full scan.

To help with this support in knownnetworks was added to limit the
number of frequencies per network. Station will now only get 5
recent frequencies per network making the maximum frequencies 25
in the worst case (~2.5s scan).

The magic values are now defines, and the recent roam frequencies
was also changed to use this define as well.
---
 src/knownnetworks.c |  9 ++++++---
 src/knownnetworks.h |  3 ++-
 src/station.c       | 10 ++++++++--
 3 files changed, 16 insertions(+), 6 deletions(-)

Comments

Denis Kenzior Jan. 24, 2024, 6:21 p.m. UTC | #1
Hi James,

On 1/24/24 07:40, James Prestwood wrote:
> In very large network deployments there could be a vast amount of APs
> which could create a large known frequency list after some time once
> all the APs are seen in scan results. This then increases the quick
> scan time significantly, in the very worst case (but unlikely) just
> as long as a full scan.
> 
> To help with this support in knownnetworks was added to limit the
> number of frequencies per network. Station will now only get 5
> recent frequencies per network making the maximum frequencies 25
> in the worst case (~2.5s scan).
> 
> The magic values are now defines, and the recent roam frequencies
> was also changed to use this define as well.

Yep, I like it.

> ---
>   src/knownnetworks.c |  9 ++++++---
>   src/knownnetworks.h |  3 ++-
>   src/station.c       | 10 ++++++++--
>   3 files changed, 16 insertions(+), 6 deletions(-)
> 
> diff --git a/src/knownnetworks.c b/src/knownnetworks.c
> index 6e549e02..fe0fce09 100644
> --- a/src/knownnetworks.c
> +++ b/src/knownnetworks.c
> @@ -518,7 +518,8 @@ struct network_info *known_networks_find(const char *ssid,
>   }
>   
>   struct scan_freq_set *known_networks_get_recent_frequencies(
> -						uint8_t num_networks_tosearch)
> +						uint8_t num_networks_tosearch,
> +						uint8_t freqs_per_network)
>   {
>   	/*
>   	 * This search function assumes that the known networks are always
> @@ -530,7 +531,7 @@ struct scan_freq_set *known_networks_get_recent_frequencies(
>   	const struct l_queue_entry *freq_entry;
>   	struct scan_freq_set *set;
>   
> -	if (!num_networks_tosearch)
> +	if (!num_networks_tosearch || !freqs_per_network)
>   		return NULL;
>   
>   	set = scan_freq_set_new();
> @@ -540,10 +541,12 @@ struct scan_freq_set *known_networks_get_recent_frequencies(
>   				network_entry = network_entry->next,
>   						num_networks_tosearch--) {
>   		const struct network_info *network = network_entry->data;
> +		uint8_t freqs_found = 0;
>   
>   		for (freq_entry = l_queue_get_entries(
>   						network->known_frequencies);
> -				freq_entry; freq_entry = freq_entry->next) {
> +				freq_entry && freqs_found < freqs_per_network;
> +				freq_entry = freq_entry->next, freqs_found++) {

This is getting a bit unreadable.  Maybe a while loop makes this look better?

freq_entry = l_queue_get_entries();

while (freq_entry && freqs_found < freq_per_network) {
	...
	freqs_found += 1;
	freq_entry = freq_entry->next;
}

>   			const struct known_frequency *known_freq =
>   							freq_entry->data;
>   

Regards,
-Denis
diff mbox series

Patch

diff --git a/src/knownnetworks.c b/src/knownnetworks.c
index 6e549e02..fe0fce09 100644
--- a/src/knownnetworks.c
+++ b/src/knownnetworks.c
@@ -518,7 +518,8 @@  struct network_info *known_networks_find(const char *ssid,
 }
 
 struct scan_freq_set *known_networks_get_recent_frequencies(
-						uint8_t num_networks_tosearch)
+						uint8_t num_networks_tosearch,
+						uint8_t freqs_per_network)
 {
 	/*
 	 * This search function assumes that the known networks are always
@@ -530,7 +531,7 @@  struct scan_freq_set *known_networks_get_recent_frequencies(
 	const struct l_queue_entry *freq_entry;
 	struct scan_freq_set *set;
 
-	if (!num_networks_tosearch)
+	if (!num_networks_tosearch || !freqs_per_network)
 		return NULL;
 
 	set = scan_freq_set_new();
@@ -540,10 +541,12 @@  struct scan_freq_set *known_networks_get_recent_frequencies(
 				network_entry = network_entry->next,
 						num_networks_tosearch--) {
 		const struct network_info *network = network_entry->data;
+		uint8_t freqs_found = 0;
 
 		for (freq_entry = l_queue_get_entries(
 						network->known_frequencies);
-				freq_entry; freq_entry = freq_entry->next) {
+				freq_entry && freqs_found < freqs_per_network;
+				freq_entry = freq_entry->next, freqs_found++) {
 			const struct known_frequency *known_freq =
 							freq_entry->data;
 
diff --git a/src/knownnetworks.h b/src/knownnetworks.h
index 36106501..108f334e 100644
--- a/src/knownnetworks.h
+++ b/src/knownnetworks.h
@@ -114,7 +114,8 @@  struct network_info *known_networks_find(const char *ssid,
 						enum security security);
 
 struct scan_freq_set *known_networks_get_recent_frequencies(
-						uint8_t num_networks_tosearch);
+						uint8_t num_networks_tosearch,
+						uint8_t freqs_per_network);
 int known_network_add_frequency(struct network_info *info,
 				struct scan_bss *bss);
 void known_network_frequency_sync(struct network_info *info);
diff --git a/src/station.c b/src/station.c
index a6442d3e..1b34b956 100644
--- a/src/station.c
+++ b/src/station.c
@@ -64,6 +64,9 @@ 
 #include "src/eap-tls-common.h"
 #include "src/storage.h"
 
+#define STATION_RECENT_NETWORK_LIMIT	5
+#define STATION_RECENT_FREQS_LIMIT	5
+
 static struct l_queue *station_list;
 static uint32_t netdev_watch;
 static uint32_t mfp_setting;
@@ -1434,7 +1437,9 @@  static int station_quick_scan_trigger(struct station *station)
 		return -EAGAIN;
 	}
 
-	known_freq_set = known_networks_get_recent_frequencies(5);
+	known_freq_set = known_networks_get_recent_frequencies(
+						STATION_RECENT_NETWORK_LIMIT,
+						STATION_RECENT_FREQS_LIMIT);
 	if (!known_freq_set)
 		return -ENODATA;
 
@@ -2757,7 +2762,8 @@  static int station_roam_scan_known_freqs(struct station *station)
 	const struct network_info *info = network_get_info(
 						station->connected_network);
 	struct scan_freq_set *freqs = network_info_get_roam_frequencies(info,
-					station->connected_bss->frequency, 5);
+					station->connected_bss->frequency,
+					STATION_RECENT_FREQS_LIMIT);
 	int r = -ENODATA;
 
 	if (!freqs)