radiotap code puts an mbuf on the stack so it can build a chain that
includes a radiotap header for bpf_mtap to chew on. bpf_mtap_hdr can do
that for you though.

bpf_mtap_hdr also cheats by using an m_hdr instead of a full mbuf,
which makes the stack usage less, but im arguing for the diff because it
makes the calling code simpler.

this only tweaks the intel wireless drivers, there's a handful of other
ones that could be fixed too if this diff goes in.

tests? ok?

Index: if_ipw.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_ipw.c,v
retrieving revision 1.123
diff -u -p -r1.123 if_ipw.c
--- if_ipw.c    25 Jul 2019 01:46:14 -0000      1.123
+++ if_ipw.c    12 Sep 2019 03:14:03 -0000
@@ -878,7 +878,6 @@ ipw_data_intr(struct ipw_softc *sc, stru
 
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct ipw_rx_radiotap_header *tap = &sc->sc_rxtap;
 
                tap->wr_flags = 0;
@@ -886,13 +885,8 @@ ipw_data_intr(struct ipw_softc *sc, stru
                tap->wr_chan_freq = htole16(ic->ic_ibss_chan->ic_freq);
                tap->wr_chan_flags = htole16(ic->ic_ibss_chan->ic_flags);
 
-               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, NULL);
        }
 #endif
 
@@ -1153,20 +1147,14 @@ ipw_tx_start(struct ifnet *ifp, struct m
 
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct ipw_tx_radiotap_header *tap = &sc->sc_txtap;
 
                tap->wt_flags = 0;
                tap->wt_chan_freq = htole16(ic->ic_ibss_chan->ic_freq);
                tap->wt_chan_flags = htole16(ic->ic_ibss_chan->ic_flags);
 
-               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, NULL);
        }
 #endif
 
Index: if_iwi.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_iwi.c,v
retrieving revision 1.140
diff -u -p -r1.140 if_iwi.c
--- if_iwi.c    25 Jul 2019 01:46:14 -0000      1.140
+++ if_iwi.c    12 Sep 2019 03:14:03 -0000
@@ -923,7 +923,6 @@ iwi_frame_intr(struct iwi_softc *sc, str
 
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct iwi_rx_radiotap_header *tap = &sc->sc_rxtap;
 
                tap->wr_flags = 0;
@@ -937,13 +936,8 @@ iwi_frame_intr(struct iwi_softc *sc, str
                if (frame->antenna & 0x40)
                        tap->wr_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
 
-               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, NULL);
        }
 #endif
 
@@ -1265,20 +1259,14 @@ iwi_tx_start(struct ifnet *ifp, struct m
 
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct iwi_tx_radiotap_header *tap = &sc->sc_txtap;
 
                tap->wt_flags = 0;
                tap->wt_chan_freq = htole16(ic->ic_bss->ni_chan->ic_freq);
                tap->wt_chan_flags = htole16(ic->ic_bss->ni_chan->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, NULL);
        }
 #endif
 
Index: if_iwm.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_iwm.c,v
retrieving revision 1.244
diff -u -p -r1.244 if_iwm.c
--- if_iwm.c    8 Aug 2019 13:56:56 -0000       1.244
+++ if_iwm.c    12 Sep 2019 03:14:03 -0000
@@ -3629,7 +3629,6 @@ iwm_rx_rx_mpdu(struct iwm_softc *sc, str
 
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct iwm_rx_radiotap_header *tap = &sc->sc_rxtap;
                uint16_t chan_flags;
 
@@ -3674,13 +3673,8 @@ iwm_rx_rx_mpdu(struct iwm_softc *sc, str
                        }
                }
 
-               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, NULL);
        }
 #endif
        ieee80211_input(IC2IFP(ic), m, ni, &rxi);
@@ -4367,7 +4361,6 @@ iwm_tx(struct iwm_softc *sc, struct mbuf
 
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct iwm_tx_radiotap_header *tap = &sc->sc_txtap;
                uint16_t chan_flags;
 
@@ -4389,13 +4382,8 @@ iwm_tx(struct iwm_softc *sc, struct mbuf
                    (wh->i_fc[1] & IEEE80211_FC1_PROTECTED))
                        tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
 
-               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, NULL);
        }
 #endif
        totlen = m->m_pkthdr.len;
Index: if_iwn.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_iwn.c,v
retrieving revision 1.212
diff -u -p -r1.212 if_iwn.c
--- if_iwn.c    29 Jul 2019 10:50:08 -0000      1.212
+++ if_iwn.c    12 Sep 2019 03:14:03 -0000
@@ -2189,7 +2189,6 @@ iwn_rx_done(struct iwn_softc *sc, struct
 
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct iwn_rx_radiotap_header *tap = &sc->sc_rxtap;
                uint16_t chan_flags;
 
@@ -2227,13 +2226,8 @@ iwn_rx_done(struct iwn_softc *sc, struct
                        }
                }
 
-               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, NULL);
        }
 #endif
 
@@ -3257,7 +3251,6 @@ iwn_tx(struct iwn_softc *sc, struct mbuf
        rinfo = &iwn_rates[ridx];
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct iwn_tx_radiotap_header *tap = &sc->sc_txtap;
                uint16_t chan_flags;
 
@@ -3278,13 +3271,8 @@ iwn_tx(struct iwn_softc *sc, struct mbuf
                    (wh->i_fc[1] & IEEE80211_FC1_PROTECTED))
                        tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
 
-               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, NULL);
        }
 #endif
 
Index: if_wpi.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_wpi.c,v
retrieving revision 1.145
diff -u -p -r1.145 if_wpi.c
--- if_wpi.c    25 Jul 2019 01:46:15 -0000      1.145
+++ if_wpi.c    12 Sep 2019 03:14:03 -0000
@@ -1298,7 +1298,6 @@ wpi_rx_done(struct wpi_softc *sc, struct
 
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct wpi_rx_radiotap_header *tap = &sc->sc_rxtap;
 
                tap->wr_flags = 0;
@@ -1331,13 +1330,8 @@ wpi_rx_done(struct wpi_softc *sc, struct
                default:  tap->wr_rate =   0;
                }
 
-               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, NULL);
        }
 #endif
 
@@ -1703,7 +1697,6 @@ wpi_tx(struct wpi_softc *sc, struct mbuf
 
 #if NBPFILTER > 0
        if (sc->sc_drvbpf != NULL) {
-               struct mbuf mb;
                struct wpi_tx_radiotap_header *tap = &sc->sc_txtap;
 
                tap->wt_flags = 0;
@@ -1715,13 +1708,8 @@ wpi_tx(struct wpi_softc *sc, struct mbuf
                    (wh->i_fc[1] & IEEE80211_FC1_PROTECTED))
                        tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
 
-               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, NULL);
        }
 #endif
 

Reply via email to