FreeBSD/sys/net/bpf.c
/*
 * Incoming linkage from device drivers, when packet is in
 * an mbuf chain and to be prepended by a contiguous header.
 */
Incoming linkage from device drivers, when packet is in
an mbuf chain and to be prepended by a contiguous header.
Incoming linkage from device drivers when packet is in an mbuf chain and to be prepended by a contiguous header .
void
bpf_mtap2(struct bpf_if *bp, void *data, u_int dlen, struct mbuf *m)
{
	struct bintime bt;
	struct mbuf mb;
	struct bpf_d *d;
	u_int pktlen, slen;
	int gottime;
	if ((m->m_flags & M_PROMISC) != 0 && m->m_pkthdr.rcvif == NULL) {
		m->m_flags &= ~M_PROMISC;
		return;
	}
	pktlen = m_length(m, NULL);
	mb.m_next = m;
	mb.m_data = data;
	mb.m_len = dlen;
	pktlen += dlen;
	gottime = BPF_TSTAMP_NONE;
	BPFIF_RLOCK(bp);
	LIST_FOREACH(d, &bp->bif_dlist, bd_next) {
		if (BPF_CHECK_DIRECTION(d, m->m_pkthdr.rcvif, bp->bif_ifp))
			continue;
		++d->bd_rcount;
		slen = bpf_filter(d->bd_rfilter, (u_char *)&mb, pktlen, 0);
		if (slen != 0) {
			BPFD_LOCK(d);
			d->bd_fcount++;
			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)
#endif
				catchpacket(d, (u_char *)&mb, pktlen, slen,
				    bpf_append_mbuf, &bt);
			BPFD_UNLOCK(d);
		}
	}
	BPFIF_RUNLOCK(bp);
}
void bpf_mtap2 ( struct bpf_if * bp , void * data , u_int dlen , struct mbuf * m ) { struct bintime bt ; struct mbuf mb ; struct bpf_d * d ; u_int pktlen , slen ; int gottime ; if ( ( m -> m_flags & M_PROMISC ) != 0 && m -> m_pkthdr . rcvif == NULL ) { m -> m_flags &= ~ M_PROMISC ; return ; } pktlen = m_length ( m , NULL ) ; mb . m_next = m ; mb . m_data = data ; mb . m_len = dlen ; pktlen += dlen ; gottime = BPF_TSTAMP_NONE ; BPFIF_RLOCK ( bp ) ; LIST_FOREACH ( d , & bp -> bif_dlist , bd_next ) { if ( BPF_CHECK_DIRECTION ( d , m -> m_pkthdr . rcvif , bp -> bif_ifp ) ) continue ; ++ d -> bd_rcount ; slen = bpf_filter ( d -> bd_rfilter , ( u_char * ) & mb , pktlen , 0 ) ; if ( slen != 0 ) { BPFD_LOCK ( d ) ; d -> bd_fcount ++ ; 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 ) #endif catchpacket ( d , ( u_char * ) & mb , pktlen , slen , bpf_append_mbuf , & bt ) ; BPFD_UNLOCK ( d ) ; } } BPFIF_RUNLOCK ( bp ) ; }
Incoming linkage from device drivers, when packet is in
 an mbuf chain and to be prepended by a contiguous header.
Incoming linkage from device drivers when packet is in an mbuf chain and to be prepended by a contiguous header .
/* Skip outgoing duplicate packets. */ /*
	 * Craft on-stack mbuf suitable for passing to bpf_filter.
	 * Note that we cut corners here; we only setup what's
	 * absolutely needed--this mbuf should never go anywhere else.
	 */