MCPcopy Create free account
hub / github.com/F-Stack/f-stack / bpf_mtap

Function bpf_mtap

freebsd/net/bpf.c:2292–2342  ·  view source on GitHub ↗

* Incoming linkage from device drivers, when packet is in an mbuf chain. * Locking model is explained in bpf_tap(). */

Source from the content-addressed store, hash-verified

2290 * Locking model is explained in bpf_tap().
2291 */
2292void
2293bpf_mtap(struct bpf_if *bp, struct mbuf *m)
2294{
2295 struct epoch_tracker et;
2296 struct bintime bt;
2297 struct bpf_d *d;
2298#ifdef BPF_JITTER
2299 bpf_jit_filter *bf;
2300#endif
2301 u_int pktlen, slen;
2302 int gottime;
2303
2304 /* Skip outgoing duplicate packets. */
2305 if ((m->m_flags & M_PROMISC) != 0 && m_rcvif(m) == NULL) {
2306 m->m_flags &= ~M_PROMISC;
2307 return;
2308 }
2309
2310 pktlen = m_length(m, NULL);
2311 gottime = BPF_TSTAMP_NONE;
2312
2313 NET_EPOCH_ENTER(et);
2314 CK_LIST_FOREACH(d, &bp->bif_dlist, bd_next) {
2315 if (BPF_CHECK_DIRECTION(d, m_rcvif(m), bp->bif_ifp))
2316 continue;
2317 counter_u64_add(d->bd_rcount, 1);
2318#ifdef BPF_JITTER
2319 bf = bpf_jitter_enable != 0 ? d->bd_bfilter : NULL;
2320 /* XXX We cannot handle multiple mbufs. */
2321 if (bf != NULL && m->m_next == NULL)
2322 slen = (*(bf->func))(mtod(m, u_char *), pktlen,
2323 pktlen);
2324 else
2325#endif
2326 slen = bpf_filter(d->bd_rfilter, (u_char *)m, pktlen, 0);
2327 if (slen != 0) {
2328 BPFD_LOCK(d);
2329
2330 counter_u64_add(d->bd_fcount, 1);
2331 if (gottime < bpf_ts_quality(d->bd_tstamp))
2332 gottime = bpf_gettime(&bt, d->bd_tstamp, m);
2333#ifdef MAC
2334 if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0)
2335#endif
2336 catchpacket(d, (u_char *)m, pktlen, slen,
2337 bpf_append_mbuf, &bt);
2338 BPFD_UNLOCK(d);
2339 }
2340 }
2341 NET_EPOCH_EXIT(et);
2342}
2343
2344/*
2345 * Incoming linkage from device drivers, when packet is in

Callers 2

ether_vlan_mtapFunction · 0.85
if_simloopFunction · 0.85

Calls 8

m_lengthFunction · 0.85
bpf_ts_qualityFunction · 0.85
bpf_gettimeFunction · 0.85
catchpacketFunction · 0.85
bpf_filterFunction · 0.70
m_rcvifFunction · 0.50
counter_u64_addFunction · 0.50

Tested by

no test coverage detected