File: candm.h

package info (click to toggle)
chrony 1.10-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,504 kB
  • ctags: 2,064
  • sloc: ansic: 15,081; sh: 152; makefile: 107
file content (564 lines) | stat: -rw-r--r-- 13,168 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
/*
  $Header: /home/richard/myntp/chrony/chrony-1.02/RCS/candm.h,v 1.26 1998/06/08 19:38:43 richard Exp $

  =======================================================================

  chronyd/chronyc - Programs for keeping computer clocks accurate.

  Copyright (C) 1997-1999 Richard P. Curnow
  All rights reserved.

  For conditions of use, refer to the file LICENCE.

  =======================================================================

  Definitions for the network protocol used for command and monitoring
  of the timeserver.

  */

#ifndef GOT_CANDM_H
#define GOT_CANDM_H

#include "sysincl.h"

/* This is the default port to use for CANDM, if no alternative is
   defined */
#define DEFAULT_CANDM_PORT 323

/* Request codes */
#define REQ_NULL 0
#define REQ_ONLINE 1
#define REQ_OFFLINE 2
#define REQ_BURST 3
#define REQ_MODIFY_MINPOLL 4
#define REQ_MODIFY_MAXPOLL 5
#define REQ_DUMP 6
#define REQ_MODIFY_MAXDELAY 7
#define REQ_MODIFY_MAXDELAYRATIO 8
#define REQ_MODIFY_MAXUPDATESKEW 9
#define REQ_LOGON 10
#define REQ_SETTIME 11
#define REQ_LOCAL 12
#define REQ_MANUAL 13
#define REQ_N_SOURCES 14
#define REQ_SOURCE_DATA 15
#define REQ_REKEY 16
#define REQ_ALLOW 17
#define REQ_ALLOWALL 18
#define REQ_DENY 19
#define REQ_DENYALL 20
#define REQ_CMDALLOW 21
#define REQ_CMDALLOWALL 22
#define REQ_CMDDENY 23
#define REQ_CMDDENYALL 24
#define REQ_ACCHECK 25
#define REQ_CMDACCHECK 26
#define REQ_ADD_SERVER 27
#define REQ_ADD_PEER 28
#define REQ_DEL_SOURCE 29
#define REQ_WRITERTC 30
#define REQ_DFREQ 31
#define REQ_DOFFSET 32
#define REQ_TRACKING 33
#define REQ_SOURCESTATS 34
#define REQ_RTCREPORT 35
#define REQ_TRIMRTC 36
#define REQ_CYCLELOGS 37
#define REQ_SUBNETS_ACCESSED 38
#define REQ_CLIENT_ACCESSES 39
#define REQ_CLIENT_ACCESSES_BY_INDEX 40
#define REQ_MANUAL_LIST 41
#define REQ_MANUAL_DELETE 42
#define REQ_MAKESTEP 43
#define N_REQUEST_TYPES 44

/* Special utoken value used to log on with first exchange being the
   password.  (This time value has long since gone by) */
#define SPECIAL_UTOKEN 0x10101010

/* The EOR (end of record) fields are used by the offsetof operator in
   pktlength.c, to get the number of bytes that ought to be
   transmitted for each packet type. */

typedef struct {
  unsigned long mask;
  unsigned long address;
  int EOR;
} REQ_Online;

typedef struct {
  unsigned long mask;
  unsigned long address;
  int EOR;
} REQ_Offline;

typedef struct {
  unsigned long mask;
  unsigned long address;
  int n_good_samples;
  int n_total_samples;
  int EOR;
} REQ_Burst;

typedef struct {
  unsigned long address;
  int new_minpoll;
  int EOR;
} REQ_Modify_Minpoll;

typedef struct {
  unsigned long address;
  int new_maxpoll;
  int EOR;
} REQ_Modify_Maxpoll;

typedef struct {
  int pad;
  int EOR;
} REQ_Dump;

typedef struct {
  unsigned long address;
  long new_max_delay;
  int EOR;
} REQ_Modify_Maxdelay;

typedef struct {
  unsigned long address;
  long new_max_delay_ratio;
  int EOR;
} REQ_Modify_Maxdelayratio;

typedef struct {
  long new_max_update_skew;
  int EOR;
} REQ_Modify_Maxupdateskew;

typedef struct {
  struct timeval ts;
  int EOR;
} REQ_Logon;

typedef struct {
  struct timeval ts;
  int EOR;
} REQ_Settime;

typedef struct {
  int on_off;
  int stratum;
  int EOR;
} REQ_Local;

typedef struct {
  int option;
  int EOR;
} REQ_Manual;

typedef struct {
  int EOR;
} REQ_N_Sources;

typedef struct {
  int index;
  int EOR;
} REQ_Source_Data;

typedef struct {
  int EOR;
} REQ_Rekey;

typedef struct {
  unsigned long ip;
  int subnet_bits;
  int EOR;
} REQ_Allow_Deny;

typedef struct {
  unsigned long ip;
  int EOR;
} REQ_Ac_Check;

typedef struct {
  unsigned long ip_addr;
  unsigned long port;
  int minpoll;
  int maxpoll;
  int presend_minpoll;
  int online;
  unsigned long authkey;
  long max_delay;
  long max_delay_ratio;
  int EOR;
} REQ_NTP_Source;

typedef struct {
  unsigned long ip_addr;
  int EOR;
} REQ_Del_Source;

typedef struct {
  int EOR;
} REQ_WriteRtc;

typedef struct {
  long dfreq;
  int EOR;
} REQ_Dfreq;

typedef struct {
  long sec;
  long usec;
  int EOR;
} REQ_Doffset;

typedef struct {
  int EOR;
} REQ_Tracking;

typedef struct {
  unsigned long index;
  int EOR;
} REQ_Sourcestats;

typedef struct {
  int EOR;
} REQ_RTCReport;

typedef struct {
  int EOR;
} REQ_TrimRTC;

typedef struct {
  int EOR;
} REQ_CycleLogs;

typedef struct {
  unsigned long ip;
  unsigned long bits_specd;
} REQ_SubnetsAccessed_Subnet;

#define MAX_SUBNETS_ACCESSED 8

typedef struct {
  unsigned long n_subnets;
  REQ_SubnetsAccessed_Subnet subnets[MAX_SUBNETS_ACCESSED];
} REQ_SubnetsAccessed;

/* This is based on the response size rather than the
   request size */
#define MAX_CLIENT_ACCESSES 16

typedef struct {
  unsigned long n_clients;
  unsigned long client_ips[MAX_CLIENT_ACCESSES];
} REQ_ClientAccesses;  

typedef struct {
  unsigned long first_index;
  unsigned long n_indices;
  int EOR;
} REQ_ClientAccessesByIndex;

typedef struct {
  int EOR;
} REQ_ManualList;

typedef struct {
  int index;
  int EOR;
} REQ_ManualDelete;

typedef struct {
  int EOR;
} REQ_MakeStep;

/* ================================================== */

#define PKT_TYPE_CMD_REQUEST 1
#define PKT_TYPE_CMD_REPLY 2

/* This version number needs to be incremented whenever the packet
   size and/or the format of any of the existing messages is changed.
   Other changes, e.g. new command types, should be handled cleanly by
   client.c and cmdmon.c anyway, so the version can stay the same.
   
   Version 1 : original version with fixed size packets

   Version 2 : both command and reply packet sizes made capable of
   being variable length.

 */

#define PROTO_VERSION_NUMBER 2

/* ================================================== */

typedef struct {
  unsigned char version; /* Protocol version */
  unsigned char pkt_type; /* What sort of packet this is */
  unsigned char res1;
  unsigned char res2;
  unsigned short command; /* Which command is being issued */
  unsigned short attempt; /* How many resends the client has done
                             (count up from zero for same sequence
                             number) */
  unsigned long sequence; /* Client's sequence number */
  unsigned long utoken; /* Unique token per incarnation of daemon */
  unsigned long token; /* Command token (to prevent replay attack) */
  unsigned long auth[4]; /* MD5 authentication of the packet */

  union {
    REQ_Online online;
    REQ_Offline offline;
    REQ_Burst burst;
    REQ_Modify_Minpoll modify_minpoll;
    REQ_Modify_Maxpoll modify_maxpoll;
    REQ_Dump dump;
    REQ_Modify_Maxdelay modify_maxdelay;
    REQ_Modify_Maxdelayratio modify_maxdelayratio;
    REQ_Modify_Maxupdateskew modify_maxupdateskew;
    REQ_Logon logon;
    REQ_Settime settime;
    REQ_Local local;
    REQ_Manual manual;
    REQ_N_Sources n_sources;
    REQ_Source_Data source_data;
    REQ_Rekey rekey;
    REQ_Allow_Deny allow_deny;
    REQ_Ac_Check ac_check;
    REQ_NTP_Source ntp_source;
    REQ_Del_Source del_source;
    REQ_WriteRtc writertc;
    REQ_Dfreq dfreq;
    REQ_Doffset doffset;
    REQ_Tracking tracking;
    REQ_Sourcestats sourcestats;
    REQ_RTCReport rtcreport;
    REQ_TrimRTC trimrtc;
    REQ_CycleLogs cyclelogs;
    REQ_SubnetsAccessed subnets_accessed;
    REQ_ClientAccesses client_accesses;
    REQ_ClientAccessesByIndex client_accesses_by_index;
    REQ_ManualList manual_list;
    REQ_ManualDelete manual_delete;
    REQ_MakeStep make_step;
  } data; /* Command specific parameters */

} CMD_Request;

/* ================================================== */
/* Authority codes for command types */

#define PERMIT_OPEN 0
#define PERMIT_LOCAL 1
#define PERMIT_AUTH 2

/* ================================================== */
/* These conversion utilities are used to convert between the internal
   and the 'wire' representation of real quantities */

#define WIRE2REAL(x) ((double) ((long) ntohl(x)) / 65536.0)
#define REAL2WIRE(x) (htonl((long)(0.5 + 65536.0 * (x))))

/* ================================================== */

/* Reply codes */
#define RPY_NULL 1
#define RPY_N_SOURCES 2
#define RPY_SOURCE_DATA 3
#define RPY_MANUAL_TIMESTAMP 4
#define RPY_TRACKING 5
#define RPY_SOURCESTATS 6
#define RPY_RTC 7
#define RPY_SUBNETS_ACCESSED 8
#define RPY_CLIENT_ACCESSES 9
#define RPY_CLIENT_ACCESSES_BY_INDEX 10
#define RPY_MANUAL_LIST 11
#define N_REPLY_TYPES 12

/* Status codes */
#define STT_SUCCESS 0
#define STT_FAILED 1
#define STT_UNAUTH 2
#define STT_INVALID 3
#define STT_NOSUCHSOURCE 4
#define STT_INVALIDTS 5
#define STT_NOTENABLED 6
#define STT_BADSUBNET 7
#define STT_ACCESSALLOWED 8
#define STT_ACCESSDENIED 9
#define STT_NOHOSTACCESS 10
#define STT_SOURCEALREADYKNOWN 11
#define STT_TOOMANYSOURCES 12
#define STT_NORTC 13
#define STT_BADRTCFILE 14
#define STT_INACTIVE 15
#define STT_BADSAMPLE 16

typedef struct {
  int EOR;
} RPY_Null;

typedef struct {
  unsigned long n_sources;
  int EOR;
} RPY_N_Sources;

#define RPY_SD_MD_CLIENT 0
#define RPY_SD_MD_PEER   1
#define RPY_SD_MD_REF    2

#define RPY_SD_ST_SYNC 0
#define RPY_SD_ST_UNREACH 1
#define RPY_SD_ST_FALSETICKER 2
#define RPY_SD_ST_JITTERY 3
#define RPY_SD_ST_OTHER 4

typedef struct {
  unsigned long ip_addr;
  unsigned short poll;
  unsigned short stratum;
  unsigned short state;
  unsigned short mode;
  unsigned long  since_sample;
  long orig_latest_meas;
  long latest_meas;
  unsigned long latest_meas_err;
  long est_offset;
  unsigned long est_offset_err;
  long resid_freq;
  unsigned long resid_skew;
  int EOR;
} RPY_Source_Data;

typedef struct {
  unsigned long ref_id;
  unsigned long stratum;
  unsigned long ref_time_s;
  unsigned long ref_time_us;
  unsigned long current_correction_s;
  unsigned long current_correction_us;
  long freq_ppm;
  long resid_freq_ppm;
  long skew_ppm;
  long root_delay;
  long root_dispersion;
  int EOR;
} RPY_Tracking;

typedef struct {
  unsigned long ip_addr;
  unsigned long n_samples;
  unsigned long n_runs;
  unsigned long span_seconds;
  unsigned long sd_us;
  long resid_freq_ppm;
  long skew_ppm;
  int EOR;
} RPY_Sourcestats;

typedef struct {
  unsigned long ref_time;
  unsigned short n_samples;
  unsigned short n_runs;
  unsigned long span_seconds;
  long rtc_seconds_fast;
  long rtc_gain_rate_ppm;
  int EOR;
} RPY_Rtc;

typedef struct {
  unsigned long centiseconds;
  long dfreq_ppm;
  long new_afreq_ppm;
  int EOR;
} RPY_ManualTimestamp;

typedef struct {
  /* Assume sizeof(unsigned long) == 4; if not so, other parts of the s/w will break
     horribly anyway */
  unsigned long ip;
  unsigned long bits_specd;
  unsigned long bitmap[8];
} RPY_SubnetsAccessed_Subnet;

typedef struct {
  unsigned long n_subnets;
  RPY_SubnetsAccessed_Subnet subnets[MAX_SUBNETS_ACCESSED];
} RPY_SubnetsAccessed;

typedef struct {
  unsigned long ip;
  unsigned long client_hits;
  unsigned long peer_hits;
  unsigned long cmd_hits_auth;
  unsigned long cmd_hits_normal;
  unsigned long cmd_hits_bad;
  unsigned long last_ntp_hit_ago;
  unsigned long last_cmd_hit_ago;
} RPY_ClientAccesses_Client;

typedef struct {
  unsigned long n_clients;
  RPY_ClientAccesses_Client clients[MAX_CLIENT_ACCESSES];
} RPY_ClientAccesses;

typedef struct {
  unsigned long n_indices;      /* how many indices there are in the server's table */
  unsigned long next_index;     /* the index 1 beyond those processed on this call */
  unsigned long n_clients;      /* the number of valid entries in the following array */
  RPY_ClientAccesses_Client clients[MAX_CLIENT_ACCESSES];
} RPY_ClientAccessesByIndex;

#define MAX_MANUAL_LIST_SAMPLES 32

typedef struct {
  unsigned long when;
  long slewed_offset;
  long orig_offset;
  long residual;
} RPY_ManualListSample;

typedef struct {
  unsigned long n_samples;
  RPY_ManualListSample samples[MAX_MANUAL_LIST_SAMPLES];
} RPY_ManualList;

typedef struct {
  unsigned char version;
  unsigned char pkt_type;
  unsigned char res1;
  unsigned char res2;
  unsigned short command; /* Which command is being replied to */
  unsigned short reply; /* Which format of reply this is */
  unsigned short status; /* Status of command processing */
  unsigned short number; /* Which packet this is in reply sequence */
  unsigned short total; /* Number of replies to expect in this sequence */
  unsigned short pad1; /* Get up to 4 byte alignment */
  unsigned long sequence; /* Echo of client's sequence number */
  unsigned long utoken; /* Unique token per incarnation of daemon */
  unsigned long token; /* New command token (only if command was successfully
                          authenticated) */
  unsigned long auth[4]; /* MD5 authentication of the packet */

  union {
    RPY_Null null;
    RPY_N_Sources n_sources;
    RPY_Source_Data source_data;
    RPY_ManualTimestamp manual_timestamp;
    RPY_Tracking tracking;
    RPY_Sourcestats sourcestats;
    RPY_Rtc rtc;
    RPY_SubnetsAccessed subnets_accessed;
    RPY_ClientAccesses client_accesses;
    RPY_ClientAccessesByIndex client_accesses_by_index;
    RPY_ManualList manual_list;
  } data; /* Reply specific parameters */

} CMD_Reply;

/* ================================================== */

#endif /* GOT_CANDM_H */