Index: net/bpf.c =================================================================== RCS file: /cvs/src/sys/net/bpf.c,v diff -u -p -r1.225 bpf.c --- net/bpf.c 15 Aug 2024 12:20:20 -0000 1.225 +++ net/bpf.c 31 Oct 2024 06:40:12 -0000 @@ -1758,6 +1758,18 @@ bpfsattach(caddr_t *bpfp, const char *na return (bp); } +void * +bpfrattach(caddr_t *driverp, const char *name, struct ifnet *ifp, + u_int dlt, u_int hdrlen) +{ + struct bpf_if *bp; + + bp = bpfsattach(driverp, name, dlt, hdrlen); + bp->bif_ifp = ifp; + + return (bp); +} + void bpfattach(caddr_t *driverp, struct ifnet *ifp, u_int dlt, u_int hdrlen) { Index: net/bpf.h =================================================================== RCS file: /cvs/src/sys/net/bpf.h,v diff -u -p -r1.73 bpf.h --- net/bpf.h 15 Aug 2024 12:20:20 -0000 1.73 +++ net/bpf.h 31 Oct 2024 06:40:12 -0000 @@ -327,6 +327,7 @@ int bpf_tap_hdr(caddr_t, const void *, void bpfattach(caddr_t *, struct ifnet *, u_int, u_int); void bpfdetach(struct ifnet *); void *bpfsattach(caddr_t *, const char *, u_int, u_int); +void *bpfrattach(caddr_t *, const char *, struct ifnet *, u_int, u_int); void bpfsdetach(void *); void bpfilterattach(int); Index: net/ifq.c =================================================================== RCS file: /cvs/src/sys/net/ifq.c,v diff -u -p -r1.53 ifq.c --- net/ifq.c 10 Nov 2023 15:51:24 -0000 1.53 +++ net/ifq.c 31 Oct 2024 06:40:12 -0000 @@ -674,6 +674,8 @@ ifiq_init(struct ifiqueue *ifiq, struct ifiq->ifiq_errors = 0; ifiq->ifiq_idx = idx; + snprintf(ifiq->ifiq_bpfname, sizeof(ifiq->ifiq_bpfname), + "%s:rx%u", ifp->if_xname, idx); #if NKSTAT > 0 /* XXX xname vs driver name and unit */ @@ -706,6 +708,32 @@ ifiq_destroy(struct ifiqueue *ifiq) unsigned int ifiq_maxlen_drop = 2048 * 5; unsigned int ifiq_maxlen_return = 2048 * 3; +#if NBPFILTER > 0 +static unsigned int +ifiq_bpfilter(struct ifnet *ifp, caddr_t if_bpf, struct mbuf_list *ml) +{ + unsigned int fdrops = 0; + struct mbuf_list ml0; + struct mbuf *m; + + if (if_bpf == NULL) + return (0); + + ml0 = *ml; + ml_init(ml); + + while ((m = ml_dequeue(&ml0)) != NULL) { + if ((*ifp->if_bpf_mtap)(if_bpf, m, BPF_DIRECTION_IN)) { + m_freem(m); + fdrops++; + } else + ml_enqueue(ml, m); + } + + return (fdrops); +} +#endif + int ifiq_input(struct ifiqueue *ifiq, struct mbuf_list *ml) { @@ -715,9 +743,6 @@ ifiq_input(struct ifiqueue *ifiq, struct uint64_t bytes = 0; uint64_t fdrops = 0; unsigned int len; -#if NBPFILTER > 0 - caddr_t if_bpf; -#endif if (ml_empty(ml)) return (0); @@ -730,29 +755,17 @@ ifiq_input(struct ifiqueue *ifiq, struct packets = ml_len(ml); #if NBPFILTER > 0 - if_bpf = ifp->if_bpf; - if (if_bpf) { - struct mbuf_list ml0 = *ml; - - ml_init(ml); - - while ((m = ml_dequeue(&ml0)) != NULL) { - if ((*ifp->if_bpf_mtap)(if_bpf, m, BPF_DIRECTION_IN)) { - m_freem(m); - fdrops++; - } else - ml_enqueue(ml, m); - } - - if (ml_empty(ml)) { - mtx_enter(&ifiq->ifiq_mtx); - ifiq->ifiq_packets += packets; - ifiq->ifiq_bytes += bytes; - ifiq->ifiq_fdrops += fdrops; - mtx_leave(&ifiq->ifiq_mtx); + fdrops += ifiq_bpfilter(ifp, ifiq->ifiq_bpf, ml); + fdrops += ifiq_bpfilter(ifp, ifp->if_bpf, ml); - return (0); - } + if (ml_empty(ml)) { + mtx_enter(&ifiq->ifiq_mtx); + ifiq->ifiq_packets += packets; + ifiq->ifiq_bytes += bytes; + ifiq->ifiq_fdrops += fdrops; + mtx_leave(&ifiq->ifiq_mtx); + + return (0); } #endif Index: net/ifq.h =================================================================== RCS file: /cvs/src/sys/net/ifq.h,v diff -u -p -r1.41 ifq.h --- net/ifq.h 10 Nov 2023 15:51:24 -0000 1.41 +++ net/ifq.h 31 Oct 2024 06:40:12 -0000 @@ -88,6 +88,8 @@ struct ifiqueue { struct task ifiq_task; unsigned int ifiq_pressure; + caddr_t ifiq_bpf; + /* counters */ uint64_t ifiq_packets; uint64_t ifiq_bytes; @@ -106,6 +108,7 @@ struct ifiqueue { /* properties */ unsigned int ifiq_idx; + char ifiq_bpfname[24]; }; #ifdef _KERNEL Index: dev/pci/if_vmx.c =================================================================== RCS file: /cvs/src/sys/dev/pci/if_vmx.c,v diff -u -p -r1.89 if_vmx.c --- dev/pci/if_vmx.c 1 Sep 2024 03:08:59 -0000 1.89 +++ dev/pci/if_vmx.c 31 Oct 2024 06:40:12 -0000 @@ -452,9 +452,17 @@ vmxnet3_attach(struct device *parent, st #endif for (i = 0; i < sc->sc_nqueues; i++) { + struct ifiqueue *ifiq; + ifp->if_ifqs[i]->ifq_softc = &sc->sc_q[i].tx; sc->sc_q[i].tx.ifq = ifp->if_ifqs[i]; - sc->sc_q[i].rx.ifiq = ifp->if_iqs[i]; + + ifiq = ifp->if_iqs[i]; + sc->sc_q[i].rx.ifiq = ifiq; +#if NBPFILTER > 0 + bpfrattach(&ifiq->ifiq_bpf, ifiq->ifiq_bpfname, + ifp, DLT_EN10MB, ETHER_HDR_LEN); +#endif #if NKSTAT > 0 vmx_kstat_txstats(sc, &sc->sc_q[i].tx, i);