1 /* $NetBSD: ntp_request.h,v 1.9 2020/05/25 20:47:19 christos Exp $ */ 2 3 /* 4 * ntp_request.h - definitions for the ntpd remote query facility 5 */ 6 7 #ifndef NTP_REQUEST_H 8 #define NTP_REQUEST_H 9 10 #include "stddef.h" 11 #include "ntp_types.h" 12 #include "recvbuff.h" 13 14 /* 15 * A mode 7 packet is used exchanging data between an NTP server 16 * and a client for purposes other than time synchronization, e.g. 17 * monitoring, statistics gathering and configuration. A mode 7 18 * packet has the following format: 19 * 20 * 0 1 2 3 21 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 22 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 23 * |R|M| VN | Mode|A| Sequence | Implementation| Req Code | 24 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 25 * | Err | Number of data items | MBZ | Size of data item | 26 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 27 * | | 28 * | Data (Minimum 0 octets, maximum 500 octets) | 29 * | | 30 * [...] 31 * | | 32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33 * | Encryption Keyid (when A bit set) | 34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 35 * | | 36 * | Message Authentication Code (when A bit set) | 37 * | | 38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 39 * 40 * where the fields are (note that the client sends requests, the server 41 * responses): 42 * 43 * Response Bit: This packet is a response (if clear, packet is a request). 44 * 45 * More Bit: Set for all packets but the last in a response which 46 * requires more than one packet. 47 * 48 * Version Number: 2 for current version 49 * 50 * Mode: Always 7 51 * 52 * Authenticated bit: If set, this packet is authenticated. 53 * 54 * Sequence number: For a multipacket response, contains the sequence 55 * number of this packet. 0 is the first in the sequence, 56 * 127 (or less) is the last. The More Bit must be set in 57 * all packets but the last. 58 * 59 * Implementation number: The number of the implementation this request code 60 * is defined by. An implementation number of zero is used 61 * for requst codes/data formats which all implementations 62 * agree on. Implementation number 255 is reserved (for 63 * extensions, in case we run out). 64 * 65 * Request code: An implementation-specific code which specifies the 66 * operation to be (which has been) performed and/or the 67 * format and semantics of the data included in the packet. 68 * 69 * Err: Must be 0 for a request. For a response, holds an error 70 * code relating to the request. If nonzero, the operation 71 * requested wasn't performed. 72 * 73 * 0 - no error 74 * 1 - incompatible implementation number 75 * 2 - unimplemented request code 76 * 3 - format error (wrong data items, data size, packet size etc.) 77 * 4 - no data available (e.g. request for details on unknown peer) 78 * 5-6 I don't know 79 * 7 - authentication failure (i.e. permission denied) 80 * 81 * Number of data items: number of data items in packet. 0 to 500 82 * 83 * MBZ: A reserved data field, must be zero in requests and responses. 84 * 85 * Size of data item: size of each data item in packet. 0 to 500 86 * 87 * Data: Variable sized area containing request/response data. For 88 * requests and responses the size in octets must be greater 89 * than or equal to the product of the number of data items 90 * and the size of a data item. For requests the data area 91 * must be exactly 40 octets in length. For responses the 92 * data area may be any length between 0 and 500 octets 93 * inclusive. 94 * 95 * Message Authentication Code: Same as NTP spec, in definition and function. 96 * May optionally be included in requests which require 97 * authentication, is never included in responses. 98 * 99 * The version number, mode and keyid have the same function and are 100 * in the same location as a standard NTP packet. The request packet 101 * is the same size as a standard NTP packet to ease receive buffer 102 * management, and to allow the same encryption procedure to be used 103 * both on mode 7 and standard NTP packets. The mac is included when 104 * it is required that a request be authenticated, the keyid should be 105 * zero in requests in which the mac is not included. 106 * 107 * The data format depends on the implementation number/request code pair 108 * and whether the packet is a request or a response. The only requirement 109 * is that data items start in the octet immediately following the size 110 * word and that data items be concatenated without padding between (i.e. 111 * if the data area is larger than data_items*size, all padding is at 112 * the end). Padding is ignored, other than for encryption purposes. 113 * Implementations using encryption might want to include a time stamp 114 * or other data in the request packet padding. The key used for requests 115 * is implementation defined, but key 15 is suggested as a default. 116 */ 117 118 /* 119 * union of raw addresses to save space 120 */ 121 union addrun { 122 struct in6_addr addr6; 123 struct in_addr addr; 124 }; 125 126 #define MODE7_PAYLOAD_LIM 176 127 128 typedef union req_data_u_tag { 129 u_int32 u32[MODE7_PAYLOAD_LIM / sizeof(u_int32)]; 130 char data[MODE7_PAYLOAD_LIM]; /* data area (176 byte max) */ 131 } req_data_u; /* struct conf_peer must fit */ 132 133 /* 134 * Structure for carrying system flags. 135 */ 136 struct conf_sys_flags { 137 u_int32 flags; 138 }; 139 140 /* 141 * System flags we can set/clear 142 */ 143 #define SYS_FLAG_BCLIENT 0x01 144 #define SYS_FLAG_PPS 0x02 145 #define SYS_FLAG_NTP 0x04 146 #define SYS_FLAG_KERNEL 0x08 147 #define SYS_FLAG_MONITOR 0x10 148 #define SYS_FLAG_FILEGEN 0x20 149 #define SYS_FLAG_AUTH 0x40 150 #define SYS_FLAG_CAL 0x80 151 152 /* 153 * A request packet. These are almost a fixed length. 154 */ 155 struct req_pkt { 156 u_char rm_vn_mode; /* response, more, version, mode */ 157 u_char auth_seq; /* key, sequence number */ 158 u_char implementation; /* implementation number */ 159 u_char request; /* request number */ 160 u_short err_nitems; /* error code/number of data items */ 161 u_short mbz_itemsize; /* item size */ 162 req_data_u u; /* data area */ 163 l_fp tstamp; /* time stamp, for authentication */ 164 keyid_t keyid; /* (optional) encryption key */ 165 char mac[MAX_MDG_LEN]; /* (optional) auth code */ 166 }; 167 168 /* 169 * The req_pkt_tail structure is used by ntpd to adjust for different 170 * packet sizes that may arrive. 171 */ 172 struct req_pkt_tail { 173 l_fp tstamp; /* time stamp, for authentication */ 174 keyid_t keyid; /* (optional) encryption key */ 175 char mac[MAX_MDG_LEN]; /* (optional) auth code */ 176 }; 177 178 /* MODE_PRIVATE request packet header length before optional items. */ 179 #define REQ_LEN_HDR (offsetof(struct req_pkt, u)) 180 /* MODE_PRIVATE request packet fixed length without MAC. */ 181 #define REQ_LEN_NOMAC (offsetof(struct req_pkt, keyid)) 182 /* MODE_PRIVATE req_pkt_tail minimum size (16 octet digest) */ 183 #define REQ_TAIL_MIN \ 184 (sizeof(struct req_pkt_tail) - (MAX_MAC_LEN - MAX_MD5_LEN)) 185 186 /* 187 * A MODE_PRIVATE response packet. The length here is variable, this 188 * is a maximally sized one. Note that this implementation doesn't 189 * authenticate responses. 190 */ 191 #define RESP_HEADER_SIZE (offsetof(struct resp_pkt, u)) 192 #define RESP_DATA_SIZE 500 193 194 typedef union resp_pkt_u_tag { 195 char data[RESP_DATA_SIZE]; 196 u_int32 u32[RESP_DATA_SIZE / sizeof(u_int32)]; 197 } resp_pkt_u; 198 199 struct resp_pkt { 200 u_char rm_vn_mode; /* response, more, version, mode */ 201 u_char auth_seq; /* key, sequence number */ 202 u_char implementation; /* implementation number */ 203 u_char request; /* request number */ 204 u_short err_nitems; /* error code/number of data items */ 205 u_short mbz_itemsize; /* item size */ 206 resp_pkt_u u; /* data area */ 207 }; 208 209 210 /* 211 * Information error codes 212 */ 213 #define INFO_OKAY 0 214 #define INFO_ERR_IMPL 1 /* incompatible implementation */ 215 #define INFO_ERR_REQ 2 /* unknown request code */ 216 #define INFO_ERR_FMT 3 /* format error */ 217 #define INFO_ERR_NODATA 4 /* no data for this request */ 218 #define INFO_ERR_AUTH 7 /* authentication failure */ 219 #define MAX_INFO_ERR INFO_ERR_AUTH 220 221 /* 222 * Maximum sequence number. 223 */ 224 #define MAXSEQ 127 225 226 227 /* 228 * Bit setting macros for multifield items. 229 */ 230 #define RESP_BIT 0x80 231 #define MORE_BIT 0x40 232 233 #define ISRESPONSE(rm_vn_mode) (((rm_vn_mode)&RESP_BIT)!=0) 234 #define ISMORE(rm_vn_mode) (((rm_vn_mode)&MORE_BIT)!=0) 235 #define INFO_VERSION(rm_vn_mode) ((u_char)(((rm_vn_mode)>>3)&0x7)) 236 #define INFO_MODE(rm_vn_mode) ((rm_vn_mode)&0x7) 237 238 #define RM_VN_MODE(resp, more, version) \ 239 ((u_char)(((resp)?RESP_BIT:0)\ 240 |((more)?MORE_BIT:0)\ 241 |((version?version:(NTP_OLDVERSION+1))<<3)\ 242 |(MODE_PRIVATE))) 243 244 #define INFO_IS_AUTH(auth_seq) (((auth_seq) & 0x80) != 0) 245 #define INFO_SEQ(auth_seq) ((auth_seq)&0x7f) 246 #define AUTH_SEQ(auth, seq) ((u_char)((((auth)!=0)?0x80:0)|((seq)&0x7f))) 247 248 #define INFO_ERR(err_nitems) ((u_short)((ntohs(err_nitems)>>12)&0xf)) 249 #define INFO_NITEMS(err_nitems) ((u_short)(ntohs(err_nitems)&0xfff)) 250 #define _ERR_EN(err) ((u_short)(((err)&0xf)<<12)) 251 #define ERR_NITEMS(err, nitems) ((u_short)htons(_ERR_EN(err)|(nitems&0xfff))) 252 253 #define INFO_MBZ(mbz_itemsize) ((ntohs(mbz_itemsize)>>12)&0xf) 254 #define INFO_ITEMSIZE(mbz_itemsize) ((u_short)(ntohs(mbz_itemsize)&0xfff)) 255 #define MBZ_ITEMSIZE(itemsize) (htons((u_short)(itemsize))) 256 257 258 /* 259 * Implementation numbers. One for universal use and one for ntpd. 260 */ 261 #define IMPL_UNIV 0 262 #define IMPL_XNTPD_OLD 2 /* Used by pre ipv6 ntpdc */ 263 #define IMPL_XNTPD 3 /* Used by post ipv6 ntpdc */ 264 265 /* 266 * Some limits related to authentication. Frames which are 267 * authenticated must include a time stamp which differs from 268 * the receive time stamp by no more than 10 seconds. 269 */ 270 #define INFO_TS_MAXSKEW 10. 271 272 /* 273 * Universal request codes go here. There aren't any. 274 */ 275 276 /* 277 * ntpdc -> ntpd request codes go here. 278 */ 279 #define REQ_PEER_LIST 0 /* return list of peers */ 280 #define REQ_PEER_LIST_SUM 1 /* return summary info for all peers */ 281 #define REQ_PEER_INFO 2 /* get standard information on peer */ 282 #define REQ_PEER_STATS 3 /* get statistics for peer */ 283 #define REQ_SYS_INFO 4 /* get system information */ 284 #define REQ_SYS_STATS 5 /* get system stats */ 285 #define REQ_IO_STATS 6 /* get I/O stats */ 286 #define REQ_MEM_STATS 7 /* stats related to peer list maint */ 287 #define REQ_LOOP_INFO 8 /* info from the loop filter */ 288 #define REQ_TIMER_STATS 9 /* get timer stats */ 289 #define REQ_CONFIG 10 /* configure a new peer */ 290 #define REQ_UNCONFIG 11 /* unconfigure an existing peer */ 291 #define REQ_SET_SYS_FLAG 12 /* set system flags */ 292 #define REQ_CLR_SYS_FLAG 13 /* clear system flags */ 293 #define REQ_MONITOR 14 /* (not used) */ 294 #define REQ_NOMONITOR 15 /* (not used) */ 295 #define REQ_GET_RESTRICT 16 /* return restrict list */ 296 #define REQ_RESADDFLAGS 17 /* add flags to restrict list */ 297 #define REQ_RESSUBFLAGS 18 /* remove flags from restrict list */ 298 #define REQ_UNRESTRICT 19 /* remove entry from restrict list */ 299 #define REQ_MON_GETLIST 20 /* return data collected by monitor */ 300 #define REQ_RESET_STATS 21 /* reset stat counters */ 301 #define REQ_RESET_PEER 22 /* reset peer stat counters */ 302 #define REQ_REREAD_KEYS 23 /* reread the encryption key file */ 303 #define REQ_DO_DIRTY_HACK 24 /* (not used) */ 304 #define REQ_DONT_DIRTY_HACK 25 /* (not used) */ 305 #define REQ_TRUSTKEY 26 /* add a trusted key */ 306 #define REQ_UNTRUSTKEY 27 /* remove a trusted key */ 307 #define REQ_AUTHINFO 28 /* return authentication info */ 308 #define REQ_TRAPS 29 /* return currently set traps */ 309 #define REQ_ADD_TRAP 30 /* add a trap */ 310 #define REQ_CLR_TRAP 31 /* clear a trap */ 311 #define REQ_REQUEST_KEY 32 /* define a new request keyid */ 312 #define REQ_CONTROL_KEY 33 /* define a new control keyid */ 313 #define REQ_GET_CTLSTATS 34 /* get stats from the control module */ 314 #define REQ_GET_LEAPINFO 35 /* (not used) */ 315 #define REQ_GET_CLOCKINFO 36 /* get clock information */ 316 #define REQ_SET_CLKFUDGE 37 /* set clock fudge factors */ 317 #define REQ_GET_KERNEL 38 /* get kernel pll/pps information */ 318 #define REQ_GET_CLKBUGINFO 39 /* get clock debugging info */ 319 #define REQ_SET_PRECISION 41 /* (not used) */ 320 #define REQ_MON_GETLIST_1 42 /* return collected v1 monitor data */ 321 #define REQ_HOSTNAME_ASSOCID 43 /* Here is a hostname + assoc_id */ 322 #define REQ_IF_STATS 44 /* get interface statistics */ 323 #define REQ_IF_RELOAD 45 /* reload interface list */ 324 325 /* Determine size of pre-v6 version of structures */ 326 #define v4sizeof(type) offsetof(type, v6_flag) 327 328 /* 329 * Flags in the peer information returns 330 */ 331 #define INFO_FLAG_CONFIG 0x1 332 #define INFO_FLAG_SYSPEER 0x2 333 #define INFO_FLAG_BURST 0x4 334 #define INFO_FLAG_REFCLOCK 0x8 335 #define INFO_FLAG_PREFER 0x10 336 #define INFO_FLAG_AUTHENABLE 0x20 337 #define INFO_FLAG_SEL_CANDIDATE 0x40 338 #define INFO_FLAG_SHORTLIST 0x80 339 #define INFO_FLAG_IBURST 0x100 340 341 /* 342 * Flags in the system information returns 343 */ 344 #define INFO_FLAG_BCLIENT 0x1 345 #define INFO_FLAG_AUTHENTICATE 0x2 346 #define INFO_FLAG_NTP 0x4 347 #define INFO_FLAG_KERNEL 0x8 348 #define INFO_FLAG_MONITOR 0x40 349 #define INFO_FLAG_FILEGEN 0x80 350 #define INFO_FLAG_CAL 0x10 351 #define INFO_FLAG_PPS_SYNC 0x20 352 353 /* 354 * Peer list structure. Used to return raw lists of peers. It goes 355 * without saying that everything returned is in network byte order. 356 * Well, it *would* have gone without saying, but somebody said it. 357 */ 358 struct info_peer_list { 359 u_int32 addr; /* address of peer */ 360 u_short port; /* port number of peer */ 361 u_char hmode; /* mode for this peer */ 362 u_char flags; /* flags (from above) */ 363 u_int v6_flag; /* is this v6 or not */ 364 u_int unused1; /* (unused) padding for addr6 */ 365 struct in6_addr addr6; /* v6 address of peer */ 366 }; 367 368 369 /* 370 * Peer summary structure. Sort of the info that ntpdc returns by default. 371 */ 372 struct info_peer_summary { 373 u_int32 dstadr; /* local address (zero for undetermined) */ 374 u_int32 srcadr; /* source address */ 375 u_short srcport; /* source port */ 376 u_char stratum; /* stratum of peer */ 377 s_char hpoll; /* host polling interval */ 378 s_char ppoll; /* peer polling interval */ 379 u_char reach; /* reachability register */ 380 u_char flags; /* flags, from above */ 381 u_char hmode; /* peer mode */ 382 s_fp delay; /* peer.estdelay */ 383 l_fp offset; /* peer.estoffset */ 384 u_fp dispersion; /* peer.estdisp */ 385 u_int v6_flag; /* is this v6 or not */ 386 u_int unused1; /* (unused) padding for dstadr6 */ 387 struct in6_addr dstadr6; /* local address (v6) */ 388 struct in6_addr srcadr6; /* source address (v6) */ 389 }; 390 391 392 /* 393 * Peer information structure. 394 */ 395 struct info_peer { 396 u_int32 dstadr; /* local address */ 397 u_int32 srcadr; /* source address */ 398 u_short srcport; /* remote port */ 399 u_char flags; /* peer flags */ 400 u_char leap; /* peer.leap */ 401 u_char hmode; /* peer.hmode */ 402 u_char pmode; /* peer.pmode */ 403 u_char stratum; /* peer.stratum */ 404 u_char ppoll; /* peer.ppoll */ 405 u_char hpoll; /* peer.hpoll */ 406 s_char precision; /* peer.precision */ 407 u_char version; /* peer.version */ 408 u_char unused8; 409 u_char reach; /* peer.reach */ 410 u_char unreach; /* peer.unreach */ 411 u_char flash; /* old peer.flash */ 412 u_char ttl; /* peer.ttl */ 413 u_short flash2; /* new peer.flash */ 414 associd_t associd; /* association ID */ 415 keyid_t keyid; /* peer.keyid */ 416 u_int32 pkeyid; /* unused */ 417 u_int32 refid; /* peer.refid */ 418 u_int32 timer; /* peer.timer */ 419 s_fp rootdelay; /* peer.delay */ 420 u_fp rootdispersion; /* peer.dispersion */ 421 l_fp reftime; /* peer.reftime */ 422 l_fp org; /* peer.org */ 423 l_fp rec; /* peer.rec */ 424 l_fp xmt; /* peer.xmt */ 425 s_fp filtdelay[NTP_SHIFT]; /* delay shift register */ 426 l_fp filtoffset[NTP_SHIFT]; /* offset shift register */ 427 u_char order[NTP_SHIFT]; /* order of peers from last filter */ 428 s_fp delay; /* peer.estdelay */ 429 u_fp dispersion; /* peer.estdisp */ 430 l_fp offset; /* peer.estoffset */ 431 u_fp selectdisp; /* peer select dispersion */ 432 int32 unused1; /* (obsolete) */ 433 int32 unused2; 434 int32 unused3; 435 int32 unused4; 436 int32 unused5; 437 int32 unused6; 438 int32 unused7; 439 s_fp estbdelay; /* broadcast offset */ 440 u_int v6_flag; /* is this v6 or not */ 441 u_int unused9; /* (unused) padding for dstadr6 */ 442 struct in6_addr dstadr6; /* local address (v6-like) */ 443 struct in6_addr srcadr6; /* sources address (v6-like) */ 444 }; 445 446 447 /* 448 * Peer statistics structure 449 */ 450 struct info_peer_stats { 451 u_int32 dstadr; /* local address */ 452 u_int32 srcadr; /* remote address */ 453 u_short srcport; /* remote port */ 454 u_short flags; /* peer flags */ 455 u_int32 timereset; /* time counters were reset */ 456 u_int32 timereceived; /* time since a packet received */ 457 u_int32 timetosend; /* time until a packet sent */ 458 u_int32 timereachable; /* time peer has been reachable */ 459 u_int32 sent; /* number sent */ 460 u_int32 unused1; /* (unused) */ 461 u_int32 processed; /* number processed */ 462 u_int32 unused2; /* (unused) */ 463 u_int32 badauth; /* bad authentication */ 464 u_int32 bogusorg; /* bogus origin */ 465 u_int32 oldpkt; /* duplicate */ 466 u_int32 unused3; /* (unused) */ 467 u_int32 unused4; /* (unused) */ 468 u_int32 seldisp; /* bad dispersion */ 469 u_int32 selbroken; /* bad reference time */ 470 u_int32 unused5; /* (unused) */ 471 u_char candidate; /* select order */ 472 u_char unused6; /* (unused) */ 473 u_char unused7; /* (unused) */ 474 u_char unused8; /* (unused) */ 475 u_int v6_flag; /* is this v6 or not */ 476 u_int unused9; /* (unused) padding for dstadr6 */ 477 struct in6_addr dstadr6; /* local address */ 478 struct in6_addr srcadr6; /* remote address */ 479 }; 480 481 482 /* 483 * Loop filter variables 484 */ 485 struct info_loop { 486 l_fp last_offset; 487 l_fp drift_comp; 488 u_int32 compliance; 489 u_int32 watchdog_timer; 490 }; 491 492 493 /* 494 * System info. Mostly the sys.* variables, plus a few unique to 495 * the implementation. 496 */ 497 struct info_sys { 498 u_int32 peer; /* system peer address (v4) */ 499 u_char peer_mode; /* mode we are syncing to peer in */ 500 u_char leap; /* system leap bits */ 501 u_char stratum; /* our stratum */ 502 s_char precision; /* local clock precision */ 503 s_fp rootdelay; /* delay from sync source */ 504 u_fp rootdispersion; /* dispersion from sync source */ 505 u_int32 refid; /* reference ID of sync source */ 506 l_fp reftime; /* system reference time */ 507 u_int32 poll; /* system poll interval */ 508 u_char flags; /* system flags */ 509 u_char unused1; /* unused */ 510 u_char unused2; /* unused */ 511 u_char unused3; /* unused */ 512 s_fp bdelay; /* default broadcast offset */ 513 s_fp frequency; /* frequency residual (scaled ppm) */ 514 l_fp authdelay; /* default authentication delay */ 515 u_fp stability; /* clock stability (scaled ppm) */ 516 u_int v6_flag; /* is this v6 or not */ 517 u_int unused4; /* unused, padding for peer6 */ 518 struct in6_addr peer6; /* system peer address (v6) */ 519 }; 520 521 522 /* 523 * System stats. These are collected in the protocol module 524 */ 525 struct info_sys_stats { 526 u_int32 timeup; /* time since restart */ 527 u_int32 timereset; /* time since reset */ 528 u_int32 denied; /* access denied */ 529 u_int32 oldversionpkt; /* recent version */ 530 u_int32 newversionpkt; /* current version */ 531 u_int32 unknownversion; /* bad version */ 532 u_int32 badlength; /* bad length or format */ 533 u_int32 processed; /* packets processed */ 534 u_int32 badauth; /* bad authentication */ 535 u_int32 received; /* packets received */ 536 u_int32 limitrejected; /* rate exceeded */ 537 u_int32 lamport; /* Lamport violations */ 538 u_int32 tsrounding; /* Timestamp rounding errors */ 539 }; 540 541 542 /* 543 * System stats - old version 544 */ 545 struct old_info_sys_stats { 546 u_int32 timeup; /* time since restart */ 547 u_int32 timereset; /* time since reset */ 548 u_int32 denied; /* access denied */ 549 u_int32 oldversionpkt; /* recent version */ 550 u_int32 newversionpkt; /* current version */ 551 u_int32 unknownversion; /* bad version */ 552 u_int32 badlength; /* bad length or format */ 553 u_int32 processed; /* packets processed */ 554 u_int32 badauth; /* bad authentication */ 555 u_int32 wanderhold; /* (not used) */ 556 }; 557 558 559 /* 560 * Peer memory statistics. Collected in the peer module. 561 */ 562 struct info_mem_stats { 563 u_int32 timereset; /* time since reset */ 564 u_short totalpeermem; 565 u_short freepeermem; 566 u_int32 findpeer_calls; 567 u_int32 allocations; 568 u_int32 demobilizations; 569 u_char hashcount[NTP_HASH_SIZE]; 570 }; 571 572 573 /* 574 * I/O statistics. Collected in the I/O module 575 */ 576 struct info_io_stats { 577 u_int32 timereset; /* time since reset */ 578 u_short totalrecvbufs; /* total receive bufs */ 579 u_short freerecvbufs; /* free buffers */ 580 u_short fullrecvbufs; /* full buffers */ 581 u_short lowwater; /* number of times we've added buffers */ 582 u_int32 dropped; /* dropped packets */ 583 u_int32 ignored; /* ignored packets */ 584 u_int32 received; /* received packets */ 585 u_int32 sent; /* packets sent */ 586 u_int32 notsent; /* packets not sent */ 587 u_int32 interrupts; /* interrupts we've handled */ 588 u_int32 int_received; /* received by interrupt handler */ 589 }; 590 591 592 /* 593 * Timer stats. Guess where from. 594 */ 595 struct info_timer_stats { 596 u_int32 timereset; /* time since reset */ 597 u_int32 alarms; /* alarms we've handled */ 598 u_int32 overflows; /* timer overflows */ 599 u_int32 xmtcalls; /* calls to xmit */ 600 }; 601 602 603 /* 604 * Structure for passing peer configuration information 605 */ 606 struct old_conf_peer { 607 u_int32 peeraddr; /* address to poll */ 608 u_char hmode; /* mode, either broadcast, active or client */ 609 u_char version; /* version number to poll with */ 610 u_char minpoll; /* min host poll interval */ 611 u_char maxpoll; /* max host poll interval */ 612 u_char flags; /* flags for this request */ 613 u_char ttl; /* time to live (multicast) or refclock mode */ 614 u_short unused; /* unused */ 615 keyid_t keyid; /* key to use for this association */ 616 }; 617 618 struct conf_peer { 619 u_int32 peeraddr; /* address to poll */ 620 u_char hmode; /* mode, either broadcast, active or client */ 621 u_char version; /* version number to poll with */ 622 u_char minpoll; /* min host poll interval */ 623 u_char maxpoll; /* max host poll interval */ 624 u_char flags; /* flags for this request */ 625 u_char ttl; /* time to live (multicast) or refclock mode */ 626 u_short unused1; /* unused */ 627 keyid_t keyid; /* key to use for this association */ 628 char keystr[128]; /* public key file name */ 629 u_int v6_flag; /* is this v6 or not */ 630 u_int unused2; /* unused, padding for peeraddr6 */ 631 struct in6_addr peeraddr6; /* ipv6 address to poll */ 632 }; 633 634 #define CONF_FLAG_AUTHENABLE 0x01 635 #define CONF_FLAG_PREFER 0x02 636 #define CONF_FLAG_BURST 0x04 637 #define CONF_FLAG_IBURST 0x08 638 #define CONF_FLAG_NOSELECT 0x10 639 #define CONF_FLAG_SKEY 0x20 640 641 /* 642 * Structure for passing peer deletion information. Currently 643 * we only pass the address and delete all configured peers with 644 * this addess. 645 */ 646 struct conf_unpeer { 647 u_int32 peeraddr; /* address of peer */ 648 u_int v6_flag; /* is this v6 or not */ 649 struct in6_addr peeraddr6; /* address of peer (v6) */ 650 }; 651 652 /* 653 * Structure used for returning restrict entries 654 */ 655 struct info_restrict { 656 u_int32 addr; /* match address */ 657 u_int32 mask; /* match mask */ 658 u_int32 count; /* number of packets matched */ 659 u_short rflags; /* restrict flags */ 660 u_short mflags; /* match flags */ 661 u_int v6_flag; /* is this v6 or not */ 662 u_int unused1; /* unused, padding for addr6 */ 663 struct in6_addr addr6; /* match address (v6) */ 664 struct in6_addr mask6; /* match mask (v6) */ 665 }; 666 667 668 /* 669 * Structure used for specifying restrict entries 670 */ 671 struct conf_restrict { 672 u_int32 addr; /* match address */ 673 u_int32 mask; /* match mask */ 674 short ippeerlimit; /* ip peer limit */ 675 int srvfuzrft; /* server response fuzz reftime: poll */ 676 u_short flags; /* restrict flags XXX: OLD size and name */ 677 u_short mflags; /* match flags */ 678 short unused1; /* (unused) padding for v6_flag */ 679 u_int v6_flag; /* is this v6 or not */ 680 struct in6_addr addr6; /* match address (v6) */ 681 struct in6_addr mask6; /* match mask (v6) */ 682 }; 683 684 685 /* 686 * Structure used for returning monitor data 687 */ 688 struct info_monitor_1 { 689 u_int32 avg_int; /* avg s between packets from this host */ 690 u_int32 last_int; /* s since we last received a packet */ 691 u_int32 restr; /* restrict bits (was named lastdrop) */ 692 u_int32 count; /* count of packets received */ 693 u_int32 addr; /* host address V4 style */ 694 u_int32 daddr; /* destination host address */ 695 u_int32 flags; /* flags about destination */ 696 u_short port; /* port number of last reception */ 697 u_char mode; /* mode of last packet */ 698 u_char version; /* version number of last packet */ 699 u_int v6_flag; /* is this v6 or not */ 700 u_int unused1; /* unused, padding for addr6 */ 701 struct in6_addr addr6; /* host address V6 style */ 702 struct in6_addr daddr6; /* host address V6 style */ 703 }; 704 705 706 /* 707 * Structure used for returning monitor data 708 */ 709 struct info_monitor { 710 u_int32 avg_int; /* avg s between packets from this host */ 711 u_int32 last_int; /* s since we last received a packet */ 712 u_int32 restr; /* restrict bits (was named lastdrop) */ 713 u_int32 count; /* count of packets received */ 714 u_int32 addr; /* host address */ 715 u_short port; /* port number of last reception */ 716 u_char mode; /* mode of last packet */ 717 u_char version; /* version number of last packet */ 718 u_int v6_flag; /* is this v6 or not */ 719 u_int unused1; /* unused, padding for addr6 */ 720 struct in6_addr addr6; /* host v6 address */ 721 }; 722 723 /* 724 * Structure used for returning monitor data (old format) 725 */ 726 struct old_info_monitor { 727 u_int32 lasttime; /* last packet from this host */ 728 u_int32 firsttime; /* first time we received a packet */ 729 u_int32 count; /* count of packets received */ 730 u_int32 addr; /* host address */ 731 u_short port; /* port number of last reception */ 732 u_char mode; /* mode of last packet */ 733 u_char version; /* version number of last packet */ 734 u_int v6_flag; /* is this v6 or not */ 735 struct in6_addr addr6; /* host address (v6)*/ 736 }; 737 738 /* 739 * Structure used for passing indication of flags to clear 740 */ 741 struct reset_flags { 742 u_int32 flags; 743 }; 744 745 #define RESET_FLAG_ALLPEERS 0x01 746 #define RESET_FLAG_IO 0x02 747 #define RESET_FLAG_SYS 0x04 748 #define RESET_FLAG_MEM 0x08 749 #define RESET_FLAG_TIMER 0x10 750 #define RESET_FLAG_AUTH 0x20 751 #define RESET_FLAG_CTL 0x40 752 753 #define RESET_ALLFLAGS ( \ 754 RESET_FLAG_ALLPEERS | \ 755 RESET_FLAG_IO | \ 756 RESET_FLAG_SYS | \ 757 RESET_FLAG_MEM | \ 758 RESET_FLAG_TIMER | \ 759 RESET_FLAG_AUTH | \ 760 RESET_FLAG_CTL \ 761 ) 762 763 /* 764 * Structure used to return information concerning the authentication 765 * module. 766 */ 767 struct info_auth { 768 u_int32 timereset; /* time counters were reset */ 769 u_int32 numkeys; /* number of keys we know */ 770 u_int32 numfreekeys; /* number of free keys */ 771 u_int32 keylookups; /* calls to authhavekey() */ 772 u_int32 keynotfound; /* requested key unknown */ 773 u_int32 encryptions; /* number of encryptions */ 774 u_int32 decryptions; /* number of decryptions */ 775 u_int32 expired; /* number of expired keys */ 776 u_int32 keyuncached; /* calls to encrypt/decrypt with uncached key */ 777 }; 778 779 780 /* 781 * Structure used to pass trap information to the client 782 */ 783 struct info_trap { 784 u_int32 local_address; /* local interface addres (v4) */ 785 u_int32 trap_address; /* remote client's addres (v4) */ 786 u_short trap_port; /* remote port number */ 787 u_short sequence; /* sequence number */ 788 u_int32 settime; /* time trap last set */ 789 u_int32 origtime; /* time trap originally set */ 790 u_int32 resets; /* number of resets on this trap */ 791 u_int32 flags; /* trap flags, as defined in ntp_control.h */ 792 u_int v6_flag; /* is this v6 or not */ 793 struct in6_addr local_address6; /* local interface address (v6) */ 794 struct in6_addr trap_address6; /* remote client's address (v6) */ 795 }; 796 797 /* 798 * Structure used to pass add/clear trap information to the client 799 */ 800 struct conf_trap { 801 u_int32 local_address; /* remote client's address */ 802 u_int32 trap_address; /* local interface address */ 803 u_short trap_port; /* remote client's port */ 804 u_short unused; /* (unused) */ 805 u_int v6_flag; /* is this v6 or not */ 806 struct in6_addr local_address6; /* local interface address (v6) */ 807 struct in6_addr trap_address6; /* remote client's address (v6) */ 808 }; 809 810 811 /* 812 * Structure used to return statistics from the control module 813 */ 814 struct info_control { 815 u_int32 ctltimereset; 816 u_int32 numctlreq; /* number of requests we've received */ 817 u_int32 numctlbadpkts; /* number of bad control packets */ 818 u_int32 numctlresponses; /* # resp packets sent */ 819 u_int32 numctlfrags; /* # of fragments sent */ 820 u_int32 numctlerrors; /* number of error responses sent */ 821 u_int32 numctltooshort; /* number of too short input packets */ 822 u_int32 numctlinputresp; /* number of responses on input */ 823 u_int32 numctlinputfrag; /* number of fragments on input */ 824 u_int32 numctlinputerr; /* # input pkts with err bit set */ 825 u_int32 numctlbadoffset; /* # input pkts with nonzero offset */ 826 u_int32 numctlbadversion; /* # input pkts with unknown version */ 827 u_int32 numctldatatooshort; /* data too short for count */ 828 u_int32 numctlbadop; /* bad op code found in packet */ 829 u_int32 numasyncmsgs; /* # async messages we've sent */ 830 }; 831 832 833 /* 834 * Structure used to return clock information 835 */ 836 struct info_clock { 837 u_int32 clockadr; 838 u_char type; 839 u_char flags; 840 u_char lastevent; 841 u_char currentstatus; 842 u_int32 polls; 843 u_int32 noresponse; 844 u_int32 badformat; 845 u_int32 baddata; 846 u_int32 timestarted; 847 l_fp fudgetime1; 848 l_fp fudgetime2; 849 int32 fudgeval1; 850 u_int32 fudgeval2; 851 }; 852 853 854 /* 855 * Structure used for setting clock fudge factors 856 */ 857 struct conf_fudge { 858 u_int32 clockadr; 859 u_int32 which; 860 l_fp fudgetime; 861 u_int32 fudgeval_flags; 862 }; 863 864 #define FUDGE_TIME1 1 865 #define FUDGE_TIME2 2 866 #define FUDGE_VAL1 3 867 #define FUDGE_VAL2 4 868 #define FUDGE_FLAGS 5 869 870 871 /* 872 * Structure used for returning clock debugging info 873 */ 874 #define NUMCBUGVALUES 16 875 #define NUMCBUGTIMES 32 876 877 struct info_clkbug { 878 u_int32 clockadr; 879 u_char nvalues; 880 u_char ntimes; 881 u_short svalues; 882 u_int32 stimes; 883 u_int32 values[NUMCBUGVALUES]; 884 l_fp times[NUMCBUGTIMES]; 885 }; 886 887 /* 888 * Structure used for returning kernel pll/PPS information 889 */ 890 struct info_kernel { 891 int32 offset; 892 int32 freq; 893 int32 maxerror; 894 int32 esterror; 895 u_short status; 896 u_short shift; 897 int32 constant; 898 int32 precision; 899 int32 tolerance; 900 901 /* 902 * Variables used only if PPS signal discipline is implemented 903 */ 904 int32 ppsfreq; 905 int32 jitter; 906 int32 stabil; 907 int32 jitcnt; 908 int32 calcnt; 909 int32 errcnt; 910 int32 stbcnt; 911 }; 912 913 /* 914 * interface statistics 915 */ 916 struct info_if_stats { 917 union addrun unaddr; /* address */ 918 union addrun unbcast; /* broadcast */ 919 union addrun unmask; /* mask */ 920 u_int32 v6_flag; /* is this v6 */ 921 char name[32]; /* name of interface */ 922 int32 flags; /* interface flags */ 923 int32 last_ttl; /* last TTL specified */ 924 int32 num_mcast; /* No. of IP addresses in multicast socket */ 925 int32 received; /* number of incoming packets */ 926 int32 sent; /* number of outgoing packets */ 927 int32 notsent; /* number of send failures */ 928 int32 uptime; /* number of seconds this interface was active */ 929 u_int32 scopeid; /* Scope used for Multicasting */ 930 u_int32 ifindex; /* interface index - from system */ 931 u_int32 ifnum; /* sequential interface number */ 932 u_int32 peercnt; /* number of peers referencinf this interface - informational only */ 933 u_short family; /* Address family */ 934 u_char ignore_packets; /* Specify whether the packet should be ignored */ 935 u_char action; /* reason the item is listed */ 936 int32 _filler0; /* pad to a 64 bit size boundary */ 937 }; 938 939 #define IFS_EXISTS 1 /* just exists */ 940 #define IFS_CREATED 2 /* was just created */ 941 #define IFS_DELETED 3 /* was just delete */ 942 943 /* 944 * Info returned with IP -> hostname lookup 945 */ 946 /* 144 might need to become 32, matching data[] member of req_pkt */ 947 #define NTP_MAXHOSTNAME (32 - sizeof(u_int32) - sizeof(u_short)) 948 struct info_dns_assoc { 949 u_int32 peeraddr; /* peer address (HMS: being careful...) */ 950 associd_t associd; /* association ID */ 951 char hostname[NTP_MAXHOSTNAME]; /* hostname */ 952 }; 953 954 /* 955 * function declarations 956 */ 957 int get_packet_mode(struct recvbuf *rbufp); /* Return packet mode */ 958 959 #endif /* NTP_REQUEST_H */ 960