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