git: 4a8e4d15465c - main - net80211: fix IEEE80211_DEBUG_REFCNT builds

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Tue, 29 Nov 2022 21:21:02 UTC
The branch main has been updated by bz:

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

commit 4a8e4d15465cbf6f1bc4c6a09f50f97ae2d5bd7d
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-11-29 18:21:05 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-11-29 21:20:37 +0000

    net80211: fix IEEE80211_DEBUG_REFCNT builds
    
    Remove the KPI/KBI changes from ieee80211_node.h and always use the
    macros to pass in __func__ and __LINE__ to the functions.
    The actual implementations are prefixed by "_" rather than suffixed
    by "_debug" as they no longer are "debug"-specific.
    
    Some of the select functions were not actually using the passed in
    func, line options; however they are calling other functions which
    use them.  Directly call the internal implementation in those cases
    passing the arguments on.
    
    Use a file-local __debrefcnt_used define to mark the arguments __unused
    in cases when we compile without IEEE80211_DEBUG_REFCNT and hope the
    toolchain is intelligent enough to not pass them at all in those cases.
    
    Also _ieee80211_free_node() now has a conflict so make the previous
    _ieee80211_free_node() the new __ieee80211_free_node().
    
    Add IEEE80211_DEBUG_REFCNT to the NOTES file on amd64 to keep exercising
    the option.
    
    Sponsored by:   The FreeBSD Foundation
    X-MFC:          never
    Discussed on:   freebsd-wireless
    Reviewed by:    adrian
    Differential Revision: https://reviews.freebsd.org/D37529
---
 sys/amd64/conf/NOTES          |   3 ++
 sys/net80211/ieee80211_node.c | 120 ++++++++++++++++--------------------------
 sys/net80211/ieee80211_node.h |  55 +++++++------------
 3 files changed, 67 insertions(+), 111 deletions(-)

diff --git a/sys/amd64/conf/NOTES b/sys/amd64/conf/NOTES
index 42cc23d076b9..0781d03900ca 100644
--- a/sys/amd64/conf/NOTES
+++ b/sys/amd64/conf/NOTES
@@ -380,6 +380,9 @@ device		iwn6000g2bfw
 device		iwn6050fw
 device		wpifw
 
+# net80211 options
+options 	IEEE80211_DEBUG_REFCNT
+
 #
 # Non-Transparent Bridge (NTB) drivers
 #
diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c
index bc8a240811de..8a31a4576b3f 100644
--- a/sys/net80211/ieee80211_node.c
+++ b/sys/net80211/ieee80211_node.c
@@ -59,6 +59,12 @@ __FBSDID("$FreeBSD$");
 
 #include <net/bpf.h>
 
+#ifdef IEEE80211_DEBUG_REFCNT
+#define	__debrefcnt_used
+#else
+#define	__debrefcnt_used	__unused
+#endif
+
 /*
  * IEEE80211_NODE_HASHSIZE must be a power of 2.
  */
@@ -89,7 +95,7 @@ static void node_getsignal(const struct ieee80211_node *, int8_t *, int8_t *);
 static void node_getmimoinfo(const struct ieee80211_node *,
 	struct ieee80211_mimo_info *);
 
-static void _ieee80211_free_node(struct ieee80211_node *);
+static void __ieee80211_free_node(struct ieee80211_node *);
 
 static void node_reclaim(struct ieee80211_node_table *nt,
 	struct ieee80211_node *ni);
@@ -1436,7 +1442,7 @@ ieee80211_alloc_node(struct ieee80211_node_table *nt,
 		vap->iv_stats.is_rx_nodealloc++;
 		ieee80211_psq_cleanup(&ni->ni_psq);
 		ieee80211_ratectl_node_deinit(ni);
-		_ieee80211_free_node(ni);
+		__ieee80211_free_node(ni);
 		return NULL;
 	}
 
@@ -1488,7 +1494,7 @@ ieee80211_tmp_node(struct ieee80211vap *vap,
 			vap->iv_stats.is_rx_nodealloc++;
 			ieee80211_psq_cleanup(&ni->ni_psq);
 			ieee80211_ratectl_node_deinit(ni);
-			_ieee80211_free_node(ni);
+			__ieee80211_free_node(ni);
 			return NULL;
 		}
 
@@ -1586,13 +1592,9 @@ ieee80211_node_create_wds(struct ieee80211vap *vap,
 }
 
 struct ieee80211_node *
-#ifdef IEEE80211_DEBUG_REFCNT
-ieee80211_find_node_locked_debug(struct ieee80211_node_table *nt,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
-#else
-ieee80211_find_node_locked(struct ieee80211_node_table *nt,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN])
-#endif
+_ieee80211_find_node_locked(struct ieee80211_node_table *nt,
+    const uint8_t macaddr[IEEE80211_ADDR_LEN],
+    const char *func __debrefcnt_used, int line __debrefcnt_used)
 {
 	struct ieee80211_node *ni;
 	int hash;
@@ -1617,32 +1619,22 @@ ieee80211_find_node_locked(struct ieee80211_node_table *nt,
 }
 
 struct ieee80211_node *
-#ifdef IEEE80211_DEBUG_REFCNT
-ieee80211_find_node_debug(struct ieee80211_node_table *nt,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
-#else
-ieee80211_find_node(struct ieee80211_node_table *nt,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN])
-#endif
+_ieee80211_find_node(struct ieee80211_node_table *nt,
+    const uint8_t macaddr[IEEE80211_ADDR_LEN],
+    const char *func __debrefcnt_used, int line __debrefcnt_used)
 {
 	struct ieee80211_node *ni;
 
 	IEEE80211_NODE_LOCK(nt);
-	ni = ieee80211_find_node_locked(nt, macaddr);
+	ni = _ieee80211_find_node_locked(nt, macaddr, func, line);
 	IEEE80211_NODE_UNLOCK(nt);
 	return ni;
 }
 
 struct ieee80211_node *
-#ifdef IEEE80211_DEBUG_REFCNT
-ieee80211_find_vap_node_locked_debug(struct ieee80211_node_table *nt,
-	const struct ieee80211vap *vap,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
-#else
-ieee80211_find_vap_node_locked(struct ieee80211_node_table *nt,
-	const struct ieee80211vap *vap,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN])
-#endif
+_ieee80211_find_vap_node_locked(struct ieee80211_node_table *nt,
+    const struct ieee80211vap *vap, const uint8_t macaddr[IEEE80211_ADDR_LEN],
+    const char *func __debrefcnt_used, int line __debrefcnt_used)
 {
 	struct ieee80211_node *ni;
 	int hash;
@@ -1668,20 +1660,14 @@ ieee80211_find_vap_node_locked(struct ieee80211_node_table *nt,
 }
 
 struct ieee80211_node *
-#ifdef IEEE80211_DEBUG_REFCNT
-ieee80211_find_vap_node_debug(struct ieee80211_node_table *nt,
-	const struct ieee80211vap *vap,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN], const char *func, int line)
-#else
-ieee80211_find_vap_node(struct ieee80211_node_table *nt,
-	const struct ieee80211vap *vap,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN])
-#endif
+_ieee80211_find_vap_node(struct ieee80211_node_table *nt,
+    const struct ieee80211vap *vap, const uint8_t macaddr[IEEE80211_ADDR_LEN],
+    const char *func __debrefcnt_used, int line __debrefcnt_used)
 {
 	struct ieee80211_node *ni;
 
 	IEEE80211_NODE_LOCK(nt);
-	ni = ieee80211_find_vap_node_locked(nt, vap, macaddr);
+	ni = _ieee80211_find_vap_node_locked(nt, vap, macaddr, func, line);
 	IEEE80211_NODE_UNLOCK(nt);
 	return ni;
 }
@@ -1933,11 +1919,12 @@ ieee80211_add_neighbor(struct ieee80211vap *vap,
 
 static __inline struct ieee80211_node *
 _find_rxnode(struct ieee80211_node_table *nt,
-    const struct ieee80211_frame_min *wh)
+    const struct ieee80211_frame_min *wh,
+    const char *func __debrefcnt_used, int line __debrefcnt_used)
 {
 	if (IS_BCAST_PROBEREQ(wh))
 		return NULL;		/* spam bcast probe req to all vap's */
-	return ieee80211_find_node_locked(nt, wh->i_addr2);
+	return _ieee80211_find_node_locked(nt, wh->i_addr2, func, line);
 }
 
 /*
@@ -1946,20 +1933,16 @@ _find_rxnode(struct ieee80211_node_table *nt,
  * we can return NULL if the sender is not in the table.
  */
 struct ieee80211_node *
-#ifdef IEEE80211_DEBUG_REFCNT
-ieee80211_find_rxnode_debug(struct ieee80211com *ic,
-	const struct ieee80211_frame_min *wh, const char *func, int line)
-#else
-ieee80211_find_rxnode(struct ieee80211com *ic,
-	const struct ieee80211_frame_min *wh)
-#endif
+_ieee80211_find_rxnode(struct ieee80211com *ic,
+    const struct ieee80211_frame_min *wh,
+    const char *func __debrefcnt_used, int line __debrefcnt_used)
 {
 	struct ieee80211_node_table *nt;
 	struct ieee80211_node *ni;
 
 	nt = &ic->ic_sta;
 	IEEE80211_NODE_LOCK(nt);
-	ni = _find_rxnode(nt, wh);
+	ni = _find_rxnode(nt, wh, func, line);
 	IEEE80211_NODE_UNLOCK(nt);
 
 	return ni;
@@ -1974,14 +1957,9 @@ ieee80211_find_rxnode(struct ieee80211com *ic,
  * key assigned to it.
  */
 struct ieee80211_node *
-#ifdef IEEE80211_DEBUG_REFCNT
-ieee80211_find_rxnode_withkey_debug(struct ieee80211com *ic,
-	const struct ieee80211_frame_min *wh, ieee80211_keyix keyix,
-	const char *func, int line)
-#else
-ieee80211_find_rxnode_withkey(struct ieee80211com *ic,
-	const struct ieee80211_frame_min *wh, ieee80211_keyix keyix)
-#endif
+_ieee80211_find_rxnode_withkey(struct ieee80211com *ic,
+    const struct ieee80211_frame_min *wh, ieee80211_keyix keyix,
+    const char *func __debrefcnt_used, int line __debrefcnt_used)
 {
 	struct ieee80211_node_table *nt;
 	struct ieee80211_node *ni;
@@ -1993,7 +1971,7 @@ ieee80211_find_rxnode_withkey(struct ieee80211com *ic,
 	else
 		ni = NULL;
 	if (ni == NULL) {
-		ni = _find_rxnode(nt, wh);
+		ni = _find_rxnode(nt, wh, func, line);
 		if (ni != NULL && nt->nt_keyixmap != NULL) {
 			/*
 			 * If the station has a unicast key cache slot
@@ -2029,14 +2007,9 @@ ieee80211_find_rxnode_withkey(struct ieee80211com *ic,
  * a data frame.  This handles node discovery in adhoc networks.
  */
 struct ieee80211_node *
-#ifdef IEEE80211_DEBUG_REFCNT
-ieee80211_find_txnode_debug(struct ieee80211vap *vap,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN],
-	const char *func, int line)
-#else
-ieee80211_find_txnode(struct ieee80211vap *vap,
-	const uint8_t macaddr[IEEE80211_ADDR_LEN])
-#endif
+_ieee80211_find_txnode(struct ieee80211vap *vap,
+    const uint8_t macaddr[IEEE80211_ADDR_LEN],
+    const char *func __debrefcnt_used, int line __debrefcnt_used)
 {
 	struct ieee80211_node_table *nt = &vap->iv_ic->ic_sta;
 	struct ieee80211_node *ni;
@@ -2054,7 +2027,7 @@ ieee80211_find_txnode(struct ieee80211vap *vap,
 	    IEEE80211_IS_MULTICAST(macaddr))
 		ni = ieee80211_ref_node(vap->iv_bss);
 	else
-		ni = ieee80211_find_node_locked(nt, macaddr);
+		ni = _ieee80211_find_node_locked(nt, macaddr, func, line);
 	IEEE80211_NODE_UNLOCK(nt);
 
 	if (ni == NULL) {
@@ -2083,7 +2056,7 @@ ieee80211_find_txnode(struct ieee80211vap *vap,
 }
 
 static void
-_ieee80211_free_node(struct ieee80211_node *ni)
+__ieee80211_free_node(struct ieee80211_node *ni)
 {
 	struct ieee80211_node_table *nt = ni->ni_table;
 
@@ -2132,11 +2105,8 @@ node_clear_keyixmap(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
 }
 
 void
-#ifdef IEEE80211_DEBUG_REFCNT
-ieee80211_free_node_debug(struct ieee80211_node *ni, const char *func, int line)
-#else
-ieee80211_free_node(struct ieee80211_node *ni)
-#endif
+_ieee80211_free_node(struct ieee80211_node *ni,
+    const char *func __debrefcnt_used, int line __debrefcnt_used)
 {
 	struct ieee80211_node_table *nt = ni->ni_table;
 
@@ -2151,14 +2121,14 @@ ieee80211_free_node(struct ieee80211_node *ni)
 			/*
 			 * Last reference, reclaim state.
 			 */
-			_ieee80211_free_node(ni);
+			__ieee80211_free_node(ni);
 		} else if (ieee80211_node_refcnt(ni) == 1)
 			if (node_clear_keyixmap(nt, ni))
-				_ieee80211_free_node(ni);
+				__ieee80211_free_node(ni);
 		IEEE80211_NODE_UNLOCK(nt);
 	} else {
 		if (ieee80211_node_dectestref(ni))
-			_ieee80211_free_node(ni);
+			__ieee80211_free_node(ni);
 	}
 }
 
@@ -2246,7 +2216,7 @@ node_reclaim(struct ieee80211_node_table *nt, struct ieee80211_node *ni)
 		 */
 		ieee80211_del_node_nt(nt, ni);
 	} else
-		_ieee80211_free_node(ni);
+		__ieee80211_free_node(ni);
 }
 
 /*
diff --git a/sys/net80211/ieee80211_node.h b/sys/net80211/ieee80211_node.h
index 0e885440687c..2d237c3d597f 100644
--- a/sys/net80211/ieee80211_node.h
+++ b/sys/net80211/ieee80211_node.h
@@ -407,71 +407,54 @@ struct ieee80211_node *ieee80211_dup_bss(struct ieee80211vap *,
 struct ieee80211_node *ieee80211_node_create_wds(struct ieee80211vap *,
 		const uint8_t bssid[IEEE80211_ADDR_LEN],
 		struct ieee80211_channel *);
-#ifdef IEEE80211_DEBUG_REFCNT
-void	ieee80211_free_node_debug(struct ieee80211_node *,
+
+/* These functions are taking __func__, __LINE__ for IEEE80211_DEBUG_REFCNT */
+void	_ieee80211_free_node(struct ieee80211_node *,
 		const char *func, int line);
-struct ieee80211_node *ieee80211_find_node_locked_debug(
+struct ieee80211_node *_ieee80211_find_node_locked(
 		struct ieee80211_node_table *,
 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
 		const char *func, int line);
-struct ieee80211_node *ieee80211_find_node_debug(struct ieee80211_node_table *,
+struct ieee80211_node *_ieee80211_find_node(struct ieee80211_node_table *,
 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
 		const char *func, int line);
-struct ieee80211_node *ieee80211_find_vap_node_locked_debug(
+struct ieee80211_node *_ieee80211_find_vap_node_locked(
 		struct ieee80211_node_table *,
 		const struct ieee80211vap *vap,
 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
 		const char *func, int line);
-struct ieee80211_node *ieee80211_find_vap_node_debug(
+struct ieee80211_node *_ieee80211_find_vap_node(
 		struct ieee80211_node_table *,
 		const struct ieee80211vap *vap,
 		const uint8_t macaddr[IEEE80211_ADDR_LEN],
 		const char *func, int line);
-struct ieee80211_node * ieee80211_find_rxnode_debug(struct ieee80211com *,
+struct ieee80211_node *_ieee80211_find_rxnode(struct ieee80211com *,
 		const struct ieee80211_frame_min *,
 		const char *func, int line);
-struct ieee80211_node * ieee80211_find_rxnode_withkey_debug(
+struct ieee80211_node *_ieee80211_find_rxnode_withkey(
 		struct ieee80211com *,
 		const struct ieee80211_frame_min *, uint16_t keyix,
 		const char *func, int line);
-struct ieee80211_node *ieee80211_find_txnode_debug(struct ieee80211vap *,
+struct ieee80211_node *_ieee80211_find_txnode(struct ieee80211vap *,
 		const uint8_t *,
 		const char *func, int line);
 #define	ieee80211_free_node(ni) \
-	ieee80211_free_node_debug(ni, __func__, __LINE__)
+	_ieee80211_free_node(ni, __func__, __LINE__)
 #define	ieee80211_find_node_locked(nt, mac) \
-	ieee80211_find_node_locked_debug(nt, mac, __func__, __LINE__)
+	_ieee80211_find_node_locked(nt, mac, __func__, __LINE__)
 #define	ieee80211_find_node(nt, mac) \
-	ieee80211_find_node_debug(nt, mac, __func__, __LINE__)
+	_ieee80211_find_node(nt, mac, __func__, __LINE__)
 #define	ieee80211_find_vap_node_locked(nt, vap, mac) \
-	ieee80211_find_vap_node_locked_debug(nt, vap, mac, __func__, __LINE__)
+	_ieee80211_find_vap_node_locked(nt, vap, mac, __func__, __LINE__)
 #define	ieee80211_find_vap_node(nt, vap, mac) \
-	ieee80211_find_vap_node_debug(nt, vap, mac, __func__, __LINE__)
+	_ieee80211_find_vap_node(nt, vap, mac, __func__, __LINE__)
 #define	ieee80211_find_rxnode(ic, wh) \
-	ieee80211_find_rxnode_debug(ic, wh, __func__, __LINE__)
+	_ieee80211_find_rxnode(ic, wh, __func__, __LINE__)
 #define	ieee80211_find_rxnode_withkey(ic, wh, keyix) \
-	ieee80211_find_rxnode_withkey_debug(ic, wh, keyix, __func__, __LINE__)
+	_ieee80211_find_rxnode_withkey(ic, wh, keyix, __func__, __LINE__)
 #define	ieee80211_find_txnode(vap, mac) \
-	ieee80211_find_txnode_debug(vap, mac, __func__, __LINE__)
-#else
-void	ieee80211_free_node(struct ieee80211_node *);
-struct ieee80211_node *ieee80211_find_node_locked(struct ieee80211_node_table *,
-		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
-struct ieee80211_node *ieee80211_find_node(struct ieee80211_node_table *,
-		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
-struct ieee80211_node *ieee80211_find_vap_node_locked(
-		struct ieee80211_node_table *, const struct ieee80211vap *,
-		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
-struct ieee80211_node *ieee80211_find_vap_node(
-		struct ieee80211_node_table *, const struct ieee80211vap *,
-		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
-struct ieee80211_node * ieee80211_find_rxnode(struct ieee80211com *,
-		const struct ieee80211_frame_min *);
-struct ieee80211_node * ieee80211_find_rxnode_withkey(struct ieee80211com *,
-		const struct ieee80211_frame_min *, uint16_t keyix);
-struct ieee80211_node *ieee80211_find_txnode(struct ieee80211vap *,
-		const uint8_t macaddr[IEEE80211_ADDR_LEN]);
-#endif
+	_ieee80211_find_txnode(vap, mac, __func__, __LINE__)
+
 int	ieee80211_node_delucastkey(struct ieee80211_node *);
 void	ieee80211_node_timeout(void *arg);