As already done on iwm(4) and one of the athn(4), there is no need to pass
the radio tap structure to bpf_mtap by faking up an mbuf. The code can
just use bpf_mtap_hdr() (which does a similar dance but with far less
memory on the stack).
There are many other wifi driver that do the same thing so I would be
happy if somebody else would apply the same logic there too :)
I could only compile test this diff.
--
:wq Claudio
Index: ar9003.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/ar9003.c,v
retrieving revision 1.49
diff -u -p -r1.49 ar9003.c
--- ar9003.c 12 Sep 2019 12:55:06 -0000 1.49
+++ ar9003.c 17 Feb 2020 15:51:19 -0000
@@ -856,7 +856,6 @@ ar9003_rx_radiotap(struct athn_softc *sc
struct athn_rx_radiotap_header *tap = &sc->sc_rxtap;
struct ieee80211com *ic = &sc->sc_ic;
- struct mbuf mb;
uint64_t tsf;
uint32_t tstamp;
uint8_t rate;
@@ -905,13 +904,7 @@ ar9003_rx_radiotap(struct athn_softc *sc
case 0xc: tap->wr_rate = 108; break;
}
}
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_rxtap_len;
- mb.m_next = m;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_IN);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_rxtap_len, m, BPF_DIRECTION_IN);
}
#endif
@@ -1484,7 +1477,6 @@ ar9003_tx(struct athn_softc *sc, struct
#if NBPFILTER > 0
if (__predict_false(sc->sc_drvbpf != NULL)) {
struct athn_tx_radiotap_header *tap = &sc->sc_txtap;
- struct mbuf mb;
tap->wt_flags = 0;
/* Use initial transmit rate. */
@@ -1496,13 +1488,8 @@ ar9003_tx(struct athn_softc *sc, struct
ridx[0] != ATHN_RIDX_CCK1 &&
(ic->ic_flags & IEEE80211_F_SHPREAMBLE))
tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_txtap_len;
- mb.m_next = m;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_OUT);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_txtap_len, m,
+ BPF_DIRECTION_OUT);
}
#endif
Index: ath.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/ath.c,v
retrieving revision 1.117
diff -u -p -r1.117 ath.c
--- ath.c 12 Sep 2019 12:55:06 -0000 1.117
+++ ath.c 17 Feb 2020 15:50:05 -0000
@@ -1922,8 +1922,6 @@ ath_rx_proc(void *arg, int npending)
#if NBPFILTER > 0
if (sc->sc_drvbpf) {
- struct mbuf mb;
-
sc->sc_rxtap.wr_flags = IEEE80211_RADIOTAP_F_FCS;
sc->sc_rxtap.wr_rate =
sc->sc_hwmap[ds->ds_rxstat.rs_rate] &
@@ -1932,13 +1930,8 @@ ath_rx_proc(void *arg, int npending)
sc->sc_rxtap.wr_rssi = ds->ds_rxstat.rs_rssi;
sc->sc_rxtap.wr_max_rssi = ic->ic_max_rssi;
- mb.m_data = (caddr_t)&sc->sc_rxtap;
- mb.m_len = sc->sc_rxtap_len;
- mb.m_next = m;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_IN);
+ bpf_mtap_hdr(sc->sc_drvbpf, &sc->sc_rxtap,
+ sc->sc_rxtap_len, m, BPF_DIRECTION_IN);
}
#endif
m_adj(m, -IEEE80211_CRC_LEN);
@@ -2307,8 +2300,6 @@ ath_tx_start(struct ath_softc *sc, struc
bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT);
if (sc->sc_drvbpf) {
- struct mbuf mb;
-
sc->sc_txtap.wt_flags = 0;
if (shortPreamble)
sc->sc_txtap.wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
@@ -2320,13 +2311,8 @@ ath_tx_start(struct ath_softc *sc, struc
sc->sc_txtap.wt_antenna = antenna;
sc->sc_txtap.wt_hwqueue = hwqueue;
- mb.m_data = (caddr_t)&sc->sc_txtap;
- mb.m_len = sc->sc_txtap_len;
- mb.m_next = m0;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_OUT);
+ bpf_mtap_hdr(sc->sc_drvbpf, &sc->sc_txtap, sc->sc_txtap_len,
+ m0, BPF_DIRECTION_OUT);
}
#endif
Index: rt2560.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/rt2560.c,v
retrieving revision 1.85
diff -u -p -r1.85 rt2560.c
--- rt2560.c 12 Sep 2019 12:55:07 -0000 1.85
+++ rt2560.c 17 Feb 2020 16:00:23 -0000
@@ -1171,7 +1171,6 @@ rt2560_decryption_intr(struct rt2560_sof
#if NBPFILTER > 0
if (sc->sc_drvbpf != NULL) {
- struct mbuf mb;
struct rt2560_rx_radiotap_header *tap = &sc->sc_rxtap;
uint32_t tsf_lo, tsf_hi;
@@ -1189,13 +1188,8 @@ rt2560_decryption_intr(struct rt2560_sof
tap->wr_antenna = sc->rx_ant;
tap->wr_antsignal = desc->rssi;
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_txtap_len;
- mb.m_next = m;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_IN);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_txtap_len, m,
+ BPF_DIRECTION_IN);
}
#endif
wh = mtod(m, struct ieee80211_frame *);
@@ -1632,7 +1626,6 @@ rt2560_tx_mgt(struct rt2560_softc *sc, s
#if NBPFILTER > 0
if (sc->sc_drvbpf != NULL) {
- struct mbuf mb;
struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap;
tap->wt_flags = 0;
@@ -1641,13 +1634,8 @@ rt2560_tx_mgt(struct rt2560_softc *sc, s
tap->wt_chan_flags = htole16(ic->ic_ibss_chan->ic_flags);
tap->wt_antenna = sc->tx_ant;
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_txtap_len;
- mb.m_next = m0;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_OUT);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_txtap_len, m0,
+ BPF_DIRECTION_OUT);
}
#endif
@@ -1864,7 +1852,6 @@ rt2560_tx_data(struct rt2560_softc *sc,
#if NBPFILTER > 0
if (sc->sc_drvbpf != NULL) {
- struct mbuf mb;
struct rt2560_tx_radiotap_header *tap = &sc->sc_txtap;
tap->wt_flags = 0;
@@ -1873,13 +1860,8 @@ rt2560_tx_data(struct rt2560_softc *sc,
tap->wt_chan_flags = htole16(ic->ic_ibss_chan->ic_flags);
tap->wt_antenna = sc->tx_ant;
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_txtap_len;
- mb.m_next = m0;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_OUT);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_txtap_len, m0,
+ BPF_DIRECTION_OUT);
}
#endif
Index: rt2661.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/rt2661.c,v
retrieving revision 1.95
diff -u -p -r1.95 rt2661.c
--- rt2661.c 12 Sep 2019 12:55:07 -0000 1.95
+++ rt2661.c 17 Feb 2020 15:55:47 -0000
@@ -1247,7 +1247,6 @@ rt2661_rx_intr(struct rt2661_softc *sc)
#if NBPFILTER > 0
if (sc->sc_drvbpf != NULL) {
- struct mbuf mb;
struct rt2661_rx_radiotap_header *tap = &sc->sc_rxtap;
uint32_t tsf_lo, tsf_hi;
@@ -1263,13 +1262,8 @@ rt2661_rx_intr(struct rt2661_softc *sc)
tap->wr_chan_flags = htole16(sc->sc_curchan->ic_flags);
tap->wr_antsignal = desc->rssi;
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_rxtap_len;
- mb.m_next = m;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_IN);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_rxtap_len, m,
+ BPF_DIRECTION_IN);
}
#endif
@@ -1632,7 +1626,6 @@ rt2661_tx_mgt(struct rt2661_softc *sc, s
#if NBPFILTER > 0
if (sc->sc_drvbpf != NULL) {
- struct mbuf mb;
struct rt2661_tx_radiotap_header *tap = &sc->sc_txtap;
tap->wt_flags = 0;
@@ -1640,13 +1633,8 @@ rt2661_tx_mgt(struct rt2661_softc *sc, s
tap->wt_chan_freq = htole16(sc->sc_curchan->ic_freq);
tap->wt_chan_flags = htole16(sc->sc_curchan->ic_flags);
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_txtap_len;
- mb.m_next = m0;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_OUT);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_txtap_len, m0,
+ BPF_DIRECTION_OUT);
}
#endif
@@ -1864,7 +1852,6 @@ rt2661_tx_data(struct rt2661_softc *sc,
#if NBPFILTER > 0
if (sc->sc_drvbpf != NULL) {
- struct mbuf mb;
struct rt2661_tx_radiotap_header *tap = &sc->sc_txtap;
tap->wt_flags = 0;
@@ -1872,13 +1859,8 @@ rt2661_tx_data(struct rt2661_softc *sc,
tap->wt_chan_freq = htole16(sc->sc_curchan->ic_freq);
tap->wt_chan_flags = htole16(sc->sc_curchan->ic_flags);
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_txtap_len;
- mb.m_next = m0;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_OUT);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_txtap_len, m0,
+ BPF_DIRECTION_OUT);
}
#endif
Index: rt2860.c
===================================================================
RCS file: /cvs/src/sys/dev/ic/rt2860.c,v
retrieving revision 1.97
diff -u -p -r1.97 rt2860.c
--- rt2860.c 12 Sep 2019 12:55:07 -0000 1.97
+++ rt2860.c 17 Feb 2020 15:58:23 -0000
@@ -1272,7 +1272,6 @@ rt2860_rx_intr(struct rt2860_softc *sc)
int error;
#if NBPFILTER > 0
struct rt2860_rx_radiotap_header *tap;
- struct mbuf mb;
uint16_t phy;
#endif
@@ -1405,13 +1404,8 @@ rt2860_rx_intr(struct rt2860_softc *sc)
}
break;
}
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_rxtap_len;
- mb.m_next = m;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_IN);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_rxtap_len, m,
+ BPF_DIRECTION_IN);
skipbpf:
#endif
/* grab a reference to the source node */
@@ -1645,7 +1639,6 @@ rt2860_tx(struct rt2860_softc *sc, struc
#if NBPFILTER > 0
if (__predict_false(sc->sc_drvbpf != NULL)) {
struct rt2860_tx_radiotap_header *tap = &sc->sc_txtap;
- struct mbuf mb;
tap->wt_flags = 0;
tap->wt_rate = rt2860_rates[ridx].rate;
@@ -1655,13 +1648,8 @@ rt2860_tx(struct rt2860_softc *sc, struc
if (mcs & RT2860_PHY_SHPRE)
tap->wt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
- mb.m_data = (caddr_t)tap;
- mb.m_len = sc->sc_txtap_len;
- mb.m_next = m;
- mb.m_nextpkt = NULL;
- mb.m_type = 0;
- mb.m_flags = 0;
- bpf_mtap(sc->sc_drvbpf, &mb, BPF_DIRECTION_OUT);
+ bpf_mtap_hdr(sc->sc_drvbpf, tap, sc->sc_txtap_len, m,
+ BPF_DIRECTION_OUT);
}
#endif