]> git.ipfire.org Git - thirdparty/chrony.git/blob - candm.h
cmdmon: add shutdown command
[thirdparty/chrony.git] / candm.h
1 /*
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
3
4 **********************************************************************
5 * Copyright (C) Richard P. Curnow 1997-2003
6 *
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.
10 *
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.
15 *
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.
19 *
20 **********************************************************************
21
22 =======================================================================
23
24 Definitions for the network protocol used for command and monitoring
25 of the timeserver.
26
27 */
28
29 #ifndef GOT_CANDM_H
30 #define GOT_CANDM_H
31
32 #include "sysincl.h"
33 #include "addressing.h"
34
35 /* This is the default port to use for CANDM, if no alternative is
36 defined */
37 #define DEFAULT_CANDM_PORT 323
38
39 /* Request codes */
40 #define REQ_NULL 0
41 #define REQ_ONLINE 1
42 #define REQ_OFFLINE 2
43 #define REQ_BURST 3
44 #define REQ_MODIFY_MINPOLL 4
45 #define REQ_MODIFY_MAXPOLL 5
46 #define REQ_DUMP 6
47 #define REQ_MODIFY_MAXDELAY 7
48 #define REQ_MODIFY_MAXDELAYRATIO 8
49 #define REQ_MODIFY_MAXUPDATESKEW 9
50 #define REQ_LOGON 10
51 #define REQ_SETTIME 11
52 #define REQ_LOCAL 12
53 #define REQ_MANUAL 13
54 #define REQ_N_SOURCES 14
55 #define REQ_SOURCE_DATA 15
56 #define REQ_REKEY 16
57 #define REQ_ALLOW 17
58 #define REQ_ALLOWALL 18
59 #define REQ_DENY 19
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
71 #define REQ_DFREQ 31
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
96 #define REQ_LOCAL2 56
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 N_REQUEST_TYPES 63
104
105 /* Structure used to exchange timespecs independent of time_t size */
106 typedef struct {
107 uint32_t tv_sec_high;
108 uint32_t tv_sec_low;
109 uint32_t tv_nsec;
110 } Timespec;
111
112 /* This is used in tv_sec_high for 32-bit timestamps */
113 #define TV_NOHIGHSEC 0x7fffffff
114
115 /* 32-bit floating-point format consisting of 7-bit signed exponent
116 and 25-bit signed coefficient without hidden bit.
117 The result is calculated as: 2^(exp - 25) * coef */
118 typedef struct {
119 int32_t f;
120 } Float;
121
122 /* The EOR (end of record) fields are used by the offsetof operator in
123 pktlength.c, to get the number of bytes that ought to be
124 transmitted for each packet type. */
125
126 typedef struct {
127 int32_t EOR;
128 } REQ_Null;
129
130 typedef struct {
131 IPAddr mask;
132 IPAddr address;
133 int32_t EOR;
134 } REQ_Online;
135
136 typedef struct {
137 IPAddr mask;
138 IPAddr address;
139 int32_t EOR;
140 } REQ_Offline;
141
142 typedef struct {
143 IPAddr mask;
144 IPAddr address;
145 int32_t n_good_samples;
146 int32_t n_total_samples;
147 int32_t EOR;
148 } REQ_Burst;
149
150 typedef struct {
151 IPAddr address;
152 int32_t new_minpoll;
153 int32_t EOR;
154 } REQ_Modify_Minpoll;
155
156 typedef struct {
157 IPAddr address;
158 int32_t new_maxpoll;
159 int32_t EOR;
160 } REQ_Modify_Maxpoll;
161
162 typedef struct {
163 int32_t pad;
164 int32_t EOR;
165 } REQ_Dump;
166
167 typedef struct {
168 IPAddr address;
169 Float new_max_delay;
170 int32_t EOR;
171 } REQ_Modify_Maxdelay;
172
173 typedef struct {
174 IPAddr address;
175 Float new_max_delay_ratio;
176 int32_t EOR;
177 } REQ_Modify_Maxdelayratio;
178
179 typedef struct {
180 IPAddr address;
181 Float new_max_delay_dev_ratio;
182 int32_t EOR;
183 } REQ_Modify_Maxdelaydevratio;
184
185 typedef struct {
186 IPAddr address;
187 int32_t new_min_stratum;
188 int32_t EOR;
189 } REQ_Modify_Minstratum;
190
191 typedef struct {
192 IPAddr address;
193 int32_t new_poll_target;
194 int32_t EOR;
195 } REQ_Modify_Polltarget;
196
197 typedef struct {
198 Float new_max_update_skew;
199 int32_t EOR;
200 } REQ_Modify_Maxupdateskew;
201
202 typedef struct {
203 int32_t limit;
204 Float threshold;
205 int32_t EOR;
206 } REQ_Modify_Makestep;
207
208 typedef struct {
209 Timespec ts;
210 int32_t EOR;
211 } REQ_Logon;
212
213 typedef struct {
214 Timespec ts;
215 int32_t EOR;
216 } REQ_Settime;
217
218 typedef struct {
219 int32_t on_off;
220 int32_t stratum;
221 Float distance;
222 int32_t orphan;
223 int32_t EOR;
224 } REQ_Local;
225
226 typedef struct {
227 int32_t option;
228 int32_t EOR;
229 } REQ_Manual;
230
231 typedef struct {
232 int32_t index;
233 int32_t EOR;
234 } REQ_Source_Data;
235
236 typedef struct {
237 IPAddr ip;
238 int32_t subnet_bits;
239 int32_t EOR;
240 } REQ_Allow_Deny;
241
242 typedef struct {
243 IPAddr ip;
244 int32_t EOR;
245 } REQ_Ac_Check;
246
247 /* Flags used in NTP source requests */
248 #define REQ_ADDSRC_ONLINE 0x1
249 #define REQ_ADDSRC_AUTOOFFLINE 0x2
250 #define REQ_ADDSRC_IBURST 0x4
251 #define REQ_ADDSRC_PREFER 0x8
252 #define REQ_ADDSRC_NOSELECT 0x10
253 #define REQ_ADDSRC_TRUST 0x20
254 #define REQ_ADDSRC_REQUIRE 0x40
255 #define REQ_ADDSRC_INTERLEAVED 0x80
256 #define REQ_ADDSRC_BURST 0x100
257
258 typedef struct {
259 IPAddr ip_addr;
260 uint32_t port;
261 int32_t minpoll;
262 int32_t maxpoll;
263 int32_t presend_minpoll;
264 uint32_t min_stratum;
265 uint32_t poll_target;
266 uint32_t version;
267 uint32_t max_sources;
268 int32_t min_samples;
269 int32_t max_samples;
270 uint32_t authkey;
271 Float max_delay;
272 Float max_delay_ratio;
273 Float max_delay_dev_ratio;
274 Float min_delay;
275 Float asymmetry;
276 Float offset;
277 uint32_t flags;
278 uint32_t reserved[4];
279 int32_t EOR;
280 } REQ_NTP_Source;
281
282 typedef struct {
283 IPAddr ip_addr;
284 int32_t EOR;
285 } REQ_Del_Source;
286
287 typedef struct {
288 Float dfreq;
289 int32_t EOR;
290 } REQ_Dfreq;
291
292 typedef struct {
293 int32_t sec;
294 int32_t usec;
295 int32_t EOR;
296 } REQ_Doffset;
297
298 typedef struct {
299 uint32_t index;
300 int32_t EOR;
301 } REQ_Sourcestats;
302
303 /* This is based on the response size rather than the
304 request size */
305 #define MAX_CLIENT_ACCESSES 8
306
307 typedef struct {
308 uint32_t first_index;
309 uint32_t n_clients;
310 int32_t EOR;
311 } REQ_ClientAccessesByIndex;
312
313 typedef struct {
314 int32_t index;
315 int32_t EOR;
316 } REQ_ManualDelete;
317
318 typedef struct {
319 Float distance;
320 int32_t EOR;
321 } REQ_ReselectDistance;
322
323 #define REQ_SMOOTHTIME_RESET 0
324 #define REQ_SMOOTHTIME_ACTIVATE 1
325
326 typedef struct {
327 int32_t option;
328 int32_t EOR;
329 } REQ_SmoothTime;
330
331 typedef struct {
332 IPAddr ip_addr;
333 int32_t EOR;
334 } REQ_NTPData;
335
336 /* ================================================== */
337
338 #define PKT_TYPE_CMD_REQUEST 1
339 #define PKT_TYPE_CMD_REPLY 2
340
341 /* This version number needs to be incremented whenever the packet
342 size and/or the format of any of the existing messages is changed.
343 Other changes, e.g. new command types, should be handled cleanly by
344 client.c and cmdmon.c anyway, so the version can stay the same.
345
346 Version 1 : original version with fixed size packets
347
348 Version 2 : both command and reply packet sizes made capable of
349 being variable length.
350
351 Version 3 : NTP_Source message lengthened (auto_offline)
352
353 Version 4 : IPv6 addressing added, 64-bit time values, sourcestats
354 and tracking reports extended, added flags to NTP source request,
355 trimmed source report, replaced fixed-point format with floating-point
356 and used also instead of integer microseconds, new commands: modify stratum,
357 modify polltarget, modify maxdelaydevratio, reselect, reselectdistance
358
359 Version 5 : auth data moved to the end of the packet to allow hashes with
360 different sizes, extended sources, tracking and activity reports, dropped
361 subnets accessed and client accesses
362
363 Version 6 : added padding to requests to prevent amplification attack,
364 changed maximum number of samples in manual list to 16, new commands: modify
365 makestep, smoothing, smoothtime
366
367 Support for authentication was removed later in version 6 of the protocol
368 and commands that required authentication are allowed only locally over Unix
369 domain socket.
370
371 Version 6 (no authentication) : changed format of client accesses by index
372 (using new request/reply types) and manual timestamp, new fields and flags
373 in NTP source request and report, new commands: ntpdata, refresh,
374 serverstats
375 */
376
377 #define PROTO_VERSION_NUMBER 6
378
379 /* The oldest protocol versions that are compatible enough with the current
380 version to report a version mismatch for the server and the client */
381 #define PROTO_VERSION_MISMATCH_COMPAT_SERVER 5
382 #define PROTO_VERSION_MISMATCH_COMPAT_CLIENT 4
383
384 /* The first protocol version using padding in requests */
385 #define PROTO_VERSION_PADDING 6
386
387 /* The maximum length of padding in request packet, currently
388 defined by MANUAL_LIST */
389 #define MAX_PADDING_LENGTH 396
390
391 /* ================================================== */
392
393 typedef struct {
394 uint8_t version; /* Protocol version */
395 uint8_t pkt_type; /* What sort of packet this is */
396 uint8_t res1;
397 uint8_t res2;
398 uint16_t command; /* Which command is being issued */
399 uint16_t attempt; /* How many resends the client has done
400 (count up from zero for same sequence
401 number) */
402 uint32_t sequence; /* Client's sequence number */
403 uint32_t pad1;
404 uint32_t pad2;
405
406 union {
407 REQ_Null null;
408 REQ_Online online;
409 REQ_Offline offline;
410 REQ_Burst burst;
411 REQ_Modify_Minpoll modify_minpoll;
412 REQ_Modify_Maxpoll modify_maxpoll;
413 REQ_Dump dump;
414 REQ_Modify_Maxdelay modify_maxdelay;
415 REQ_Modify_Maxdelayratio modify_maxdelayratio;
416 REQ_Modify_Maxdelaydevratio modify_maxdelaydevratio;
417 REQ_Modify_Minstratum modify_minstratum;
418 REQ_Modify_Polltarget modify_polltarget;
419 REQ_Modify_Maxupdateskew modify_maxupdateskew;
420 REQ_Modify_Makestep modify_makestep;
421 REQ_Logon logon;
422 REQ_Settime settime;
423 REQ_Local local;
424 REQ_Manual manual;
425 REQ_Source_Data source_data;
426 REQ_Allow_Deny allow_deny;
427 REQ_Ac_Check ac_check;
428 REQ_NTP_Source ntp_source;
429 REQ_Del_Source del_source;
430 REQ_Dfreq dfreq;
431 REQ_Doffset doffset;
432 REQ_Sourcestats sourcestats;
433 REQ_ClientAccessesByIndex client_accesses_by_index;
434 REQ_ManualDelete manual_delete;
435 REQ_ReselectDistance reselect_distance;
436 REQ_SmoothTime smoothtime;
437 REQ_NTPData ntp_data;
438 } data; /* Command specific parameters */
439
440 /* Padding used to prevent traffic amplification. It only defines the
441 maximum size of the packet, there is no hole after the data field. */
442 uint8_t padding[MAX_PADDING_LENGTH];
443
444 } CMD_Request;
445
446 /* ================================================== */
447 /* Authority codes for command types */
448
449 #define PERMIT_OPEN 0
450 #define PERMIT_LOCAL 1
451 #define PERMIT_AUTH 2
452
453 /* ================================================== */
454
455 /* Reply codes */
456 #define RPY_NULL 1
457 #define RPY_N_SOURCES 2
458 #define RPY_SOURCE_DATA 3
459 #define RPY_MANUAL_TIMESTAMP 4
460 #define RPY_TRACKING 5
461 #define RPY_SOURCESTATS 6
462 #define RPY_RTC 7
463 #define RPY_SUBNETS_ACCESSED 8
464 #define RPY_CLIENT_ACCESSES 9
465 #define RPY_CLIENT_ACCESSES_BY_INDEX 10
466 #define RPY_MANUAL_LIST 11
467 #define RPY_ACTIVITY 12
468 #define RPY_SMOOTHING 13
469 #define RPY_SERVER_STATS 14
470 #define RPY_CLIENT_ACCESSES_BY_INDEX2 15
471 #define RPY_NTP_DATA 16
472 #define RPY_MANUAL_TIMESTAMP2 17
473 #define N_REPLY_TYPES 18
474
475 /* Status codes */
476 #define STT_SUCCESS 0
477 #define STT_FAILED 1
478 #define STT_UNAUTH 2
479 #define STT_INVALID 3
480 #define STT_NOSUCHSOURCE 4
481 #define STT_INVALIDTS 5
482 #define STT_NOTENABLED 6
483 #define STT_BADSUBNET 7
484 #define STT_ACCESSALLOWED 8
485 #define STT_ACCESSDENIED 9
486 /* Deprecated */
487 #define STT_NOHOSTACCESS 10
488 #define STT_SOURCEALREADYKNOWN 11
489 #define STT_TOOMANYSOURCES 12
490 #define STT_NORTC 13
491 #define STT_BADRTCFILE 14
492 #define STT_INACTIVE 15
493 #define STT_BADSAMPLE 16
494 #define STT_INVALIDAF 17
495 #define STT_BADPKTVERSION 18
496 #define STT_BADPKTLENGTH 19
497
498 typedef struct {
499 int32_t EOR;
500 } RPY_Null;
501
502 typedef struct {
503 uint32_t n_sources;
504 int32_t EOR;
505 } RPY_N_Sources;
506
507 #define RPY_SD_MD_CLIENT 0
508 #define RPY_SD_MD_PEER 1
509 #define RPY_SD_MD_REF 2
510
511 #define RPY_SD_ST_SYNC 0
512 #define RPY_SD_ST_UNREACH 1
513 #define RPY_SD_ST_FALSETICKER 2
514 #define RPY_SD_ST_JITTERY 3
515 #define RPY_SD_ST_CANDIDATE 4
516 #define RPY_SD_ST_OUTLIER 5
517
518 #define RPY_SD_FLAG_NOSELECT 0x1
519 #define RPY_SD_FLAG_PREFER 0x2
520 #define RPY_SD_FLAG_TRUST 0x4
521 #define RPY_SD_FLAG_REQUIRE 0x8
522
523 typedef struct {
524 IPAddr ip_addr;
525 int16_t poll;
526 uint16_t stratum;
527 uint16_t state;
528 uint16_t mode;
529 uint16_t flags;
530 uint16_t reachability;
531 uint32_t since_sample;
532 Float orig_latest_meas;
533 Float latest_meas;
534 Float latest_meas_err;
535 int32_t EOR;
536 } RPY_Source_Data;
537
538 typedef struct {
539 uint32_t ref_id;
540 IPAddr ip_addr;
541 uint16_t stratum;
542 uint16_t leap_status;
543 Timespec ref_time;
544 Float current_correction;
545 Float last_offset;
546 Float rms_offset;
547 Float freq_ppm;
548 Float resid_freq_ppm;
549 Float skew_ppm;
550 Float root_delay;
551 Float root_dispersion;
552 Float last_update_interval;
553 int32_t EOR;
554 } RPY_Tracking;
555
556 typedef struct {
557 uint32_t ref_id;
558 IPAddr ip_addr;
559 uint32_t n_samples;
560 uint32_t n_runs;
561 uint32_t span_seconds;
562 Float sd;
563 Float resid_freq_ppm;
564 Float skew_ppm;
565 Float est_offset;
566 Float est_offset_err;
567 int32_t EOR;
568 } RPY_Sourcestats;
569
570 typedef struct {
571 Timespec ref_time;
572 uint16_t n_samples;
573 uint16_t n_runs;
574 uint32_t span_seconds;
575 Float rtc_seconds_fast;
576 Float rtc_gain_rate_ppm;
577 int32_t EOR;
578 } RPY_Rtc;
579
580 typedef struct {
581 Float offset;
582 Float dfreq_ppm;
583 Float new_afreq_ppm;
584 int32_t EOR;
585 } RPY_ManualTimestamp;
586
587 typedef struct {
588 IPAddr ip;
589 uint32_t ntp_hits;
590 uint32_t cmd_hits;
591 uint32_t ntp_drops;
592 uint32_t cmd_drops;
593 int8_t ntp_interval;
594 int8_t cmd_interval;
595 int8_t ntp_timeout_interval;
596 int8_t pad;
597 uint32_t last_ntp_hit_ago;
598 uint32_t last_cmd_hit_ago;
599 } RPY_ClientAccesses_Client;
600
601 typedef struct {
602 uint32_t n_indices; /* how many indices there are in the server's table */
603 uint32_t next_index; /* the index 1 beyond those processed on this call */
604 uint32_t n_clients; /* the number of valid entries in the following array */
605 RPY_ClientAccesses_Client clients[MAX_CLIENT_ACCESSES];
606 int32_t EOR;
607 } RPY_ClientAccessesByIndex;
608
609 typedef struct {
610 uint32_t ntp_hits;
611 uint32_t cmd_hits;
612 uint32_t ntp_drops;
613 uint32_t cmd_drops;
614 uint32_t log_drops;
615 int32_t EOR;
616 } RPY_ServerStats;
617
618 #define MAX_MANUAL_LIST_SAMPLES 16
619
620 typedef struct {
621 Timespec when;
622 Float slewed_offset;
623 Float orig_offset;
624 Float residual;
625 } RPY_ManualListSample;
626
627 typedef struct {
628 uint32_t n_samples;
629 RPY_ManualListSample samples[MAX_MANUAL_LIST_SAMPLES];
630 int32_t EOR;
631 } RPY_ManualList;
632
633 typedef struct {
634 int32_t online;
635 int32_t offline;
636 int32_t burst_online;
637 int32_t burst_offline;
638 int32_t unresolved;
639 int32_t EOR;
640 } RPY_Activity;
641
642 #define RPY_SMT_FLAG_ACTIVE 0x1
643 #define RPY_SMT_FLAG_LEAPONLY 0x2
644
645 typedef struct {
646 uint32_t flags;
647 Float offset;
648 Float freq_ppm;
649 Float wander_ppm;
650 Float last_update_ago;
651 Float remaining_time;
652 int32_t EOR;
653 } RPY_Smoothing;
654
655 #define RPY_NTP_FLAGS_TESTS 0x3ff
656 #define RPY_NTP_FLAG_INTERLEAVED 0x4000
657 #define RPY_NTP_FLAG_AUTHENTICATED 0x8000
658
659 typedef struct {
660 IPAddr remote_addr;
661 IPAddr local_addr;
662 uint16_t remote_port;
663 uint8_t leap;
664 uint8_t version;
665 uint8_t mode;
666 uint8_t stratum;
667 int8_t poll;
668 int8_t precision;
669 Float root_delay;
670 Float root_dispersion;
671 uint32_t ref_id;
672 Timespec ref_time;
673 Float offset;
674 Float peer_delay;
675 Float peer_dispersion;
676 Float response_time;
677 Float jitter_asymmetry;
678 uint16_t flags;
679 uint8_t tx_tss_char;
680 uint8_t rx_tss_char;
681 uint32_t total_tx_count;
682 uint32_t total_rx_count;
683 uint32_t total_valid_count;
684 uint32_t reserved[4];
685 int32_t EOR;
686 } RPY_NTPData;
687
688 typedef struct {
689 uint8_t version;
690 uint8_t pkt_type;
691 uint8_t res1;
692 uint8_t res2;
693 uint16_t command; /* Which command is being replied to */
694 uint16_t reply; /* Which format of reply this is */
695 uint16_t status; /* Status of command processing */
696 uint16_t pad1; /* Padding for compatibility and 4 byte alignment */
697 uint16_t pad2;
698 uint16_t pad3;
699 uint32_t sequence; /* Echo of client's sequence number */
700 uint32_t pad4;
701 uint32_t pad5;
702
703 union {
704 RPY_Null null;
705 RPY_N_Sources n_sources;
706 RPY_Source_Data source_data;
707 RPY_ManualTimestamp manual_timestamp;
708 RPY_Tracking tracking;
709 RPY_Sourcestats sourcestats;
710 RPY_Rtc rtc;
711 RPY_ClientAccessesByIndex client_accesses_by_index;
712 RPY_ServerStats server_stats;
713 RPY_ManualList manual_list;
714 RPY_Activity activity;
715 RPY_Smoothing smoothing;
716 RPY_NTPData ntp_data;
717 } data; /* Reply specific parameters */
718
719 } CMD_Reply;
720
721 /* ================================================== */
722
723 #endif /* GOT_CANDM_H */