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