]> git.ipfire.org Git - thirdparty/chrony.git/blob - candm.h
Add polltarget command
[thirdparty/chrony.git] / candm.h
1 /*
2 $Header: /cvs/src/chrony/candm.h,v 1.40 2003/09/22 21:22:30 richard Exp $
3
4 =======================================================================
5
6 chronyd/chronyc - Programs for keeping computer clocks accurate.
7
8 **********************************************************************
9 * Copyright (C) Richard P. Curnow 1997-2003
10 *
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.
14 *
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.
19 *
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.
23 *
24 **********************************************************************
25
26 =======================================================================
27
28 Definitions for the network protocol used for command and monitoring
29 of the timeserver.
30
31 */
32
33 #ifndef GOT_CANDM_H
34 #define GOT_CANDM_H
35
36 #include "sysincl.h"
37 #include "addressing.h"
38
39 /* This is the default port to use for CANDM, if no alternative is
40 defined */
41 #define DEFAULT_CANDM_PORT 323
42
43 /* Request codes */
44 #define REQ_NULL 0
45 #define REQ_ONLINE 1
46 #define REQ_OFFLINE 2
47 #define REQ_BURST 3
48 #define REQ_MODIFY_MINPOLL 4
49 #define REQ_MODIFY_MAXPOLL 5
50 #define REQ_DUMP 6
51 #define REQ_MODIFY_MAXDELAY 7
52 #define REQ_MODIFY_MAXDELAYRATIO 8
53 #define REQ_MODIFY_MAXUPDATESKEW 9
54 #define REQ_LOGON 10
55 #define REQ_SETTIME 11
56 #define REQ_LOCAL 12
57 #define REQ_MANUAL 13
58 #define REQ_N_SOURCES 14
59 #define REQ_SOURCE_DATA 15
60 #define REQ_REKEY 16
61 #define REQ_ALLOW 17
62 #define REQ_ALLOWALL 18
63 #define REQ_DENY 19
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
75 #define REQ_DFREQ 31
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 REQ_MODIFY_MINSTRATUM 45
90 #define REQ_MODIFY_POLLTARGET 46
91 #define N_REQUEST_TYPES 47
92
93 /* Special utoken value used to log on with first exchange being the
94 password. (This time value has long since gone by) */
95 #define SPECIAL_UTOKEN 0x10101010
96
97 /* Structure used to exchange timevals independent on size of time_t */
98 typedef struct {
99 uint32_t tv_sec_high;
100 uint32_t tv_sec_low;
101 uint32_t tv_nsec;
102 } Timeval;
103
104 /* This is used in tv_sec_high for 32-bit timestamps */
105 #define TV_NOHIGHSEC 0x7fffffff
106
107 /* 32-bit floating-point format consisting of 7-bit signed exponent
108 and 25-bit signed coefficient without hidden bit.
109 The result is calculated as: 2^(exp - 25) * coef */
110 typedef struct {
111 int32_t f;
112 } Float;
113
114 /* The EOR (end of record) fields are used by the offsetof operator in
115 pktlength.c, to get the number of bytes that ought to be
116 transmitted for each packet type. */
117
118 typedef struct {
119 IPAddr mask;
120 IPAddr address;
121 int32_t EOR;
122 } REQ_Online;
123
124 typedef struct {
125 IPAddr mask;
126 IPAddr address;
127 int32_t EOR;
128 } REQ_Offline;
129
130 typedef struct {
131 IPAddr mask;
132 IPAddr address;
133 int32_t n_good_samples;
134 int32_t n_total_samples;
135 int32_t EOR;
136 } REQ_Burst;
137
138 typedef struct {
139 IPAddr address;
140 int32_t new_minpoll;
141 int32_t EOR;
142 } REQ_Modify_Minpoll;
143
144 typedef struct {
145 IPAddr address;
146 int32_t new_maxpoll;
147 int32_t EOR;
148 } REQ_Modify_Maxpoll;
149
150 typedef struct {
151 int32_t pad;
152 int32_t EOR;
153 } REQ_Dump;
154
155 typedef struct {
156 IPAddr address;
157 Float new_max_delay;
158 int32_t EOR;
159 } REQ_Modify_Maxdelay;
160
161 typedef struct {
162 IPAddr address;
163 Float new_max_delay_ratio;
164 int32_t EOR;
165 } REQ_Modify_Maxdelayratio;
166
167 typedef struct {
168 IPAddr address;
169 int32_t new_min_stratum;
170 int32_t EOR;
171 } REQ_Modify_Minstratum;
172
173 typedef struct {
174 IPAddr address;
175 int32_t new_poll_target;
176 int32_t EOR;
177 } REQ_Modify_Polltarget;
178
179 typedef struct {
180 Float new_max_update_skew;
181 int32_t EOR;
182 } REQ_Modify_Maxupdateskew;
183
184 typedef struct {
185 Timeval ts;
186 int32_t EOR;
187 } REQ_Logon;
188
189 typedef struct {
190 Timeval ts;
191 int32_t EOR;
192 } REQ_Settime;
193
194 typedef struct {
195 int32_t on_off;
196 int32_t stratum;
197 int32_t EOR;
198 } REQ_Local;
199
200 typedef struct {
201 int32_t option;
202 int32_t EOR;
203 } REQ_Manual;
204
205 typedef struct {
206 int32_t EOR;
207 } REQ_N_Sources;
208
209 typedef struct {
210 int32_t index;
211 int32_t EOR;
212 } REQ_Source_Data;
213
214 typedef struct {
215 int32_t EOR;
216 } REQ_Rekey;
217
218 typedef struct {
219 IPAddr ip;
220 int32_t subnet_bits;
221 int32_t EOR;
222 } REQ_Allow_Deny;
223
224 typedef struct {
225 IPAddr ip;
226 int32_t EOR;
227 } REQ_Ac_Check;
228
229 /* Flags used in NTP source requests */
230 #define REQ_ADDSRC_ONLINE 0x1
231 #define REQ_ADDSRC_AUTOOFFLINE 0x2
232 #define REQ_ADDSRC_IBURST 0x4
233 #define REQ_ADDSRC_PREFER 0x8
234 #define REQ_ADDSRC_NOSELECT 0x10
235
236 typedef struct {
237 IPAddr ip_addr;
238 uint32_t port;
239 int32_t minpoll;
240 int32_t maxpoll;
241 int32_t presend_minpoll;
242 uint32_t authkey;
243 Float max_delay;
244 Float max_delay_ratio;
245 uint32_t flags;
246 int32_t EOR;
247 } REQ_NTP_Source;
248
249 typedef struct {
250 IPAddr ip_addr;
251 int32_t EOR;
252 } REQ_Del_Source;
253
254 typedef struct {
255 int32_t EOR;
256 } REQ_WriteRtc;
257
258 typedef struct {
259 Float dfreq;
260 int32_t EOR;
261 } REQ_Dfreq;
262
263 typedef struct {
264 int32_t sec;
265 int32_t usec;
266 int32_t EOR;
267 } REQ_Doffset;
268
269 typedef struct {
270 int32_t EOR;
271 } REQ_Tracking;
272
273 typedef struct {
274 uint32_t index;
275 int32_t EOR;
276 } REQ_Sourcestats;
277
278 typedef struct {
279 int32_t EOR;
280 } REQ_RTCReport;
281
282 typedef struct {
283 int32_t EOR;
284 } REQ_TrimRTC;
285
286 typedef struct {
287 int32_t EOR;
288 } REQ_CycleLogs;
289
290 typedef struct {
291 IPAddr ip;
292 uint32_t bits_specd;
293 } REQ_SubnetsAccessed_Subnet;
294
295 #define MAX_SUBNETS_ACCESSED 8
296
297 typedef struct {
298 uint32_t n_subnets;
299 REQ_SubnetsAccessed_Subnet subnets[MAX_SUBNETS_ACCESSED];
300 } REQ_SubnetsAccessed;
301
302 /* This is based on the response size rather than the
303 request size */
304 #define MAX_CLIENT_ACCESSES 8
305
306 typedef struct {
307 uint32_t n_clients;
308 IPAddr client_ips[MAX_CLIENT_ACCESSES];
309 } REQ_ClientAccesses;
310
311 typedef struct {
312 uint32_t first_index;
313 uint32_t n_indices;
314 int32_t EOR;
315 } REQ_ClientAccessesByIndex;
316
317 typedef struct {
318 int32_t EOR;
319 } REQ_ManualList;
320
321 typedef struct {
322 int32_t index;
323 int32_t EOR;
324 } REQ_ManualDelete;
325
326 typedef struct {
327 int32_t EOR;
328 } REQ_MakeStep;
329
330 typedef struct {
331 int32_t EOR;
332 } REQ_Activity;
333
334 /* ================================================== */
335
336 #define PKT_TYPE_CMD_REQUEST 1
337 #define PKT_TYPE_CMD_REPLY 2
338
339 /* This version number needs to be incremented whenever the packet
340 size and/or the format of any of the existing messages is changed.
341 Other changes, e.g. new command types, should be handled cleanly by
342 client.c and cmdmon.c anyway, so the version can stay the same.
343
344 Version 1 : original version with fixed size packets
345
346 Version 2 : both command and reply packet sizes made capable of
347 being variable length.
348
349 Version 3 : NTP_Source message lengthened (auto_offline)
350
351 Version 4 : IPv6 addressing added, 64-bit time values, sourcestats
352 and tracking reports extended, added flags to NTP source request,
353 trimmed source report, replaced fixed-point format with floating-point
354 and used also instead of integer microseconds
355
356 */
357
358 #define PROTO_VERSION_NUMBER 4
359
360 /* The oldest protocol version that is compatible enough with
361 the current version to report a version mismatch */
362 #define PROTO_VERSION_MISMATCH_COMPAT 4
363
364 /* ================================================== */
365
366 typedef struct {
367 uint8_t version; /* Protocol version */
368 uint8_t pkt_type; /* What sort of packet this is */
369 uint8_t res1;
370 uint8_t res2;
371 uint16_t command; /* Which command is being issued */
372 uint16_t attempt; /* How many resends the client has done
373 (count up from zero for same sequence
374 number) */
375 uint32_t sequence; /* Client's sequence number */
376 uint32_t utoken; /* Unique token per incarnation of daemon */
377 uint32_t token; /* Command token (to prevent replay attack) */
378 uint32_t auth[4]; /* MD5 authentication of the packet */
379
380 union {
381 REQ_Online online;
382 REQ_Offline offline;
383 REQ_Burst burst;
384 REQ_Modify_Minpoll modify_minpoll;
385 REQ_Modify_Maxpoll modify_maxpoll;
386 REQ_Dump dump;
387 REQ_Modify_Maxdelay modify_maxdelay;
388 REQ_Modify_Maxdelayratio modify_maxdelayratio;
389 REQ_Modify_Minstratum modify_minstratum;
390 REQ_Modify_Polltarget modify_polltarget;
391 REQ_Modify_Maxupdateskew modify_maxupdateskew;
392 REQ_Logon logon;
393 REQ_Settime settime;
394 REQ_Local local;
395 REQ_Manual manual;
396 REQ_N_Sources n_sources;
397 REQ_Source_Data source_data;
398 REQ_Rekey rekey;
399 REQ_Allow_Deny allow_deny;
400 REQ_Ac_Check ac_check;
401 REQ_NTP_Source ntp_source;
402 REQ_Del_Source del_source;
403 REQ_WriteRtc writertc;
404 REQ_Dfreq dfreq;
405 REQ_Doffset doffset;
406 REQ_Tracking tracking;
407 REQ_Sourcestats sourcestats;
408 REQ_RTCReport rtcreport;
409 REQ_TrimRTC trimrtc;
410 REQ_CycleLogs cyclelogs;
411 REQ_SubnetsAccessed subnets_accessed;
412 REQ_ClientAccesses client_accesses;
413 REQ_ClientAccessesByIndex client_accesses_by_index;
414 REQ_ManualList manual_list;
415 REQ_ManualDelete manual_delete;
416 REQ_MakeStep make_step;
417 REQ_Activity activity;
418 } data; /* Command specific parameters */
419
420 } CMD_Request;
421
422 /* ================================================== */
423 /* Authority codes for command types */
424
425 #define PERMIT_OPEN 0
426 #define PERMIT_LOCAL 1
427 #define PERMIT_AUTH 2
428
429 /* ================================================== */
430
431 /* Reply codes */
432 #define RPY_NULL 1
433 #define RPY_N_SOURCES 2
434 #define RPY_SOURCE_DATA 3
435 #define RPY_MANUAL_TIMESTAMP 4
436 #define RPY_TRACKING 5
437 #define RPY_SOURCESTATS 6
438 #define RPY_RTC 7
439 #define RPY_SUBNETS_ACCESSED 8
440 #define RPY_CLIENT_ACCESSES 9
441 #define RPY_CLIENT_ACCESSES_BY_INDEX 10
442 #define RPY_MANUAL_LIST 11
443 #define RPY_ACTIVITY 12
444 #define N_REPLY_TYPES 13
445
446 /* Status codes */
447 #define STT_SUCCESS 0
448 #define STT_FAILED 1
449 #define STT_UNAUTH 2
450 #define STT_INVALID 3
451 #define STT_NOSUCHSOURCE 4
452 #define STT_INVALIDTS 5
453 #define STT_NOTENABLED 6
454 #define STT_BADSUBNET 7
455 #define STT_ACCESSALLOWED 8
456 #define STT_ACCESSDENIED 9
457 #define STT_NOHOSTACCESS 10
458 #define STT_SOURCEALREADYKNOWN 11
459 #define STT_TOOMANYSOURCES 12
460 #define STT_NORTC 13
461 #define STT_BADRTCFILE 14
462 #define STT_INACTIVE 15
463 #define STT_BADSAMPLE 16
464 #define STT_INVALIDAF 17
465 #define STT_BADPKTVERSION 18
466 #define STT_BADPKTLENGTH 19
467
468 typedef struct {
469 int32_t EOR;
470 } RPY_Null;
471
472 typedef struct {
473 uint32_t n_sources;
474 int32_t EOR;
475 } RPY_N_Sources;
476
477 #define RPY_SD_MD_CLIENT 0
478 #define RPY_SD_MD_PEER 1
479 #define RPY_SD_MD_REF 2
480
481 #define RPY_SD_ST_SYNC 0
482 #define RPY_SD_ST_UNREACH 1
483 #define RPY_SD_ST_FALSETICKER 2
484 #define RPY_SD_ST_JITTERY 3
485 #define RPY_SD_ST_OTHER 4
486
487 typedef struct {
488 IPAddr ip_addr;
489 uint16_t poll;
490 uint16_t stratum;
491 uint16_t state;
492 uint16_t mode;
493 uint32_t since_sample;
494 Float orig_latest_meas;
495 Float latest_meas;
496 Float latest_meas_err;
497 int32_t EOR;
498 } RPY_Source_Data;
499
500 typedef struct {
501 uint32_t ref_id;
502 IPAddr ip_addr;
503 uint32_t stratum;
504 Timeval ref_time;
505 Float current_correction;
506 Float freq_ppm;
507 Float resid_freq_ppm;
508 Float skew_ppm;
509 Float root_delay;
510 Float root_dispersion;
511 int32_t EOR;
512 } RPY_Tracking;
513
514 typedef struct {
515 uint32_t ref_id;
516 IPAddr ip_addr;
517 uint32_t n_samples;
518 uint32_t n_runs;
519 uint32_t span_seconds;
520 Float sd;
521 Float resid_freq_ppm;
522 Float skew_ppm;
523 Float est_offset;
524 Float est_offset_err;
525 int32_t EOR;
526 } RPY_Sourcestats;
527
528 typedef struct {
529 Timeval ref_time;
530 uint16_t n_samples;
531 uint16_t n_runs;
532 uint32_t span_seconds;
533 Float rtc_seconds_fast;
534 Float rtc_gain_rate_ppm;
535 int32_t EOR;
536 } RPY_Rtc;
537
538 typedef struct {
539 uint32_t centiseconds;
540 Float dfreq_ppm;
541 Float new_afreq_ppm;
542 int32_t EOR;
543 } RPY_ManualTimestamp;
544
545 typedef struct {
546 IPAddr ip;
547 uint32_t bits_specd;
548 uint32_t bitmap[8];
549 } RPY_SubnetsAccessed_Subnet;
550
551 typedef struct {
552 uint32_t n_subnets;
553 RPY_SubnetsAccessed_Subnet subnets[MAX_SUBNETS_ACCESSED];
554 } RPY_SubnetsAccessed;
555
556 typedef struct {
557 IPAddr ip;
558 uint32_t client_hits;
559 uint32_t peer_hits;
560 uint32_t cmd_hits_auth;
561 uint32_t cmd_hits_normal;
562 uint32_t cmd_hits_bad;
563 uint32_t last_ntp_hit_ago;
564 uint32_t last_cmd_hit_ago;
565 } RPY_ClientAccesses_Client;
566
567 typedef struct {
568 uint32_t n_clients;
569 RPY_ClientAccesses_Client clients[MAX_CLIENT_ACCESSES];
570 } RPY_ClientAccesses;
571
572 typedef struct {
573 uint32_t n_indices; /* how many indices there are in the server's table */
574 uint32_t next_index; /* the index 1 beyond those processed on this call */
575 uint32_t n_clients; /* the number of valid entries in the following array */
576 RPY_ClientAccesses_Client clients[MAX_CLIENT_ACCESSES];
577 } RPY_ClientAccessesByIndex;
578
579 #define MAX_MANUAL_LIST_SAMPLES 32
580
581 typedef struct {
582 Timeval when;
583 Float slewed_offset;
584 Float orig_offset;
585 Float residual;
586 } RPY_ManualListSample;
587
588 typedef struct {
589 uint32_t n_samples;
590 RPY_ManualListSample samples[MAX_MANUAL_LIST_SAMPLES];
591 } RPY_ManualList;
592
593 typedef struct {
594 int32_t online;
595 int32_t offline;
596 int32_t burst_online;
597 int32_t burst_offline;
598 int32_t EOR;
599 } RPY_Activity;
600
601 typedef struct {
602 uint8_t version;
603 uint8_t pkt_type;
604 uint8_t res1;
605 uint8_t res2;
606 uint16_t command; /* Which command is being replied to */
607 uint16_t reply; /* Which format of reply this is */
608 uint16_t status; /* Status of command processing */
609 uint16_t number; /* Which packet this is in reply sequence */
610 uint16_t total; /* Number of replies to expect in this sequence */
611 uint16_t pad1; /* Get up to 4 byte alignment */
612 uint32_t sequence; /* Echo of client's sequence number */
613 uint32_t utoken; /* Unique token per incarnation of daemon */
614 uint32_t token; /* New command token (only if command was successfully
615 authenticated) */
616 uint32_t auth[4]; /* MD5 authentication of the packet */
617
618 union {
619 RPY_Null null;
620 RPY_N_Sources n_sources;
621 RPY_Source_Data source_data;
622 RPY_ManualTimestamp manual_timestamp;
623 RPY_Tracking tracking;
624 RPY_Sourcestats sourcestats;
625 RPY_Rtc rtc;
626 RPY_SubnetsAccessed subnets_accessed;
627 RPY_ClientAccesses client_accesses;
628 RPY_ClientAccessesByIndex client_accesses_by_index;
629 RPY_ManualList manual_list;
630 RPY_Activity activity;
631 } data; /* Reply specific parameters */
632
633 } CMD_Reply;
634
635 /* ================================================== */
636
637 #endif /* GOT_CANDM_H */