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 REQ_NTP_SOURCE_NAME 65
106 #define REQ_RESET_SOURCES 66
107 #define REQ_AUTH_DATA 67
108 #define REQ_CLIENT_ACCESSES_BY_INDEX3 68
109 #define N_REQUEST_TYPES 69
111 /* Structure used to exchange timespecs independent of time_t size */
113 uint32_t tv_sec_high
;
118 /* This is used in tv_sec_high for 32-bit timestamps */
119 #define TV_NOHIGHSEC 0x7fffffff
121 /* 32-bit floating-point format consisting of 7-bit signed exponent
122 and 25-bit signed coefficient without hidden bit.
123 The result is calculated as: 2^(exp - 25) * coef */
128 /* The EOR (end of record) fields are used by the offsetof operator in
129 pktlength.c, to get the number of bytes that ought to be
130 transmitted for each packet type. */
151 int32_t n_good_samples
;
152 int32_t n_total_samples
;
160 } REQ_Modify_Minpoll
;
166 } REQ_Modify_Maxpoll
;
177 } REQ_Modify_Maxdelay
;
181 Float new_max_delay_ratio
;
183 } REQ_Modify_Maxdelayratio
;
187 Float new_max_delay_dev_ratio
;
189 } REQ_Modify_Maxdelaydevratio
;
193 int32_t new_min_stratum
;
195 } REQ_Modify_Minstratum
;
199 int32_t new_poll_target
;
201 } REQ_Modify_Polltarget
;
204 Float new_max_update_skew
;
206 } REQ_Modify_Maxupdateskew
;
212 } REQ_Modify_Makestep
;
253 /* Source types in NTP source requests */
254 #define REQ_ADDSRC_SERVER 1
255 #define REQ_ADDSRC_PEER 2
256 #define REQ_ADDSRC_POOL 3
258 /* Flags used in NTP source requests */
259 #define REQ_ADDSRC_ONLINE 0x1
260 #define REQ_ADDSRC_AUTOOFFLINE 0x2
261 #define REQ_ADDSRC_IBURST 0x4
262 #define REQ_ADDSRC_PREFER 0x8
263 #define REQ_ADDSRC_NOSELECT 0x10
264 #define REQ_ADDSRC_TRUST 0x20
265 #define REQ_ADDSRC_REQUIRE 0x40
266 #define REQ_ADDSRC_INTERLEAVED 0x80
267 #define REQ_ADDSRC_BURST 0x100
268 #define REQ_ADDSRC_NTS 0x200
276 int32_t presend_minpoll
;
277 uint32_t min_stratum
;
278 uint32_t poll_target
;
280 uint32_t max_sources
;
286 Float max_delay_ratio
;
287 Float max_delay_dev_ratio
;
292 int32_t filter_length
;
293 uint32_t reserved
[3];
318 /* This is based on the response size rather than the
320 #define MAX_CLIENT_ACCESSES 8
323 uint32_t first_index
;
328 } REQ_ClientAccessesByIndex
;
338 } REQ_ReselectDistance
;
340 #define REQ_SMOOTHTIME_RESET 0
341 #define REQ_SMOOTHTIME_ACTIVATE 1
363 /* ================================================== */
365 #define PKT_TYPE_CMD_REQUEST 1
366 #define PKT_TYPE_CMD_REPLY 2
368 /* This version number needs to be incremented whenever the packet
369 size and/or the format of any of the existing messages is changed.
370 Other changes, e.g. new command types, should be handled cleanly by
371 client.c and cmdmon.c anyway, so the version can stay the same.
373 Version 1 : original version with fixed size packets
375 Version 2 : both command and reply packet sizes made capable of
376 being variable length.
378 Version 3 : NTP_Source message lengthened (auto_offline)
380 Version 4 : IPv6 addressing added, 64-bit time values, sourcestats
381 and tracking reports extended, added flags to NTP source request,
382 trimmed source report, replaced fixed-point format with floating-point
383 and used also instead of integer microseconds, new commands: modify stratum,
384 modify polltarget, modify maxdelaydevratio, reselect, reselectdistance
386 Version 5 : auth data moved to the end of the packet to allow hashes with
387 different sizes, extended sources, tracking and activity reports, dropped
388 subnets accessed and client accesses
390 Version 6 : added padding to requests to prevent amplification attack,
391 changed maximum number of samples in manual list to 16, new commands: modify
392 makestep, smoothing, smoothtime
394 Support for authentication was removed later in version 6 of the protocol
395 and commands that required authentication are allowed only locally over Unix
398 Version 6 (no authentication) : changed format of client accesses by index
399 (using new request/reply types) and manual timestamp, added new fields and
400 flags to NTP source request and report, made length of manual list constant,
401 added new commands: ntpdata, refresh, serverstats, shutdown
404 #define PROTO_VERSION_NUMBER 6
406 /* The oldest protocol versions that are compatible enough with the current
407 version to report a version mismatch for the server and the client */
408 #define PROTO_VERSION_MISMATCH_COMPAT_SERVER 5
409 #define PROTO_VERSION_MISMATCH_COMPAT_CLIENT 4
411 /* The first protocol version using padding in requests */
412 #define PROTO_VERSION_PADDING 6
414 /* The maximum length of padding in request packet, currently
415 defined by MANUAL_LIST */
416 #define MAX_PADDING_LENGTH 396
418 /* ================================================== */
421 uint8_t version
; /* Protocol version */
422 uint8_t pkt_type
; /* What sort of packet this is */
425 uint16_t command
; /* Which command is being issued */
426 uint16_t attempt
; /* How many resends the client has done
427 (count up from zero for same sequence
429 uint32_t sequence
; /* Client's sequence number */
438 REQ_Modify_Minpoll modify_minpoll
;
439 REQ_Modify_Maxpoll modify_maxpoll
;
441 REQ_Modify_Maxdelay modify_maxdelay
;
442 REQ_Modify_Maxdelayratio modify_maxdelayratio
;
443 REQ_Modify_Maxdelaydevratio modify_maxdelaydevratio
;
444 REQ_Modify_Minstratum modify_minstratum
;
445 REQ_Modify_Polltarget modify_polltarget
;
446 REQ_Modify_Maxupdateskew modify_maxupdateskew
;
447 REQ_Modify_Makestep modify_makestep
;
452 REQ_Source_Data source_data
;
453 REQ_Allow_Deny allow_deny
;
454 REQ_Ac_Check ac_check
;
455 REQ_NTP_Source ntp_source
;
456 REQ_Del_Source del_source
;
459 REQ_Sourcestats sourcestats
;
460 REQ_ClientAccessesByIndex client_accesses_by_index
;
461 REQ_ManualDelete manual_delete
;
462 REQ_ReselectDistance reselect_distance
;
463 REQ_SmoothTime smoothtime
;
464 REQ_NTPData ntp_data
;
465 REQ_NTPSourceName ntp_source_name
;
466 REQ_AuthData auth_data
;
467 } data
; /* Command specific parameters */
469 /* Padding used to prevent traffic amplification. It only defines the
470 maximum size of the packet, there is no hole after the data field. */
471 uint8_t padding
[MAX_PADDING_LENGTH
];
475 /* ================================================== */
476 /* Authority codes for command types */
478 #define PERMIT_OPEN 0
479 #define PERMIT_LOCAL 1
480 #define PERMIT_AUTH 2
482 /* ================================================== */
486 #define RPY_N_SOURCES 2
487 #define RPY_SOURCE_DATA 3
488 #define RPY_MANUAL_TIMESTAMP 4
489 #define RPY_TRACKING 5
490 #define RPY_SOURCESTATS 6
492 #define RPY_SUBNETS_ACCESSED 8
493 #define RPY_CLIENT_ACCESSES 9
494 #define RPY_CLIENT_ACCESSES_BY_INDEX 10
495 #define RPY_MANUAL_LIST 11
496 #define RPY_ACTIVITY 12
497 #define RPY_SMOOTHING 13
498 #define RPY_SERVER_STATS 14
499 #define RPY_CLIENT_ACCESSES_BY_INDEX2 15
500 #define RPY_NTP_DATA 16
501 #define RPY_MANUAL_TIMESTAMP2 17
502 #define RPY_MANUAL_LIST2 18
503 #define RPY_NTP_SOURCE_NAME 19
504 #define RPY_AUTH_DATA 20
505 #define N_REPLY_TYPES 21
508 #define STT_SUCCESS 0
511 #define STT_INVALID 3
512 #define STT_NOSUCHSOURCE 4
513 #define STT_INVALIDTS 5
514 #define STT_NOTENABLED 6
515 #define STT_BADSUBNET 7
516 #define STT_ACCESSALLOWED 8
517 #define STT_ACCESSDENIED 9
519 #define STT_NOHOSTACCESS 10
520 #define STT_SOURCEALREADYKNOWN 11
521 #define STT_TOOMANYSOURCES 12
523 #define STT_BADRTCFILE 14
524 #define STT_INACTIVE 15
525 #define STT_BADSAMPLE 16
526 #define STT_INVALIDAF 17
527 #define STT_BADPKTVERSION 18
528 #define STT_BADPKTLENGTH 19
529 #define STT_INVALIDNAME 21
540 #define RPY_SD_MD_CLIENT 0
541 #define RPY_SD_MD_PEER 1
542 #define RPY_SD_MD_REF 2
544 #define RPY_SD_ST_SYNC 0
545 #define RPY_SD_ST_UNREACH 1
546 #define RPY_SD_ST_FALSETICKER 2
547 #define RPY_SD_ST_JITTERY 3
548 #define RPY_SD_ST_CANDIDATE 4
549 #define RPY_SD_ST_OUTLIER 5
551 #define RPY_SD_FLAG_NOSELECT 0x1
552 #define RPY_SD_FLAG_PREFER 0x2
553 #define RPY_SD_FLAG_TRUST 0x4
554 #define RPY_SD_FLAG_REQUIRE 0x8
563 uint16_t reachability
;
564 uint32_t since_sample
;
565 Float orig_latest_meas
;
567 Float latest_meas_err
;
575 uint16_t leap_status
;
577 Float current_correction
;
581 Float resid_freq_ppm
;
584 Float root_dispersion
;
585 Float last_update_interval
;
594 uint32_t span_seconds
;
596 Float resid_freq_ppm
;
599 Float est_offset_err
;
607 uint32_t span_seconds
;
608 Float rtc_seconds_fast
;
609 Float rtc_gain_rate_ppm
;
618 } RPY_ManualTimestamp
;
628 int8_t ntp_timeout_interval
;
630 uint32_t last_ntp_hit_ago
;
631 uint32_t last_cmd_hit_ago
;
632 } RPY_ClientAccesses_Client
;
635 uint32_t n_indices
; /* how many indices there are in the server's table */
636 uint32_t next_index
; /* the index 1 beyond those processed on this call */
637 uint32_t n_clients
; /* the number of valid entries in the following array */
638 RPY_ClientAccesses_Client clients
[MAX_CLIENT_ACCESSES
];
640 } RPY_ClientAccessesByIndex
;
651 #define MAX_MANUAL_LIST_SAMPLES 16
658 } RPY_ManualListSample
;
662 RPY_ManualListSample samples
[MAX_MANUAL_LIST_SAMPLES
];
669 int32_t burst_online
;
670 int32_t burst_offline
;
675 #define RPY_SMT_FLAG_ACTIVE 0x1
676 #define RPY_SMT_FLAG_LEAPONLY 0x2
683 Float last_update_ago
;
684 Float remaining_time
;
688 #define RPY_NTP_FLAGS_TESTS 0x3ff
689 #define RPY_NTP_FLAG_INTERLEAVED 0x4000
690 #define RPY_NTP_FLAG_AUTHENTICATED 0x8000
695 uint16_t remote_port
;
703 Float root_dispersion
;
708 Float peer_dispersion
;
710 Float jitter_asymmetry
;
714 uint32_t total_tx_count
;
715 uint32_t total_rx_count
;
716 uint32_t total_valid_count
;
717 uint32_t reserved
[4];
726 #define RPY_AD_MD_NONE 0
727 #define RPY_AD_MD_SYMMETRIC 1
728 #define RPY_AD_MD_NTS 2
735 uint16_t ke_attempts
;
736 uint32_t last_ke_ago
;
747 uint16_t command
; /* Which command is being replied to */
748 uint16_t reply
; /* Which format of reply this is */
749 uint16_t status
; /* Status of command processing */
750 uint16_t pad1
; /* Padding for compatibility and 4 byte alignment */
753 uint32_t sequence
; /* Echo of client's sequence number */
759 RPY_N_Sources n_sources
;
760 RPY_Source_Data source_data
;
761 RPY_ManualTimestamp manual_timestamp
;
762 RPY_Tracking tracking
;
763 RPY_Sourcestats sourcestats
;
765 RPY_ClientAccessesByIndex client_accesses_by_index
;
766 RPY_ServerStats server_stats
;
767 RPY_ManualList manual_list
;
768 RPY_Activity activity
;
769 RPY_Smoothing smoothing
;
770 RPY_NTPData ntp_data
;
771 RPY_NTPSourceName ntp_source_name
;
772 RPY_AuthData auth_data
;
773 } data
; /* Reply specific parameters */
777 /* ================================================== */
779 #endif /* GOT_CANDM_H */