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