xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/ntp.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1991, 2000, 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*
28*0Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
29*0Sstevel@tonic-gate  * The Regents of the University of California
30*0Sstevel@tonic-gate  * All Rights Reserved
31*0Sstevel@tonic-gate  *
32*0Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
33*0Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
34*0Sstevel@tonic-gate  * contributors.
35*0Sstevel@tonic-gate  */
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #ifndef	_NTP_H
38*0Sstevel@tonic-gate #define	_NTP_H
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate #ifdef __cplusplus
43*0Sstevel@tonic-gate extern "C" {
44*0Sstevel@tonic-gate #endif
45*0Sstevel@tonic-gate 
46*0Sstevel@tonic-gate /* $Source: /usr/users/louie/ntp/RCS/ntp.h,v $  */
47*0Sstevel@tonic-gate /* $Revision: 3.4.1.5 $ $Date: 89/04/10 15:55:42 $ */
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /*
50*0Sstevel@tonic-gate  *  $Log:	ntp.h,v $
51*0Sstevel@tonic-gate  * Revision 3.4.1.5  89/04/10  15:55:42  louie
52*0Sstevel@tonic-gate  * Provide default value for number of bits/byte if not defined.  Compute the
53*0Sstevel@tonic-gate  * Window shift mask inside of conditional code on XTAL so we get the correct
54*0Sstevel@tonic-gate  * value if configured without a crystal controled clock (!!)
55*0Sstevel@tonic-gate  *
56*0Sstevel@tonic-gate  * Revision 3.4.1.4  89/03/31  16:34:50  louie
57*0Sstevel@tonic-gate  * Add bit in flags which allow a peer to be synced to.  Changed a char to a bit
58*0Sstevel@tonic-gate  * field so that it is always signed.
59*0Sstevel@tonic-gate  *
60*0Sstevel@tonic-gate  * Revision 3.4.1.3  89/03/29  12:26:18  louie
61*0Sstevel@tonic-gate  * Removed some unused #defines.  Replaced MAXSTRATUM with NTP_INFIN per new
62*0Sstevel@tonic-gate  * spec.  The variable 'mode' in the peer structure has been renamed 'hmode'
63*0Sstevel@tonic-gate  * per the new spec.
64*0Sstevel@tonic-gate  *
65*0Sstevel@tonic-gate  * Revision 3.4.1.2  89/03/22  18:28:18  louie
66*0Sstevel@tonic-gate  * patch3: Use new RCS headers.
67*0Sstevel@tonic-gate  *
68*0Sstevel@tonic-gate  * Revision 3.4.1.1  89/03/20  00:02:53  louie
69*0Sstevel@tonic-gate  * 1
70*0Sstevel@tonic-gate  *
71*0Sstevel@tonic-gate  * Revision 3.4  89/03/17  18:37:00  louie
72*0Sstevel@tonic-gate  * Latest test release.
73*0Sstevel@tonic-gate  *
74*0Sstevel@tonic-gate  * Revision 3.3.1.1  89/03/17  18:23:49  louie
75*0Sstevel@tonic-gate  * Change CLOCK_FACTOR to be a power of 2.
76*0Sstevel@tonic-gate  *
77*0Sstevel@tonic-gate  * Revision 3.3  89/03/15  14:19:36  louie
78*0Sstevel@tonic-gate  * New baseline for next release.
79*0Sstevel@tonic-gate  *
80*0Sstevel@tonic-gate  * Revision 3.2.1.2  89/03/15  13:46:52  louie
81*0Sstevel@tonic-gate  * The version number for that particular flavor of ntpd <--> ntpdc interaction
82*0Sstevel@tonic-gate  * is now defined by NTPDC_VERSION.  The packet format for the ntpdc program
83*0Sstevel@tonic-gate  * has changed slightly to improve robustness when dealing with multiple packets
84*0Sstevel@tonic-gate  * of status data.
85*0Sstevel@tonic-gate  *
86*0Sstevel@tonic-gate  * Revision 3.2.1.1  89/03/09  17:11:24  louie
87*0Sstevel@tonic-gate  * patch1: Updated constants, which were previously in incorrect units.
88*0Sstevel@tonic-gate  *
89*0Sstevel@tonic-gate  * Revision 3.2  89/03/07  18:21:45  louie
90*0Sstevel@tonic-gate  * New version of UNIX NTP daemon and software based on the 6 March 1989
91*0Sstevel@tonic-gate  * draft of the new NTP protocol specification.  This version doesn't
92*0Sstevel@tonic-gate  * implement authentication, and accepts and send only NTP Version 1
93*0Sstevel@tonic-gate  * packets.
94*0Sstevel@tonic-gate  *
95*0Sstevel@tonic-gate  * Revision 3.1.1.1  89/02/15  08:54:42  louie
96*0Sstevel@tonic-gate  * *** empty log message ***
97*0Sstevel@tonic-gate  *
98*0Sstevel@tonic-gate  *
99*0Sstevel@tonic-gate  * Revision 3.1  89/01/30  14:43:07  louie
100*0Sstevel@tonic-gate  * Second UNIX NTP test release.
101*0Sstevel@tonic-gate  *
102*0Sstevel@tonic-gate  * Revision 3.0  88/12/12  16:01:07  louie
103*0Sstevel@tonic-gate  * Test release of new UNIX NTP software.  This version should conform to the
104*0Sstevel@tonic-gate  * revised NTP protocol specification.
105*0Sstevel@tonic-gate  *
106*0Sstevel@tonic-gate  */
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate #ifndef FD_SET
109*0Sstevel@tonic-gate #define	NFDBITS		32
110*0Sstevel@tonic-gate #define	FD_SETSIZE	32
111*0Sstevel@tonic-gate #define	FD_SET(n, p)	((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
112*0Sstevel@tonic-gate #define	FD_CLR(n, p)	((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
113*0Sstevel@tonic-gate #define	FD_ISSET(n, p)	((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
114*0Sstevel@tonic-gate #define	FD_ZERO(p)	bzero((char *)(p), sizeof (*(p)))
115*0Sstevel@tonic-gate #endif
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate #ifndef	NBBY
118*0Sstevel@tonic-gate #define	NBBY	8	/* number of bits per byte */
119*0Sstevel@tonic-gate #endif
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate #define	MAXNETIF	10
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate struct intf {
124*0Sstevel@tonic-gate 	int fd;
125*0Sstevel@tonic-gate 	char *name;
126*0Sstevel@tonic-gate 	struct sockaddr_in sin;
127*0Sstevel@tonic-gate 	struct sockaddr_in bcast;
128*0Sstevel@tonic-gate 	struct sockaddr_in mask;
129*0Sstevel@tonic-gate 	int uses;
130*0Sstevel@tonic-gate 	int if_flags;
131*0Sstevel@tonic-gate };
132*0Sstevel@tonic-gate extern struct intf addrs[];
133*0Sstevel@tonic-gate extern int nintf;
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate /*
136*0Sstevel@tonic-gate  *  Definitions for the masses
137*0Sstevel@tonic-gate  */
138*0Sstevel@tonic-gate #define	JAN_1970	2208988800	/* 1970 - 1900 in seconds */
139*0Sstevel@tonic-gate 
140*0Sstevel@tonic-gate /*
141*0Sstevel@tonic-gate  *  Daemon specific (ntpd.c)
142*0Sstevel@tonic-gate  */
143*0Sstevel@tonic-gate #define	SHIFT_MASK	0xff	/* number of intervals to wait */
144*0Sstevel@tonic-gate 
145*0Sstevel@tonic-gate #ifndef	WAYTOOBIG
146*0Sstevel@tonic-gate #define	WAYTOOBIG	1000.0	/* Too many seconds to correct, something is */
147*0Sstevel@tonic-gate 				/* really wrong */
148*0Sstevel@tonic-gate #endif
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate #ifndef	XTAL
151*0Sstevel@tonic-gate #define	XTAL	1	/* crystal controlled clock by default */
152*0Sstevel@tonic-gate #endif
153*0Sstevel@tonic-gate 
154*0Sstevel@tonic-gate #ifndef	NTPINITFILE
155*0Sstevel@tonic-gate #define	NTPINITFILE	"/etc/ntp.conf"
156*0Sstevel@tonic-gate #endif
157*0Sstevel@tonic-gate 
158*0Sstevel@tonic-gate struct list {
159*0Sstevel@tonic-gate 	struct ntp_peer *head;
160*0Sstevel@tonic-gate 	struct ntp_peer *tail;
161*0Sstevel@tonic-gate 	int members;
162*0Sstevel@tonic-gate };
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate #define	STRMCMP(a, cond, b) \
165*0Sstevel@tonic-gate 	(((a) == UNSPECIFIED ? NTP_INFIN+1 : a) cond \
166*0Sstevel@tonic-gate 		((b) == UNSPECIFIED ? NTP_INFIN+1 : (b)))
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate /*
170*0Sstevel@tonic-gate  *  Definitions outlined in the NTP spec
171*0Sstevel@tonic-gate  */
172*0Sstevel@tonic-gate #define	NTP_VERSION	1
173*0Sstevel@tonic-gate #define	NTP_PORT	123	/* for ref only (see /etc/services) */
174*0Sstevel@tonic-gate #define	NTP_INFIN	15
175*0Sstevel@tonic-gate #define	NTP_MAXAGE	86400
176*0Sstevel@tonic-gate #define	NTP_MAXSKW	0.01	/* seconds */
177*0Sstevel@tonic-gate #define	NTP_MINDIST	0.02	/* seconds */
178*0Sstevel@tonic-gate #define	NTP_MINPOLL	6	/* (64) seconds between messages */
179*0Sstevel@tonic-gate #define	NTP_MAXPOLL	10	/* (1024) secs to poll */
180*0Sstevel@tonic-gate #define	NTP_WINDOW	8	/* size of shift register */
181*0Sstevel@tonic-gate #define	NTP_MAXWGT	8	/* maximum allowable dispersion */
182*0Sstevel@tonic-gate #define	NTP_MAXLIST	5	/* max size of selection list */
183*0Sstevel@tonic-gate #define	NTP_MAXSTRA	2	/* max number of strata in selection list */
184*0Sstevel@tonic-gate #define	X_NTP_CANDIDATES 64	/* number of peers to consider when doing */
185*0Sstevel@tonic-gate 				/*	clock selection */
186*0Sstevel@tonic-gate #define	NTP_SELECT	0.75	/* weight used to compute dispersion */
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate #define	PEER_MAXDISP	64.0	/* Maximum dispersion  */
189*0Sstevel@tonic-gate #define	PEER_THRESHOLD	0.5	/* dispersion threshold */
190*0Sstevel@tonic-gate #define	PEER_FILTER	0.5	/* filter weight */
191*0Sstevel@tonic-gate 
192*0Sstevel@tonic-gate #if	XTAL == 0
193*0Sstevel@tonic-gate #define	PEER_SHIFT	4
194*0Sstevel@tonic-gate #define	NTP_WINDOW_SHIFT_MASK 0x0f
195*0Sstevel@tonic-gate #else
196*0Sstevel@tonic-gate #define	PEER_SHIFT	8
197*0Sstevel@tonic-gate #define	NTP_WINDOW_SHIFT_MASK 0xff
198*0Sstevel@tonic-gate #endif
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate 
201*0Sstevel@tonic-gate /*
202*0Sstevel@tonic-gate  *  5.1 Uniform Phase Adjustments
203*0Sstevel@tonic-gate  *  Clock parameters
204*0Sstevel@tonic-gate  */
205*0Sstevel@tonic-gate #define	CLOCK_UPDATE	8	/* update interval (1<<CLOCK_UPDATE secs) */
206*0Sstevel@tonic-gate #if	XTAL
207*0Sstevel@tonic-gate #define	CLOCK_ADJ	2	/* adjustment interval (1<<CLOCK_ADJ secs) */
208*0Sstevel@tonic-gate #define	CLOCK_PHASE	8	/* phase shift */
209*0Sstevel@tonic-gate #define	CLOCK_MAX	0.128	/* maximum aperture (milliseconds) */
210*0Sstevel@tonic-gate #else
211*0Sstevel@tonic-gate #define	CLOCK_ADJ	0
212*0Sstevel@tonic-gate #define	CLOCK_PHASE	6	/* phase shift */
213*0Sstevel@tonic-gate #define	CLOCK_MAX	0.512	/* maximum aperture (milliseconds) */
214*0Sstevel@tonic-gate #endif
215*0Sstevel@tonic-gate #define	CLOCK_FREQ	10	/* frequency shift */
216*0Sstevel@tonic-gate #define	CLOCK_TRACK	8
217*0Sstevel@tonic-gate #define	CLOCK_COMP	4
218*0Sstevel@tonic-gate #define	CLOCK_FACTOR	18
219*0Sstevel@tonic-gate 
220*0Sstevel@tonic-gate /*
221*0Sstevel@tonic-gate  * Structure definitions for NTP fixed point values
222*0Sstevel@tonic-gate  *
223*0Sstevel@tonic-gate  *    0			  1		      2			  3
224*0Sstevel@tonic-gate  *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
225*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
226*0Sstevel@tonic-gate  *   |			       Integer Part			     |
227*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
228*0Sstevel@tonic-gate  *   |			       Fraction Part			     |
229*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
230*0Sstevel@tonic-gate  *
231*0Sstevel@tonic-gate  *
232*0Sstevel@tonic-gate  *    0			  1		      2			  3
233*0Sstevel@tonic-gate  *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
234*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
235*0Sstevel@tonic-gate  *   |		  Integer Part	     |	   Fraction Part	     |
236*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
237*0Sstevel@tonic-gate  */
238*0Sstevel@tonic-gate struct l_fixedpt {
239*0Sstevel@tonic-gate 	u_long int_part;
240*0Sstevel@tonic-gate 	u_long fraction;
241*0Sstevel@tonic-gate };
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate struct s_fixedpt {
244*0Sstevel@tonic-gate 	u_short int_part;
245*0Sstevel@tonic-gate 	u_short fraction;
246*0Sstevel@tonic-gate };
247*0Sstevel@tonic-gate 
248*0Sstevel@tonic-gate /*
249*0Sstevel@tonic-gate  *  =================  Table 3.3. Packet Variables   =================
250*0Sstevel@tonic-gate  *    0			  1		      2			  3
251*0Sstevel@tonic-gate  *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
252*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
253*0Sstevel@tonic-gate  *   |LI | VN  | Mode|	  Stratum    |	    Poll     |	 Precision   |
254*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
255*0Sstevel@tonic-gate  *   |			   Synchronizing Distance		     |
256*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
257*0Sstevel@tonic-gate  *   |			  Synchronizing Dispersion		     |
258*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
259*0Sstevel@tonic-gate  *   |			Reference Clock Identifier		     |
260*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
261*0Sstevel@tonic-gate  *   |								     |
262*0Sstevel@tonic-gate  *   |		       Reference Timestamp (64 bits)		     |
263*0Sstevel@tonic-gate  *   |								     |
264*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
265*0Sstevel@tonic-gate  *   |								     |
266*0Sstevel@tonic-gate  *   |		       Originate Timestamp (64 bits)		     |
267*0Sstevel@tonic-gate  *   |								     |
268*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
269*0Sstevel@tonic-gate  *   |								     |
270*0Sstevel@tonic-gate  *   |			Receive Timestamp (64 bits)		     |
271*0Sstevel@tonic-gate  *   |								     |
272*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
273*0Sstevel@tonic-gate  *   |								     |
274*0Sstevel@tonic-gate  *   |			Transmit Timestamp (64 bits)		     |
275*0Sstevel@tonic-gate  *   |								     |
276*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
277*0Sstevel@tonic-gate  *   |		     Encryption Keyid (32 bits, when A bit set)	     |
278*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
279*0Sstevel@tonic-gate  *   |								     |
280*0Sstevel@tonic-gate  *   |		Message Authentication Code/MAC (when A bit set)     |
281*0Sstevel@tonic-gate  *   |								     |
282*0Sstevel@tonic-gate  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
283*0Sstevel@tonic-gate  */
284*0Sstevel@tonic-gate 
285*0Sstevel@tonic-gate #define	MAC_OCTETS_DES	8
286*0Sstevel@tonic-gate #define	MAC_OCTETS_MD5	16
287*0Sstevel@tonic-gate #define	MAC_OCTETS_MIN	MAC_OCTETS_DES
288*0Sstevel@tonic-gate #define	MAC_OCTETS_MAX	MAC_OCTETS_MD5
289*0Sstevel@tonic-gate #define	AUTH_OCTETS_V3	(MAC_OCTETS_MAX + sizeof (uint32_t))
290*0Sstevel@tonic-gate 
291*0Sstevel@tonic-gate struct ntpdata {
292*0Sstevel@tonic-gate 	u_char  li_vn_mode;	/* contains leap indicator, version and mode */
293*0Sstevel@tonic-gate 	u_char stratum; 	/* Stratum level */
294*0Sstevel@tonic-gate 	u_char ppoll;		/* poll value */
295*0Sstevel@tonic-gate 	int precision:8;
296*0Sstevel@tonic-gate 	struct s_fixedpt distance;
297*0Sstevel@tonic-gate 	struct s_fixedpt dispersion;
298*0Sstevel@tonic-gate 	u_long refid;
299*0Sstevel@tonic-gate 	struct l_fixedpt reftime;
300*0Sstevel@tonic-gate 	struct l_fixedpt org;
301*0Sstevel@tonic-gate 	struct l_fixedpt rec;
302*0Sstevel@tonic-gate 	struct l_fixedpt xmt;
303*0Sstevel@tonic-gate 	uint32_t keyid;
304*0Sstevel@tonic-gate 	u_char mac[MAC_OCTETS_MAX];
305*0Sstevel@tonic-gate };
306*0Sstevel@tonic-gate 
307*0Sstevel@tonic-gate #define	LEN_PKT_NOMAC	(sizeof (struct ntpdata) - AUTH_OCTETS_V3)
308*0Sstevel@tonic-gate 
309*0Sstevel@tonic-gate /*
310*0Sstevel@tonic-gate  *	Leap Second Codes (high order two bits)
311*0Sstevel@tonic-gate  */
312*0Sstevel@tonic-gate #define	NO_WARNING	0x00	/* no warning */
313*0Sstevel@tonic-gate #define	PLUS_SEC	0x40	/* add a second (61 seconds) */
314*0Sstevel@tonic-gate #define	MINUS_SEC	0x80	/* minus a second (59 seconds) */
315*0Sstevel@tonic-gate #define	ALARM		0xc0	/* alarm condition (clock unsynchronized) */
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate /*
318*0Sstevel@tonic-gate  *	Clock Status Bits that Encode Version
319*0Sstevel@tonic-gate  */
320*0Sstevel@tonic-gate #define	NTPVERSION_1	0x08
321*0Sstevel@tonic-gate #define	VERSIONMASK	0x38
322*0Sstevel@tonic-gate #define	LEAPMASK	0xc0
323*0Sstevel@tonic-gate #define	NTPMODEMASK	0x07
324*0Sstevel@tonic-gate 
325*0Sstevel@tonic-gate /*
326*0Sstevel@tonic-gate  *	Code values
327*0Sstevel@tonic-gate  */
328*0Sstevel@tonic-gate #define	MODE_UNSPEC	0	/* unspecified */
329*0Sstevel@tonic-gate #define	MODE_SYM_ACT	1	/* symmetric active */
330*0Sstevel@tonic-gate #define	MODE_SYM_PAS	2	/* symmetric passive */
331*0Sstevel@tonic-gate #define	MODE_CLIENT	3	/* client */
332*0Sstevel@tonic-gate #define	MODE_SERVER	4	/* server */
333*0Sstevel@tonic-gate #define	MODE_BROADCAST	5	/* broadcast */
334*0Sstevel@tonic-gate #define	MODE_CONTROL	6	/* control */
335*0Sstevel@tonic-gate #define	MODE_PRIVATE	7	/* private */
336*0Sstevel@tonic-gate 
337*0Sstevel@tonic-gate /*
338*0Sstevel@tonic-gate  *	Stratum Definitions
339*0Sstevel@tonic-gate  */
340*0Sstevel@tonic-gate #define	UNSPECIFIED	0
341*0Sstevel@tonic-gate #define	PRIM_REF	1	/* radio clock */
342*0Sstevel@tonic-gate #define	INFO_QUERY	62	/* **** THIS implementation dependent **** */
343*0Sstevel@tonic-gate #define	INFO_REPLY	63	/* **** THIS implementation dependent **** */
344*0Sstevel@tonic-gate 
345*0Sstevel@tonic-gate 
346*0Sstevel@tonic-gate /* =================  table 3.2 Peer Variables	================= */
347*0Sstevel@tonic-gate struct ntp_peer {
348*0Sstevel@tonic-gate 	struct ntp_peer *next, *prev;
349*0Sstevel@tonic-gate 	struct sockaddr_in src;		/* both peer.srcadr and peer.srcport */
350*0Sstevel@tonic-gate 	int	flags;			/* local flags */
351*0Sstevel@tonic-gate #define	PEER_FL_CONFIG		1
352*0Sstevel@tonic-gate #define	PEER_FL_AUTHENABLE	2
353*0Sstevel@tonic-gate #define	PEER_FL_SYNC		0x1000	/* peer can bet sync'd to */
354*0Sstevel@tonic-gate #define	PEER_FL_BCAST		0x2000	/* broadcast peer */
355*0Sstevel@tonic-gate #define	PEER_FL_SELECTED	0x8000	/* actually used by query routine */
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate 	int	sock;			/* index into sockets to derive */
358*0Sstevel@tonic-gate 					/*   peer.dstadr and peer.dstport */
359*0Sstevel@tonic-gate 	u_char	leap;			/* receive */
360*0Sstevel@tonic-gate 	u_char	hmode;			/* receive */
361*0Sstevel@tonic-gate 	u_char	stratum;		/* receive */
362*0Sstevel@tonic-gate 	u_char	ppoll;			/* receive */
363*0Sstevel@tonic-gate 	u_char	hpoll;			/* poll update */
364*0Sstevel@tonic-gate 	short	precision;		/* receive */
365*0Sstevel@tonic-gate 	struct	s_fixedpt distance;	/* receive */
366*0Sstevel@tonic-gate 	struct	s_fixedpt dispersion;	/* receive */
367*0Sstevel@tonic-gate 	u_long	refid;			/* receive */
368*0Sstevel@tonic-gate 	struct	l_fixedpt reftime;	/* receive */
369*0Sstevel@tonic-gate 	struct	l_fixedpt org;		/* receive, clear */
370*0Sstevel@tonic-gate 	struct	l_fixedpt rec;		/* receive, clear */
371*0Sstevel@tonic-gate 	struct	l_fixedpt xmt;		/* transmit, clear */
372*0Sstevel@tonic-gate 	u_long	reach;			/* receive, transmit, clear */
373*0Sstevel@tonic-gate 	u_long	valid;			/* packet, transmit, clear */
374*0Sstevel@tonic-gate 	u_long	timer;			/* receive, transmit, poll update */
375*0Sstevel@tonic-gate 	long	stopwatch;		/* <<local>> for timing */
376*0Sstevel@tonic-gate 	/*
377*0Sstevel@tonic-gate 	 * first order offsets
378*0Sstevel@tonic-gate 	 */
379*0Sstevel@tonic-gate 	struct	filter {
380*0Sstevel@tonic-gate 		short samples;		/* <<local>> */
381*0Sstevel@tonic-gate 		double offset[PEER_SHIFT];
382*0Sstevel@tonic-gate 		double delay[PEER_SHIFT];
383*0Sstevel@tonic-gate 	} filter;			/* filter, clear */
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate 	double	estdelay;		/* filter */
386*0Sstevel@tonic-gate 	double	estoffset;		/* filter */
387*0Sstevel@tonic-gate 	double	estdisp;		/* filter */
388*0Sstevel@tonic-gate 
389*0Sstevel@tonic-gate 	u_long	pkt_sent;		/* <<local>> */
390*0Sstevel@tonic-gate 	u_long 	pkt_rcvd;		/* <<local>> */
391*0Sstevel@tonic-gate 	u_long	pkt_dropped;		/* <<local>> */
392*0Sstevel@tonic-gate };
393*0Sstevel@tonic-gate 
394*0Sstevel@tonic-gate /* ================= table 3.1:  System Variables ================= */
395*0Sstevel@tonic-gate 
396*0Sstevel@tonic-gate struct sysdata {			/* procedure */
397*0Sstevel@tonic-gate 	u_char leap;			/* clock update */
398*0Sstevel@tonic-gate 	u_char stratum;			/* clock update */
399*0Sstevel@tonic-gate 	short precision;		/* system */
400*0Sstevel@tonic-gate 	struct s_fixedpt distance;	/* clock update */
401*0Sstevel@tonic-gate 	struct s_fixedpt dispersion;	/* clock update */
402*0Sstevel@tonic-gate 	u_long refid;			/* clock update */
403*0Sstevel@tonic-gate 	struct l_fixedpt reftime;	/* clock update */
404*0Sstevel@tonic-gate 	int hold;			/* clock update */
405*0Sstevel@tonic-gate 	struct ntp_peer *peer;		/* selection */
406*0Sstevel@tonic-gate 	int maxpeers;			/* <<local>> */
407*0Sstevel@tonic-gate 	u_char filler;		/* put here for %&*%$$ SUNs */
408*0Sstevel@tonic-gate };
409*0Sstevel@tonic-gate 
410*0Sstevel@tonic-gate #define	NTPDC_VERSION	2
411*0Sstevel@tonic-gate 
412*0Sstevel@tonic-gate /*
413*0Sstevel@tonic-gate  *  These structures are used to pass information to the ntpdc (control)
414*0Sstevel@tonic-gate  *  program.  They are unique to this implementation and not part of the
415*0Sstevel@tonic-gate  *  NTP specification.
416*0Sstevel@tonic-gate  */
417*0Sstevel@tonic-gate struct clockinfo {
418*0Sstevel@tonic-gate 	u_long net_address;
419*0Sstevel@tonic-gate 	u_long my_address;
420*0Sstevel@tonic-gate 	u_short port;
421*0Sstevel@tonic-gate 	u_short flags;
422*0Sstevel@tonic-gate 	u_long pkt_sent;
423*0Sstevel@tonic-gate 	u_long pkt_rcvd;
424*0Sstevel@tonic-gate 	u_long pkt_dropped;
425*0Sstevel@tonic-gate 	u_long timer;
426*0Sstevel@tonic-gate 	u_char leap;
427*0Sstevel@tonic-gate 	u_char stratum;
428*0Sstevel@tonic-gate 	u_char ppoll;
429*0Sstevel@tonic-gate 	int precision:8;
430*0Sstevel@tonic-gate 
431*0Sstevel@tonic-gate 	u_char hpoll;
432*0Sstevel@tonic-gate 	u_char filler1;
433*0Sstevel@tonic-gate 	u_short reach;
434*0Sstevel@tonic-gate 
435*0Sstevel@tonic-gate 	long	estdisp;			/* scaled by 1000 */
436*0Sstevel@tonic-gate 	long	estdelay;			/* in milliseconds */
437*0Sstevel@tonic-gate 	long	estoffset;			/* in milliseconds */
438*0Sstevel@tonic-gate 	u_long refid;
439*0Sstevel@tonic-gate 	struct l_fixedpt reftime;
440*0Sstevel@tonic-gate 	struct info_filter {
441*0Sstevel@tonic-gate 		short index;
442*0Sstevel@tonic-gate 		short filler;
443*0Sstevel@tonic-gate 		long offset[PEER_SHIFT];	/* in milliseconds */
444*0Sstevel@tonic-gate 		long delay[PEER_SHIFT];		/* in milliseconds */
445*0Sstevel@tonic-gate 	} info_filter;
446*0Sstevel@tonic-gate };
447*0Sstevel@tonic-gate 
448*0Sstevel@tonic-gate struct ntpinfo {
449*0Sstevel@tonic-gate 	u_char version;
450*0Sstevel@tonic-gate 	u_char type;		/* request type (stratum in ntp packets) */
451*0Sstevel@tonic-gate 	u_char count;		/* number of entries in this packet */
452*0Sstevel@tonic-gate 	u_char seq;		/* sequence number of this packet */
453*0Sstevel@tonic-gate 
454*0Sstevel@tonic-gate 	u_char npkts;		/* total number of packets */
455*0Sstevel@tonic-gate 	u_char peers;
456*0Sstevel@tonic-gate 	u_char fill3;
457*0Sstevel@tonic-gate 	u_char fill4;
458*0Sstevel@tonic-gate };
459*0Sstevel@tonic-gate 
460*0Sstevel@tonic-gate /*
461*0Sstevel@tonic-gate  * From usr/src/cmd/xntpd/include/ntp_control.h:
462*0Sstevel@tonic-gate  * Definition of a mode 6 packet.
463*0Sstevel@tonic-gate  */
464*0Sstevel@tonic-gate struct ntp_control {
465*0Sstevel@tonic-gate 	u_char li_vn_mode;		/* leap, version, mode */
466*0Sstevel@tonic-gate 	u_char r_m_e_op;		/* response, more, error, opcode */
467*0Sstevel@tonic-gate 	u_short sequence;		/* sequence number of request */
468*0Sstevel@tonic-gate 	u_short status;			/* status word for association */
469*0Sstevel@tonic-gate 	u_short associd;		/* association ID */
470*0Sstevel@tonic-gate 	u_short offset;			/* offset of this batch of data */
471*0Sstevel@tonic-gate 	u_short count;			/* count of data in this packet */
472*0Sstevel@tonic-gate 	u_char data[1];			/* data + auth */
473*0Sstevel@tonic-gate };
474*0Sstevel@tonic-gate 
475*0Sstevel@tonic-gate #define	NTPC_DATA_MAXLEN	(480 + AUTH_OCTETS_V3)
476*0Sstevel@tonic-gate 
477*0Sstevel@tonic-gate /*
478*0Sstevel@tonic-gate  * Decoding for the r_m_e_op field
479*0Sstevel@tonic-gate  */
480*0Sstevel@tonic-gate #define	CTL_RESPONSE	0x80
481*0Sstevel@tonic-gate #define	CTL_ERROR	0x40
482*0Sstevel@tonic-gate #define	CTL_MORE	0x20
483*0Sstevel@tonic-gate #define	CTL_OP_MASK	0x1f
484*0Sstevel@tonic-gate 
485*0Sstevel@tonic-gate /*
486*0Sstevel@tonic-gate  * Opcodes
487*0Sstevel@tonic-gate  */
488*0Sstevel@tonic-gate #define	CTL_OP_UNSPEC		0
489*0Sstevel@tonic-gate #define	CTL_OP_READSTAT		1
490*0Sstevel@tonic-gate #define	CTL_OP_READVAR		2
491*0Sstevel@tonic-gate #define	CTL_OP_WRITEVAR		3
492*0Sstevel@tonic-gate #define	CTL_OP_READCLOCK	4
493*0Sstevel@tonic-gate #define	CTL_OP_WRITECLOCK	5
494*0Sstevel@tonic-gate #define	CTL_OP_SETTRAP		6
495*0Sstevel@tonic-gate #define	CTL_OP_ASYNCMSG		7
496*0Sstevel@tonic-gate #define	CTL_OP_UNSETTRAP	31
497*0Sstevel@tonic-gate 
498*0Sstevel@tonic-gate /*
499*0Sstevel@tonic-gate  * From usr/src/cmd/xntpd/include/ntp_request.h:
500*0Sstevel@tonic-gate  * A mode 7 packet is used exchanging data between an NTP server
501*0Sstevel@tonic-gate  * and a client for purposes other than time synchronization, e.g.
502*0Sstevel@tonic-gate  * monitoring, statistics gathering and configuration.  A mode 7
503*0Sstevel@tonic-gate  * packet has the following format:
504*0Sstevel@tonic-gate  */
505*0Sstevel@tonic-gate 
506*0Sstevel@tonic-gate struct ntp_private {
507*0Sstevel@tonic-gate 	u_char rm_vn_mode;		/* response, more, version, mode */
508*0Sstevel@tonic-gate 	u_char auth_seq;		/* key, sequence number */
509*0Sstevel@tonic-gate 	u_char implementation;		/* implementation number */
510*0Sstevel@tonic-gate 	u_char request;			/* request number */
511*0Sstevel@tonic-gate 	u_short err_nitems;		/* error code/number of data items */
512*0Sstevel@tonic-gate 	u_short mbz_itemsize;		/* item size */
513*0Sstevel@tonic-gate 	char data[1];			/* data area */
514*0Sstevel@tonic-gate };
515*0Sstevel@tonic-gate 
516*0Sstevel@tonic-gate #define	RESP_BIT		0x80
517*0Sstevel@tonic-gate #define	MORE_BIT		0x40
518*0Sstevel@tonic-gate #define	INFO_VERSION(rm_vn_mode) ((u_char)(((rm_vn_mode)>>3) & 0x7))
519*0Sstevel@tonic-gate #define	INFO_MODE(rm_vn_mode)	((rm_vn_mode) & 0x7)
520*0Sstevel@tonic-gate 
521*0Sstevel@tonic-gate #define	AUTH_BIT		0x80
522*0Sstevel@tonic-gate #define	INFO_SEQ(auth_seq)	((auth_seq) & 0x7f)
523*0Sstevel@tonic-gate 
524*0Sstevel@tonic-gate #define	INFO_ERR(err_nitems)	((u_short)((ntohs(err_nitems) >> 12) & 0xf))
525*0Sstevel@tonic-gate #define	INFO_NITEMS(err_nitems)	((u_short)(ntohs(err_nitems) & 0xfff))
526*0Sstevel@tonic-gate 
527*0Sstevel@tonic-gate #define	INFO_ITEMSIZE(mbz_itemsize) (ntohs(mbz_itemsize) & 0xfff)
528*0Sstevel@tonic-gate 
529*0Sstevel@tonic-gate #ifdef __cplusplus
530*0Sstevel@tonic-gate }
531*0Sstevel@tonic-gate #endif
532*0Sstevel@tonic-gate 
533*0Sstevel@tonic-gate #endif	/* _NTP_H */
534