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 N_REQUEST_TYPES 45
91 /* Special utoken value used to log on with first exchange being the
92 password. (This time value has long since gone by) */
93 #define SPECIAL_UTOKEN 0x10101010
95 /* Structure used to exchange timevals independent on size of time_t */
102 /* This is used in tv_sec_high for 32-bit timestamps */
103 #define TV_NOHIGHSEC 0x7fffffff
105 /* 32-bit floating-point format consisting of 7-bit signed exponent
106 and 25-bit signed coefficient without hidden bit.
107 The result is calculated as: 2^(exp - 25) * coef */
112 /* The EOR (end of record) fields are used by the offsetof operator in
113 pktlength.c, to get the number of bytes that ought to be
114 transmitted for each packet type. */
131 int32_t n_good_samples
;
132 int32_t n_total_samples
;
140 } REQ_Modify_Minpoll
;
146 } REQ_Modify_Maxpoll
;
157 } REQ_Modify_Maxdelay
;
161 Float new_max_delay_ratio
;
163 } REQ_Modify_Maxdelayratio
;
166 Float new_max_update_skew
;
168 } REQ_Modify_Maxupdateskew
;
215 /* Flags used in NTP source requests */
216 #define REQ_ADDSRC_ONLINE 0x1
217 #define REQ_ADDSRC_AUTOOFFLINE 0x2
224 int32_t presend_minpoll
;
227 Float max_delay_ratio
;
276 } REQ_SubnetsAccessed_Subnet
;
278 #define MAX_SUBNETS_ACCESSED 8
282 REQ_SubnetsAccessed_Subnet subnets
[MAX_SUBNETS_ACCESSED
];
283 } REQ_SubnetsAccessed
;
285 /* This is based on the response size rather than the
287 #define MAX_CLIENT_ACCESSES 8
291 IPAddr client_ips
[MAX_CLIENT_ACCESSES
];
292 } REQ_ClientAccesses
;
295 uint32_t first_index
;
298 } REQ_ClientAccessesByIndex
;
317 /* ================================================== */
319 #define PKT_TYPE_CMD_REQUEST 1
320 #define PKT_TYPE_CMD_REPLY 2
322 /* This version number needs to be incremented whenever the packet
323 size and/or the format of any of the existing messages is changed.
324 Other changes, e.g. new command types, should be handled cleanly by
325 client.c and cmdmon.c anyway, so the version can stay the same.
327 Version 1 : original version with fixed size packets
329 Version 2 : both command and reply packet sizes made capable of
330 being variable length.
332 Version 3 : NTP_Source message lengthened (auto_offline)
334 Version 4 : IPv6 addressing added, 64-bit time values, sourcestats
335 and tracking reports extended, added flags to NTP source request,
336 replaced fixed-point format with floating-point
340 #define PROTO_VERSION_NUMBER 4
342 /* The oldest protocol version that is compatible enough with
343 the current version to report a version mismatch */
344 #define PROTO_VERSION_MISMATCH_COMPAT 4
346 /* ================================================== */
349 uint8_t version
; /* Protocol version */
350 uint8_t pkt_type
; /* What sort of packet this is */
353 uint16_t command
; /* Which command is being issued */
354 uint16_t attempt
; /* How many resends the client has done
355 (count up from zero for same sequence
357 uint32_t sequence
; /* Client's sequence number */
358 uint32_t utoken
; /* Unique token per incarnation of daemon */
359 uint32_t token
; /* Command token (to prevent replay attack) */
360 uint32_t auth
[4]; /* MD5 authentication of the packet */
366 REQ_Modify_Minpoll modify_minpoll
;
367 REQ_Modify_Maxpoll modify_maxpoll
;
369 REQ_Modify_Maxdelay modify_maxdelay
;
370 REQ_Modify_Maxdelayratio modify_maxdelayratio
;
371 REQ_Modify_Maxupdateskew modify_maxupdateskew
;
376 REQ_N_Sources n_sources
;
377 REQ_Source_Data source_data
;
379 REQ_Allow_Deny allow_deny
;
380 REQ_Ac_Check ac_check
;
381 REQ_NTP_Source ntp_source
;
382 REQ_Del_Source del_source
;
383 REQ_WriteRtc writertc
;
386 REQ_Tracking tracking
;
387 REQ_Sourcestats sourcestats
;
388 REQ_RTCReport rtcreport
;
390 REQ_CycleLogs cyclelogs
;
391 REQ_SubnetsAccessed subnets_accessed
;
392 REQ_ClientAccesses client_accesses
;
393 REQ_ClientAccessesByIndex client_accesses_by_index
;
394 REQ_ManualList manual_list
;
395 REQ_ManualDelete manual_delete
;
396 REQ_MakeStep make_step
;
397 REQ_Activity activity
;
398 } data
; /* Command specific parameters */
402 /* ================================================== */
403 /* Authority codes for command types */
405 #define PERMIT_OPEN 0
406 #define PERMIT_LOCAL 1
407 #define PERMIT_AUTH 2
409 /* ================================================== */
413 #define RPY_N_SOURCES 2
414 #define RPY_SOURCE_DATA 3
415 #define RPY_MANUAL_TIMESTAMP 4
416 #define RPY_TRACKING 5
417 #define RPY_SOURCESTATS 6
419 #define RPY_SUBNETS_ACCESSED 8
420 #define RPY_CLIENT_ACCESSES 9
421 #define RPY_CLIENT_ACCESSES_BY_INDEX 10
422 #define RPY_MANUAL_LIST 11
423 #define RPY_ACTIVITY 12
424 #define N_REPLY_TYPES 13
427 #define STT_SUCCESS 0
430 #define STT_INVALID 3
431 #define STT_NOSUCHSOURCE 4
432 #define STT_INVALIDTS 5
433 #define STT_NOTENABLED 6
434 #define STT_BADSUBNET 7
435 #define STT_ACCESSALLOWED 8
436 #define STT_ACCESSDENIED 9
437 #define STT_NOHOSTACCESS 10
438 #define STT_SOURCEALREADYKNOWN 11
439 #define STT_TOOMANYSOURCES 12
441 #define STT_BADRTCFILE 14
442 #define STT_INACTIVE 15
443 #define STT_BADSAMPLE 16
444 #define STT_INVALIDAF 17
445 #define STT_BADPKTVERSION 18
446 #define STT_BADPKTLENGTH 19
457 #define RPY_SD_MD_CLIENT 0
458 #define RPY_SD_MD_PEER 1
459 #define RPY_SD_MD_REF 2
461 #define RPY_SD_ST_SYNC 0
462 #define RPY_SD_ST_UNREACH 1
463 #define RPY_SD_ST_FALSETICKER 2
464 #define RPY_SD_ST_JITTERY 3
465 #define RPY_SD_ST_OTHER 4
473 uint32_t since_sample
;
474 int32_t orig_latest_meas
;
476 uint32_t latest_meas_err
;
478 uint32_t est_offset_err
;
489 uint32_t current_correction_s
;
490 uint32_t current_correction_us
;
492 Float resid_freq_ppm
;
495 Float root_dispersion
;
504 uint32_t span_seconds
;
506 Float resid_freq_ppm
;
515 uint32_t span_seconds
;
516 Float rtc_seconds_fast
;
517 Float rtc_gain_rate_ppm
;
522 uint32_t centiseconds
;
526 } RPY_ManualTimestamp
;
532 } RPY_SubnetsAccessed_Subnet
;
536 RPY_SubnetsAccessed_Subnet subnets
[MAX_SUBNETS_ACCESSED
];
537 } RPY_SubnetsAccessed
;
541 uint32_t client_hits
;
543 uint32_t cmd_hits_auth
;
544 uint32_t cmd_hits_normal
;
545 uint32_t cmd_hits_bad
;
546 uint32_t last_ntp_hit_ago
;
547 uint32_t last_cmd_hit_ago
;
548 } RPY_ClientAccesses_Client
;
552 RPY_ClientAccesses_Client clients
[MAX_CLIENT_ACCESSES
];
553 } RPY_ClientAccesses
;
556 uint32_t n_indices
; /* how many indices there are in the server's table */
557 uint32_t next_index
; /* the index 1 beyond those processed on this call */
558 uint32_t n_clients
; /* the number of valid entries in the following array */
559 RPY_ClientAccesses_Client clients
[MAX_CLIENT_ACCESSES
];
560 } RPY_ClientAccessesByIndex
;
562 #define MAX_MANUAL_LIST_SAMPLES 32
569 } RPY_ManualListSample
;
573 RPY_ManualListSample samples
[MAX_MANUAL_LIST_SAMPLES
];
579 int32_t burst_online
;
580 int32_t burst_offline
;
589 uint16_t command
; /* Which command is being replied to */
590 uint16_t reply
; /* Which format of reply this is */
591 uint16_t status
; /* Status of command processing */
592 uint16_t number
; /* Which packet this is in reply sequence */
593 uint16_t total
; /* Number of replies to expect in this sequence */
594 uint16_t pad1
; /* Get up to 4 byte alignment */
595 uint32_t sequence
; /* Echo of client's sequence number */
596 uint32_t utoken
; /* Unique token per incarnation of daemon */
597 uint32_t token
; /* New command token (only if command was successfully
599 uint32_t auth
[4]; /* MD5 authentication of the packet */
603 RPY_N_Sources n_sources
;
604 RPY_Source_Data source_data
;
605 RPY_ManualTimestamp manual_timestamp
;
606 RPY_Tracking tracking
;
607 RPY_Sourcestats sourcestats
;
609 RPY_SubnetsAccessed subnets_accessed
;
610 RPY_ClientAccesses client_accesses
;
611 RPY_ClientAccessesByIndex client_accesses_by_index
;
612 RPY_ManualList manual_list
;
613 RPY_Activity activity
;
614 } data
; /* Reply specific parameters */
618 /* ================================================== */
620 #endif /* GOT_CANDM_H */