git: dd39ea27f356 - stable/13 - net80211: introduce (*iv_update_bss)()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 27 Mar 2022 20:13:55 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=dd39ea27f356f660736d5eb45b0a5aece63698bb

commit dd39ea27f356f660736d5eb45b0a5aece63698bb
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-03-22 14:46:51 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-03-27 18:02:20 +0000

    net80211: introduce (*iv_update_bss)()
    
    Introduce (*iv_update_bss)() with a default implementation to allow
    drivers to overload/intercept the time when we swap iv_bss.
    
    This helps firmware based drivers to synchronize state with firmware.
    Otherwise, for some state changes, we begin with one ni (and in
    LinuxKPI lsta) and try to finish with another ni (and a new lsta
    in different state) and may no longer have access to the previous state.
    This also saves us from constantly checking for ni changes complicating
    code.
    
    No functional changes intended.
    
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 91b4225aa1d81155668db6deed22084abf2ce23c)
---
 sys/net80211/ieee80211_node.c  |  8 +++-----
 sys/net80211/ieee80211_proto.c | 14 ++++++++++++++
 sys/net80211/ieee80211_var.h   |  8 +++++++-
 sys/net80211/ieee80211_wds.c   |  6 ++----
 4 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c
index 3df534edfa55..66629ab87af3 100644
--- a/sys/net80211/ieee80211_node.c
+++ b/sys/net80211/ieee80211_node.c
@@ -197,7 +197,7 @@ ieee80211_node_vdetach(struct ieee80211vap *vap)
 	ieee80211_node_table_reset(&ic->ic_sta, vap);
 	if (vap->iv_bss != NULL) {
 		ieee80211_free_node(vap->iv_bss);
-		vap->iv_bss = NULL;
+		vap->iv_update_bss(vap, NULL);
 	}
 	if (vap->iv_aid_bitmap != NULL) {
 		IEEE80211_FREE(vap->iv_aid_bitmap, M_80211_NODE);
@@ -453,8 +453,7 @@ ieee80211_reset_bss(struct ieee80211vap *vap)
 
 	ni = ieee80211_alloc_node(&ic->ic_sta, vap, vap->iv_myaddr);
 	KASSERT(ni != NULL, ("unable to setup initial BSS node"));
-	obss = vap->iv_bss;
-	vap->iv_bss = ieee80211_ref_node(ni);
+	obss = vap->iv_update_bss(vap, ieee80211_ref_node(ni));
 	if (obss != NULL) {
 		copy_bss(ni, obss);
 		ni->ni_intval = ic->ic_bintval;
@@ -846,7 +845,7 @@ ieee80211_sta_join1(struct ieee80211_node *selbs)
 	/*
 	 * Committed to selbs, setup state.
 	 */
-	obss = vap->iv_bss;
+	obss = vap->iv_update_bss(vap, selbs);	/* NB: caller assumed to bump refcnt */
 	/*
 	 * Check if old+new node have the same address in which
 	 * case we can reassociate when operating in sta mode.
@@ -855,7 +854,6 @@ ieee80211_sta_join1(struct ieee80211_node *selbs)
 	canreassoc = (obss != NULL &&
 		vap->iv_state == IEEE80211_S_RUN &&
 		IEEE80211_ADDR_EQ(obss->ni_macaddr, selbs->ni_macaddr));
-	vap->iv_bss = selbs;		/* NB: caller assumed to bump refcnt */
 	if (obss != NULL) {
 		struct ieee80211_node_table *nt = obss->ni_table;
 
diff --git a/sys/net80211/ieee80211_proto.c b/sys/net80211/ieee80211_proto.c
index 98a04e5251f0..2228983050a2 100644
--- a/sys/net80211/ieee80211_proto.c
+++ b/sys/net80211/ieee80211_proto.c
@@ -249,6 +249,8 @@ static void vap_update_erp_protmode(void *, int);
 static void vap_update_preamble(void *, int);
 static void vap_update_ht_protmode(void *, int);
 static void ieee80211_newstate_cb(void *, int);
+static struct ieee80211_node *vap_update_bss(struct ieee80211vap *,
+    struct ieee80211_node *);
 
 static int
 null_raw_xmit(struct ieee80211_node *ni, struct mbuf *m,
@@ -394,6 +396,7 @@ ieee80211_proto_vattach(struct ieee80211vap *vap)
 	vap->iv_update_beacon = null_update_beacon;
 	vap->iv_deliver_data = ieee80211_deliver_data;
 	vap->iv_protmode = IEEE80211_PROT_CTSONLY;
+	vap->iv_update_bss = vap_update_bss;
 
 	/* attach support for operating mode */
 	ic->ic_vattach[vap->iv_opmode](vap);
@@ -824,6 +827,17 @@ ieee80211_reset_erp(struct ieee80211com *ic)
 	/* XXX TODO: schedule a new per-VAP ERP calculation */
 }
 
+static struct ieee80211_node *
+vap_update_bss(struct ieee80211vap *vap, struct ieee80211_node *ni)
+{
+	struct ieee80211_node *obss;
+
+	obss = vap->iv_bss;
+	vap->iv_bss = ni;
+
+	return (obss);
+}
+
 /*
  * Deferred slot time update.
  *
diff --git a/sys/net80211/ieee80211_var.h b/sys/net80211/ieee80211_var.h
index e70b7f8e2bb6..a361e2c72028 100644
--- a/sys/net80211/ieee80211_var.h
+++ b/sys/net80211/ieee80211_var.h
@@ -605,7 +605,13 @@ struct ieee80211vap {
 	struct ieee80211_rx_histogram	*rx_histogram;
 	struct ieee80211_tx_histogram	*tx_histogram;
 
-	uint64_t		iv_spare[6];
+	struct ieee80211_node *	(*iv_update_bss)(struct ieee80211vap *,
+				    struct ieee80211_node *);
+
+#ifdef __ILP32__
+	uint32_t		iv_spare0;
+#endif
+	uint64_t		iv_spare[5];
 };
 MALLOC_DECLARE(M_80211_VAP);
 
diff --git a/sys/net80211/ieee80211_wds.c b/sys/net80211/ieee80211_wds.c
index b73988b10d5e..464e658797e6 100644
--- a/sys/net80211/ieee80211_wds.c
+++ b/sys/net80211/ieee80211_wds.c
@@ -179,8 +179,7 @@ ieee80211_create_wds(struct ieee80211vap *vap, struct ieee80211_channel *chan)
 			/*
 			 * Committed to new node, setup state.
 			 */
-			obss = vap->iv_bss;
-			vap->iv_bss = ni;
+			obss = vap->iv_update_bss(vap, ni);
 			ni->ni_wdsvap = vap;
 		}
 		IEEE80211_NODE_UNLOCK(nt);
@@ -201,8 +200,7 @@ ieee80211_create_wds(struct ieee80211vap *vap, struct ieee80211_channel *chan)
 		 */
 		ni = ieee80211_node_create_wds(vap, vap->iv_des_bssid, chan);
 		if (ni != NULL) {
-			obss = vap->iv_bss;
-			vap->iv_bss = ieee80211_ref_node(ni);
+			obss = vap->iv_update_bss(vap, ieee80211_ref_node(ni));
 			ni->ni_flags |= IEEE80211_NODE_AREF;
 			if (obss != NULL)
 				ieee80211_free_node(obss);