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