diff options
author | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2012-12-21 11:17:23 +0000 |
---|---|---|
committer | Mike Belopuhov <mikeb@cvs.openbsd.org> | 2012-12-21 11:17:23 +0000 |
commit | 3f3513fc0a8415728b4ddc5fdb7e43ba676aab73 (patch) | |
tree | 37848298653baa09dd1585616a782971a657ea23 /sys | |
parent | fa01876e725de1dd298e6c894f6d228bd0e0b762 (diff) |
Rather than calling mircotime in bpf_catchpacket each time it's called
on a packet, make bpf_catchpacket take a timeval indicating when the
packet was captured. Move microtime to the calling functions and grab
the timestamp as soon as we know that we're going to call catchpacket
at least once.
From NetBSD, ok deraadt, claudio, sthen
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/bpf.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 26ec765cfe3..bb54caeba18 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.81 2012/12/21 11:13:43 mikeb Exp $ */ +/* $OpenBSD: bpf.c,v 1.82 2012/12/21 11:17:22 mikeb Exp $ */ /* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */ /* @@ -102,7 +102,7 @@ int bpfpoll(dev_t, int, struct proc *); int bpfkqfilter(dev_t, struct knote *); void bpf_wakeup(struct bpf_d *); void bpf_catchpacket(struct bpf_d *, u_char *, size_t, size_t, - void (*)(const void *, void *, size_t)); + void (*)(const void *, void *, size_t), struct timeval *); void bpf_reset_d(struct bpf_d *); int bpf_getdltlist(struct bpf_d *, struct bpf_dltlist *); int bpf_setdlt(struct bpf_d *, u_int); @@ -1124,7 +1124,8 @@ bpf_tap(caddr_t arg, u_char *pkt, u_int pktlen, u_int direction) struct bpf_if *bp; struct bpf_d *d; size_t slen; - int drop = 0; + struct timeval tv; + int drop = 0, gottime = 0; /* * Note that the ipl does not have to be raised at this point. @@ -1139,7 +1140,9 @@ bpf_tap(caddr_t arg, u_char *pkt, u_int pktlen, u_int direction) else slen = bpf_filter(d->bd_rfilter, pkt, pktlen, pktlen); if (slen != 0) { - bpf_catchpacket(d, pkt, pktlen, slen, bcopy); + if (!gottime++) + microtime(&tv); + bpf_catchpacket(d, pkt, pktlen, slen, bcopy, &tv); if (d->bd_fildrop) drop++; } @@ -1182,6 +1185,8 @@ bpf_mtap(caddr_t arg, struct mbuf *m, u_int direction) struct bpf_d *d; size_t pktlen, slen; struct mbuf *m0; + struct timeval tv; + int gottime = 0; if (m == NULL) return; @@ -1199,9 +1204,11 @@ bpf_mtap(caddr_t arg, struct mbuf *m, u_int direction) pktlen, 0); if (slen == 0) - continue; + continue; - bpf_catchpacket(d, (u_char *)m, pktlen, slen, bpf_mcopy); + if (!gottime++) + microtime(&tv); + bpf_catchpacket(d, (u_char *)m, pktlen, slen, bpf_mcopy, &tv); if (d->bd_fildrop) m->m_flags |= M_FILDROP; } @@ -1309,6 +1316,8 @@ bpf_mtap_pflog(caddr_t arg, caddr_t data, struct mbuf *m) struct bpf_d *d; size_t pktlen, slen; struct mbuf *m0; + struct timeval tv; + int gottime = 0; if (m == NULL) return; @@ -1331,9 +1340,12 @@ bpf_mtap_pflog(caddr_t arg, caddr_t data, struct mbuf *m) pktlen, 0); if (slen == 0) - continue; + continue; - bpf_catchpacket(d, (u_char *)&mh, pktlen, slen, pflog_bpfcopy); + if (!gottime++) + microtime(&tv); + bpf_catchpacket(d, (u_char *)&mh, pktlen, slen, pflog_bpfcopy, + &tv); } #endif } @@ -1349,12 +1361,11 @@ bpf_mtap_pflog(caddr_t arg, caddr_t data, struct mbuf *m) */ void bpf_catchpacket(struct bpf_d *d, u_char *pkt, size_t pktlen, size_t snaplen, - void (*cpfn)(const void *, void *, size_t)) + void (*cpfn)(const void *, void *, size_t), struct timeval *tv) { struct bpf_hdr *hp; int totlen, curlen; int hdrlen = d->bd_bif->bif_hdrlen; - struct timeval tv; /* * Figure out how many bytes to move. If the packet is @@ -1393,9 +1404,8 @@ bpf_catchpacket(struct bpf_d *d, u_char *pkt, size_t pktlen, size_t snaplen, * Append the bpf header. */ hp = (struct bpf_hdr *)(d->bd_sbuf + curlen); - microtime(&tv); - hp->bh_tstamp.tv_sec = tv.tv_sec; - hp->bh_tstamp.tv_usec = tv.tv_usec; + hp->bh_tstamp.tv_sec = tv->tv_sec; + hp->bh_tstamp.tv_usec = tv->tv_usec; hp->bh_datalen = pktlen; hp->bh_hdrlen = hdrlen; /* |