Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Jul 2024 18:43:56 GMT
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 4aff4048f5b1 - main - LinuxKPI: 802.11: support manual lladdr changes
Message-ID:  <202407251843.46PIhuBr057417@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by bz:

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

commit 4aff4048f5b1b6ab0b905726853ba6083e37cc37
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-07-25 07:53:32 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-07-25 18:42:26 +0000

    LinuxKPI: 802.11: support manual lladdr changes
    
    Allow a user to change the "ether" address by ifconfig while a VAP is
    not UP.  Compared to net80211 (given we have no callback) we register
    an eventhandler per-vif (a global one would force us to use hacks to
    derive if a vap is indeed also a lkpi_80211 vif).
    
    Sponsored by:   The FreeBSD Foundation
    PR:             277356
    Tested by:      lwhsu
    MFC after:      3 days
    Differential Revision: https://reviews.freebsd.org/D46121
---
 sys/compat/linuxkpi/common/src/linux_80211.c | 30 ++++++++++++++++++++++++++++
 sys/compat/linuxkpi/common/src/linux_80211.h |  1 +
 2 files changed, 31 insertions(+)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index adef35ec2d5c..b46e56133725 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -2750,6 +2750,32 @@ lkpi_ic_wme_update(struct ieee80211com *ic)
 	return (0);	/* unused */
 }
 
+/*
+ * Change link-layer address on the vif (if the vap is not started/"UP").
+ * This can happen if a user changes 'ether' using ifconfig.
+ * The code is based on net80211/ieee80211_freebsd.c::wlan_iflladdr() but
+ * we do use a per-[l]vif event handler to be sure we exist as we
+ * cannot assume that from every vap derives a vif and we have a hard
+ * time checking based on net80211 information.
+ */
+static void
+lkpi_vif_iflladdr(void *arg, struct ifnet *ifp)
+{
+	struct epoch_tracker et;
+	struct ieee80211_vif *vif;
+
+	NET_EPOCH_ENTER(et);
+	/* NB: identify vap's by if_init; left as an extra check. */
+	if (ifp->if_init != ieee80211_init || (ifp->if_flags & IFF_UP) != 0) {
+		NET_EPOCH_EXIT(et);
+		return;
+	}
+
+	vif = arg;
+	IEEE80211_ADDR_COPY(vif->bss_conf.addr, IF_LLADDR(ifp));
+	NET_EPOCH_EXIT(et);
+}
+
 static struct ieee80211vap *
 lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ],
     int unit, enum ieee80211_opmode opmode, int flags,
@@ -2798,6 +2824,8 @@ lkpi_ic_vap_create(struct ieee80211com *ic, const char name[IFNAMSIZ],
 	vif->bss_conf.vif = vif;
 	/* vap->iv_myaddr is not set until net80211::vap_setup or vap_attach. */
 	IEEE80211_ADDR_COPY(vif->bss_conf.addr, mac);
+	lvif->lvif_ifllevent = EVENTHANDLER_REGISTER(iflladdr_event,
+	    lkpi_vif_iflladdr, vif, EVENTHANDLER_PRI_ANY);
 	vif->bss_conf.link_id = 0;	/* Non-MLO operation. */
 	vif->bss_conf.chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
 	vif->bss_conf.use_short_preamble = false;	/* vap->iv_flags IEEE80211_F_SHPREAMBLE */
@@ -2971,6 +2999,8 @@ lkpi_ic_vap_delete(struct ieee80211vap *vap)
 	lhw = ic->ic_softc;
 	hw = LHW_TO_HW(lhw);
 
+	EVENTHANDLER_DEREGISTER(iflladdr_event, lvif->lvif_ifllevent);
+
 	LKPI_80211_LHW_LVIF_LOCK(lhw);
 	TAILQ_REMOVE(&lhw->lvif_head, lvif, lvif_entry);
 	LKPI_80211_LHW_LVIF_UNLOCK(lhw);
diff --git a/sys/compat/linuxkpi/common/src/linux_80211.h b/sys/compat/linuxkpi/common/src/linux_80211.h
index 80be87ebe231..7675a8b6cebf 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.h
+++ b/sys/compat/linuxkpi/common/src/linux_80211.h
@@ -165,6 +165,7 @@ struct lkpi_sta {
 struct lkpi_vif {
         TAILQ_ENTRY(lkpi_vif)	lvif_entry;
 	struct ieee80211vap	iv_vap;
+	eventhandler_tag	lvif_ifllevent;
 
 	struct mtx		mtx;
 	struct wireless_dev	wdev;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202407251843.46PIhuBr057417>