File: candm.h

package info (click to toggle)
chrony 1.21z-5
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 2,080 kB
  • ctags: 2,375
  • sloc: ansic: 14,831; yacc: 858; sh: 588; perl: 426; makefile: 148
file content (594 lines) | stat: -rw-r--r-- 13,952 bytes parent folder | download | duplicates (4)
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
/*
  $Header: /cvs/src/chrony/candm.h,v 1.40 2003/09/22 21:22:30 richard Exp $

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

  chronyd/chronyc - Programs for keeping computer clocks accurate.

 **********************************************************************
 * Copyright (C) Richard P. Curnow  1997-2003
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 * 
 **********************************************************************

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

  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 REQ_ACTIVITY 44
#define N_REQUEST_TYPES 45

/* 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 {
  uint32_t mask;
  uint32_t address;
  int32_t EOR;
} REQ_Online;

typedef struct {
  uint32_t mask;
  uint32_t address;
  int32_t EOR;
} REQ_Offline;

typedef struct {
  uint32_t mask;
  uint32_t address;
  int32_t n_good_samples;
  int32_t n_total_samples;
  int32_t EOR;
} REQ_Burst;

typedef struct {
  uint32_t address;
  int32_t new_minpoll;
  int32_t EOR;
} REQ_Modify_Minpoll;

typedef struct {
  uint32_t address;
  int32_t new_maxpoll;
  int32_t EOR;
} REQ_Modify_Maxpoll;

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

typedef struct {
  uint32_t address;
  int32_t new_max_delay;
  int32_t EOR;
} REQ_Modify_Maxdelay;

typedef struct {
  uint32_t address;
  int32_t new_max_delay_ratio;
  int32_t EOR;
} REQ_Modify_Maxdelayratio;

typedef struct {
  int32_t new_max_update_skew;
  int32_t EOR;
} REQ_Modify_Maxupdateskew;

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

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

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

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

typedef struct {
  int32_t EOR;
} REQ_N_Sources;

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

typedef struct {
  int32_t EOR;
} REQ_Rekey;

typedef struct {
  uint32_t ip;
  int32_t subnet_bits;
  int32_t EOR;
} REQ_Allow_Deny;

typedef struct {
  uint32_t ip;
  int32_t EOR;
} REQ_Ac_Check;

typedef struct {
  uint32_t ip_addr;
  uint32_t port;
  int32_t minpoll;
  int32_t maxpoll;
  int32_t presend_minpoll;
  int32_t online;
  int32_t auto_offline;
  uint32_t authkey;
  int32_t max_delay;
  int32_t max_delay_ratio;
  int32_t EOR;
} REQ_NTP_Source;

typedef struct {
  uint32_t ip_addr;
  int32_t EOR;
} REQ_Del_Source;

typedef struct {
  int32_t EOR;
} REQ_WriteRtc;

typedef struct {
  int32_t dfreq;
  int32_t EOR;
} REQ_Dfreq;

typedef struct {
  int32_t sec;
  int32_t usec;
  int32_t EOR;
} REQ_Doffset;

typedef struct {
  int32_t EOR;
} REQ_Tracking;

typedef struct {
  uint32_t index;
  int32_t EOR;
} REQ_Sourcestats;

typedef struct {
  int32_t EOR;
} REQ_RTCReport;

typedef struct {
  int32_t EOR;
} REQ_TrimRTC;

typedef struct {
  int32_t EOR;
} REQ_CycleLogs;

typedef struct {
  uint32_t ip;
  uint32_t bits_specd;
} REQ_SubnetsAccessed_Subnet;

#define MAX_SUBNETS_ACCESSED 8

typedef struct {
  uint32_t 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 {
  uint32_t n_clients;
  uint32_t client_ips[MAX_CLIENT_ACCESSES];
} REQ_ClientAccesses;  

typedef struct {
  uint32_t first_index;
  uint32_t n_indices;
  int32_t EOR;
} REQ_ClientAccessesByIndex;

typedef struct {
  int32_t EOR;
} REQ_ManualList;

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

typedef struct {
  int32_t EOR;
} REQ_MakeStep;

typedef struct {
  int32_t EOR;
} REQ_Activity;

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

#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.

   Version 3 : NTP_Source message lengthened (auto_offline)

 */

#define PROTO_VERSION_NUMBER 3

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

typedef struct {
  uint8_t version; /* Protocol version */
  uint8_t pkt_type; /* What sort of packet this is */
  uint8_t res1;
  uint8_t res2;
  uint16_t command; /* Which command is being issued */
  uint16_t attempt; /* How many resends the client has done
                             (count up from zero for same sequence
                             number) */
  uint32_t sequence; /* Client's sequence number */
  uint32_t utoken; /* Unique token per incarnation of daemon */
  uint32_t token; /* Command token (to prevent replay attack) */
  uint32_t 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;
    REQ_Activity activity;
  } 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) ((int32_t) ntohl(x)) / 65536.0)
#define REAL2WIRE(x) (htonl((int32_t)(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 RPY_ACTIVITY 12
#define N_REPLY_TYPES 13

/* 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 {
  int32_t EOR;
} RPY_Null;

typedef struct {
  uint32_t n_sources;
  int32_t 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 {
  uint32_t ip_addr;
  uint16_t poll;
  uint16_t stratum;
  uint16_t state;
  uint16_t mode;
  uint32_t  since_sample;
  int32_t orig_latest_meas;
  int32_t latest_meas;
  uint32_t latest_meas_err;
  int32_t est_offset;
  uint32_t est_offset_err;
  int32_t resid_freq;
  uint32_t resid_skew;
  int32_t EOR;
} RPY_Source_Data;

typedef struct {
  uint32_t ref_id;
  uint32_t stratum;
  uint32_t ref_time_s;
  uint32_t ref_time_us;
  uint32_t current_correction_s;
  uint32_t current_correction_us;
  int32_t freq_ppm;
  int32_t resid_freq_ppm;
  int32_t skew_ppm;
  int32_t root_delay;
  int32_t root_dispersion;
  int32_t EOR;
} RPY_Tracking;

typedef struct {
  uint32_t ip_addr;
  uint32_t n_samples;
  uint32_t n_runs;
  uint32_t span_seconds;
  uint32_t sd_us;
  int32_t resid_freq_ppm;
  int32_t skew_ppm;
  int32_t EOR;
} RPY_Sourcestats;

typedef struct {
  uint32_t ref_time;
  uint16_t n_samples;
  uint16_t n_runs;
  uint32_t span_seconds;
  int32_t rtc_seconds_fast;
  int32_t rtc_gain_rate_ppm;
  int32_t EOR;
} RPY_Rtc;

typedef struct {
  uint32_t centiseconds;
  int32_t dfreq_ppm;
  int32_t new_afreq_ppm;
  int32_t EOR;
} RPY_ManualTimestamp;

typedef struct {
  uint32_t ip;
  uint32_t bits_specd;
  uint32_t bitmap[8];
} RPY_SubnetsAccessed_Subnet;

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

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

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

typedef struct {
  uint32_t n_indices;      /* how many indices there are in the server's table */
  uint32_t next_index;     /* the index 1 beyond those processed on this call */
  uint32_t 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 {
  uint32_t when;
  int32_t slewed_offset;
  int32_t orig_offset;
  int32_t residual;
} RPY_ManualListSample;

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

typedef struct {
  int32_t online;
  int32_t offline;
  int32_t burst_online;
  int32_t burst_offline;
  int32_t EOR;
} RPY_Activity;

typedef struct {
  uint8_t version;
  uint8_t pkt_type;
  uint8_t res1;
  uint8_t res2;
  uint16_t command; /* Which command is being replied to */
  uint16_t reply; /* Which format of reply this is */
  uint16_t status; /* Status of command processing */
  uint16_t number; /* Which packet this is in reply sequence */
  uint16_t total; /* Number of replies to expect in this sequence */
  uint16_t pad1; /* Get up to 4 byte alignment */
  uint32_t sequence; /* Echo of client's sequence number */
  uint32_t utoken; /* Unique token per incarnation of daemon */
  uint32_t token; /* New command token (only if command was successfully
                          authenticated) */
  uint32_t 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;
    RPY_Activity activity;
  } data; /* Reply specific parameters */

} CMD_Reply;

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

#endif /* GOT_CANDM_H */