ntp_control.h revision 280849
154359Sroberto/*
254359Sroberto * ntp_control.h - definitions related to NTP mode 6 control messages
354359Sroberto */
454359Sroberto
554359Sroberto#include "ntp_types.h"
654359Sroberto
7280849Scytypedef union ctl_pkt_u_tag {
8280849Scy	u_char data[480 + MAX_MAC_LEN]; /* data + auth */
9280849Scy	u_int32 u32[(480 + MAX_MAC_LEN) / sizeof(u_int32)];
10280849Scy} ctl_pkt_u;
11280849Scy
1254359Srobertostruct ntp_control {
1354359Sroberto	u_char li_vn_mode;		/* leap, version, mode */
1454359Sroberto	u_char r_m_e_op;		/* response, more, error, opcode */
1554359Sroberto	u_short sequence;		/* sequence number of request */
1654359Sroberto	u_short status;			/* status word for association */
1782498Sroberto	associd_t associd;		/* association ID */
1854359Sroberto	u_short offset;			/* offset of this batch of data */
1954359Sroberto	u_short count;			/* count of data in this packet */
20280849Scy	ctl_pkt_u u;
2154359Sroberto};
2254359Sroberto
2354359Sroberto/*
2454359Sroberto * Length of the control header, in octets
2554359Sroberto */
26280849Scy#define	CTL_HEADER_LEN		(offsetof(struct ntp_control, u))
2754359Sroberto#define	CTL_MAX_DATA_LEN	468
2854359Sroberto
2954359Sroberto
3054359Sroberto/*
3154359Sroberto * Limits and things
3254359Sroberto */
3354359Sroberto#define	CTL_MAXTRAPS	3		/* maximum number of traps we allow */
3454359Sroberto#define	CTL_TRAPTIME	(60*60)		/* time out traps in 1 hour */
3554359Sroberto#define	CTL_MAXAUTHSIZE	64		/* maximum size of an authen'ed req */
3654359Sroberto
3754359Sroberto/*
3854359Sroberto * Decoding for the r_m_e_op field
3954359Sroberto */
4054359Sroberto#define	CTL_RESPONSE	0x80
4154359Sroberto#define	CTL_ERROR	0x40
4254359Sroberto#define	CTL_MORE	0x20
4354359Sroberto#define	CTL_OP_MASK	0x1f
4454359Sroberto
45280849Scy#define	CTL_ISRESPONSE(r_m_e_op) ((CTL_RESPONSE	& (r_m_e_op)) != 0)
46280849Scy#define	CTL_ISMORE(r_m_e_op)	 ((CTL_MORE	& (r_m_e_op)) != 0)
47280849Scy#define	CTL_ISERROR(r_m_e_op)	 ((CTL_ERROR	& (r_m_e_op)) != 0)
48280849Scy#define	CTL_OP(r_m_e_op)	 (CTL_OP_MASK	& (r_m_e_op))
4954359Sroberto
5054359Sroberto/*
5154359Sroberto * Opcodes
5254359Sroberto */
53280849Scy#define	CTL_OP_UNSPEC		0	/* unspeciffied */
54280849Scy#define	CTL_OP_READSTAT		1	/* read status */
55280849Scy#define	CTL_OP_READVAR		2	/* read variables */
56280849Scy#define	CTL_OP_WRITEVAR		3	/* write variables */
57280849Scy#define	CTL_OP_READCLOCK	4	/* read clock variables */
58280849Scy#define	CTL_OP_WRITECLOCK	5	/* write clock variables */
59280849Scy#define	CTL_OP_SETTRAP		6	/* set trap address */
60280849Scy#define	CTL_OP_ASYNCMSG		7	/* asynchronous message */
61280849Scy#define CTL_OP_CONFIGURE	8	/* runtime configuration */
62280849Scy#define CTL_OP_SAVECONFIG	9	/* save config to file */
63280849Scy#define CTL_OP_READ_MRU		10	/* retrieve MRU (mrulist) */
64280849Scy#define CTL_OP_READ_ORDLIST_A	11	/* ordered list req. auth. */
65280849Scy#define CTL_OP_REQ_NONCE	12	/* request a client nonce */
66280849Scy#define	CTL_OP_UNSETTRAP	31	/* unset trap */
6754359Sroberto
6854359Sroberto/*
6954359Sroberto * {En,De}coding of the system status word
7054359Sroberto */
71280849Scy#define	CTL_SST_TS_UNSPEC	0	/* unspec */
72280849Scy#define	CTL_SST_TS_ATOM		1	/* pps */
73280849Scy#define	CTL_SST_TS_LF		2	/* lf radio */
74280849Scy#define	CTL_SST_TS_HF		3	/* hf radio */
75280849Scy#define	CTL_SST_TS_UHF		4	/* uhf radio */
76280849Scy#define	CTL_SST_TS_LOCAL	5	/* local */
77280849Scy#define	CTL_SST_TS_NTP		6	/* ntp */
78280849Scy#define	CTL_SST_TS_UDPTIME	7	/* other */
79280849Scy#define	CTL_SST_TS_WRSTWTCH	8	/* wristwatch */
80280849Scy#define	CTL_SST_TS_TELEPHONE	9	/* telephone */
8154359Sroberto
8254359Sroberto#define	CTL_SYS_MAXEVENTS	15
8354359Sroberto
8454359Sroberto#define	CTL_SYS_STATUS(li, source, nevnt, evnt) \
8554359Sroberto		(((((unsigned short)(li))<< 14)&0xc000) | \
8654359Sroberto		(((source)<<8)&0x3f00) | \
8754359Sroberto		(((nevnt)<<4)&0x00f0) | \
8854359Sroberto		((evnt)&0x000f))
8954359Sroberto
9054359Sroberto#define	CTL_SYS_LI(status)	(((status)>>14) & 0x3)
9154359Sroberto#define	CTL_SYS_SOURCE(status)	(((status)>>8) & 0x3f)
9254359Sroberto#define	CTL_SYS_NEVNT(status)	(((status)>>4) & 0xf)
9354359Sroberto#define	CTL_SYS_EVENT(status)	((status) & 0xf)
9454359Sroberto
9554359Sroberto/*
9654359Sroberto * {En,De}coding of the peer status word
9754359Sroberto */
9854359Sroberto#define	CTL_PST_CONFIG		0x80
9954359Sroberto#define	CTL_PST_AUTHENABLE	0x40
10054359Sroberto#define	CTL_PST_AUTHENTIC	0x20
10154359Sroberto#define	CTL_PST_REACH		0x10
102280849Scy#define	CTL_PST_BCAST		0x08
10354359Sroberto
10454359Sroberto#define	CTL_PST_SEL_REJECT	0	/*   reject */
10554359Sroberto#define	CTL_PST_SEL_SANE	1	/* x falsetick */
10654359Sroberto#define	CTL_PST_SEL_CORRECT	2	/* . excess */
10754359Sroberto#define	CTL_PST_SEL_SELCAND	3	/* - outlyer */
108280849Scy#define	CTL_PST_SEL_SYNCCAND	4	/* + candidate */
109280849Scy#define	CTL_PST_SEL_EXCESS	5	/* # backup */
11054359Sroberto#define	CTL_PST_SEL_SYSPEER	6	/* * sys.peer */
11154359Sroberto#define	CTL_PST_SEL_PPS		7	/* o pps.peer */
11254359Sroberto
11354359Sroberto#define	CTL_PEER_MAXEVENTS	15
11454359Sroberto
11554359Sroberto#define	CTL_PEER_STATUS(status, nevnt, evnt) \
11654359Sroberto		((((status)<<8) & 0xff00) | \
11754359Sroberto		(((nevnt)<<4) & 0x00f0) | \
11854359Sroberto		((evnt) & 0x000f))
11954359Sroberto
12054359Sroberto#define	CTL_PEER_STATVAL(status)(((status)>>8) & 0xff)
12154359Sroberto#define	CTL_PEER_NEVNT(status)	(((status)>>4) & 0xf)
12254359Sroberto#define	CTL_PEER_EVENT(status)	((status) & 0xf)
12354359Sroberto
12454359Sroberto/*
12554359Sroberto * {En,De}coding of the clock status word
12654359Sroberto */
12754359Sroberto#define	CTL_CLK_OKAY		0
12854359Sroberto#define	CTL_CLK_NOREPLY		1
12954359Sroberto#define	CTL_CLK_BADFORMAT	2
13054359Sroberto#define	CTL_CLK_FAULT		3
13154359Sroberto#define	CTL_CLK_PROPAGATION	4
13254359Sroberto#define	CTL_CLK_BADDATE		5
13354359Sroberto#define	CTL_CLK_BADTIME		6
13454359Sroberto
13554359Sroberto#define	CTL_CLK_STATUS(status, event) \
13654359Sroberto		((((status)<<8) & 0xff00) | \
13754359Sroberto		((event) & 0x00ff))
13854359Sroberto
13954359Sroberto/*
14054359Sroberto * Error code responses returned when the E bit is set.
14154359Sroberto */
14254359Sroberto#define	CERR_UNSPEC	0
14354359Sroberto#define	CERR_PERMISSION	1
14454359Sroberto#define	CERR_BADFMT	2
14554359Sroberto#define	CERR_BADOP	3
14654359Sroberto#define	CERR_BADASSOC	4
14754359Sroberto#define	CERR_UNKNOWNVAR	5
14854359Sroberto#define	CERR_BADVALUE	6
14954359Sroberto#define	CERR_RESTRICT	7
15054359Sroberto
15154359Sroberto#define	CERR_NORESOURCE	CERR_PERMISSION	/* wish there was a different code */
15254359Sroberto
15354359Sroberto
15454359Sroberto/*
15554359Sroberto * Definition of the structure used internally to hold trap information.
15654359Sroberto * ntp_request.c wants to see this.
15754359Sroberto */
15854359Srobertostruct ctl_trap {
159280849Scy	sockaddr_u tr_addr;		/* address of trap recipient */
16054359Sroberto	struct interface *tr_localaddr;	/* interface to send this through */
16154359Sroberto	u_long tr_settime;		/* time trap was set */
16254359Sroberto	u_long tr_count;		/* async messages sent to this guy */
16354359Sroberto	u_long tr_origtime;		/* time trap was originally set */
16454359Sroberto	u_long tr_resets;		/* count of resets for this trap */
16554359Sroberto	u_short tr_sequence;		/* trap sequence id */
16654359Sroberto	u_char tr_flags;		/* trap flags */
16754359Sroberto	u_char tr_version;		/* version number of trapper */
16854359Sroberto};
169280849Scyextern struct ctl_trap ctl_traps[CTL_MAXTRAPS];
17054359Sroberto
17154359Sroberto/*
17254359Sroberto * Flag bits
17354359Sroberto */
17454359Sroberto#define	TRAP_INUSE	0x1		/* this trap is active */
17554359Sroberto#define	TRAP_NONPRIO	0x2		/* this trap is non-priority */
17654359Sroberto#define	TRAP_CONFIGURED	0x4		/* this trap was configured */
17754359Sroberto
17854359Sroberto/*
17954359Sroberto * Types of things we may deal with
18054359Sroberto * shared between ntpq and library
18154359Sroberto */
18254359Sroberto#define	TYPE_SYS	1
18354359Sroberto#define	TYPE_PEER	2
18454359Sroberto#define	TYPE_CLOCK	3
185280849Scy
186280849Scy/*
187280849Scy * IFSTATS_FIELDS is the number of fields ntpd supplies for each ifstats
188280849Scy * row.  Similarly RESLIST_FIELDS for reslist.
189280849Scy */
190280849Scy#define	IFSTATS_FIELDS	12
191280849Scy#define	RESLIST_FIELDS	4
192280849Scy
193