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