* Move the packet data from interface memory (pkt) into the * store buffer. "cpfn" is the routine called to do the actual data * transfer. bcopy is passed in to copy contiguous chunks, while * bpf_append_mbuf is passed in to copy mbuf chains. In the latter case, * pkt is really an mbuf. */
| 2471 | * pkt is really an mbuf. |
| 2472 | */ |
| 2473 | static void |
| 2474 | catchpacket(struct bpf_d *d, u_char *pkt, u_int pktlen, u_int snaplen, |
| 2475 | void (*cpfn)(struct bpf_d *, caddr_t, u_int, void *, u_int), |
| 2476 | struct bintime *bt) |
| 2477 | { |
| 2478 | struct bpf_xhdr hdr; |
| 2479 | #ifndef BURN_BRIDGES |
| 2480 | struct bpf_hdr hdr_old; |
| 2481 | #ifdef COMPAT_FREEBSD32 |
| 2482 | struct bpf_hdr32 hdr32_old; |
| 2483 | #endif |
| 2484 | #endif |
| 2485 | int caplen, curlen, hdrlen, totlen; |
| 2486 | int do_wakeup = 0; |
| 2487 | int do_timestamp; |
| 2488 | int tstype; |
| 2489 | |
| 2490 | BPFD_LOCK_ASSERT(d); |
| 2491 | if (d->bd_bif == NULL) { |
| 2492 | /* Descriptor was detached in concurrent thread */ |
| 2493 | counter_u64_add(d->bd_dcount, 1); |
| 2494 | return; |
| 2495 | } |
| 2496 | |
| 2497 | /* |
| 2498 | * Detect whether user space has released a buffer back to us, and if |
| 2499 | * so, move it from being a hold buffer to a free buffer. This may |
| 2500 | * not be the best place to do it (for example, we might only want to |
| 2501 | * run this check if we need the space), but for now it's a reliable |
| 2502 | * spot to do it. |
| 2503 | */ |
| 2504 | if (d->bd_fbuf == NULL && bpf_canfreebuf(d)) { |
| 2505 | d->bd_fbuf = d->bd_hbuf; |
| 2506 | d->bd_hbuf = NULL; |
| 2507 | d->bd_hlen = 0; |
| 2508 | bpf_buf_reclaimed(d); |
| 2509 | } |
| 2510 | |
| 2511 | /* |
| 2512 | * Figure out how many bytes to move. If the packet is |
| 2513 | * greater or equal to the snapshot length, transfer that |
| 2514 | * much. Otherwise, transfer the whole packet (unless |
| 2515 | * we hit the buffer size limit). |
| 2516 | */ |
| 2517 | hdrlen = bpf_hdrlen(d); |
| 2518 | totlen = hdrlen + min(snaplen, pktlen); |
| 2519 | if (totlen > d->bd_bufsize) |
| 2520 | totlen = d->bd_bufsize; |
| 2521 | |
| 2522 | /* |
| 2523 | * Round up the end of the previous packet to the next longword. |
| 2524 | * |
| 2525 | * Drop the packet if there's no room and no hope of room |
| 2526 | * If the packet would overflow the storage buffer or the storage |
| 2527 | * buffer is considered immutable by the buffer model, try to rotate |
| 2528 | * the buffer and wakeup pending processes. |
| 2529 | */ |
| 2530 | #ifdef COMPAT_FREEBSD32 |
no test coverage detected