1 /*        $NetBSD: ntpdate.h,v 1.5 2020/05/25 20:47:26 christos Exp $ */
2 
3 /*
4  * ntpdate.h - declarations for the ntpdate and ntptimeset programs
5  */
6 
7 #include "ntp_malloc.h"
8 
9 extern void         loadservers         (char *cfgpath);
10 
11 /*
12  * The server structure is a much simplified version of the
13  * peer structure, for ntpdate's use.  Since we always send
14  * in client mode and expect to receive in server mode, this
15  * leaves only a very limited number of things we need to
16  * remember about the server.
17  */
18 struct server {
19           struct server *next_server;   /* next server in build list */
20           sockaddr_u srcadr;            /* address of remote host */
21           u_char version;                         /* version to use */
22           u_char leap;                            /* leap indicator */
23           u_char stratum;                         /* stratum of remote server */
24           s_char precision;             /* server's clock precision */
25           u_char trust;                           /* trustability of the filtered data */
26           u_fp rootdelay;                         /* distance from primary clock */
27           u_fp rootdisp;                          /* peer clock dispersion */
28           u_int32 refid;                          /* peer reference ID */
29           l_fp reftime;                           /* time of peer's last update */
30           u_long event_time;            /* time for next timeout */
31           u_long last_xmit;             /* time of last transmit */
32           u_short xmtcnt;                         /* number of packets transmitted */
33           u_short rcvcnt;                         /* number of packets received */
34           u_char reach;                           /* reachability, NTP_WINDOW bits */
35           u_short filter_nextpt;                  /* index into filter shift register */
36           s_fp filter_delay[NTP_SHIFT]; /* delay part of shift register */
37           l_fp filter_offset[NTP_SHIFT];          /* offset part of shift register */
38           s_fp filter_soffset[NTP_SHIFT]; /* offset in s_fp format, for disp */
39           u_fp filter_error[NTP_SHIFT]; /* error part of shift register */
40           l_fp org;                     /* peer's originate time stamp */
41           l_fp xmt;                     /* transmit time stamp */
42           u_fp delay;                             /* filter estimated delay */
43           u_fp dispersion;              /* filter estimated dispersion */
44           l_fp offset;                            /* filter estimated clock offset */
45           s_fp soffset;                           /* fp version of above */
46 };
47 
48 
49 /*
50  * ntpdate runs everything on a simple, short timeout.  It sends a
51  * packet and sets the timeout (by default, to a small value suitable
52  * for a LAN).  If it receives a response it sends another request.
53  * If it times out it shifts zeroes into the filter and sends another
54  * request.
55  *
56  * The timer routine is run often (once every 1/5 second currently)
57  * so that time outs are done with reasonable precision.
58  */
59 #define TIMER_HZ    (5)                 /* 5 per second */
60 
61 /*
62  * ntpdate will make a long adjustment using adjtime() if the times
63  * are close, or step the time if the times are farther apart.  The
64  * following defines what is "close".
65  */
66 #define   NTPDATE_THRESHOLD   (FP_SECOND >> 1)    /* 1/2 second */
67 
68 #define NTP_MAXAGE  86400     /* one day in seconds */
69 
70 /*
71  * When doing adjustments, ntpdate actually overadjusts (currently
72  * by 50%, though this may change).  While this will make it take longer
73  * to reach a steady state condition, it will typically result in
74  * the clock keeping more accurate time, on average.  The amount of
75  * overshoot is limited.
76  */
77 #ifdef    NOTNOW
78 #define   ADJ_OVERSHOOT       1/2       /* this is hard coded */
79 #endif    /* NOTNOW */
80 #define   ADJ_MAXOVERSHOOT    0x10000000          /* 50 ms as a ts fraction */
81 
82 /*
83  * Since ntpdate isn't aware of some of the things that normally get
84  * put in an NTP packet, we fix some values.
85  */
86 #define   NTPDATE_PRECISION   (-6)                /* use this precision */
87 #define   NTPDATE_DISTANCE    FP_SECOND /* distance is 1 sec */
88 #define   NTPDATE_DISP                  FP_SECOND /* so is the dispersion */
89 #define   NTPDATE_REFID                 (0)                 /* reference ID to use */
90 #define PEER_MAXDISP          (64*FP_SECOND)      /* maximum dispersion (fp 64) */
91 
92 
93 /*
94  * No less than 2s between requests to a server to stay within ntpd's
95  * default "discard minimum 1" (and 1s enforcement slop).  That is
96  * enforced only if the nondefault limited restriction is in place, such
97  * as with "restrict ... limited" and "restrict ... kod limited".
98  */
99 #define   MINTIMEOUT          (1 * TIMER_HZ)      /* 1s min. between packets */
100 #define   DEFTIMEOUT          (2 * TIMER_HZ)      /* 2s by default */
101 #define   DEFSAMPLES          4                   /* get 4 samples per server */
102 #define   DEFPRECISION        (-5)                /* the precision we claim */
103 #define   DEFMAXPERIOD        60                  /* maximum time to wait */
104 #define   DEFMINSERVERS       3                   /* minimum responding servers */
105 #define   DEFMINVALID         1                   /* mimimum servers with valid time */
106 
107 /*
108  * Define the max number of sockets we can open
109  */
110 #define MAX_AF 2
111