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