xref: /netbsd-src/external/bsd/ntp/dist/include/ntp_request.h (revision a536ee5124e62c9a0051a252f7833dc8f50f44c9)
1 /*	$NetBSD: ntp_request.h,v 1.3 2012/02/01 07:46:21 kardel Exp $	*/
2 
3 /*
4  * ntp_request.h - definitions for the ntpd remote query facility
5  */
6 
7 #ifndef NTP_REQUEST_H
8 #define NTP_REQUEST_H
9 
10 #include "stddef.h"
11 #include "ntp_types.h"
12 #include "recvbuff.h"
13 
14 /*
15  * A mode 7 packet is used exchanging data between an NTP server
16  * and a client for purposes other than time synchronization, e.g.
17  * monitoring, statistics gathering and configuration.  A mode 7
18  * packet has the following format:
19  *
20  *    0			  1		      2			  3
21  *    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
22  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
23  *   |R|M| VN  | Mode|A|  Sequence   | Implementation|   Req Code    |
24  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
25  *   |  Err  | Number of data items  |  MBZ  |   Size of data item   |
26  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27  *   |								     |
28  *   |            Data (Minimum 0 octets, maximum 500 octets)        |
29  *   |								     |
30  *                            [...]
31  *   |								     |
32  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33  *   |               Encryption Keyid (when A bit set)               |
34  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35  *   |								     |
36  *   |          Message Authentication Code (when A bit set)         |
37  *   |								     |
38  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39  *
40  * where the fields are (note that the client sends requests, the server
41  * responses):
42  *
43  * Response Bit:  This packet is a response (if clear, packet is a request).
44  *
45  * More Bit:	Set for all packets but the last in a response which
46  *		requires more than one packet.
47  *
48  * Version Number: 2 for current version
49  *
50  * Mode:	Always 7
51  *
52  * Authenticated bit: If set, this packet is authenticated.
53  *
54  * Sequence number: For a multipacket response, contains the sequence
55  *		number of this packet.  0 is the first in the sequence,
56  *		127 (or less) is the last.  The More Bit must be set in
57  *		all packets but the last.
58  *
59  * Implementation number: The number of the implementation this request code
60  *		is defined by.  An implementation number of zero is used
61  *		for requst codes/data formats which all implementations
62  *		agree on.  Implementation number 255 is reserved (for
63  *		extensions, in case we run out).
64  *
65  * Request code: An implementation-specific code which specifies the
66  *		operation to be (which has been) performed and/or the
67  *		format and semantics of the data included in the packet.
68  *
69  * Err:		Must be 0 for a request.  For a response, holds an error
70  *		code relating to the request.  If nonzero, the operation
71  *		requested wasn't performed.
72  *
73  *		0 - no error
74  *		1 - incompatable implementation number
75  *		2 - unimplemented request code
76  *		3 - format error (wrong data items, data size, packet size etc.)
77  *		4 - no data available (e.g. request for details on unknown peer)
78  *		5-6 I don't know
79  *		7 - authentication failure (i.e. permission denied)
80  *
81  * Number of data items: number of data items in packet.  0 to 500
82  *
83  * MBZ:		A reserved data field, must be zero in requests and responses.
84  *
85  * Size of data item: size of each data item in packet.  0 to 500
86  *
87  * Data:	Variable sized area containing request/response data.  For
88  *		requests and responses the size in octets must be greater
89  *		than or equal to the product of the number of data items
90  *		and the size of a data item.  For requests the data area
91  *		must be exactly 40 octets in length.  For responses the
92  *		data area may be any length between 0 and 500 octets
93  *		inclusive.
94  *
95  * Message Authentication Code: Same as NTP spec, in definition and function.
96  *		May optionally be included in requests which require
97  *		authentication, is never included in responses.
98  *
99  * The version number, mode and keyid have the same function and are
100  * in the same location as a standard NTP packet.  The request packet
101  * is the same size as a standard NTP packet to ease receive buffer
102  * management, and to allow the same encryption procedure to be used
103  * both on mode 7 and standard NTP packets.  The mac is included when
104  * it is required that a request be authenticated, the keyid should be
105  * zero in requests in which the mac is not included.
106  *
107  * The data format depends on the implementation number/request code pair
108  * and whether the packet is a request or a response.  The only requirement
109  * is that data items start in the octet immediately following the size
110  * word and that data items be concatenated without padding between (i.e.
111  * if the data area is larger than data_items*size, all padding is at
112  * the end).  Padding is ignored, other than for encryption purposes.
113  * Implementations using encryption might want to include a time stamp
114  * or other data in the request packet padding.  The key used for requests
115  * is implementation defined, but key 15 is suggested as a default.
116  */
117 
118 /*
119  * union of raw addresses to save space
120  */
121 union addrun
122 {
123 	struct in6_addr addr6;
124 	struct in_addr  addr;
125 };
126 
127 /*
128  * Structure for carrying system flags.
129  */
130 struct conf_sys_flags {
131 	u_int32 flags;
132 };
133 
134 /*
135  * System flags we can set/clear
136  */
137 #define	SYS_FLAG_BCLIENT	0x01
138 #define	SYS_FLAG_PPS		0x02
139 #define SYS_FLAG_NTP		0x04
140 #define SYS_FLAG_KERNEL		0x08
141 #define SYS_FLAG_MONITOR	0x10
142 #define SYS_FLAG_FILEGEN	0x20
143 #define SYS_FLAG_AUTH		0x40
144 #define SYS_FLAG_CAL		0x80
145 
146 /*
147  * Structure used for passing indication of flags to clear
148  */
149 struct reset_flags {
150 	u_int32 flags;
151 };
152 
153 #define	RESET_FLAG_ALLPEERS	0x01
154 #define	RESET_FLAG_IO		0x02
155 #define	RESET_FLAG_SYS		0x04
156 #define	RESET_FLAG_MEM		0x08
157 #define	RESET_FLAG_TIMER	0x10
158 #define	RESET_FLAG_AUTH		0x20
159 #define	RESET_FLAG_CTL		0x40
160 
161 #define	RESET_ALLFLAGS \
162 	(RESET_FLAG_ALLPEERS|RESET_FLAG_IO|RESET_FLAG_SYS \
163 	|RESET_FLAG_MEM|RESET_FLAG_TIMER|RESET_FLAG_AUTH|RESET_FLAG_CTL)
164 
165 /*
166  * A request packet.  These are almost a fixed length.
167  */
168 struct req_pkt {
169 	u_char rm_vn_mode;		/* response, more, version, mode */
170 	u_char auth_seq;		/* key, sequence number */
171 	u_char implementation;		/* implementation number */
172 	u_char request;			/* request number */
173 	u_short err_nitems;		/* error code/number of data items */
174 	u_short mbz_itemsize;		/* item size */
175 	union {
176 	    char data[MAXFILENAME + 48];/* data area [32 prev](176 byte max) */
177 	    struct conf_sys_flags c_s_flags;
178 	    struct reset_flags r_flags;
179 	    u_int32_t ui;
180 	};
181 	l_fp tstamp;			/* time stamp, for authentication */
182 	keyid_t keyid;			/* (optional) encryption key */
183 	char mac[MAX_MAC_LEN-sizeof(keyid_t)]; /* (optional) auth code */
184 };
185 
186 /*
187  * The req_pkt_tail structure is used by ntpd to adjust for different
188  * packet sizes that may arrive.
189  */
190 struct req_pkt_tail {
191 	l_fp tstamp;			/* time stamp, for authentication */
192 	keyid_t keyid;			/* (optional) encryption key */
193 	char mac[MAX_MAC_LEN-sizeof(keyid_t)]; /* (optional) auth code */
194 };
195 
196 /* MODE_PRIVATE request packet header length before optional items. */
197 #define	REQ_LEN_HDR	(offsetof(struct req_pkt, data))
198 /* MODE_PRIVATE request packet fixed length without MAC. */
199 #define	REQ_LEN_NOMAC	(offsetof(struct req_pkt, keyid))
200 /* MODE_PRIVATE req_pkt_tail minimum size (16 octet digest) */
201 #define REQ_TAIL_MIN	\
202 	(sizeof(struct req_pkt_tail) - (MAX_MAC_LEN - MAX_MD5_LEN))
203 
204 /*
205  * A MODE_PRIVATE response packet.  The length here is variable, this
206  * is a maximally sized one.  Note that this implementation doesn't
207  * authenticate responses.
208  */
209 #define	RESP_HEADER_SIZE	(offsetof(struct resp_pkt, data))
210 #define	RESP_DATA_SIZE		(500)
211 
212 struct resp_pkt {
213 	u_char rm_vn_mode;		/* response, more, version, mode */
214 	u_char auth_seq;		/* key, sequence number */
215 	u_char implementation;		/* implementation number */
216 	u_char request;			/* request number */
217 	u_short err_nitems;		/* error code/number of data items */
218 	u_short mbz_itemsize;		/* item size */
219 	char data[RESP_DATA_SIZE];	/* data area */
220 };
221 
222 
223 /*
224  * Information error codes
225  */
226 #define	INFO_OKAY	0
227 #define	INFO_ERR_IMPL	1	/* incompatable implementation */
228 #define	INFO_ERR_REQ	2	/* unknown request code */
229 #define	INFO_ERR_FMT	3	/* format error */
230 #define	INFO_ERR_NODATA	4	/* no data for this request */
231 #define	INFO_ERR_AUTH	7	/* authentication failure */
232 
233 /*
234  * Maximum sequence number.
235  */
236 #define	MAXSEQ	127
237 
238 
239 /*
240  * Bit setting macros for multifield items.
241  */
242 #define	RESP_BIT	0x80
243 #define	MORE_BIT	0x40
244 
245 #define	ISRESPONSE(rm_vn_mode)	(((rm_vn_mode)&RESP_BIT)!=0)
246 #define	ISMORE(rm_vn_mode)	(((rm_vn_mode)&MORE_BIT)!=0)
247 #define INFO_VERSION(rm_vn_mode) ((u_char)(((rm_vn_mode)>>3)&0x7))
248 #define	INFO_MODE(rm_vn_mode)	((rm_vn_mode)&0x7)
249 
250 #define	RM_VN_MODE(resp, more, version)		\
251 				((u_char)(((resp)?RESP_BIT:0)\
252 				|((more)?MORE_BIT:0)\
253 				|((version?version:(NTP_OLDVERSION+1))<<3)\
254 				|(MODE_PRIVATE)))
255 
256 #define	INFO_IS_AUTH(auth_seq)	(((auth_seq) & 0x80) != 0)
257 #define	INFO_SEQ(auth_seq)	((auth_seq)&0x7f)
258 #define	AUTH_SEQ(auth, seq)	((u_char)((((auth)!=0)?0x80:0)|((seq)&0x7f)))
259 
260 #define	INFO_ERR(err_nitems)	((u_short)((ntohs(err_nitems)>>12)&0xf))
261 #define	INFO_NITEMS(err_nitems)	((u_short)(ntohs(err_nitems)&0xfff))
262 #define _ERR_EN(err)		((u_short)(((err)&0xf)<<12))
263 #define	ERR_NITEMS(err, nitems)	((u_short)htons(_ERR_EN(err)|(nitems&0xfff)))
264 
265 #define	INFO_MBZ(mbz_itemsize)	((ntohs(mbz_itemsize)>>12)&0xf)
266 #define	INFO_ITEMSIZE(mbz_itemsize)	((u_short)(ntohs(mbz_itemsize)&0xfff))
267 #define	MBZ_ITEMSIZE(itemsize)	(htons((u_short)(itemsize)))
268 
269 
270 /*
271  * Implementation numbers.  One for universal use and one for ntpd.
272  */
273 #define	IMPL_UNIV	0
274 #define	IMPL_XNTPD_OLD	2	/* Used by pre ipv6 ntpdc */
275 #define	IMPL_XNTPD	3	/* Used by post ipv6 ntpdc */
276 
277 /*
278  * Some limits related to authentication.  Frames which are
279  * authenticated must include a time stamp which differs from
280  * the receive time stamp by no more than 10 seconds.
281  */
282 #define	INFO_TS_MAXSKEW	10.
283 
284 /*
285  * Universal request codes go here.  There aren't any.
286  */
287 
288 /*
289  * NTPD request codes go here.
290  */
291 #define	REQ_PEER_LIST		0	/* return list of peers */
292 #define	REQ_PEER_LIST_SUM	1	/* return summary info for all peers */
293 #define	REQ_PEER_INFO		2	/* get standard information on peer */
294 #define	REQ_PEER_STATS		3	/* get statistics for peer */
295 #define	REQ_SYS_INFO		4	/* get system information */
296 #define	REQ_SYS_STATS		5	/* get system stats */
297 #define	REQ_IO_STATS		6	/* get I/O stats */
298 #define REQ_MEM_STATS		7	/* stats related to peer list maint */
299 #define	REQ_LOOP_INFO		8	/* info from the loop filter */
300 #define	REQ_TIMER_STATS		9	/* get timer stats */
301 #define	REQ_CONFIG		10	/* configure a new peer */
302 #define	REQ_UNCONFIG		11	/* unconfigure an existing peer */
303 #define	REQ_SET_SYS_FLAG	12	/* set system flags */
304 #define	REQ_CLR_SYS_FLAG	13	/* clear system flags */
305 #define	REQ_MONITOR		14	/* (not used) */
306 #define	REQ_NOMONITOR		15	/* (not used) */
307 #define	REQ_GET_RESTRICT	16	/* return restrict list */
308 #define	REQ_RESADDFLAGS		17	/* add flags to restrict list */
309 #define	REQ_RESSUBFLAGS		18	/* remove flags from restrict list */
310 #define	REQ_UNRESTRICT		19	/* remove entry from restrict list */
311 #define	REQ_MON_GETLIST		20	/* return data collected by monitor */
312 #define	REQ_RESET_STATS		21	/* reset stat counters */
313 #define	REQ_RESET_PEER		22	/* reset peer stat counters */
314 #define	REQ_REREAD_KEYS		23	/* reread the encryption key file */
315 #define	REQ_DO_DIRTY_HACK	24	/* (not used) */
316 #define	REQ_DONT_DIRTY_HACK	25	/* (not used) */
317 #define	REQ_TRUSTKEY		26	/* add a trusted key */
318 #define	REQ_UNTRUSTKEY		27	/* remove a trusted key */
319 #define	REQ_AUTHINFO		28	/* return authentication info */
320 #define REQ_TRAPS		29	/* return currently set traps */
321 #define	REQ_ADD_TRAP		30	/* add a trap */
322 #define	REQ_CLR_TRAP		31	/* clear a trap */
323 #define	REQ_REQUEST_KEY		32	/* define a new request keyid */
324 #define	REQ_CONTROL_KEY		33	/* define a new control keyid */
325 #define	REQ_GET_CTLSTATS	34	/* get stats from the control module */
326 #define	REQ_GET_LEAPINFO	35	/* (not used) */
327 #define	REQ_GET_CLOCKINFO	36	/* get clock information */
328 #define	REQ_SET_CLKFUDGE	37	/* set clock fudge factors */
329 #define REQ_GET_KERNEL		38	/* get kernel pll/pps information */
330 #define	REQ_GET_CLKBUGINFO	39	/* get clock debugging info */
331 #define	REQ_SET_PRECISION	41	/* (not used) */
332 #define	REQ_MON_GETLIST_1	42	/* return collected v1 monitor data */
333 #define	REQ_HOSTNAME_ASSOCID	43	/* Here is a hostname + assoc_id */
334 #define REQ_IF_STATS		44	/* get interface statistics */
335 #define REQ_IF_RELOAD		45	/* reload interface list */
336 
337 /* Determine size of pre-v6 version of structures */
338 #define v4sizeof(type)		offsetof(type, v6_flag)
339 
340 /*
341  * Flags in the peer information returns
342  */
343 #define	INFO_FLAG_CONFIG	0x1
344 #define	INFO_FLAG_SYSPEER	0x2
345 #define INFO_FLAG_BURST		0x4
346 #define	INFO_FLAG_REFCLOCK	0x8
347 #define	INFO_FLAG_PREFER	0x10
348 #define	INFO_FLAG_AUTHENABLE	0x20
349 #define	INFO_FLAG_SEL_CANDIDATE	0x40
350 #define	INFO_FLAG_SHORTLIST	0x80
351 #define	INFO_FLAG_IBURST	0x100
352 
353 /*
354  * Flags in the system information returns
355  */
356 #define INFO_FLAG_BCLIENT	0x1
357 #define INFO_FLAG_AUTHENTICATE	0x2
358 #define INFO_FLAG_NTP		0x4
359 #define INFO_FLAG_KERNEL	0x8
360 #define INFO_FLAG_MONITOR	0x40
361 #define INFO_FLAG_FILEGEN	0x80
362 #define INFO_FLAG_CAL		0x10
363 #define INFO_FLAG_PPS_SYNC	0x20
364 
365 /*
366  * Peer list structure.  Used to return raw lists of peers.  It goes
367  * without saying that everything returned is in network byte order.
368  * Well, it *would* have gone without saying, but somebody said it.
369  */
370 struct info_peer_list {
371 	u_int32 addr;		/* address of peer */
372 	u_short port;		/* port number of peer */
373 	u_char hmode;		/* mode for this peer */
374 	u_char flags;		/* flags (from above) */
375 	u_int v6_flag;		/* is this v6 or not */
376 	u_int unused1;		/* (unused) padding for addr6 */
377 	struct in6_addr addr6;	/* v6 address of peer */
378 };
379 
380 
381 /*
382  * Peer summary structure.  Sort of the info that ntpdc returns by default.
383  */
384 struct info_peer_summary {
385 	u_int32 dstadr;		/* local address (zero for undetermined) */
386 	u_int32 srcadr;		/* source address */
387 	u_short srcport;	/* source port */
388 	u_char stratum;		/* stratum of peer */
389 	s_char hpoll;		/* host polling interval */
390 	s_char ppoll;		/* peer polling interval */
391 	u_char reach;		/* reachability register */
392 	u_char flags;		/* flags, from above */
393 	u_char hmode;		/* peer mode */
394 	s_fp delay;		/* peer.estdelay */
395 	l_fp offset;		/* peer.estoffset */
396 	u_fp dispersion;	/* peer.estdisp */
397 	u_int v6_flag;			/* is this v6 or not */
398 	u_int unused1;			/* (unused) padding for dstadr6 */
399 	struct in6_addr dstadr6;	/* local address (v6) */
400 	struct in6_addr srcadr6;	/* source address (v6) */
401 };
402 
403 
404 /*
405  * Peer information structure.
406  */
407 struct info_peer {
408 	u_int32 dstadr;		/* local address */
409 	u_int32	srcadr;		/* source address */
410 	u_short srcport;	/* remote port */
411 	u_char flags;		/* peer flags */
412 	u_char leap;		/* peer.leap */
413 	u_char hmode;		/* peer.hmode */
414 	u_char pmode;		/* peer.pmode */
415 	u_char stratum;		/* peer.stratum */
416 	u_char ppoll;		/* peer.ppoll */
417 	u_char hpoll;		/* peer.hpoll */
418 	s_char precision;	/* peer.precision */
419 	u_char version;		/* peer.version */
420 	u_char unused8;
421 	u_char reach;		/* peer.reach */
422 	u_char unreach;		/* peer.unreach */
423 	u_char flash;		/* old peer.flash */
424 	u_char ttl;		/* peer.ttl */
425 	u_short flash2;		/* new peer.flash */
426 	associd_t associd;	/* association ID */
427 	keyid_t keyid;		/* peer.keyid */
428 	u_int32 pkeyid;		/* unused */
429 	u_int32 refid;		/* peer.refid */
430 	u_int32 timer;		/* peer.timer */
431 	s_fp rootdelay;		/* peer.delay */
432 	u_fp rootdispersion;	/* peer.dispersion */
433 	l_fp reftime;		/* peer.reftime */
434 	l_fp org;		/* peer.org */
435 	l_fp rec;		/* peer.rec */
436 	l_fp xmt;		/* peer.xmt */
437 	s_fp filtdelay[NTP_SHIFT];	/* delay shift register */
438 	l_fp filtoffset[NTP_SHIFT];	/* offset shift register */
439 	u_char order[NTP_SHIFT];	/* order of peers from last filter */
440 	s_fp delay;		/* peer.estdelay */
441 	u_fp dispersion;	/* peer.estdisp */
442 	l_fp offset;		/* peer.estoffset */
443 	u_fp selectdisp;	/* peer select dispersion */
444 	int32 unused1;		/* (obsolete) */
445 	int32 unused2;
446 	int32 unused3;
447 	int32 unused4;
448 	int32 unused5;
449 	int32 unused6;
450 	int32 unused7;
451 	s_fp estbdelay;		/* broadcast offset */
452 	u_int v6_flag;			/* is this v6 or not */
453 	u_int unused9;			/* (unused) padding for dstadr6 */
454 	struct in6_addr dstadr6; 	/* local address (v6-like) */
455 	struct in6_addr srcadr6; 	/* sources address (v6-like) */
456 };
457 
458 
459 /*
460  * Peer statistics structure
461  */
462 struct info_peer_stats {
463 	u_int32 dstadr;		/* local address */
464 	u_int32 srcadr;		/* remote address */
465 	u_short srcport;	/* remote port */
466 	u_short flags;		/* peer flags */
467 	u_int32 timereset;	/* time counters were reset */
468 	u_int32 timereceived;	/* time since a packet received */
469 	u_int32 timetosend;	/* time until a packet sent */
470 	u_int32 timereachable;	/* time peer has been reachable */
471 	u_int32 sent;		/* number sent */
472 	u_int32 unused1;	/* (unused) */
473 	u_int32 processed;	/* number processed */
474 	u_int32 unused2;	/* (unused) */
475 	u_int32 badauth;	/* bad authentication */
476 	u_int32 bogusorg;	/* bogus origin */
477 	u_int32 oldpkt;		/* duplicate */
478 	u_int32 unused3;	/* (unused) */
479 	u_int32 unused4;	/* (unused) */
480 	u_int32 seldisp;	/* bad dispersion */
481 	u_int32 selbroken;	/* bad reference time */
482 	u_int32 unused5;	/* (unused) */
483 	u_char candidate;	/* select order */
484 	u_char unused6;		/* (unused) */
485 	u_char unused7;		/* (unused) */
486 	u_char unused8;		/* (unused) */
487 	u_int v6_flag;			/* is this v6 or not */
488 	u_int unused9;			/* (unused) padding for dstadr6 */
489 	struct in6_addr dstadr6;	/* local address */
490 	struct in6_addr srcadr6;	/* remote address */
491 };
492 
493 
494 /*
495  * Loop filter variables
496  */
497 struct info_loop {
498 	l_fp last_offset;
499 	l_fp drift_comp;
500 	u_int32 compliance;
501 	u_int32 watchdog_timer;
502 };
503 
504 
505 /*
506  * System info.  Mostly the sys.* variables, plus a few unique to
507  * the implementation.
508  */
509 struct info_sys {
510 	u_int32 peer;		/* system peer address (v4) */
511 	u_char peer_mode;	/* mode we are syncing to peer in */
512 	u_char leap;		/* system leap bits */
513 	u_char stratum;		/* our stratum */
514 	s_char precision;	/* local clock precision */
515 	s_fp rootdelay;		/* delay from sync source */
516 	u_fp rootdispersion;	/* dispersion from sync source */
517 	u_int32 refid;		/* reference ID of sync source */
518 	l_fp reftime;		/* system reference time */
519 	u_int32 poll;		/* system poll interval */
520 	u_char flags;		/* system flags */
521 	u_char unused1;		/* unused */
522 	u_char unused2;		/* unused */
523 	u_char unused3;		/* unused */
524 	s_fp bdelay;		/* default broadcast offset */
525 	s_fp frequency;		/* frequency residual (scaled ppm)  */
526 	l_fp authdelay;		/* default authentication delay */
527 	u_fp stability;		/* clock stability (scaled ppm) */
528 	u_int v6_flag;		/* is this v6 or not */
529 	u_int unused4;		/* unused, padding for peer6 */
530 	struct in6_addr peer6;	/* system peer address (v6) */
531 };
532 
533 
534 /*
535  * System stats.  These are collected in the protocol module
536  */
537 struct info_sys_stats {
538 	u_int32 timeup;		/* time since restart */
539 	u_int32 timereset;	/* time since reset */
540 	u_int32 denied;		/* access denied */
541 	u_int32 oldversionpkt;	/* recent version */
542 	u_int32 newversionpkt;	/* current version */
543 	u_int32 unknownversion;	/* bad version */
544 	u_int32 badlength;	/* bad length or format */
545 	u_int32 processed;	/* packets processed */
546 	u_int32 badauth;	/* bad authentication */
547 	u_int32 received;	/* packets received */
548 	u_int32 limitrejected;	/* rate exceeded */
549 };
550 
551 
552 /*
553  * System stats - old version
554  */
555 struct old_info_sys_stats {
556 	u_int32 timeup;		/* time since restart */
557 	u_int32 timereset;	/* time since reset */
558 	u_int32 denied;		/* access denied */
559 	u_int32 oldversionpkt;	/* recent version */
560 	u_int32 newversionpkt;	/* current version */
561 	u_int32 unknownversion;	/* bad version */
562 	u_int32 badlength;	/* bad length or format */
563 	u_int32 processed;	/* packets processed */
564 	u_int32 badauth;	/* bad authentication */
565 	u_int32 wanderhold;	/* (not used) */
566 };
567 
568 
569 /*
570  * Peer memory statistics.  Collected in the peer module.
571  */
572 struct info_mem_stats {
573 	u_int32 timereset;	/* time since reset */
574 	u_short totalpeermem;
575 	u_short freepeermem;
576 	u_int32 findpeer_calls;
577 	u_int32 allocations;
578 	u_int32 demobilizations;
579 	u_char hashcount[NTP_HASH_SIZE];
580 };
581 
582 
583 /*
584  * I/O statistics.  Collected in the I/O module
585  */
586 struct info_io_stats {
587 	u_int32 timereset;	/* time since reset */
588 	u_short totalrecvbufs;	/* total receive bufs */
589 	u_short freerecvbufs;	/* free buffers */
590 	u_short fullrecvbufs;	/* full buffers */
591 	u_short lowwater;	/* number of times we've added buffers */
592 	u_int32 dropped;	/* dropped packets */
593 	u_int32 ignored;	/* ignored packets */
594 	u_int32 received;	/* received packets */
595 	u_int32 sent;		/* packets sent */
596 	u_int32 notsent;	/* packets not sent */
597 	u_int32 interrupts;	/* interrupts we've handled */
598 	u_int32 int_received;	/* received by interrupt handler */
599 };
600 
601 
602 /*
603  * Timer stats.  Guess where from.
604  */
605 struct info_timer_stats {
606 	u_int32 timereset;	/* time since reset */
607 	u_int32 alarms;		/* alarms we've handled */
608 	u_int32 overflows;	/* timer overflows */
609 	u_int32 xmtcalls;	/* calls to xmit */
610 };
611 
612 
613 /*
614  * Structure for passing peer configuration information
615  */
616 struct old_conf_peer {
617 	u_int32 peeraddr;	/* address to poll */
618 	u_char hmode;		/* mode, either broadcast, active or client */
619 	u_char version;		/* version number to poll with */
620 	u_char minpoll;		/* min host poll interval */
621 	u_char maxpoll;		/* max host poll interval */
622 	u_char flags;		/* flags for this request */
623 	u_char ttl;		/* time to live (multicast) or refclock mode */
624 	u_short unused;		/* unused */
625 	keyid_t keyid;		/* key to use for this association */
626 };
627 
628 struct conf_peer {
629 	u_int32 peeraddr;	/* address to poll */
630 	u_char hmode;		/* mode, either broadcast, active or client */
631 	u_char version;		/* version number to poll with */
632 	u_char minpoll;		/* min host poll interval */
633 	u_char maxpoll;		/* max host poll interval */
634 	u_char flags;		/* flags for this request */
635 	u_char ttl;		/* time to live (multicast) or refclock mode */
636 	u_short unused1;	/* unused */
637 	keyid_t keyid;		/* key to use for this association */
638 	char keystr[MAXFILENAME]; /* public key file name*/
639 	u_int v6_flag;		/* is this v6 or not */
640 	u_int unused2;			/* unused, padding for peeraddr6 */
641 	struct in6_addr peeraddr6;	/* ipv6 address to poll */
642 };
643 
644 #define	CONF_FLAG_AUTHENABLE	0x01
645 #define CONF_FLAG_PREFER	0x02
646 #define CONF_FLAG_BURST		0x04
647 #define CONF_FLAG_IBURST	0x08
648 #define CONF_FLAG_NOSELECT	0x10
649 #define CONF_FLAG_SKEY		0x20
650 
651 /*
652  * Structure for passing peer deletion information.  Currently
653  * we only pass the address and delete all configured peers with
654  * this addess.
655  */
656 struct conf_unpeer {
657 	u_int32 peeraddr;		/* address of peer */
658 	u_int v6_flag;			/* is this v6 or not */
659 	struct in6_addr peeraddr6;	/* address of peer (v6) */
660 };
661 
662 /*
663  * Structure used for returning restrict entries
664  */
665 struct info_restrict {
666 	u_int32 addr;		/* match address */
667 	u_int32 mask;		/* match mask */
668 	u_int32 count;		/* number of packets matched */
669 	u_short flags;		/* restrict flags */
670 	u_short mflags;		/* match flags */
671 	u_int v6_flag;		/* is this v6 or not */
672 	u_int unused1;		/* unused, padding for addr6 */
673 	struct in6_addr addr6;	/* match address (v6) */
674 	struct in6_addr mask6; 	/* match mask (v6) */
675 };
676 
677 
678 /*
679  * Structure used for specifying restrict entries
680  */
681 struct conf_restrict {
682 	u_int32	addr;		/* match address */
683 	u_int32 mask;		/* match mask */
684 	u_short flags;		/* restrict flags */
685 	u_short mflags;		/* match flags */
686 	u_int v6_flag;		/* is this v6 or not */
687 	struct in6_addr addr6; 	/* match address (v6) */
688 	struct in6_addr mask6; 	/* match mask (v6) */
689 };
690 
691 
692 /*
693  * Structure used for returning monitor data
694  */
695 struct info_monitor_1 {
696 	u_int32 lasttime;	/* last packet from this host */
697 	u_int32 firsttime;	/* first time we received a packet */
698 	u_int32 restr;		/* restrict bits (was named lastdrop) */
699 	u_int32 count;		/* count of packets received */
700 	u_int32 addr;		/* host address V4 style */
701 	u_int32 daddr;		/* destination host address */
702 	u_int32 flags;		/* flags about destination */
703 	u_short port;		/* port number of last reception */
704 	u_char mode;		/* mode of last packet */
705 	u_char version;		/* version number of last packet */
706 	u_int v6_flag;		/* is this v6 or not */
707 	u_int unused1;		/* unused, padding for addr6 */
708 	struct in6_addr addr6;	/* host address V6 style */
709 	struct in6_addr daddr6;	/* host address V6 style */
710 };
711 
712 
713 /*
714  * Structure used for returning monitor data
715  */
716 struct info_monitor {
717 	u_int32 lasttime;	/* last packet from this host */
718 	u_int32 firsttime;	/* first time we received a packet */
719 	u_int32 restr;		/* restrict bits (was named lastdrop) */
720 	u_int32 count;		/* count of packets received */
721 	u_int32 addr;		/* host address */
722 	u_short port;		/* port number of last reception */
723 	u_char mode;		/* mode of last packet */
724 	u_char version;		/* version number of last packet */
725 	u_int v6_flag;		/* is this v6 or not */
726 	u_int unused1;		/* unused, padding for addr6 */
727 	struct in6_addr addr6;	/* host v6 address */
728 };
729 
730 /*
731  * Structure used for returning monitor data (old format)
732  */
733 struct old_info_monitor {
734 	u_int32 lasttime;	/* last packet from this host */
735 	u_int32 firsttime;	/* first time we received a packet */
736 	u_int32 count;		/* count of packets received */
737 	u_int32 addr;		/* host address */
738 	u_short port;		/* port number of last reception */
739 	u_char mode;		/* mode of last packet */
740 	u_char version;		/* version number of last packet */
741 	u_int v6_flag;		/* is this v6 or not */
742 	struct in6_addr addr6;	/* host address  (v6)*/
743 };
744 
745 /*
746  * Structure used to return information concerning the authentication
747  * module.
748  */
749 struct info_auth {
750 	u_int32 timereset;	/* time counters were reset */
751 	u_int32 numkeys;	/* number of keys we know */
752 	u_int32 numfreekeys;	/* number of free keys */
753 	u_int32 keylookups;	/* calls to authhavekey() */
754 	u_int32 keynotfound;	/* requested key unknown */
755 	u_int32 encryptions;	/* number of encryptions */
756 	u_int32 decryptions;	/* number of decryptions */
757 	u_int32 expired;	/* number of expired keys */
758 	u_int32 keyuncached;	/* calls to encrypt/decrypt with uncached key */
759 };
760 
761 
762 /*
763  * Structure used to pass trap information to the client
764  */
765 struct info_trap {
766 	u_int32 local_address;	/* local interface addres (v4) */
767 	u_int32 trap_address;	/* remote client's addres (v4) */
768 	u_short trap_port;	/* remote port number */
769 	u_short sequence;	/* sequence number */
770 	u_int32 settime;	/* time trap last set */
771 	u_int32 origtime;	/* time trap originally set */
772 	u_int32 resets;		/* number of resets on this trap */
773 	u_int32 flags;		/* trap flags, as defined in ntp_control.h */
774 	u_int v6_flag;			/* is this v6 or not */
775 	struct in6_addr local_address6;	/* local interface address (v6) */
776 	struct in6_addr trap_address6;	/* remote client's address (v6) */
777 };
778 
779 /*
780  * Structure used to pass add/clear trap information to the client
781  */
782 struct conf_trap {
783 	u_int32 local_address;	/* remote client's address */
784 	u_int32 trap_address;	/* local interface address */
785 	u_short trap_port;	/* remote client's port */
786 	u_short unused;		/* (unused) */
787 	u_int v6_flag;			/* is this v6 or not */
788 	struct in6_addr local_address6;	/* local interface address (v6) */
789 	struct in6_addr trap_address6;	/* remote client's address (v6) */
790 };
791 
792 
793 /*
794  * Structure used to return statistics from the control module
795  */
796 struct info_control {
797 	u_int32 ctltimereset;
798 	u_int32 numctlreq;	/* number of requests we've received */
799 	u_int32 numctlbadpkts;	/* number of bad control packets */
800 	u_int32 numctlresponses;	/* # resp packets sent */
801 	u_int32 numctlfrags;	/* # of fragments sent */
802 	u_int32 numctlerrors;	/* number of error responses sent */
803 	u_int32 numctltooshort;	/* number of too short input packets */
804 	u_int32 numctlinputresp;	/* number of responses on input */
805 	u_int32 numctlinputfrag;	/* number of fragments on input */
806 	u_int32 numctlinputerr;	/* # input pkts with err bit set */
807 	u_int32 numctlbadoffset;	/* # input pkts with nonzero offset */
808 	u_int32 numctlbadversion;	/* # input pkts with unknown version */
809 	u_int32 numctldatatooshort;	/* data too short for count */
810 	u_int32 numctlbadop;	/* bad op code found in packet */
811 	u_int32 numasyncmsgs;		/* # async messages we've sent */
812 };
813 
814 
815 /*
816  * Structure used to return clock information
817  */
818 struct info_clock {
819 	u_int32 clockadr;
820 	u_char type;
821 	u_char flags;
822 	u_char lastevent;
823 	u_char currentstatus;
824 	u_int32 polls;
825 	u_int32 noresponse;
826 	u_int32 badformat;
827 	u_int32 baddata;
828 	u_int32 timestarted;
829 	l_fp fudgetime1;
830 	l_fp fudgetime2;
831 	int32 fudgeval1;
832 	u_int32 fudgeval2;
833 };
834 
835 
836 /*
837  * Structure used for setting clock fudge factors
838  */
839 struct conf_fudge {
840 	u_int32 clockadr;
841 	u_int32 which;
842 	l_fp fudgetime;
843 	u_int32 fudgeval_flags;
844 };
845 
846 #define	FUDGE_TIME1	1
847 #define	FUDGE_TIME2	2
848 #define	FUDGE_VAL1	3
849 #define	FUDGE_VAL2	4
850 #define	FUDGE_FLAGS	5
851 
852 
853 /*
854  * Structure used for returning clock debugging info
855  */
856 #define	NUMCBUGVALUES	16
857 #define	NUMCBUGTIMES	32
858 
859 struct info_clkbug {
860 	u_int32 clockadr;
861 	u_char nvalues;
862 	u_char ntimes;
863 	u_short svalues;
864 	u_int32 stimes;
865 	u_int32 values[NUMCBUGVALUES];
866 	l_fp times[NUMCBUGTIMES];
867 };
868 
869 /*
870  * Structure used for returning kernel pll/PPS information
871  */
872 struct info_kernel {
873 	int32 offset;
874 	int32 freq;
875 	int32 maxerror;
876 	int32 esterror;
877 	u_short status;
878 	u_short shift;
879 	int32 constant;
880 	int32 precision;
881 	int32 tolerance;
882 
883 /*
884  * Variables used only if PPS signal discipline is implemented
885  */
886 	int32 ppsfreq;
887 	int32 jitter;
888 	int32 stabil;
889 	int32 jitcnt;
890 	int32 calcnt;
891 	int32 errcnt;
892 	int32 stbcnt;
893 };
894 
895 /*
896  * interface statistics
897  */
898 struct info_if_stats {
899 	union addrun unaddr;            /* address */
900         union addrun unbcast;	        /* broadcast */
901 	union addrun unmask;	        /* mask */
902 	u_int32 v6_flag;                /* is this v6 */
903 	char name[32];			/* name of interface */
904 	int32 flags;			/* interface flags */
905 	int32 last_ttl;			/* last TTL specified */
906 	int32 num_mcast;		/* No. of IP addresses in multicast socket */
907         int32 received;	                /* number of incoming packets */
908 	int32 sent;			/* number of outgoing packets */
909 	int32 notsent;			/* number of send failures */
910 	int32 uptime;		        /* number of seconds this interface was active */
911 	u_int32 scopeid;		/* Scope used for Multicasting */
912 	u_int32 ifindex;		/* interface index - from system */
913 	u_int32 ifnum;		        /* sequential interface number */
914         u_int32 peercnt;		/* number of peers referencinf this interface - informational only */
915 	u_short family;			/* Address family */
916 	u_char ignore_packets;	        /* Specify whether the packet should be ignored */
917         u_char action;		        /* reason the item is listed */
918 	int32 _filler0;		        /* pad to a 64 bit size boundary */
919 };
920 
921 #define IFS_EXISTS	1	/* just exists */
922 #define IFS_CREATED	2	/* was just created */
923 #define IFS_DELETED	3	/* was just delete */
924 
925 /*
926  * Info returned with IP -> hostname lookup
927  */
928 /* 144 might need to become 32, matching data[] member of req_pkt */
929 #define NTP_MAXHOSTNAME (32 - sizeof(u_int32) - sizeof(u_short))
930 struct info_dns_assoc {
931 	u_int32 peeraddr;	/* peer address (HMS: being careful...) */
932 	associd_t associd;	/* association ID */
933 	char hostname[NTP_MAXHOSTNAME];	/* hostname */
934 };
935 
936 /*
937  * function declarations
938  */
939 int get_packet_mode(struct recvbuf *rbufp); /* Return packet mode */
940 
941 #endif /* NTP_REQUEST_H */
942