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

Function bpf_tap

freebsd/net/bpf.c:2235–2282  ·  view source on GitHub ↗

* Incoming linkage from device drivers. Process the packet pkt, of length * pktlen, which is stored in a contiguous buffer. The packet is parsed * by each process' filter, and if accepted, stashed into the corresponding * buffer. */

Source from the content-addressed store, hash-verified

2233 * buffer.
2234 */
2235void
2236bpf_tap(struct bpf_if *bp, u_char *pkt, u_int pktlen)
2237{
2238 struct epoch_tracker et;
2239 struct bintime bt;
2240 struct bpf_d *d;
2241#ifdef BPF_JITTER
2242 bpf_jit_filter *bf;
2243#endif
2244 u_int slen;
2245 int gottime;
2246
2247 gottime = BPF_TSTAMP_NONE;
2248 NET_EPOCH_ENTER(et);
2249 CK_LIST_FOREACH(d, &bp->bif_dlist, bd_next) {
2250 counter_u64_add(d->bd_rcount, 1);
2251 /*
2252 * NB: We dont call BPF_CHECK_DIRECTION() here since there
2253 * is no way for the caller to indiciate to us whether this
2254 * packet is inbound or outbound. In the bpf_mtap() routines,
2255 * we use the interface pointers on the mbuf to figure it out.
2256 */
2257#ifdef BPF_JITTER
2258 bf = bpf_jitter_enable != 0 ? d->bd_bfilter : NULL;
2259 if (bf != NULL)
2260 slen = (*(bf->func))(pkt, pktlen, pktlen);
2261 else
2262#endif
2263 slen = bpf_filter(d->bd_rfilter, pkt, pktlen, pktlen);
2264 if (slen != 0) {
2265 /*
2266 * Filter matches. Let's to acquire write lock.
2267 */
2268 BPFD_LOCK(d);
2269 counter_u64_add(d->bd_fcount, 1);
2270 if (gottime < bpf_ts_quality(d->bd_tstamp))
2271 gottime = bpf_gettime(&bt, d->bd_tstamp,
2272 NULL);
2273#ifdef MAC
2274 if (mac_bpfdesc_check_receive(d, bp->bif_ifp) == 0)
2275#endif
2276 catchpacket(d, pkt, pktlen, slen,
2277 bpf_append_bytes, &bt);
2278 BPFD_UNLOCK(d);
2279 }
2280 }
2281 NET_EPOCH_EXIT(et);
2282}
2283
2284#define BPF_CHECK_DIRECTION(d, r, i) \
2285 (((d)->bd_direction == BPF_D_IN && (r) != (i)) || \

Callers

nothing calls this directly

Calls 6

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