Skip to contentSkip to conversation

network: add network_bss_update

PATCH In review James Prestwood 2 participants 4 messages Mar 15, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 network: add network_bss_update

This will swap out a scan_bss object with a duplicate that may exist in a networks bss_list. The duplicate will be removed by since the object is owned by station it is assumed that it will be freed elsewhere.

---
 src/network.c | 21 +++++++++++++++++++++
 src/network.h |  1 +
 2 files changed, 22 insertions(+)
src/network.c +21 -0
index 5a8d93ee..0f5106b7 100644
@@ -672,6 +672,27 @@ bool network_bss_add(struct network *network, struct scan_bss *bss)
 	return true;
 }
 
+static bool match_addr(const void *a, const void *b)
+{
+	const struct scan_bss *bss = a;
+
+	return memcmp(bss->addr, b, 6) == 0;
+}
+
+/*
+ * Replaces an old scan_bss (if exists) in the bss list with a new bss object.
+ * Note this BSS is *not* freed and must be by the caller. scan_bss objects are
+ * shared between network/station but station technically owns them.
+ */
+bool network_bss_update(struct network *network, struct scan_bss *bss)
+{
+	l_queue_remove_if(network->bss_list, match_addr, bss->addr);
+
+	l_queue_insert(network->bss_list, bss, scan_bss_rank_compare, NULL);
+
+	return true;
+}
+
 bool network_bss_list_isempty(struct network *network)
 {
 	return l_queue_isempty(network->bss_list);
src/network.h +1 -0
index 30d8145e..17890496 100644
@@ -55,6 +55,7 @@ void network_set_info(struct network *network, struct network_info *info);
 int network_autoconnect(struct network *network, struct scan_bss *bss);
 void network_connect_failed(struct network *network, bool in_handshake);
 bool network_bss_add(struct network *network, struct scan_bss *bss);
+bool network_bss_update(struct network *network, struct scan_bss *bss);
 bool network_bss_list_isempty(struct network *network);
 void network_bss_list_clear(struct network *network);
 struct scan_bss *network_bss_list_pop(struct network *network);
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/3 network: replace l_queue_get_entries loop

After adding network_bss_update, network now has a match_addr queue function which can be used to replace an unneeded l_queue_get_entries loop with l_queue_find.

---
 src/network.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
src/network.c +1 -11
index 0f5106b7..53fc98a1 100644
@@ -712,17 +712,7 @@ struct scan_bss *network_bss_list_pop(struct network *network)
 struct scan_bss *network_bss_find_by_addr(struct network *network,
 						const uint8_t *addr)
 {
-	const struct l_queue_entry *bss_entry;
-
-	for (bss_entry = l_queue_get_entries(network->bss_list); bss_entry;
-						bss_entry = bss_entry->next) {
-		struct scan_bss *bss = bss_entry->data;
-
-		if (!memcmp(bss->addr, addr, sizeof(bss->addr)))
-			return bss;
-	}
-
-	return NULL;
+	return l_queue_find(network->bss_list, match_addr, addr);
 }
 
 static bool match_bss(const void *a, const void *b)
Signature · 1 line
2.26.2
#2 lore raw

PATCH 3/3 station: use network_bss_update

In reply to James Prestwood

This fixes a dangling pointer in network where station was freeing the scan_bss but network still had a pointer to it in its own bss_list.

---
 src/station.c | 2 ++
 1 file changed, 2 insertions(+)
src/station.c +2 -0
index 3a082d02..2e577290 100644
@@ -2303,6 +2303,8 @@ static void station_event_roamed(struct station *station, struct scan_bss *new)
 {
 	struct scan_bss *stale;
 
+	network_bss_update(station->connected_network, new);
+
 	/* Remove new BSS if it exists in past scan results */
 	stale = l_queue_remove_if(station->bss_list, bss_match_bssid,
 					new->addr);
Signature · 1 line
2.26.2
#3 lore raw
In reply to James Prestwood

Hi James,

Quoted 9 lines · James Prestwood

This will swap out a scan_bss object with a duplicate that may exist in a networks bss_list. The duplicate will be removed by since the object is owned by station it is assumed that it will be freed elsewhere.

---
  src/network.c | 21 +++++++++++++++++++++
  src/network.h |  1 +
  2 files changed, 22 insertions(+)

All applied, thanks.

Regards,
-Denis