From owner-freebsd-net@FreeBSD.ORG Wed Sep 8 09:26:32 2004 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6FAD816A4CE for ; Wed, 8 Sep 2004 09:26:32 +0000 (GMT) Received: from arginine.spc.org (arginine.spc.org [195.206.69.236]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3E26B43D31 for ; Wed, 8 Sep 2004 09:26:31 +0000 (GMT) (envelope-from bms@spc.org) Received: from localhost (localhost [127.0.0.1]) by arginine.spc.org (Postfix) with ESMTP id 25CB465216; Wed, 8 Sep 2004 10:26:29 +0100 (BST) Received: from arginine.spc.org ([127.0.0.1]) by localhost (arginine.spc.org [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 71078-01; Wed, 8 Sep 2004 10:26:28 +0100 (BST) Received: from empiric.dek.spc.org (adsl-67-124-246-28.dsl.snfc21.pacbell.net [67.124.246.28]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by arginine.spc.org (Postfix) with ESMTP id 5A5BA65213; Wed, 8 Sep 2004 10:26:27 +0100 (BST) Received: by empiric.dek.spc.org (Postfix, from userid 1001) id 64D4763B1; Wed, 8 Sep 2004 02:26:24 -0700 (PDT) Date: Wed, 8 Sep 2004 02:26:24 -0700 From: Bruce M Simpson To: freebsd-net@FreeBSD.org, tcpdump-workers@tcpdump.org Message-ID: <20040908092624.GD793@empiric.icir.org> Mail-Followup-To: freebsd-net@FreeBSD.org, tcpdump-workers@tcpdump.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="p2kqVDKq5asng8Dg" Content-Disposition: inline Subject: [PATCH] Add ioctl to disable bpf timestamping X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2004 09:26:32 -0000 --p2kqVDKq5asng8Dg Content-Type: multipart/mixed; boundary="xXmbgvnjoT4axfJE" Content-Disposition: inline --xXmbgvnjoT4axfJE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Here's a patch against 5.3 to add a per-instance switch which allows the user to specify if captured packets should be timestamped (and, if so, whether microtime() or the faster but less accurate getmicrotime() call should be used). Comments/flames/etc to the usual... BMS --xXmbgvnjoT4axfJE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="bpf-tstamp.diff" Content-Transfer-Encoding: quoted-printable Index: bpf.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/sys/net/bpf.c,v retrieving revision 1.130 diff -u -p -r1.130 bpf.c --- bpf.c 5 Jul 2004 16:28:31 -0000 1.130 +++ bpf.c 8 Sep 2004 09:22:09 -0000 @@ -347,6 +347,7 @@ bpfopen(dev, flags, fmt, td) d->bd_bufsize =3D bpf_bufsize; d->bd_sig =3D SIGIO; d->bd_seesent =3D 1; + d->bd_tstamp =3D BPF_TSTAMP_MICROTIME; #ifdef MAC mac_init_bpfdesc(d); mac_create_bpfdesc(td->td_ucred, d); @@ -629,6 +630,7 @@ reset_d(d) * BIOCSHDRCMPLT Set "header already complete" flag * BIOCGSEESENT Get "see packets sent" flag * BIOCSSEESENT Set "see packets sent" flag + * BIOCSTSTAMP Set "timestamp preference" flag */ /* ARGSUSED */ static int @@ -880,6 +882,13 @@ bpfioctl(dev, cmd, addr, flags, td) d->bd_seesent =3D *(u_int *)addr; break; =20 + /* + * Set "timestamp preference" flag + */ + case BIOCSTSTAMP: + d->bd_tstamp =3D *(u_int *)addr; + break; + case FIONBIO: /* Non-blocking I/O */ break; =20 @@ -1331,7 +1340,14 @@ catchpacket(d, pkt, pktlen, snaplen, cpf * Append the bpf header. */ hp =3D (struct bpf_hdr *)(d->bd_sbuf + curlen); - microtime(&hp->bh_tstamp); + /* + * Only prepend a timestamp if instructed to do so. + * getmicrotime() is less accurate but potentially faster. + */ + if (d->bd_tstamp =3D=3D BPF_TSTAMP_MICROTIME) + microtime(&hp->bh_tstamp); + else if (d->bd_tstamp =3D=3D BPF_TSTAMP_GETMICROTIME) + getmicrotime(&hp->bh_tstamp); hp->bh_datalen =3D pktlen; hp->bh_hdrlen =3D hdrlen; /* Index: bpf.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/sys/net/bpf.h,v retrieving revision 1.36 diff -u -p -r1.36 bpf.h --- bpf.h 30 May 2004 17:03:48 -0000 1.36 +++ bpf.h 8 Sep 2004 09:15:35 -0000 @@ -113,6 +113,7 @@ struct bpf_version { #define BIOCSSEESENT _IOW('B',119, u_int) #define BIOCSDLT _IOW('B',120, u_int) #define BIOCGDLTLIST _IOWR('B',121, struct bpf_dltlist) +#define BIOCSTSTAMP _IOW('B',122, u_int) =20 /* * Structure prepended to each packet. @@ -491,4 +492,13 @@ u_int bpf_filter(const struct bpf_insn=20 */ #define BPF_MEMWORDS 16 =20 +/* + * Defines to specify timestamping preference for a BPF instance. + * BPF_TSTAMP_MICROTIME is the default when none is specified. + * Other settings may increase BPF capture performance under load. + */ +#define BPF_TSTAMP_NONE 0x00 /* Don't timestamp packets */ +#define BPF_TSTAMP_MICROTIME 0x01 /* Use microtime() (slower) */ +#define BPF_TSTAMP_GETMICROTIME 0x02 /* Use getmicrotime() */ + #endif /* _NET_BPF_H_ */ Index: bpfdesc.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /home/ncvs/src/sys/net/bpfdesc.h,v retrieving revision 1.27 diff -u -p -r1.27 bpfdesc.h --- bpfdesc.h 7 Apr 2004 20:46:11 -0000 1.27 +++ bpfdesc.h 8 Sep 2004 09:17:16 -0000 @@ -73,6 +73,7 @@ struct bpf_d { u_char bd_promisc; /* true if listening promiscuously */ u_char bd_state; /* idle, waiting, or timed out */ u_char bd_immediate; /* true to return on packet arrival */ + u_char bd_tstamp; /* timestamping preferences */ int bd_hdrcmplt; /* false to fill in src lladdr automatically */ int bd_seesent; /* true if bpf should see sent packets */ int bd_async; /* non-zero if packet reception should generate signal */ --xXmbgvnjoT4axfJE-- --p2kqVDKq5asng8Dg Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Comment: '' iD8DBQFBPtA/ueUpAYYNtTsRAniIAKCCmT2iQ2Y0VicC4xIbmfjBIi8hhgCdFIaZ H536iAZXbcNRYpq4E924s5k= =9VmV -----END PGP SIGNATURE----- --p2kqVDKq5asng8Dg--