git: e035e8661c37 - main - net80211: move references to IF_LLADDR() into ieee80211_freebsd.c

From: Adrian Chadd <adrian_at_FreeBSD.org>
Date: Sun, 25 May 2025 15:24:24 UTC
The branch main has been updated by adrian:

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

commit e035e8661c37b9f0669d31e146ec4afb73f4f435
Author:     Adrian Chadd <adrian@FreeBSD.org>
AuthorDate: 2025-04-25 18:27:29 +0000
Commit:     Adrian Chadd <adrian@FreeBSD.org>
CommitDate: 2025-05-25 15:23:02 +0000

    net80211: move references to IF_LLADDR() into ieee80211_freebsd.c
    
    * Move references to IF_LLADDR() into ieee80211_freebsd.c
    * Add a comment on one that I need to verify before I move it
    * Implement ieee80211_vap_sync_mac_address() which syncs the VAP
      mac address from the network interface MAC address.
      This uses FreeBSD-isms (network epoch, IF_LLADDR()) so it shouldn't
      be in net80211 itself.
    
    Differential Revision:  https://reviews.freebsd.org/D50023
---
 sys/net80211/ieee80211.c         |  3 ++-
 sys/net80211/ieee80211_freebsd.c | 44 ++++++++++++++++++++++++++++++++++++++++
 sys/net80211/ieee80211_freebsd.h |  3 +++
 sys/net80211/ieee80211_ioctl.c   | 18 +---------------
 sys/net80211/ieee80211_sta.c     |  4 ++--
 5 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/sys/net80211/ieee80211.c b/sys/net80211/ieee80211.c
index dbc7023c7fee..e64568abb024 100644
--- a/sys/net80211/ieee80211.c
+++ b/sys/net80211/ieee80211.c
@@ -722,7 +722,8 @@ ieee80211_vap_attach(struct ieee80211vap *vap, ifm_change_cb_t media_change,
 		ifp->if_baudrate = IF_Mbps(maxrate);
 
 	ether_ifattach(ifp, macaddr);
-	IEEE80211_ADDR_COPY(vap->iv_myaddr, IF_LLADDR(ifp));
+	/* Do initial MAC address sync */
+	ieee80211_vap_copy_mac_address(vap);
 	/* hook output method setup by ether_ifattach */
 	vap->iv_output = ifp->if_output;
 	ifp->if_output = ieee80211_output;
diff --git a/sys/net80211/ieee80211_freebsd.c b/sys/net80211/ieee80211_freebsd.c
index 6979e601ce41..5098529beb47 100644
--- a/sys/net80211/ieee80211_freebsd.c
+++ b/sys/net80211/ieee80211_freebsd.c
@@ -1192,6 +1192,50 @@ ieee80211_debugnet_poll(struct ifnet *ifp, int count)
 }
 #endif
 
+/**
+ * @brief Check if the MAC address was changed by the upper layer.
+ *
+ * This is specifically to handle cases like the MAC address
+ * being changed via an ioctl (eg SIOCSIFLLADDR).
+ *
+ * @param vap	VAP to sync MAC address for
+ */
+void
+ieee80211_vap_sync_mac_address(struct ieee80211vap *vap)
+{
+	struct epoch_tracker et;
+	const struct ifnet *ifp = vap->iv_ifp;
+
+	/*
+	 * Check if the MAC address was changed
+	 * via SIOCSIFLLADDR ioctl.
+	 *
+	 * NB: device may be detached during initialization;
+	 * use if_ioctl for existence check.
+	 */
+	NET_EPOCH_ENTER(et);
+	if (ifp->if_ioctl == ieee80211_ioctl &&
+	    (ifp->if_flags & IFF_UP) == 0 &&
+	    !IEEE80211_ADDR_EQ(vap->iv_myaddr, IF_LLADDR(ifp)))
+		IEEE80211_ADDR_COPY(vap->iv_myaddr, IF_LLADDR(ifp));
+	NET_EPOCH_EXIT(et);
+}
+
+/**
+ * @brief Initial MAC address setup for a VAP.
+ *
+ * @param vap	VAP to sync MAC address for
+ */
+void
+ieee80211_vap_copy_mac_address(struct ieee80211vap *vap)
+{
+	struct epoch_tracker et;
+
+	NET_EPOCH_ENTER(et);
+	IEEE80211_ADDR_COPY(vap->iv_myaddr, IF_LLADDR(vap->iv_ifp));
+	NET_EPOCH_EXIT(et);
+}
+
 /*
  * Module glue.
  *
diff --git a/sys/net80211/ieee80211_freebsd.h b/sys/net80211/ieee80211_freebsd.h
index ed913f7b3661..bdc78fe99d36 100644
--- a/sys/net80211/ieee80211_freebsd.h
+++ b/sys/net80211/ieee80211_freebsd.h
@@ -540,6 +540,9 @@ struct debugnet80211_methods {
 #define DEBUGNET80211_SET(ic, driver)
 #endif /* DEBUGNET */
 
+void ieee80211_vap_sync_mac_address(struct ieee80211vap *);
+void ieee80211_vap_copy_mac_address(struct ieee80211vap *);
+
 #endif /* _KERNEL */
 
 /* XXX this stuff belongs elsewhere */
diff --git a/sys/net80211/ieee80211_ioctl.c b/sys/net80211/ieee80211_ioctl.c
index 6c30325e5e32..d70004c0fb7a 100644
--- a/sys/net80211/ieee80211_ioctl.c
+++ b/sys/net80211/ieee80211_ioctl.c
@@ -3631,24 +3631,8 @@ ieee80211_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
 		IEEE80211_UNLOCK(ic);
 		/* Wait for parent ioctl handler if it was queued */
 		if (wait) {
-			struct epoch_tracker et;
-
 			ieee80211_waitfor_parent(ic);
-
-			/*
-			 * Check if the MAC address was changed
-			 * via SIOCSIFLLADDR ioctl.
-			 *
-			 * NB: device may be detached during initialization;
-			 * use if_ioctl for existence check.
-			 */
-			NET_EPOCH_ENTER(et);
-			if (ifp->if_ioctl == ieee80211_ioctl &&
-			    (ifp->if_flags & IFF_UP) == 0 &&
-			    !IEEE80211_ADDR_EQ(vap->iv_myaddr, IF_LLADDR(ifp)))
-				IEEE80211_ADDR_COPY(vap->iv_myaddr,
-				    IF_LLADDR(ifp));
-			NET_EPOCH_EXIT(et);
+			ieee80211_vap_sync_mac_address(vap);
 		}
 		break;
 	case SIOCADDMULTI:
diff --git a/sys/net80211/ieee80211_sta.c b/sys/net80211/ieee80211_sta.c
index 887eb81dd3c4..0dd007fef508 100644
--- a/sys/net80211/ieee80211_sta.c
+++ b/sys/net80211/ieee80211_sta.c
@@ -634,10 +634,10 @@ sta_input(struct ieee80211_node *ni, struct mbuf *m,
 		 * XXX process data frames whilst scanning.
 		 */
 		if ((! IEEE80211_IS_MULTICAST(wh->i_addr1))
-		    && (! IEEE80211_ADDR_EQ(wh->i_addr1, IF_LLADDR(ifp)))) {
+		    && (! IEEE80211_ADDR_EQ(wh->i_addr1, vap->iv_myaddr))) {
 			IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT,
 			    bssid, NULL, "not to cur sta: lladdr=%6D, addr1=%6D",
-			    IF_LLADDR(ifp), ":", wh->i_addr1, ":");
+			    vap->iv_myaddr, ":", wh->i_addr1, ":");
 			vap->iv_stats.is_rx_wrongbss++;
 			goto out;
 		}