ntp_control.h revision 290001
1/*
2 * ntp_control.h - definitions related to NTP mode 6 control messages
3 */
4
5#include "ntp_types.h"
6
7typedef union ctl_pkt_u_tag {
8	u_char data[480 + MAX_MAC_LEN]; /* data + auth */
9	u_int32 u32[(480 + MAX_MAC_LEN) / sizeof(u_int32)];
10} ctl_pkt_u;
11
12struct ntp_control {
13	u_char li_vn_mode;		/* leap, version, mode */
14	u_char r_m_e_op;		/* response, more, error, opcode */
15	u_short sequence;		/* sequence number of request */
16	u_short status;			/* status word for association */
17	associd_t associd;		/* association ID */
18	u_short offset;			/* offset of this batch of data */
19	u_short count;			/* count of data in this packet */
20	ctl_pkt_u u;
21};
22
23/*
24 * Length of the control header, in octets
25 */
26#define	CTL_HEADER_LEN		(offsetof(struct ntp_control, u))
27#define	CTL_MAX_DATA_LEN	468
28
29
30/*
31 * Limits and things
32 */
33#define	CTL_MAXTRAPS	3		/* maximum number of traps we allow */
34#define	CTL_TRAPTIME	(60*60)		/* time out traps in 1 hour */
35#define	CTL_MAXAUTHSIZE	64		/* maximum size of an authen'ed req */
36
37/*
38 * Decoding for the r_m_e_op field
39 */
40#define	CTL_RESPONSE	0x80
41#define	CTL_ERROR	0x40
42#define	CTL_MORE	0x20
43#define	CTL_OP_MASK	0x1f
44
45#define	CTL_ISRESPONSE(r_m_e_op) ((CTL_RESPONSE	& (r_m_e_op)) != 0)
46#define	CTL_ISMORE(r_m_e_op)	 ((CTL_MORE	& (r_m_e_op)) != 0)
47#define	CTL_ISERROR(r_m_e_op)	 ((CTL_ERROR	& (r_m_e_op)) != 0)
48#define	CTL_OP(r_m_e_op)	 (CTL_OP_MASK	& (r_m_e_op))
49
50/*
51 * Opcodes
52 */
53#define	CTL_OP_UNSPEC		0	/* unspeciffied */
54#define	CTL_OP_READSTAT		1	/* read status */
55#define	CTL_OP_READVAR		2	/* read variables */
56#define	CTL_OP_WRITEVAR		3	/* write variables */
57#define	CTL_OP_READCLOCK	4	/* read clock variables */
58#define	CTL_OP_WRITECLOCK	5	/* write clock variables */
59#define	CTL_OP_SETTRAP		6	/* set trap address */
60#define	CTL_OP_ASYNCMSG		7	/* asynchronous message */
61#define CTL_OP_CONFIGURE	8	/* runtime configuration */
62#define CTL_OP_SAVECONFIG	9	/* save config to file */
63#define CTL_OP_READ_MRU		10	/* retrieve MRU (mrulist) */
64#define CTL_OP_READ_ORDLIST_A	11	/* ordered list req. auth. */
65#define CTL_OP_REQ_NONCE	12	/* request a client nonce */
66#define	CTL_OP_UNSETTRAP	31	/* unset trap */
67
68/*
69 * {En,De}coding of the system status word
70 */
71#define	CTL_SST_TS_UNSPEC	0	/* unspec */
72#define	CTL_SST_TS_ATOM		1	/* pps */
73#define	CTL_SST_TS_LF		2	/* lf radio */
74#define	CTL_SST_TS_HF		3	/* hf radio */
75#define	CTL_SST_TS_UHF		4	/* uhf radio */
76#define	CTL_SST_TS_LOCAL	5	/* local */
77#define	CTL_SST_TS_NTP		6	/* ntp */
78#define	CTL_SST_TS_UDPTIME	7	/* other */
79#define	CTL_SST_TS_WRSTWTCH	8	/* wristwatch */
80#define	CTL_SST_TS_TELEPHONE	9	/* telephone */
81
82#define	CTL_SYS_MAXEVENTS	15
83
84#define	CTL_SYS_STATUS(li, source, nevnt, evnt) \
85		(((((unsigned short)(li))<< 14)&0xc000) | \
86		(((source)<<8)&0x3f00) | \
87		(((nevnt)<<4)&0x00f0) | \
88		((evnt)&0x000f))
89
90#define	CTL_SYS_LI(status)	(((status)>>14) & 0x3)
91#define	CTL_SYS_SOURCE(status)	(((status)>>8) & 0x3f)
92#define	CTL_SYS_NEVNT(status)	(((status)>>4) & 0xf)
93#define	CTL_SYS_EVENT(status)	((status) & 0xf)
94
95/*
96 * {En,De}coding of the peer status word
97 */
98#define	CTL_PST_CONFIG		0x80
99#define	CTL_PST_AUTHENABLE	0x40
100#define	CTL_PST_AUTHENTIC	0x20
101#define	CTL_PST_REACH		0x10
102#define	CTL_PST_BCAST		0x08
103
104#define	CTL_PST_SEL_REJECT	0	/*   reject */
105#define	CTL_PST_SEL_SANE	1	/* x falsetick */
106#define	CTL_PST_SEL_CORRECT	2	/* . excess */
107#define	CTL_PST_SEL_SELCAND	3	/* - outlier */
108#define	CTL_PST_SEL_SYNCCAND	4	/* + candidate */
109#define	CTL_PST_SEL_EXCESS	5	/* # backup */
110#define	CTL_PST_SEL_SYSPEER	6	/* * sys.peer */
111#define	CTL_PST_SEL_PPS		7	/* o pps.peer */
112
113#define	CTL_PEER_MAXEVENTS	15
114
115#define	CTL_PEER_STATUS(status, nevnt, evnt) \
116		((((status)<<8) & 0xff00) | \
117		(((nevnt)<<4) & 0x00f0) | \
118		((evnt) & 0x000f))
119
120#define	CTL_PEER_STATVAL(status)(((status)>>8) & 0xff)
121#define	CTL_PEER_NEVNT(status)	(((status)>>4) & 0xf)
122#define	CTL_PEER_EVENT(status)	((status) & 0xf)
123
124/*
125 * {En,De}coding of the clock status word
126 */
127#define	CTL_CLK_OKAY		0
128#define	CTL_CLK_NOREPLY		1
129#define	CTL_CLK_BADFORMAT	2
130#define	CTL_CLK_FAULT		3
131#define	CTL_CLK_PROPAGATION	4
132#define	CTL_CLK_BADDATE		5
133#define	CTL_CLK_BADTIME		6
134
135#define	CTL_CLK_STATUS(status, event) \
136		((((status)<<8) & 0xff00) | \
137		((event) & 0x00ff))
138
139/*
140 * Error code responses returned when the E bit is set.
141 */
142#define	CERR_UNSPEC	0
143#define	CERR_PERMISSION	1
144#define	CERR_BADFMT	2
145#define	CERR_BADOP	3
146#define	CERR_BADASSOC	4
147#define	CERR_UNKNOWNVAR	5
148#define	CERR_BADVALUE	6
149#define	CERR_RESTRICT	7
150
151#define	CERR_NORESOURCE	CERR_PERMISSION	/* wish there was a different code */
152
153
154/*
155 * Definition of the structure used internally to hold trap information.
156 * ntp_request.c wants to see this.
157 */
158struct ctl_trap {
159	sockaddr_u tr_addr;		/* address of trap recipient */
160	struct interface *tr_localaddr;	/* interface to send this through */
161	u_long tr_settime;		/* time trap was set */
162	u_long tr_count;		/* async messages sent to this guy */
163	u_long tr_origtime;		/* time trap was originally set */
164	u_long tr_resets;		/* count of resets for this trap */
165	u_short tr_sequence;		/* trap sequence id */
166	u_char tr_flags;		/* trap flags */
167	u_char tr_version;		/* version number of trapper */
168};
169extern struct ctl_trap ctl_traps[CTL_MAXTRAPS];
170
171/*
172 * Flag bits
173 */
174#define	TRAP_INUSE	0x1		/* this trap is active */
175#define	TRAP_NONPRIO	0x2		/* this trap is non-priority */
176#define	TRAP_CONFIGURED	0x4		/* this trap was configured */
177
178/*
179 * Types of things we may deal with
180 * shared between ntpq and library
181 */
182#define	TYPE_SYS	1
183#define	TYPE_PEER	2
184#define	TYPE_CLOCK	3
185
186/*
187 * IFSTATS_FIELDS is the number of fields ntpd supplies for each ifstats
188 * row.  Similarly RESLIST_FIELDS for reslist.
189 */
190#define	IFSTATS_FIELDS	12
191#define	RESLIST_FIELDS	4
192
193