diff options
author | sam <sam@FreeBSD.org> | 2003-12-28 03:56:00 +0000 |
---|---|---|
committer | sam <sam@FreeBSD.org> | 2003-12-28 03:56:00 +0000 |
commit | c165a87f8dfc070bceb68d9c3ff183ec2135e060 (patch) | |
tree | f663da0db11fcecb5ff2d3e93732492fb4d7bd29 /sys/net/bpf.c | |
parent | 853a4ae85d691a2f3500efc16c2eab14e3c117b0 (diff) | |
download | FreeBSD-src-c165a87f8dfc070bceb68d9c3ff183ec2135e060.zip FreeBSD-src-c165a87f8dfc070bceb68d9c3ff183ec2135e060.tar.gz |
o eliminate widespread on-stack mbuf use for bpf by introducing
a new bpf_mtap2 routine that does the right thing for an mbuf
and a variable-length chunk of data that should be prepended.
o while we're sweeping the drivers, use u_int32_t uniformly when
when prepending the address family (several places were assuming
sizeof(int) was 4)
o return M_ASSERTVALID to BPF_MTAP* now that all stack-allocated
mbufs have been eliminated; this may better be moved to the bpf
routines
Reviewed by: arch@ and several others
Diffstat (limited to 'sys/net/bpf.c')
-rw-r--r-- | sys/net/bpf.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c index c282dcf..c06312e 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1227,6 +1227,50 @@ bpf_mtap(bp, m) } /* + * Incoming linkage from device drivers, when packet is in + * an mbuf chain and to be prepended by a contiguous header. + */ +void +bpf_mtap2(bp, data, dlen, m) + struct bpf_if *bp; + void *data; + u_int dlen; + struct mbuf *m; +{ + struct mbuf mb; + struct bpf_d *d; + u_int pktlen, slen; + + pktlen = m_length(m, NULL); + /* + * 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. + */ + mb.m_next = m; + mb.m_data = data; + mb.m_len = dlen; + pktlen += dlen; + + BPFIF_LOCK(bp); + for (d = bp->bif_dlist; d != 0; d = d->bd_next) { + if (!d->bd_seesent && (m->m_pkthdr.rcvif == NULL)) + continue; + BPFD_LOCK(d); + ++d->bd_rcount; + slen = bpf_filter(d->bd_filter, (u_char *)&mb, pktlen, 0); + if (slen != 0) +#ifdef MAC + if (mac_check_bpfdesc_receive(d, bp->bif_ifp) == 0) +#endif + catchpacket(d, (u_char *)&mb, pktlen, slen, + bpf_mcopy); + BPFD_UNLOCK(d); + } + BPFIF_UNLOCK(bp); +} + +/* * Move the packet data from interface memory (pkt) into the * store buffer. Return 1 if it's time to wakeup a listener (buffer full), * otherwise 0. "copy" is the routine called to do the actual data @@ -1580,6 +1624,15 @@ bpf_mtap(bp, m) } void +bpf_mtap2(bp, d, l, m) + struct bpf_if *bp; + const void *d; + u_int l; + struct mbuf *m; +{ +} + +void bpfattach(ifp, dlt, hdrlen) struct ifnet *ifp; u_int dlt, hdrlen; |