From 7c94704cb99078cee07e1c556323f4cc4d17f2f8 Mon Sep 17 00:00:00 2001 From: stsp Date: Wed, 12 Jan 2022 08:29:27 +0000 Subject: [PATCH] Remove ieee80211_find_node_for_beacon(). The original purpose of ieee80211_find_node_for_beacon() was to avoid storing duplicate nodes with the same source MAC address in a hash table. Later on, our node table data structure was changed from a hash table to an RB tree. The RB tree can only store a single node per MAC address. However, find_node_for_beacon() was kept regardless, now documented to serve a different purpose. Its new purpose is to tell apart different nodes which happen to use the same MAC address and hence cannot both be stored in the RB tree. The idea is to filter such duplicate nodes out during a scan. But colliding nodes are told apart by RSSI and channel, and either may change over time. So this does not really prevent duplicate MAC addresses from causing issues. The code which decides which node is "better" can erroneously match an AP against itself, in case the AP uses a hidden SSID. This caused workarounds for hidden SSID to pile up over time. Just a bit further down, the code looks up the same node again and performs all of the intended node state updates. Simply skipping the ieee80211_find_node_for_beacon() check makes such state updates work. ok tobhe@ --- sys/net80211/ieee80211_input.c | 39 +++++++--------------------------- sys/net80211/ieee80211_node.c | 26 +---------------------- sys/net80211/ieee80211_node.h | 6 +----- 3 files changed, 10 insertions(+), 61 deletions(-) diff --git a/sys/net80211/ieee80211_input.c b/sys/net80211/ieee80211_input.c index 13673bda75f..d764aa0cc43 100644 --- a/sys/net80211/ieee80211_input.c +++ b/sys/net80211/ieee80211_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_input.c,v 1.241 2022/01/05 05:18:25 dlg Exp $ */ +/* $OpenBSD: ieee80211_input.c,v 1.242 2022/01/12 08:29:27 stsp Exp $ */ /*- * Copyright (c) 2001 Atsushi Onoe @@ -1751,36 +1751,6 @@ ieee80211_recv_probe_resp(struct ieee80211com *ic, struct mbuf *m, ic->ic_stats.is_rx_chanmismatch++; return; } - /* - * Use mac, channel and rssi so we collect only the - * best potential AP with the equal bssid while scanning. - * Collecting all potential APs may result in bloat of - * the node tree. This call will return NULL if the node - * for this APs does not exist or if the new node is the - * potential better one. - */ - ni = ieee80211_find_node_for_beacon(ic, wh->i_addr2, - &ic->ic_channels[chan], ssid, rxi->rxi_rssi); - if (ni != NULL) { - /* - * If we are doing a directed scan for an AP with a hidden SSID - * we must collect the SSID from a probe response to override - * a non-zero-length SSID filled with zeroes that we may have - * received earlier in a beacon. - */ - if (isprobe && ssid[1] != 0 && ni->ni_essid[0] == '\0') { - ni->ni_esslen = ssid[1]; - memset(ni->ni_essid, 0, sizeof(ni->ni_essid)); - /* we know that ssid[1] <= IEEE80211_NWID_LEN */ - memcpy(ni->ni_essid, &ssid[2], ssid[1]); - } - - /* Update channel in case AP has switched */ - if (ic->ic_opmode == IEEE80211_M_STA) - ni->ni_chan = rni->ni_chan; - - return; - } #ifdef IEEE80211_DEBUG if (ieee80211_debug > 1 && @@ -1977,6 +1947,13 @@ ieee80211_recv_probe_resp(struct ieee80211com *ic, struct mbuf *m, } } + /* + * Set our SSID if we do not know it yet. + * If we are doing a directed scan for an AP with a hidden SSID + * we must collect the SSID from a probe response to override + * a non-zero-length SSID filled with zeroes that we may have + * received earlier in a beacon. + */ if (ssid[1] != 0 && ni->ni_essid[0] == '\0') { ni->ni_esslen = ssid[1]; memset(ni->ni_essid, 0, sizeof(ni->ni_essid)); diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c index 98cac0edbe5..02c5a00fef8 100644 --- a/sys/net80211/ieee80211_node.c +++ b/sys/net80211/ieee80211_node.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_node.c,v 1.190 2021/12/07 20:06:38 stsp Exp $ */ +/* $OpenBSD: ieee80211_node.c,v 1.191 2022/01/12 08:29:27 stsp Exp $ */ /* $NetBSD: ieee80211_node.c,v 1.14 2004/05/09 09:18:47 dyoung Exp $ */ /*- @@ -2025,30 +2025,6 @@ ieee80211_find_rxnode(struct ieee80211com *ic, return ieee80211_ref_node(ni); } -struct ieee80211_node * -ieee80211_find_node_for_beacon(struct ieee80211com *ic, - const u_int8_t *macaddr, const struct ieee80211_channel *chan, - const char *ssid, u_int8_t rssi) -{ - struct ieee80211_node *ni, *keep = NULL; - int s, score = 0; - - if ((ni = ieee80211_find_node(ic, macaddr)) != NULL) { - s = splnet(); - - if (ni->ni_chan != chan && ni->ni_rssi >= rssi) - score++; - if (ssid[1] == 0 && ni->ni_esslen != 0) - score++; - if (score > 0) - keep = ni; - - splx(s); - } - - return (keep); -} - void ieee80211_node_tx_ba_clear(struct ieee80211_node *ni, int tid) { diff --git a/sys/net80211/ieee80211_node.h b/sys/net80211/ieee80211_node.h index ca7f9cd59bb..82cddbfb3a6 100644 --- a/sys/net80211/ieee80211_node.h +++ b/sys/net80211/ieee80211_node.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ieee80211_node.h,v 1.90 2021/12/03 12:41:36 stsp Exp $ */ +/* $OpenBSD: ieee80211_node.h,v 1.91 2022/01/12 08:29:27 stsp Exp $ */ /* $NetBSD: ieee80211_node.h,v 1.9 2004/04/30 22:57:32 dyoung Exp $ */ /*- @@ -524,10 +524,6 @@ struct ieee80211_node *ieee80211_find_rxnode(struct ieee80211com *, const struct ieee80211_frame *); struct ieee80211_node *ieee80211_find_txnode(struct ieee80211com *, const u_int8_t *); -struct ieee80211_node * - ieee80211_find_node_for_beacon(struct ieee80211com *, - const u_int8_t *, const struct ieee80211_channel *, - const char *, u_int8_t); void ieee80211_release_node(struct ieee80211com *, struct ieee80211_node *); void ieee80211_node_cleanup(struct ieee80211com *, struct ieee80211_node *); -- 2.20.1