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