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