2 chronyd/chronyc - Programs for keeping computer clocks accurate.
4 **********************************************************************
5 * Copyright (C) Richard P. Curnow 1997-2003
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 **********************************************************************
22 =======================================================================
24 Definitions for the network protocol used for command and monitoring
33 #include "addressing.h"
35 /* This is the default port to use for CANDM, if no alternative is
37 #define DEFAULT_CANDM_PORT 323
44 #define REQ_MODIFY_MINPOLL 4
45 #define REQ_MODIFY_MAXPOLL 5
47 #define REQ_MODIFY_MAXDELAY 7
48 #define REQ_MODIFY_MAXDELAYRATIO 8
49 #define REQ_MODIFY_MAXUPDATESKEW 9
51 #define REQ_SETTIME 11
54 #define REQ_N_SOURCES 14
55 #define REQ_SOURCE_DATA 15
58 #define REQ_ALLOWALL 18
60 #define REQ_DENYALL 20
61 #define REQ_CMDALLOW 21
62 #define REQ_CMDALLOWALL 22
63 #define REQ_CMDDENY 23
64 #define REQ_CMDDENYALL 24
65 #define REQ_ACCHECK 25
66 #define REQ_CMDACCHECK 26
67 #define REQ_ADD_SERVER 27
68 #define REQ_ADD_PEER 28
69 #define REQ_DEL_SOURCE 29
70 #define REQ_WRITERTC 30
72 #define REQ_DOFFSET 32
73 #define REQ_TRACKING 33
74 #define REQ_SOURCESTATS 34
75 #define REQ_RTCREPORT 35
76 #define REQ_TRIMRTC 36
77 #define REQ_CYCLELOGS 37
78 #define REQ_SUBNETS_ACCESSED 38
79 #define REQ_CLIENT_ACCESSES 39
80 #define REQ_CLIENT_ACCESSES_BY_INDEX 40
81 #define REQ_MANUAL_LIST 41
82 #define REQ_MANUAL_DELETE 42
83 #define REQ_MAKESTEP 43
84 #define REQ_ACTIVITY 44
85 #define REQ_MODIFY_MINSTRATUM 45
86 #define REQ_MODIFY_POLLTARGET 46
87 #define REQ_MODIFY_MAXDELAYDEVRATIO 47
88 #define REQ_RESELECT 48
89 #define REQ_RESELECTDISTANCE 49
90 #define REQ_MODIFY_MAKESTEP 50
91 #define REQ_SMOOTHING 51
92 #define REQ_SMOOTHTIME 52
93 #define REQ_REFRESH 53
94 #define REQ_SERVER_STATS 54
95 #define REQ_CLIENT_ACCESSES_BY_INDEX2 55
97 #define REQ_NTP_DATA 57
98 #define REQ_ADD_SERVER2 58
99 #define REQ_ADD_PEER2 59
100 #define REQ_ADD_SERVER3 60
101 #define REQ_ADD_PEER3 61
102 #define REQ_SHUTDOWN 62
103 #define REQ_ONOFFLINE 63
104 #define REQ_ADD_SOURCE 64
105 #define N_REQUEST_TYPES 65
107 /* Structure used to exchange timespecs independent of time_t size */
109 uint32_t tv_sec_high
;
114 /* This is used in tv_sec_high for 32-bit timestamps */
115 #define TV_NOHIGHSEC 0x7fffffff
117 /* 32-bit floating-point format consisting of 7-bit signed exponent
118 and 25-bit signed coefficient without hidden bit.
119 The result is calculated as: 2^(exp - 25) * coef */
124 /* The EOR (end of record) fields are used by the offsetof operator in
125 pktlength.c, to get the number of bytes that ought to be
126 transmitted for each packet type. */
147 int32_t n_good_samples
;
148 int32_t n_total_samples
;
156 } REQ_Modify_Minpoll
;
162 } REQ_Modify_Maxpoll
;
173 } REQ_Modify_Maxdelay
;
177 Float new_max_delay_ratio
;
179 } REQ_Modify_Maxdelayratio
;
183 Float new_max_delay_dev_ratio
;
185 } REQ_Modify_Maxdelaydevratio
;
189 int32_t new_min_stratum
;
191 } REQ_Modify_Minstratum
;
195 int32_t new_poll_target
;
197 } REQ_Modify_Polltarget
;
200 Float new_max_update_skew
;
202 } REQ_Modify_Maxupdateskew
;
208 } REQ_Modify_Makestep
;
249 /* Source types in NTP source requests */
250 #define REQ_ADDSRC_SERVER 1
251 #define REQ_ADDSRC_PEER 2
253 /* Flags used in NTP source requests */
254 #define REQ_ADDSRC_ONLINE 0x1
255 #define REQ_ADDSRC_AUTOOFFLINE 0x2
256 #define REQ_ADDSRC_IBURST 0x4
257 #define REQ_ADDSRC_PREFER 0x8
258 #define REQ_ADDSRC_NOSELECT 0x10
259 #define REQ_ADDSRC_TRUST 0x20
260 #define REQ_ADDSRC_REQUIRE 0x40
261 #define REQ_ADDSRC_INTERLEAVED 0x80
262 #define REQ_ADDSRC_BURST 0x100
270 int32_t presend_minpoll
;
271 uint32_t min_stratum
;
272 uint32_t poll_target
;
274 uint32_t max_sources
;
279 Float max_delay_ratio
;
280 Float max_delay_dev_ratio
;
285 int32_t filter_length
;
286 uint32_t reserved
[3];
311 /* This is based on the response size rather than the
313 #define MAX_CLIENT_ACCESSES 8
316 uint32_t first_index
;
319 } REQ_ClientAccessesByIndex
;
329 } REQ_ReselectDistance
;
331 #define REQ_SMOOTHTIME_RESET 0
332 #define REQ_SMOOTHTIME_ACTIVATE 1
344 /* ================================================== */
346 #define PKT_TYPE_CMD_REQUEST 1
347 #define PKT_TYPE_CMD_REPLY 2
349 /* This version number needs to be incremented whenever the packet
350 size and/or the format of any of the existing messages is changed.
351 Other changes, e.g. new command types, should be handled cleanly by
352 client.c and cmdmon.c anyway, so the version can stay the same.
354 Version 1 : original version with fixed size packets
356 Version 2 : both command and reply packet sizes made capable of
357 being variable length.
359 Version 3 : NTP_Source message lengthened (auto_offline)
361 Version 4 : IPv6 addressing added, 64-bit time values, sourcestats
362 and tracking reports extended, added flags to NTP source request,
363 trimmed source report, replaced fixed-point format with floating-point
364 and used also instead of integer microseconds, new commands: modify stratum,
365 modify polltarget, modify maxdelaydevratio, reselect, reselectdistance
367 Version 5 : auth data moved to the end of the packet to allow hashes with
368 different sizes, extended sources, tracking and activity reports, dropped
369 subnets accessed and client accesses
371 Version 6 : added padding to requests to prevent amplification attack,
372 changed maximum number of samples in manual list to 16, new commands: modify
373 makestep, smoothing, smoothtime
375 Support for authentication was removed later in version 6 of the protocol
376 and commands that required authentication are allowed only locally over Unix
379 Version 6 (no authentication) : changed format of client accesses by index
380 (using new request/reply types) and manual timestamp, added new fields and
381 flags to NTP source request and report, made length of manual list constant,
382 added new commands: ntpdata, refresh, serverstats, shutdown
385 #define PROTO_VERSION_NUMBER 6
387 /* The oldest protocol versions that are compatible enough with the current
388 version to report a version mismatch for the server and the client */
389 #define PROTO_VERSION_MISMATCH_COMPAT_SERVER 5
390 #define PROTO_VERSION_MISMATCH_COMPAT_CLIENT 4
392 /* The first protocol version using padding in requests */
393 #define PROTO_VERSION_PADDING 6
395 /* The maximum length of padding in request packet, currently
396 defined by MANUAL_LIST */
397 #define MAX_PADDING_LENGTH 396
399 /* ================================================== */
402 uint8_t version
; /* Protocol version */
403 uint8_t pkt_type
; /* What sort of packet this is */
406 uint16_t command
; /* Which command is being issued */
407 uint16_t attempt
; /* How many resends the client has done
408 (count up from zero for same sequence
410 uint32_t sequence
; /* Client's sequence number */
419 REQ_Modify_Minpoll modify_minpoll
;
420 REQ_Modify_Maxpoll modify_maxpoll
;
422 REQ_Modify_Maxdelay modify_maxdelay
;
423 REQ_Modify_Maxdelayratio modify_maxdelayratio
;
424 REQ_Modify_Maxdelaydevratio modify_maxdelaydevratio
;
425 REQ_Modify_Minstratum modify_minstratum
;
426 REQ_Modify_Polltarget modify_polltarget
;
427 REQ_Modify_Maxupdateskew modify_maxupdateskew
;
428 REQ_Modify_Makestep modify_makestep
;
433 REQ_Source_Data source_data
;
434 REQ_Allow_Deny allow_deny
;
435 REQ_Ac_Check ac_check
;
436 REQ_NTP_Source ntp_source
;
437 REQ_Del_Source del_source
;
440 REQ_Sourcestats sourcestats
;
441 REQ_ClientAccessesByIndex client_accesses_by_index
;
442 REQ_ManualDelete manual_delete
;
443 REQ_ReselectDistance reselect_distance
;
444 REQ_SmoothTime smoothtime
;
445 REQ_NTPData ntp_data
;
446 } data
; /* Command specific parameters */
448 /* Padding used to prevent traffic amplification. It only defines the
449 maximum size of the packet, there is no hole after the data field. */
450 uint8_t padding
[MAX_PADDING_LENGTH
];
454 /* ================================================== */
455 /* Authority codes for command types */
457 #define PERMIT_OPEN 0
458 #define PERMIT_LOCAL 1
459 #define PERMIT_AUTH 2
461 /* ================================================== */
465 #define RPY_N_SOURCES 2
466 #define RPY_SOURCE_DATA 3
467 #define RPY_MANUAL_TIMESTAMP 4
468 #define RPY_TRACKING 5
469 #define RPY_SOURCESTATS 6
471 #define RPY_SUBNETS_ACCESSED 8
472 #define RPY_CLIENT_ACCESSES 9
473 #define RPY_CLIENT_ACCESSES_BY_INDEX 10
474 #define RPY_MANUAL_LIST 11
475 #define RPY_ACTIVITY 12
476 #define RPY_SMOOTHING 13
477 #define RPY_SERVER_STATS 14
478 #define RPY_CLIENT_ACCESSES_BY_INDEX2 15
479 #define RPY_NTP_DATA 16
480 #define RPY_MANUAL_TIMESTAMP2 17
481 #define RPY_MANUAL_LIST2 18
482 #define N_REPLY_TYPES 19
485 #define STT_SUCCESS 0
488 #define STT_INVALID 3
489 #define STT_NOSUCHSOURCE 4
490 #define STT_INVALIDTS 5
491 #define STT_NOTENABLED 6
492 #define STT_BADSUBNET 7
493 #define STT_ACCESSALLOWED 8
494 #define STT_ACCESSDENIED 9
496 #define STT_NOHOSTACCESS 10
497 #define STT_SOURCEALREADYKNOWN 11
498 #define STT_TOOMANYSOURCES 12
500 #define STT_BADRTCFILE 14
501 #define STT_INACTIVE 15
502 #define STT_BADSAMPLE 16
503 #define STT_INVALIDAF 17
504 #define STT_BADPKTVERSION 18
505 #define STT_BADPKTLENGTH 19
506 #define STT_INVALIDNAME 21
517 #define RPY_SD_MD_CLIENT 0
518 #define RPY_SD_MD_PEER 1
519 #define RPY_SD_MD_REF 2
521 #define RPY_SD_ST_SYNC 0
522 #define RPY_SD_ST_UNREACH 1
523 #define RPY_SD_ST_FALSETICKER 2
524 #define RPY_SD_ST_JITTERY 3
525 #define RPY_SD_ST_CANDIDATE 4
526 #define RPY_SD_ST_OUTLIER 5
528 #define RPY_SD_FLAG_NOSELECT 0x1
529 #define RPY_SD_FLAG_PREFER 0x2
530 #define RPY_SD_FLAG_TRUST 0x4
531 #define RPY_SD_FLAG_REQUIRE 0x8
540 uint16_t reachability
;
541 uint32_t since_sample
;
542 Float orig_latest_meas
;
544 Float latest_meas_err
;
552 uint16_t leap_status
;
554 Float current_correction
;
558 Float resid_freq_ppm
;
561 Float root_dispersion
;
562 Float last_update_interval
;
571 uint32_t span_seconds
;
573 Float resid_freq_ppm
;
576 Float est_offset_err
;
584 uint32_t span_seconds
;
585 Float rtc_seconds_fast
;
586 Float rtc_gain_rate_ppm
;
595 } RPY_ManualTimestamp
;
605 int8_t ntp_timeout_interval
;
607 uint32_t last_ntp_hit_ago
;
608 uint32_t last_cmd_hit_ago
;
609 } RPY_ClientAccesses_Client
;
612 uint32_t n_indices
; /* how many indices there are in the server's table */
613 uint32_t next_index
; /* the index 1 beyond those processed on this call */
614 uint32_t n_clients
; /* the number of valid entries in the following array */
615 RPY_ClientAccesses_Client clients
[MAX_CLIENT_ACCESSES
];
617 } RPY_ClientAccessesByIndex
;
628 #define MAX_MANUAL_LIST_SAMPLES 16
635 } RPY_ManualListSample
;
639 RPY_ManualListSample samples
[MAX_MANUAL_LIST_SAMPLES
];
646 int32_t burst_online
;
647 int32_t burst_offline
;
652 #define RPY_SMT_FLAG_ACTIVE 0x1
653 #define RPY_SMT_FLAG_LEAPONLY 0x2
660 Float last_update_ago
;
661 Float remaining_time
;
665 #define RPY_NTP_FLAGS_TESTS 0x3ff
666 #define RPY_NTP_FLAG_INTERLEAVED 0x4000
667 #define RPY_NTP_FLAG_AUTHENTICATED 0x8000
672 uint16_t remote_port
;
680 Float root_dispersion
;
685 Float peer_dispersion
;
687 Float jitter_asymmetry
;
691 uint32_t total_tx_count
;
692 uint32_t total_rx_count
;
693 uint32_t total_valid_count
;
694 uint32_t reserved
[4];
703 uint16_t command
; /* Which command is being replied to */
704 uint16_t reply
; /* Which format of reply this is */
705 uint16_t status
; /* Status of command processing */
706 uint16_t pad1
; /* Padding for compatibility and 4 byte alignment */
709 uint32_t sequence
; /* Echo of client's sequence number */
715 RPY_N_Sources n_sources
;
716 RPY_Source_Data source_data
;
717 RPY_ManualTimestamp manual_timestamp
;
718 RPY_Tracking tracking
;
719 RPY_Sourcestats sourcestats
;
721 RPY_ClientAccessesByIndex client_accesses_by_index
;
722 RPY_ServerStats server_stats
;
723 RPY_ManualList manual_list
;
724 RPY_Activity activity
;
725 RPY_Smoothing smoothing
;
726 RPY_NTPData ntp_data
;
727 } data
; /* Reply specific parameters */
731 /* ================================================== */
733 #endif /* GOT_CANDM_H */