From owner-svn-src-head@freebsd.org Thu Aug 4 03:40:43 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7C669BAC053; Thu, 4 Aug 2016 03:40:43 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail108.syd.optusnet.com.au (mail108.syd.optusnet.com.au [211.29.132.59]) by mx1.freebsd.org (Postfix) with ESMTP id 4735D1EAB; Thu, 4 Aug 2016 03:40:42 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c122-106-149-109.carlnfd1.nsw.optusnet.com.au (c122-106-149-109.carlnfd1.nsw.optusnet.com.au [122.106.149.109]) by mail108.syd.optusnet.com.au (Postfix) with ESMTPS id D500D1A48E6; Thu, 4 Aug 2016 13:40:39 +1000 (AEST) Date: Thu, 4 Aug 2016 13:40:38 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Jung-uk Kim cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r303733 - head/contrib/libpcap In-Reply-To: <201608032008.u73K8dWe047330@repo.freebsd.org> Message-ID: <20160804124849.Y1045@besplex.bde.org> References: <201608032008.u73K8dWe047330@repo.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=EfU1O6SC c=1 sm=1 tr=0 a=R/f3m204ZbWUO/0rwPSMPw==:117 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=YDmY72k8xEVSsdaq3ocA:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Aug 2016 03:40:43 -0000 On Wed, 3 Aug 2016, Jung-uk Kim wrote: > Log: > Support nanosecond time stamps for pcap_dispatch(3) and pcap_loop(3). > > Modified: > head/contrib/libpcap/pcap-bpf.c > > Modified: head/contrib/libpcap/pcap-bpf.c > ============================================================================== > --- head/contrib/libpcap/pcap-bpf.c Wed Aug 3 19:23:22 2016 (r303732) > +++ head/contrib/libpcap/pcap-bpf.c Wed Aug 3 20:08:39 2016 (r303733) > @@ -1008,7 +1028,25 @@ pcap_read_bpf(pcap_t *p, int cnt, pcap_h > if (pb->filtering_in_kernel || > bpf_filter(p->fcode.bf_insns, datap, bhp->bh_datalen, caplen)) { > struct pcap_pkthdr pkthdr; > +#ifdef BIOCSTSTAMP > + struct bintime bt; > + > + bt.sec = bhp->bh_tstamp.bt_sec; > + bt.frac = bhp->bh_tstamp.bt_frac; The names are very confusing since bt_sec and bt_frac are only misnamed as sec and frac in struct bintime. > + if (p->opt.tstamp_precision == PCAP_TSTAMP_PRECISION_NANO) { > + struct timespec ts; > + > + bintime2timespec(&bt, &ts); > + pkthdr.ts.tv_sec = ts.tv_sec; > + pkthdr.ts.tv_usec = ts.tv_nsec; And this abuses tv_usec to hold nanoseconds. Old code is even more confusing, and at least partly wrong. X contrib/libpcap/pcap-bpf.c: pkthdr.ts.tv_usec = bhp->bh_tstamp.tv_usec/1000; This is to convert for tv_usec actually being tv_nsec on AIX. If the above works with no conversion, then it might work for AIX too. X sys/net/bpf.c: struct timeval32 bh_tstamp; /* time stamp */ Banal comment. The complexities are from what sort of timestamp this is. It is obviously a timestamp. This bh_tstamp is in struct bpf_hdr32 for the !BURN_BRIDGES case. There is also struct timeval bh_timestamp in struct bpf_hdr. This header is bogusly marked Obsolete. X sys/net/bpf.c: hdr32_old.bh_tstamp.tv_usec = ts.bt_frac; This is in the !BURN_BRIDGES && COMPAT_FREEBSD32 case. Since struct timeval32 always has a 32-bit tv_usec, this assignment discards the most significant bits in bt_frac but keeps the noise. X sys/net/bpf.c: hdr_old.bh_tstamp.tv_usec = ts.bt_frac; This is in the !BURN_BRIDGES && !COMPAT_FREEBSD32 case. Since tv_sec in a normal timetamp is bogusly long, this accidentally preserves all of the bits in bt_frac on 64-bit arches. On 32-bit arches, it loses the signal as for the COMPAT_FREEBSD32 case. Bruce