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 REQ_SELECT_DATA 69
110 #define REQ_RELOAD_SOURCES 70
111 #define N_REQUEST_TYPES 71
113 /* Structure used to exchange timespecs independent of time_t size */
115 uint32_t tv_sec_high
;
120 /* This is used in tv_sec_high for 32-bit timestamps */
121 #define TV_NOHIGHSEC 0x7fffffff
123 /* 32-bit floating-point format consisting of 7-bit signed exponent
124 and 25-bit signed coefficient without hidden bit.
125 The result is calculated as: 2^(exp - 25) * coef */
130 /* The EOR (end of record) fields are used by the offsetof operator in
131 pktlength.c, to get the number of bytes that ought to be
132 transmitted for each packet type. */
153 int32_t n_good_samples
;
154 int32_t n_total_samples
;
162 } REQ_Modify_Minpoll
;
168 } REQ_Modify_Maxpoll
;
179 } REQ_Modify_Maxdelay
;
183 Float new_max_delay_ratio
;
185 } REQ_Modify_Maxdelayratio
;
189 Float new_max_delay_dev_ratio
;
191 } REQ_Modify_Maxdelaydevratio
;
195 int32_t new_min_stratum
;
197 } REQ_Modify_Minstratum
;
201 int32_t new_poll_target
;
203 } REQ_Modify_Polltarget
;
206 Float new_max_update_skew
;
208 } REQ_Modify_Maxupdateskew
;
214 } REQ_Modify_Makestep
;
255 /* Source types in NTP source requests */
256 #define REQ_ADDSRC_SERVER 1
257 #define REQ_ADDSRC_PEER 2
258 #define REQ_ADDSRC_POOL 3
260 /* Flags used in NTP source requests */
261 #define REQ_ADDSRC_ONLINE 0x1
262 #define REQ_ADDSRC_AUTOOFFLINE 0x2
263 #define REQ_ADDSRC_IBURST 0x4
264 #define REQ_ADDSRC_PREFER 0x8
265 #define REQ_ADDSRC_NOSELECT 0x10
266 #define REQ_ADDSRC_TRUST 0x20
267 #define REQ_ADDSRC_REQUIRE 0x40
268 #define REQ_ADDSRC_INTERLEAVED 0x80
269 #define REQ_ADDSRC_BURST 0x100
270 #define REQ_ADDSRC_NTS 0x200
278 int32_t presend_minpoll
;
279 uint32_t min_stratum
;
280 uint32_t poll_target
;
282 uint32_t max_sources
;
288 Float max_delay_ratio
;
289 Float max_delay_dev_ratio
;
294 int32_t filter_length
;
295 uint32_t reserved
[3];
320 /* This is based on the response size rather than the
322 #define MAX_CLIENT_ACCESSES 8
325 uint32_t first_index
;
330 } REQ_ClientAccessesByIndex
;
340 } REQ_ReselectDistance
;
342 #define REQ_SMOOTHTIME_RESET 0
343 #define REQ_SMOOTHTIME_ACTIVATE 1
370 /* ================================================== */
372 #define PKT_TYPE_CMD_REQUEST 1
373 #define PKT_TYPE_CMD_REPLY 2
375 /* This version number needs to be incremented whenever the packet
376 size and/or the format of any of the existing messages is changed.
377 Other changes, e.g. new command types, should be handled cleanly by
378 client.c and cmdmon.c anyway, so the version can stay the same.
380 Version 1 : original version with fixed size packets
382 Version 2 : both command and reply packet sizes made capable of
383 being variable length.
385 Version 3 : NTP_Source message lengthened (auto_offline)
387 Version 4 : IPv6 addressing added, 64-bit time values, sourcestats
388 and tracking reports extended, added flags to NTP source request,
389 trimmed source report, replaced fixed-point format with floating-point
390 and used also instead of integer microseconds, new commands: modify stratum,
391 modify polltarget, modify maxdelaydevratio, reselect, reselectdistance
393 Version 5 : auth data moved to the end of the packet to allow hashes with
394 different sizes, extended sources, tracking and activity reports, dropped
395 subnets accessed and client accesses
397 Version 6 : added padding to requests to prevent amplification attack,
398 changed maximum number of samples in manual list to 16, new commands: modify
399 makestep, smoothing, smoothtime
401 Support for authentication was removed later in version 6 of the protocol
402 and commands that required authentication are allowed only locally over Unix
405 Version 6 (no authentication) : changed format of client accesses by index
406 (using new request/reply types) and manual timestamp, added new fields and
407 flags to NTP source request and report, made length of manual list constant,
408 added new commands: authdata, ntpdata, onoffline, refresh, reset,
409 selectdata, serverstats, shutdown, sourcename
412 #define PROTO_VERSION_NUMBER 6
414 /* The oldest protocol versions that are compatible enough with the current
415 version to report a version mismatch for the server and the client */
416 #define PROTO_VERSION_MISMATCH_COMPAT_SERVER 5
417 #define PROTO_VERSION_MISMATCH_COMPAT_CLIENT 4
419 /* The first protocol version using padding in requests */
420 #define PROTO_VERSION_PADDING 6
422 /* The maximum length of padding in request packet, currently
423 defined by CLIENT_ACCESSES_BY_INDEX3 */
424 #define MAX_PADDING_LENGTH 484
426 /* ================================================== */
429 uint8_t version
; /* Protocol version */
430 uint8_t pkt_type
; /* What sort of packet this is */
433 uint16_t command
; /* Which command is being issued */
434 uint16_t attempt
; /* How many resends the client has done
435 (count up from zero for same sequence
437 uint32_t sequence
; /* Client's sequence number */
446 REQ_Modify_Minpoll modify_minpoll
;
447 REQ_Modify_Maxpoll modify_maxpoll
;
449 REQ_Modify_Maxdelay modify_maxdelay
;
450 REQ_Modify_Maxdelayratio modify_maxdelayratio
;
451 REQ_Modify_Maxdelaydevratio modify_maxdelaydevratio
;
452 REQ_Modify_Minstratum modify_minstratum
;
453 REQ_Modify_Polltarget modify_polltarget
;
454 REQ_Modify_Maxupdateskew modify_maxupdateskew
;
455 REQ_Modify_Makestep modify_makestep
;
460 REQ_Source_Data source_data
;
461 REQ_Allow_Deny allow_deny
;
462 REQ_Ac_Check ac_check
;
463 REQ_NTP_Source ntp_source
;
464 REQ_Del_Source del_source
;
467 REQ_Sourcestats sourcestats
;
468 REQ_ClientAccessesByIndex client_accesses_by_index
;
469 REQ_ManualDelete manual_delete
;
470 REQ_ReselectDistance reselect_distance
;
471 REQ_SmoothTime smoothtime
;
472 REQ_NTPData ntp_data
;
473 REQ_NTPSourceName ntp_source_name
;
474 REQ_AuthData auth_data
;
475 REQ_SelectData select_data
;
476 } data
; /* Command specific parameters */
478 /* Padding used to prevent traffic amplification. It only defines the
479 maximum size of the packet, there is no hole after the data field. */
480 uint8_t padding
[MAX_PADDING_LENGTH
];
484 /* ================================================== */
485 /* Authority codes for command types */
487 #define PERMIT_OPEN 0
488 #define PERMIT_LOCAL 1
489 #define PERMIT_AUTH 2
491 /* ================================================== */
495 #define RPY_N_SOURCES 2
496 #define RPY_SOURCE_DATA 3
497 #define RPY_MANUAL_TIMESTAMP 4
498 #define RPY_TRACKING 5
499 #define RPY_SOURCESTATS 6
501 #define RPY_SUBNETS_ACCESSED 8
502 #define RPY_CLIENT_ACCESSES 9
503 #define RPY_CLIENT_ACCESSES_BY_INDEX 10
504 #define RPY_MANUAL_LIST 11
505 #define RPY_ACTIVITY 12
506 #define RPY_SMOOTHING 13
507 #define RPY_SERVER_STATS 14
508 #define RPY_CLIENT_ACCESSES_BY_INDEX2 15
509 #define RPY_NTP_DATA 16
510 #define RPY_MANUAL_TIMESTAMP2 17
511 #define RPY_MANUAL_LIST2 18
512 #define RPY_NTP_SOURCE_NAME 19
513 #define RPY_AUTH_DATA 20
514 #define RPY_CLIENT_ACCESSES_BY_INDEX3 21
515 #define RPY_SERVER_STATS2 22
516 #define RPY_SELECT_DATA 23
517 #define N_REPLY_TYPES 24
520 #define STT_SUCCESS 0
523 #define STT_INVALID 3
524 #define STT_NOSUCHSOURCE 4
525 #define STT_INVALIDTS 5
526 #define STT_NOTENABLED 6
527 #define STT_BADSUBNET 7
528 #define STT_ACCESSALLOWED 8
529 #define STT_ACCESSDENIED 9
531 #define STT_NOHOSTACCESS 10
532 #define STT_SOURCEALREADYKNOWN 11
533 #define STT_TOOMANYSOURCES 12
535 #define STT_BADRTCFILE 14
536 #define STT_INACTIVE 15
537 #define STT_BADSAMPLE 16
538 #define STT_INVALIDAF 17
539 #define STT_BADPKTVERSION 18
540 #define STT_BADPKTLENGTH 19
541 #define STT_INVALIDNAME 21
552 #define RPY_SD_MD_CLIENT 0
553 #define RPY_SD_MD_PEER 1
554 #define RPY_SD_MD_REF 2
556 #define RPY_SD_ST_SYNC 0
557 #define RPY_SD_ST_UNREACH 1
558 #define RPY_SD_ST_FALSETICKER 2
559 #define RPY_SD_ST_JITTERY 3
560 #define RPY_SD_ST_CANDIDATE 4
561 #define RPY_SD_ST_OUTLIER 5
570 uint16_t reachability
;
571 uint32_t since_sample
;
572 Float orig_latest_meas
;
574 Float latest_meas_err
;
582 uint16_t leap_status
;
584 Float current_correction
;
588 Float resid_freq_ppm
;
591 Float root_dispersion
;
592 Float last_update_interval
;
601 uint32_t span_seconds
;
603 Float resid_freq_ppm
;
606 Float est_offset_err
;
614 uint32_t span_seconds
;
615 Float rtc_seconds_fast
;
616 Float rtc_gain_rate_ppm
;
625 } RPY_ManualTimestamp
;
638 int8_t ntp_timeout_interval
;
639 uint32_t last_ntp_hit_ago
;
640 uint32_t last_nke_hit_ago
;
641 uint32_t last_cmd_hit_ago
;
642 } RPY_ClientAccesses_Client
;
645 uint32_t n_indices
; /* how many indices there are in the server's table */
646 uint32_t next_index
; /* the index 1 beyond those processed on this call */
647 uint32_t n_clients
; /* the number of valid entries in the following array */
648 RPY_ClientAccesses_Client clients
[MAX_CLIENT_ACCESSES
];
650 } RPY_ClientAccessesByIndex
;
660 uint32_t ntp_auth_hits
;
664 #define MAX_MANUAL_LIST_SAMPLES 16
671 } RPY_ManualListSample
;
675 RPY_ManualListSample samples
[MAX_MANUAL_LIST_SAMPLES
];
682 int32_t burst_online
;
683 int32_t burst_offline
;
688 #define RPY_SMT_FLAG_ACTIVE 0x1
689 #define RPY_SMT_FLAG_LEAPONLY 0x2
696 Float last_update_ago
;
697 Float remaining_time
;
701 #define RPY_NTP_FLAGS_TESTS 0x3ff
702 #define RPY_NTP_FLAG_INTERLEAVED 0x4000
703 #define RPY_NTP_FLAG_AUTHENTICATED 0x8000
708 uint16_t remote_port
;
716 Float root_dispersion
;
721 Float peer_dispersion
;
723 Float jitter_asymmetry
;
727 uint32_t total_tx_count
;
728 uint32_t total_rx_count
;
729 uint32_t total_valid_count
;
730 uint32_t reserved
[4];
739 #define RPY_AD_MD_NONE 0
740 #define RPY_AD_MD_SYMMETRIC 1
741 #define RPY_AD_MD_NTS 2
748 uint16_t ke_attempts
;
749 uint32_t last_ke_ago
;
751 uint16_t cookie_length
;
757 #define RPY_SD_OPTION_NOSELECT 0x1
758 #define RPY_SD_OPTION_PREFER 0x2
759 #define RPY_SD_OPTION_TRUST 0x4
760 #define RPY_SD_OPTION_REQUIRE 0x8
766 uint8_t authentication
;
768 uint16_t conf_options
;
769 uint16_t eff_options
;
770 uint32_t last_sample_ago
;
782 uint16_t command
; /* Which command is being replied to */
783 uint16_t reply
; /* Which format of reply this is */
784 uint16_t status
; /* Status of command processing */
785 uint16_t pad1
; /* Padding for compatibility and 4 byte alignment */
788 uint32_t sequence
; /* Echo of client's sequence number */
794 RPY_N_Sources n_sources
;
795 RPY_Source_Data source_data
;
796 RPY_ManualTimestamp manual_timestamp
;
797 RPY_Tracking tracking
;
798 RPY_Sourcestats sourcestats
;
800 RPY_ClientAccessesByIndex client_accesses_by_index
;
801 RPY_ServerStats server_stats
;
802 RPY_ManualList manual_list
;
803 RPY_Activity activity
;
804 RPY_Smoothing smoothing
;
805 RPY_NTPData ntp_data
;
806 RPY_NTPSourceName ntp_source_name
;
807 RPY_AuthData auth_data
;
808 RPY_SelectData select_data
;
809 } data
; /* Reply specific parameters */
813 /* ================================================== */
815 #endif /* GOT_CANDM_H */