use the interface pointers on the mbuf to figure it out. @@ -2327,7 +2146,7 @@ bpf_tap(struct bpf_if *bp, u_char *pkt, u_int pktlen) gottime = bpf_gettime(&bt, d->bd_tstamp, NULL); #ifdef MAC - if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0) + if (bif_mac_check_receive(bp, d) == 0) #endif catchpacket(d, pkt, pktlen, slen, bpf_append_bytes, &bt); @@ -2344,10 +2163,6 @@ bpf_tap_if(if_t ifp, u_char *pkt, u_int pktlen) bpf_tap(ifp->if_bpf, pkt, pktlen); } -#define BPF_CHECK_DIRECTION(d, r, i) \ - (((d)->bd_direction == BPF_D_IN && (r) != (i)) || \ - ((d)->bd_direction == BPF_D_OUT && (r) == (i))) - /* * Incoming linkage from device drivers, when packet is in an mbuf chain. * Locking model is explained in bpf_tap(). @@ -2375,7 +2190,7 @@ bpf_mtap(struct bpf_if *bp, struct mbuf *m) NET_EPOCH_ENTER(et); CK_LIST_FOREACH(d, &bp->bif_dlist, bd_next) { - if (BPF_CHECK_DIRECTION(d, m_rcvif(m), bp->bif_ifp)) + if (bpf_chkdir(d, m)) continue; counter_u64_add(d->bd_rcount, 1); #ifdef BPF_JITTER @@ -2394,7 +2209,7 @@ bpf_mtap(struct bpf_if *bp, struct mbuf *m) if (gottime < bpf_ts_quality(d->bd_tstamp)) gottime = bpf_gettime(&bt, d->bd_tstamp, m); #ifdef MAC - if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0) + if (bif_mac_check_receive(bp, d) == 0) #endif catchpacket(d, (u_char *)m, pktlen, slen, bpf_append_mbuf, &bt); @@ -2449,7 +2264,7 @@ bpf_mtap2(struct bpf_if *bp, void *data, u_int dlen, struct mbuf *m) NET_EPOCH_ENTER(et); CK_LIST_FOREACH(d, &bp->bif_dlist, bd_next) { - if (BPF_CHECK_DIRECTION(d, m->m_pkthdr.rcvif, bp->bif_ifp)) + if (bpf_chkdir(d, m)) continue; counter_u64_add(d->bd_rcount, 1); slen = bpf_filter(d->bd_rfilter, (u_char *)&mb, pktlen, 0); @@ -2460,7 +2275,7 @@ bpf_mtap2(struct bpf_if *bp, void *data, u_int dlen, struct mbuf *m) if (gottime < bpf_ts_quality(d->bd_tstamp)) gottime = bpf_gettime(&bt, d->bd_tstamp, m); #ifdef MAC - if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0) + if (bif_mac_check_receive(bp, d) == 0) #endif catchpacket(d, (u_char *)&mb, pktlen, slen, bpf_append_mbuf, &bt); @@ -2479,7 +2294,6 @@ bpf_mtap2_if(if_t ifp, void *data, u_int dlen, struct mbuf *m) } } -#undef BPF_CHECK_DIRECTION #undef BPF_TSTAMP_NONE #undef BPF_TSTAMP_FAST #undef BPF_TSTAMP_NORMAL @@ -2759,57 +2573,36 @@ bpfd_free(epoch_context_t ctx) } /* - * Attach an interface to bpf. dlt is the link layer type; hdrlen is the - * fixed size of the link header (variable length headers not yet supported). + * Attach a tap point to bpf. + * XXX: with current KPI it is consumer's responsibility to avoid duplicates. */ -void -bpfattach(struct ifnet *ifp, u_int dlt, u_int hdrlen) -{ - - bpfattach2(ifp, dlt, hdrlen, &ifp->if_bpf); -} - -/* - * Attach an interface to bpf. ifp is a pointer to the structure - * defining the interface to be attached, dlt is the link layer type, - * and hdrlen is the fixed size of the link header (variable length - * headers are not yet supporrted). - */ -void -bpfattach2(struct ifnet *ifp, u_int dlt, u_int hdrlen, - struct bpf_if **driverp) +struct bpf_if * +bpf_attach(const char *name, u_int dlt, u_int hdrlen, + const struct bif_methods *methods, void *sc) { struct bpf_if *bp; - KASSERT(*driverp == NULL, - ("bpfattach2: driverp already initialized")); - bp = malloc(sizeof(*bp), M_BPF, M_WAITOK | M_ZERO); CK_LIST_INIT(&bp->bif_dlist); CK_LIST_INIT(&bp->bif_wlist); - bp->bif_ifp = ifp; bp->bif_dlt = dlt; bp->bif_hdrlen = hdrlen; - bp->bif_bpf = driverp; + bp->bif_softc = sc; + bp->bif_name = name; + bp->bif_methods = methods; refcount_init(&bp->bif_refcnt, 1); - *driverp = bp; - /* - * Reference ifnet pointer, so it won't freed until - * we release it. - */ - if_ref(ifp); BPF_LOCK(); LIST_INSERT_HEAD(&bpf_iflist, bp, bif_next); BPF_UNLOCK(); - if (bootverbose && IS_DEFAULT_VNET(curvnet)) - if_printf(ifp, "bpf attached\n"); + return (bp); } #ifdef VIMAGE /* * Detach descriptors on interface's vmove event. + * XXXGL: shouldn't be a special case, but a full detach. */ void bpf_ifdetach(struct ifnet *ifp) @@ -2819,7 +2612,8 @@ bpf_ifdetach(struct ifnet *ifp) BPF_LOCK(); LIST_FOREACH(bp, &bpf_iflist, bif_next) { - if (bp->bif_ifp != ifp) *** 706 LINES SKIPPED ***