Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Sep 2004 02:26:24 -0700
From:      Bruce M Simpson <bms@spc.org>
To:        freebsd-net@FreeBSD.org, tcpdump-workers@tcpdump.org
Subject:   [PATCH] Add ioctl to disable bpf timestamping
Message-ID:  <20040908092624.GD793@empiric.icir.org>

next in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040908092624.GD793>