2 $Header: /cvs/src/chrony/candm.h,v 1.40 2003/09/22 21:22:30 richard Exp $
4 =======================================================================
6 chronyd/chronyc - Programs for keeping computer clocks accurate.
8 **********************************************************************
9 * Copyright (C) Richard P. Curnow 1997-2003
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 **********************************************************************
26 =======================================================================
28 Definitions for the network protocol used for command and monitoring
37 #include "addressing.h"
39 /* This is the default port to use for CANDM, if no alternative is
41 #define DEFAULT_CANDM_PORT 323
48 #define REQ_MODIFY_MINPOLL 4
49 #define REQ_MODIFY_MAXPOLL 5
51 #define REQ_MODIFY_MAXDELAY 7
52 #define REQ_MODIFY_MAXDELAYRATIO 8
53 #define REQ_MODIFY_MAXUPDATESKEW 9
55 #define REQ_SETTIME 11
58 #define REQ_N_SOURCES 14
59 #define REQ_SOURCE_DATA 15
62 #define REQ_ALLOWALL 18
64 #define REQ_DENYALL 20
65 #define REQ_CMDALLOW 21
66 #define REQ_CMDALLOWALL 22
67 #define REQ_CMDDENY 23
68 #define REQ_CMDDENYALL 24
69 #define REQ_ACCHECK 25
70 #define REQ_CMDACCHECK 26
71 #define REQ_ADD_SERVER 27
72 #define REQ_ADD_PEER 28
73 #define REQ_DEL_SOURCE 29
74 #define REQ_WRITERTC 30
76 #define REQ_DOFFSET 32
77 #define REQ_TRACKING 33
78 #define REQ_SOURCESTATS 34
79 #define REQ_RTCREPORT 35
80 #define REQ_TRIMRTC 36
81 #define REQ_CYCLELOGS 37
82 #define REQ_SUBNETS_ACCESSED 38
83 #define REQ_CLIENT_ACCESSES 39
84 #define REQ_CLIENT_ACCESSES_BY_INDEX 40
85 #define REQ_MANUAL_LIST 41
86 #define REQ_MANUAL_DELETE 42
87 #define REQ_MAKESTEP 43
88 #define REQ_ACTIVITY 44
89 #define REQ_MODIFY_MINSTRATUM 45
90 #define REQ_MODIFY_POLLTARGET 46
91 #define N_REQUEST_TYPES 47
93 /* Special utoken value used to log on with first exchange being the
94 password. (This time value has long since gone by) */
95 #define SPECIAL_UTOKEN 0x10101010
97 /* Structure used to exchange timevals independent on size of time_t */
104 /* This is used in tv_sec_high for 32-bit timestamps */
105 #define TV_NOHIGHSEC 0x7fffffff
107 /* 32-bit floating-point format consisting of 7-bit signed exponent
108 and 25-bit signed coefficient without hidden bit.
109 The result is calculated as: 2^(exp - 25) * coef */
114 /* The EOR (end of record) fields are used by the offsetof operator in
115 pktlength.c, to get the number of bytes that ought to be
116 transmitted for each packet type. */
133 int32_t n_good_samples
;
134 int32_t n_total_samples
;
142 } REQ_Modify_Minpoll
;
148 } REQ_Modify_Maxpoll
;
159 } REQ_Modify_Maxdelay
;
163 Float new_max_delay_ratio
;
165 } REQ_Modify_Maxdelayratio
;
169 int32_t new_min_stratum
;
171 } REQ_Modify_Minstratum
;
175 int32_t new_poll_target
;
177 } REQ_Modify_Polltarget
;
180 Float new_max_update_skew
;
182 } REQ_Modify_Maxupdateskew
;
229 /* Flags used in NTP source requests */
230 #define REQ_ADDSRC_ONLINE 0x1
231 #define REQ_ADDSRC_AUTOOFFLINE 0x2
232 #define REQ_ADDSRC_IBURST 0x4
233 #define REQ_ADDSRC_PREFER 0x8
234 #define REQ_ADDSRC_NOSELECT 0x10
241 int32_t presend_minpoll
;
244 Float max_delay_ratio
;
293 } REQ_SubnetsAccessed_Subnet
;
295 #define MAX_SUBNETS_ACCESSED 8
299 REQ_SubnetsAccessed_Subnet subnets
[MAX_SUBNETS_ACCESSED
];
300 } REQ_SubnetsAccessed
;
302 /* This is based on the response size rather than the
304 #define MAX_CLIENT_ACCESSES 8
308 IPAddr client_ips
[MAX_CLIENT_ACCESSES
];
309 } REQ_ClientAccesses
;
312 uint32_t first_index
;
315 } REQ_ClientAccessesByIndex
;
334 /* ================================================== */
336 #define PKT_TYPE_CMD_REQUEST 1
337 #define PKT_TYPE_CMD_REPLY 2
339 /* This version number needs to be incremented whenever the packet
340 size and/or the format of any of the existing messages is changed.
341 Other changes, e.g. new command types, should be handled cleanly by
342 client.c and cmdmon.c anyway, so the version can stay the same.
344 Version 1 : original version with fixed size packets
346 Version 2 : both command and reply packet sizes made capable of
347 being variable length.
349 Version 3 : NTP_Source message lengthened (auto_offline)
351 Version 4 : IPv6 addressing added, 64-bit time values, sourcestats
352 and tracking reports extended, added flags to NTP source request,
353 trimmed source report, replaced fixed-point format with floating-point
354 and used also instead of integer microseconds
358 #define PROTO_VERSION_NUMBER 4
360 /* The oldest protocol version that is compatible enough with
361 the current version to report a version mismatch */
362 #define PROTO_VERSION_MISMATCH_COMPAT 4
364 /* ================================================== */
367 uint8_t version
; /* Protocol version */
368 uint8_t pkt_type
; /* What sort of packet this is */
371 uint16_t command
; /* Which command is being issued */
372 uint16_t attempt
; /* How many resends the client has done
373 (count up from zero for same sequence
375 uint32_t sequence
; /* Client's sequence number */
376 uint32_t utoken
; /* Unique token per incarnation of daemon */
377 uint32_t token
; /* Command token (to prevent replay attack) */
378 uint32_t auth
[4]; /* MD5 authentication of the packet */
384 REQ_Modify_Minpoll modify_minpoll
;
385 REQ_Modify_Maxpoll modify_maxpoll
;
387 REQ_Modify_Maxdelay modify_maxdelay
;
388 REQ_Modify_Maxdelayratio modify_maxdelayratio
;
389 REQ_Modify_Minstratum modify_minstratum
;
390 REQ_Modify_Polltarget modify_polltarget
;
391 REQ_Modify_Maxupdateskew modify_maxupdateskew
;
396 REQ_N_Sources n_sources
;
397 REQ_Source_Data source_data
;
399 REQ_Allow_Deny allow_deny
;
400 REQ_Ac_Check ac_check
;
401 REQ_NTP_Source ntp_source
;
402 REQ_Del_Source del_source
;
403 REQ_WriteRtc writertc
;
406 REQ_Tracking tracking
;
407 REQ_Sourcestats sourcestats
;
408 REQ_RTCReport rtcreport
;
410 REQ_CycleLogs cyclelogs
;
411 REQ_SubnetsAccessed subnets_accessed
;
412 REQ_ClientAccesses client_accesses
;
413 REQ_ClientAccessesByIndex client_accesses_by_index
;
414 REQ_ManualList manual_list
;
415 REQ_ManualDelete manual_delete
;
416 REQ_MakeStep make_step
;
417 REQ_Activity activity
;
418 } data
; /* Command specific parameters */
422 /* ================================================== */
423 /* Authority codes for command types */
425 #define PERMIT_OPEN 0
426 #define PERMIT_LOCAL 1
427 #define PERMIT_AUTH 2
429 /* ================================================== */
433 #define RPY_N_SOURCES 2
434 #define RPY_SOURCE_DATA 3
435 #define RPY_MANUAL_TIMESTAMP 4
436 #define RPY_TRACKING 5
437 #define RPY_SOURCESTATS 6
439 #define RPY_SUBNETS_ACCESSED 8
440 #define RPY_CLIENT_ACCESSES 9
441 #define RPY_CLIENT_ACCESSES_BY_INDEX 10
442 #define RPY_MANUAL_LIST 11
443 #define RPY_ACTIVITY 12
444 #define N_REPLY_TYPES 13
447 #define STT_SUCCESS 0
450 #define STT_INVALID 3
451 #define STT_NOSUCHSOURCE 4
452 #define STT_INVALIDTS 5
453 #define STT_NOTENABLED 6
454 #define STT_BADSUBNET 7
455 #define STT_ACCESSALLOWED 8
456 #define STT_ACCESSDENIED 9
457 #define STT_NOHOSTACCESS 10
458 #define STT_SOURCEALREADYKNOWN 11
459 #define STT_TOOMANYSOURCES 12
461 #define STT_BADRTCFILE 14
462 #define STT_INACTIVE 15
463 #define STT_BADSAMPLE 16
464 #define STT_INVALIDAF 17
465 #define STT_BADPKTVERSION 18
466 #define STT_BADPKTLENGTH 19
477 #define RPY_SD_MD_CLIENT 0
478 #define RPY_SD_MD_PEER 1
479 #define RPY_SD_MD_REF 2
481 #define RPY_SD_ST_SYNC 0
482 #define RPY_SD_ST_UNREACH 1
483 #define RPY_SD_ST_FALSETICKER 2
484 #define RPY_SD_ST_JITTERY 3
485 #define RPY_SD_ST_OTHER 4
493 uint32_t since_sample
;
494 Float orig_latest_meas
;
496 Float latest_meas_err
;
505 Float current_correction
;
507 Float resid_freq_ppm
;
510 Float root_dispersion
;
519 uint32_t span_seconds
;
521 Float resid_freq_ppm
;
524 Float est_offset_err
;
532 uint32_t span_seconds
;
533 Float rtc_seconds_fast
;
534 Float rtc_gain_rate_ppm
;
539 uint32_t centiseconds
;
543 } RPY_ManualTimestamp
;
549 } RPY_SubnetsAccessed_Subnet
;
553 RPY_SubnetsAccessed_Subnet subnets
[MAX_SUBNETS_ACCESSED
];
554 } RPY_SubnetsAccessed
;
558 uint32_t client_hits
;
560 uint32_t cmd_hits_auth
;
561 uint32_t cmd_hits_normal
;
562 uint32_t cmd_hits_bad
;
563 uint32_t last_ntp_hit_ago
;
564 uint32_t last_cmd_hit_ago
;
565 } RPY_ClientAccesses_Client
;
569 RPY_ClientAccesses_Client clients
[MAX_CLIENT_ACCESSES
];
570 } RPY_ClientAccesses
;
573 uint32_t n_indices
; /* how many indices there are in the server's table */
574 uint32_t next_index
; /* the index 1 beyond those processed on this call */
575 uint32_t n_clients
; /* the number of valid entries in the following array */
576 RPY_ClientAccesses_Client clients
[MAX_CLIENT_ACCESSES
];
577 } RPY_ClientAccessesByIndex
;
579 #define MAX_MANUAL_LIST_SAMPLES 32
586 } RPY_ManualListSample
;
590 RPY_ManualListSample samples
[MAX_MANUAL_LIST_SAMPLES
];
596 int32_t burst_online
;
597 int32_t burst_offline
;
606 uint16_t command
; /* Which command is being replied to */
607 uint16_t reply
; /* Which format of reply this is */
608 uint16_t status
; /* Status of command processing */
609 uint16_t number
; /* Which packet this is in reply sequence */
610 uint16_t total
; /* Number of replies to expect in this sequence */
611 uint16_t pad1
; /* Get up to 4 byte alignment */
612 uint32_t sequence
; /* Echo of client's sequence number */
613 uint32_t utoken
; /* Unique token per incarnation of daemon */
614 uint32_t token
; /* New command token (only if command was successfully
616 uint32_t auth
[4]; /* MD5 authentication of the packet */
620 RPY_N_Sources n_sources
;
621 RPY_Source_Data source_data
;
622 RPY_ManualTimestamp manual_timestamp
;
623 RPY_Tracking tracking
;
624 RPY_Sourcestats sourcestats
;
626 RPY_SubnetsAccessed subnets_accessed
;
627 RPY_ClientAccesses client_accesses
;
628 RPY_ClientAccessesByIndex client_accesses_by_index
;
629 RPY_ManualList manual_list
;
630 RPY_Activity activity
;
631 } data
; /* Reply specific parameters */
635 /* ================================================== */
637 #endif /* GOT_CANDM_H */