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

Function bpf_mtap2

freebsd/net/bpf.c:2348–2399  ·  view source on GitHub ↗

* Incoming linkage from device drivers, when packet is in * an mbuf chain and to be prepended by a contiguous header. */

Source from the content-addressed store, hash-verified

2346 * an mbuf chain and to be prepended by a contiguous header.
2347 */
2348void
2349bpf_mtap2(struct bpf_if *bp, void *data, u_int dlen, struct mbuf *m)
2350{
2351 struct epoch_tracker et;
2352 struct bintime bt;
2353 struct mbuf mb;
2354 struct bpf_d *d;
2355 u_int pktlen, slen;
2356 int gottime;
2357
2358 /* Skip outgoing duplicate packets. */
2359 if ((m->m_flags & M_PROMISC) != 0 && m->m_pkthdr.rcvif == NULL) {
2360 m->m_flags &= ~M_PROMISC;
2361 return;
2362 }
2363
2364 pktlen = m_length(m, NULL);
2365 /*
2366 * Craft on-stack mbuf suitable for passing to bpf_filter.
2367 * Note that we cut corners here; we only setup what's
2368 * absolutely needed--this mbuf should never go anywhere else.
2369 */
2370 mb.m_flags = 0;
2371 mb.m_next = m;
2372 mb.m_data = data;
2373 mb.m_len = dlen;
2374 pktlen += dlen;
2375
2376 gottime = BPF_TSTAMP_NONE;
2377
2378 NET_EPOCH_ENTER(et);
2379 CK_LIST_FOREACH(d, &bp->bif_dlist, bd_next) {
2380 if (BPF_CHECK_DIRECTION(d, m->m_pkthdr.rcvif, bp->bif_ifp))
2381 continue;
2382 counter_u64_add(d->bd_rcount, 1);
2383 slen = bpf_filter(d->bd_rfilter, (u_char *)&mb, pktlen, 0);
2384 if (slen != 0) {
2385 BPFD_LOCK(d);
2386
2387 counter_u64_add(d->bd_fcount, 1);
2388 if (gottime < bpf_ts_quality(d->bd_tstamp))
2389 gottime = bpf_gettime(&bt, d->bd_tstamp, m);
2390#ifdef MAC
2391 if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0)
2392#endif
2393 catchpacket(d, (u_char *)&mb, pktlen, slen,
2394 bpf_append_mbuf, &bt);
2395 BPFD_UNLOCK(d);
2396 }
2397 }
2398 NET_EPOCH_EXIT(et);
2399}
2400
2401#undef BPF_CHECK_DIRECTION
2402#undef BPF_TSTAMP_NONE

Callers 15

spam_vapsFunction · 0.85
ieee80211_radiotap_txFunction · 0.85
ieee80211_radiotap_rxFunction · 0.85
stf_outputFunction · 0.85
in_stf_inputFunction · 0.85
ether_vlan_mtapFunction · 0.85
firewire_outputFunction · 0.85
firewire_inputFunction · 0.85
enc_bpftapFunction · 0.85
gif_inputFunction · 0.85
tunoutputFunction · 0.85

Calls 7

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

Tested by

no test coverage detected