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