From 83fcb81283e2bed6572e4dcd9075af6a4837a0d2 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Tue, 19 Jan 2010 05:00:57 +0000 Subject: [PATCH] Use the iflladdr_event event to keep the mac address on the vap in sync with the parent wirless interface. If the user passed in a mac address or it was autogenerated then flag this to avoid trashing it on update. This will fix wlan+lagg in a post vap world. --- sys/net80211/ieee80211.c | 3 +++ sys/net80211/ieee80211_freebsd.c | 35 ++++++++++++++++++++++++++++++++ sys/net80211/ieee80211_var.h | 3 ++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/sys/net80211/ieee80211.c b/sys/net80211/ieee80211.c index d0fc692dc2e0..f72e10b84144 100644 --- a/sys/net80211/ieee80211.c +++ b/sys/net80211/ieee80211.c @@ -440,6 +440,9 @@ ieee80211_vap_setup(struct ieee80211com *ic, struct ieee80211vap *vap, /* auto-enable s/w beacon miss support */ if (flags & IEEE80211_CLONE_NOBEACONS) vap->iv_flags_ext |= IEEE80211_FEXT_SWBMISS; + /* auto-generated or user supplied MAC address */ + if (flags & (IEEE80211_CLONE_BSSID|IEEE80211_CLONE_MACADDR)) + vap->iv_flags_ext |= IEEE80211_FEXT_UNIQMAC; /* * Enable various functionality by default if we're * capable; the driver can override us if it knows better. diff --git a/sys/net80211/ieee80211_freebsd.c b/sys/net80211/ieee80211_freebsd.c index 22800fb6c768..1de580023428 100644 --- a/sys/net80211/ieee80211_freebsd.c +++ b/sys/net80211/ieee80211_freebsd.c @@ -730,6 +730,7 @@ ieee80211_load_module(const char *modname) } static eventhandler_tag wlan_bpfevent; +static eventhandler_tag wlan_ifllevent; static void bpf_track(void *arg, struct ifnet *ifp, int dlt, int attach) @@ -756,6 +757,33 @@ bpf_track(void *arg, struct ifnet *ifp, int dlt, int attach) } } +static void +wlan_iflladdr(void *arg __unused, struct ifnet *ifp) +{ + struct ieee80211com *ic = ifp->if_l2com; + struct ieee80211vap *vap, *next; + + if (ifp->if_type != IFT_IEEE80211 || ic == NULL) + return; + + IEEE80211_LOCK(ic); + TAILQ_FOREACH_SAFE(vap, &ic->ic_vaps, iv_next, next) { + /* + * If the MAC address has changed on the parent and it was + * copied to the vap on creation then re-sync. + */ + if (vap->iv_ic == ic && + (vap->iv_flags_ext & IEEE80211_FEXT_UNIQMAC) == 0) { + IEEE80211_ADDR_COPY(vap->iv_myaddr, IF_LLADDR(ifp)); + IEEE80211_UNLOCK(ic); + if_setlladdr(vap->iv_ifp, IF_LLADDR(ifp), + IEEE80211_ADDR_LEN); + IEEE80211_LOCK(ic); + } + } + IEEE80211_UNLOCK(ic); +} + /* * Module glue. * @@ -772,6 +800,12 @@ wlan_modevent(module_t mod, int type, void *unused) bpf_track, 0, EVENTHANDLER_PRI_ANY); if (wlan_bpfevent == NULL) return ENOMEM; + wlan_ifllevent = EVENTHANDLER_REGISTER(iflladdr_event, + wlan_iflladdr, NULL, EVENTHANDLER_PRI_ANY); + if (wlan_ifllevent == NULL) { + EVENTHANDLER_DEREGISTER(bpf_track, wlan_bpfevent); + return ENOMEM; + } if_clone_attach(&wlan_cloner); if_register_com_alloc(IFT_IEEE80211, wlan_alloc, wlan_free); return 0; @@ -779,6 +813,7 @@ wlan_modevent(module_t mod, int type, void *unused) if_deregister_com_alloc(IFT_IEEE80211); if_clone_detach(&wlan_cloner); EVENTHANDLER_DEREGISTER(bpf_track, wlan_bpfevent); + EVENTHANDLER_DEREGISTER(iflladdr_event, wlan_ifllevent); return 0; } return EINVAL; diff --git a/sys/net80211/ieee80211_var.h b/sys/net80211/ieee80211_var.h index 9fe0242a94bc..d6f3e6669ec9 100644 --- a/sys/net80211/ieee80211_var.h +++ b/sys/net80211/ieee80211_var.h @@ -545,11 +545,12 @@ MALLOC_DECLARE(M_80211_VAP); /* NB: immutable: should be set only when creating a vap */ #define IEEE80211_FEXT_WDSLEGACY 0x00010000 /* CONF: legacy WDS operation */ #define IEEE80211_FEXT_PROBECHAN 0x00020000 /* CONF: probe passive channel*/ +#define IEEE80211_FEXT_UNIQMAC 0x00040000 /* CONF: user or computed mac */ #define IEEE80211_FEXT_BITS \ "\20\2INACT\3SCANWAIT\4BGSCAN\5WPS\6TSN\7SCANREQ\10RESUME" \ "\0114ADDR\12NONEPR_PR\13SWBMISS\14DFS\15DOTD\16STATEWAIT\17REINIT" \ - "\20BPF\21WDSLEGACY\22PROBECHAN" + "\20BPF\21WDSLEGACY\22PROBECHAN\23UNIQMAC" /* ic_flags_ht/iv_flags_ht */ #define IEEE80211_FHT_NONHT_PR 0x00000001 /* STATUS: non-HT sta present */