/contrib/ntp/include/ntp_control.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 287 lines · 211 code · 29 blank · 47 comment · 3 complexity · e433bda4acfce2ef441d26c07eabba8e MD5 · raw file

  1. /*
  2. * ntp_control.h - definitions related to NTP mode 6 control messages
  3. */
  4. #include "ntp_types.h"
  5. struct ntp_control {
  6. u_char li_vn_mode; /* leap, version, mode */
  7. u_char r_m_e_op; /* response, more, error, opcode */
  8. u_short sequence; /* sequence number of request */
  9. u_short status; /* status word for association */
  10. associd_t associd; /* association ID */
  11. u_short offset; /* offset of this batch of data */
  12. u_short count; /* count of data in this packet */
  13. u_char data[(480 + MAX_MAC_LEN)]; /* data + auth */
  14. };
  15. /*
  16. * Length of the control header, in octets
  17. */
  18. #define CTL_HEADER_LEN 12
  19. #define CTL_MAX_DATA_LEN 468
  20. /*
  21. * Limits and things
  22. */
  23. #define CTL_MAXTRAPS 3 /* maximum number of traps we allow */
  24. #define CTL_TRAPTIME (60*60) /* time out traps in 1 hour */
  25. #define CTL_MAXAUTHSIZE 64 /* maximum size of an authen'ed req */
  26. /*
  27. * Decoding for the r_m_e_op field
  28. */
  29. #define CTL_RESPONSE 0x80
  30. #define CTL_ERROR 0x40
  31. #define CTL_MORE 0x20
  32. #define CTL_OP_MASK 0x1f
  33. #define CTL_ISRESPONSE(r_m_e_op) (((r_m_e_op) & 0x80) != 0)
  34. #define CTL_ISMORE(r_m_e_op) (((r_m_e_op) & 0x20) != 0)
  35. #define CTL_ISERROR(r_m_e_op) (((r_m_e_op) & 0x40) != 0)
  36. #define CTL_OP(r_m_e_op) ((r_m_e_op) & CTL_OP_MASK)
  37. /*
  38. * Opcodes
  39. */
  40. #define CTL_OP_UNSPEC 0
  41. #define CTL_OP_READSTAT 1
  42. #define CTL_OP_READVAR 2
  43. #define CTL_OP_WRITEVAR 3
  44. #define CTL_OP_READCLOCK 4
  45. #define CTL_OP_WRITECLOCK 5
  46. #define CTL_OP_SETTRAP 6
  47. #define CTL_OP_ASYNCMSG 7
  48. #define CTL_OP_UNSETTRAP 31
  49. /*
  50. * {En,De}coding of the system status word
  51. */
  52. #define CTL_SST_TS_UNSPEC 0 /* time source unspecified */
  53. #define CTL_SST_TS_ATOM 1 /* time source calibrated atomic */
  54. #define CTL_SST_TS_LF 2 /* time source VLF or LF radio */
  55. #define CTL_SST_TS_HF 3 /* time source HF radio */
  56. #define CTL_SST_TS_UHF 4 /* time source UHF radio */
  57. #define CTL_SST_TS_LOCAL 5 /* time source LOCAL */
  58. #define CTL_SST_TS_NTP 6 /* time source NTP */
  59. #define CTL_SST_TS_UDPTIME 7 /* time source UDP/TIME */
  60. #define CTL_SST_TS_WRSTWTCH 8 /* time source is wristwatch */
  61. #define CTL_SST_TS_TELEPHONE 9 /* time source is telephone modem */
  62. #define CTL_SST_TS_PPS 0x20 /* time source is PPS signal */
  63. #define CTL_SYS_MAXEVENTS 15
  64. #define CTL_SYS_STATUS(li, source, nevnt, evnt) \
  65. (((((unsigned short)(li))<< 14)&0xc000) | \
  66. (((source)<<8)&0x3f00) | \
  67. (((nevnt)<<4)&0x00f0) | \
  68. ((evnt)&0x000f))
  69. #define CTL_SYS_LI(status) (((status)>>14) & 0x3)
  70. #define CTL_SYS_SOURCE(status) (((status)>>8) & 0x3f)
  71. #define CTL_SYS_NEVNT(status) (((status)>>4) & 0xf)
  72. #define CTL_SYS_EVENT(status) ((status) & 0xf)
  73. /*
  74. * {En,De}coding of the peer status word
  75. */
  76. #define CTL_PST_CONFIG 0x80
  77. #define CTL_PST_AUTHENABLE 0x40
  78. #define CTL_PST_AUTHENTIC 0x20
  79. #define CTL_PST_REACH 0x10
  80. #define CTL_PST_UNSPEC 0x08
  81. #define CTL_PST_SEL_REJECT 0 /* reject */
  82. #define CTL_PST_SEL_SANE 1 /* x falsetick */
  83. #define CTL_PST_SEL_CORRECT 2 /* . excess */
  84. #define CTL_PST_SEL_SELCAND 3 /* - outlyer */
  85. #define CTL_PST_SEL_SYNCCAND 4 /* + candidat */
  86. #define CTL_PST_SEL_DISTSYSPEER 5 /* # selected */
  87. #define CTL_PST_SEL_SYSPEER 6 /* * sys.peer */
  88. #define CTL_PST_SEL_PPS 7 /* o pps.peer */
  89. #define CTL_PEER_MAXEVENTS 15
  90. #define CTL_PEER_STATUS(status, nevnt, evnt) \
  91. ((((status)<<8) & 0xff00) | \
  92. (((nevnt)<<4) & 0x00f0) | \
  93. ((evnt) & 0x000f))
  94. #define CTL_PEER_STATVAL(status)(((status)>>8) & 0xff)
  95. #define CTL_PEER_NEVNT(status) (((status)>>4) & 0xf)
  96. #define CTL_PEER_EVENT(status) ((status) & 0xf)
  97. /*
  98. * {En,De}coding of the clock status word
  99. */
  100. #define CTL_CLK_OKAY 0
  101. #define CTL_CLK_NOREPLY 1
  102. #define CTL_CLK_BADFORMAT 2
  103. #define CTL_CLK_FAULT 3
  104. #define CTL_CLK_PROPAGATION 4
  105. #define CTL_CLK_BADDATE 5
  106. #define CTL_CLK_BADTIME 6
  107. #define CTL_CLK_STATUS(status, event) \
  108. ((((status)<<8) & 0xff00) | \
  109. ((event) & 0x00ff))
  110. /*
  111. * Error code responses returned when the E bit is set.
  112. */
  113. #define CERR_UNSPEC 0
  114. #define CERR_PERMISSION 1
  115. #define CERR_BADFMT 2
  116. #define CERR_BADOP 3
  117. #define CERR_BADASSOC 4
  118. #define CERR_UNKNOWNVAR 5
  119. #define CERR_BADVALUE 6
  120. #define CERR_RESTRICT 7
  121. #define CERR_NORESOURCE CERR_PERMISSION /* wish there was a different code */
  122. /*
  123. * System variables we understand
  124. */
  125. #define CS_LEAP 1
  126. #define CS_STRATUM 2
  127. #define CS_PRECISION 3
  128. #define CS_ROOTDELAY 4
  129. #define CS_ROOTDISPERSION 5
  130. #define CS_REFID 6
  131. #define CS_REFTIME 7
  132. #define CS_POLL 8
  133. #define CS_PEERID 9
  134. #define CS_STATE 10
  135. #define CS_OFFSET 11
  136. #define CS_DRIFT 12
  137. #define CS_JITTER 13
  138. #define CS_ERROR 14
  139. #define CS_CLOCK 15
  140. #define CS_PROCESSOR 16
  141. #define CS_SYSTEM 17
  142. #define CS_VERSION 18
  143. #define CS_STABIL 19
  144. #define CS_VARLIST 20
  145. #ifdef OPENSSL
  146. #define CS_FLAGS 21
  147. #define CS_HOST 22
  148. #define CS_PUBLIC 23
  149. #define CS_CERTIF 24
  150. #define CS_REVTIME 25
  151. #define CS_LEAPTAB 26
  152. #define CS_TAI 27
  153. #define CS_DIGEST 28
  154. #define CS_IDENT 29
  155. #define CS_REVOKE 30
  156. #define CS_MAXCODE CS_REVOKE
  157. #else
  158. #define CS_MAXCODE CS_VARLIST
  159. #endif /* OPENSSL */
  160. /*
  161. * Peer variables we understand
  162. */
  163. #define CP_CONFIG 1
  164. #define CP_AUTHENABLE 2
  165. #define CP_AUTHENTIC 3
  166. #define CP_SRCADR 4
  167. #define CP_SRCPORT 5
  168. #define CP_DSTADR 6
  169. #define CP_DSTPORT 7
  170. #define CP_LEAP 8
  171. #define CP_HMODE 9
  172. #define CP_STRATUM 10
  173. #define CP_PPOLL 11
  174. #define CP_HPOLL 12
  175. #define CP_PRECISION 13
  176. #define CP_ROOTDELAY 14
  177. #define CP_ROOTDISPERSION 15
  178. #define CP_REFID 16
  179. #define CP_REFTIME 17
  180. #define CP_ORG 18
  181. #define CP_REC 19
  182. #define CP_XMT 20
  183. #define CP_REACH 21
  184. #define CP_UNREACH 22
  185. #define CP_TIMER 23
  186. #define CP_DELAY 24
  187. #define CP_OFFSET 25
  188. #define CP_JITTER 26
  189. #define CP_DISPERSION 27
  190. #define CP_KEYID 28
  191. #define CP_FILTDELAY 29
  192. #define CP_FILTOFFSET 30
  193. #define CP_PMODE 31
  194. #define CP_RECEIVED 32
  195. #define CP_SENT 33
  196. #define CP_FILTERROR 34
  197. #define CP_FLASH 35
  198. #define CP_TTL 36
  199. #define CP_VARLIST 37
  200. #ifdef OPENSSL
  201. #define CP_FLAGS 38
  202. #define CP_HOST 39
  203. #define CP_VALID 40
  204. #define CP_INITSEQ 41
  205. #define CP_INITKEY 42
  206. #define CP_INITTSP 43
  207. #define CP_DIGEST 44
  208. #define CP_IDENT 45
  209. #define CP_MAXCODE CP_IDENT
  210. #else
  211. #define CP_MAXCODE CP_VARLIST
  212. #endif /* OPENSSL */
  213. /*
  214. * Clock variables we understand
  215. */
  216. #define CC_TYPE 1
  217. #define CC_TIMECODE 2
  218. #define CC_POLL 3
  219. #define CC_NOREPLY 4
  220. #define CC_BADFORMAT 5
  221. #define CC_BADDATA 6
  222. #define CC_FUDGETIME1 7
  223. #define CC_FUDGETIME2 8
  224. #define CC_FUDGEVAL1 9
  225. #define CC_FUDGEVAL2 10
  226. #define CC_FLAGS 11
  227. #define CC_DEVICE 12
  228. #define CC_VARLIST 13
  229. #define CC_MAXCODE CC_VARLIST
  230. /*
  231. * Definition of the structure used internally to hold trap information.
  232. * ntp_request.c wants to see this.
  233. */
  234. struct ctl_trap {
  235. struct sockaddr_storage tr_addr;/* address of trap recipient */
  236. struct interface *tr_localaddr; /* interface to send this through */
  237. u_long tr_settime; /* time trap was set */
  238. u_long tr_count; /* async messages sent to this guy */
  239. u_long tr_origtime; /* time trap was originally set */
  240. u_long tr_resets; /* count of resets for this trap */
  241. u_short tr_sequence; /* trap sequence id */
  242. u_char tr_flags; /* trap flags */
  243. u_char tr_version; /* version number of trapper */
  244. };
  245. extern struct ctl_trap ctl_trap[];
  246. /*
  247. * Flag bits
  248. */
  249. #define TRAP_INUSE 0x1 /* this trap is active */
  250. #define TRAP_NONPRIO 0x2 /* this trap is non-priority */
  251. #define TRAP_CONFIGURED 0x4 /* this trap was configured */
  252. /*
  253. * Types of things we may deal with
  254. * shared between ntpq and library
  255. */
  256. #define TYPE_SYS 1
  257. #define TYPE_PEER 2
  258. #define TYPE_CLOCK 3