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