ntp.h (302408) | ntp.h (54359) |
---|---|
1/* 2 * ntp.h - NTP definitions for the masses 3 */ | 1/* 2 * ntp.h - NTP definitions for the masses 3 */ |
4 |
|
4#ifndef NTP_H 5#define NTP_H 6 | 5#ifndef NTP_H 6#define NTP_H 7 |
7#include <stddef.h> | 8#include "ntp_types.h" |
8#include <math.h> 9 | 9#include <math.h> 10 |
10#include <ntp_fp.h> 11#include <ntp_types.h> 12#include <ntp_lists.h> 13#include <ntp_stdlib.h> 14#include <ntp_crypto.h> 15#include <ntp_random.h> 16#include <ntp_net.h> | 11 /* common definitions for Y2K repairs [ Y2KFixes */ |
17 | 12 |
18#include <isc/boolean.h> | 13 /* (this might better be put in ntp_calendar.h) */ 14#define YEAR_BREAK 500 /* assume years < this are tm_year values: */ 15 /* Break < AnyFourDigitYear 16 && Break > Anytm_yearYear */ 17#define YEAR_PIVOT 98 /* 97/98: assume years < this are year 2000+ */ 18 /* FYI: official UNIX pivot year is 68/69 */ |
19 | 19 |
20/* 21 * Calendar arithmetic - contributed by G. Healton 22 */ 23#define YEAR_BREAK 500 /* years < this are tm_year values: 24 * Break < AnyFourDigitYear && Break > 25 * Anytm_yearYear */ | 20 /* Number of Days since (mythical) 1.BC Gregorian to 1 January of given year*/ 21#define julian0(year) \ 22 ( \ 23 ( (year) * 365 ) + ( (year) > 0 \ 24 ? ( ((year)+3) / 4 - ((year-1) / 100) + ((year-1) / 400) ) \ 25 : 0 ) \ 26 ) |
26 | 27 |
27#define YEAR_PIVOT 98 /* 97/98: years < this are year 2000+ 28 * FYI: official UNIX pivot year is 29 * 68/69 */ | 28 /* Number of days since start of NTP time to 1 January of given year */ 29#define ntp0(year) ( julian0(year) - julian0(1900) ) |
30 | 30 |
31/* 32 * Number of Days since 1 BC Gregorian to 1 January of given year 33 */ 34#define julian0(year) (((year) * 365 ) + ((year) > 0 ? (((year) + 3) \ 35 / 4 - ((year - 1) / 100) + ((year - 1) / \ 36 400)) : 0)) | 31 /* Number of days since start of UNIX time to 1 January of given year */ 32#define unix0(year) ( julian0(year) - julian0(1970) ) |
37 | 33 |
38/* 39 * Number of days since start of NTP time to 1 January of given year 40 */ 41#define ntp0(year) (julian0(year) - julian0(1900)) | 34 /* LEAP YEAR test for full 4-digit years (e.g, 1999, 2010) */ 35#define isleap_4(y) /* a TRUE and PROPER leap year test */ \ 36 ((y)%4 == 0 && !((y)%100 == 0 && !(y%400 == 0))) 37 /* NOTE: year 2000 TRULY IS A LEAP YEAR!!! */ |
42 | 38 |
43/* 44 * Number of days since start of UNIX time to 1 January of given year 45 */ 46#define unix0(year) (julian0(year) - julian0(1970)) | 39 /* LEAP YEAR test for tm_year (struct tm) years (e.g, 99, 110) */ 40#define isleap_tm(y) /* a TRUE and PROPER leap year test */ \ 41 ((y)%4 == 0 && !((y)%100 == 0 && !(((y)+1900)%400 == 0))) |
47 | 42 |
48/* 49 * LEAP YEAR test for full 4-digit years (e.g, 1999, 2010) 50 */ 51#define isleap_4(y) ((y) % 4 == 0 && !((y) % 100 == 0 && !(y % \ 52 400 == 0))) | 43 /* to convert simple two-digit years to tm_year style years: 44 if ( year < YEAR_PIVOT ) year += 100; |
53 | 45 |
54/* 55 * LEAP YEAR test for tm_year (struct tm) years (e.g, 99, 110) 56 */ 57#define isleap_tm(y) ((y) % 4 == 0 && !((y) % 100 == 0 && !(((y) \ 58 + 1900) % 400 == 0))) | 46 * to convert either two-digit OR tm_year years to four-digit years: 47 if ( year < YEAR_PIVOT ) year += 100; 48 if ( year < YEAR_BREAK ) year += 1900; |
59 | 49 |
60/* 61 * to convert simple two-digit years to tm_year style years: 62 * 63 * if (year < YEAR_PIVOT) 64 * year += 100; 65 * 66 * to convert either two-digit OR tm_year years to four-digit years: 67 * 68 * if (year < YEAR_PIVOT) 69 * year += 100; 70 * 71 * if (year < YEAR_BREAK) 72 * year += 1900; 73 */ | 50 CALL TO STANDARD: 51 * As the Internet is an INTERNATIONAL network, it makes SENSE to use 52 the international standard ISO 8601 to format dates and times. 53 Basically this is yyyy-mm-dd for years and hh:mm:ss for times 54 (joining the two togeather in computer readable media calls for 55 yyyy-mm-ddThh:mm:ss, though yyyy-mm-dd hh:mm:ss is often used 56 for human readable forms even though it is not not strictly 57 valid ISO 8601). Standard time-zone offsets ([+-]hh:mm) are allowed. 58 ghealton ] Y2KFixes */ |
74 75/* 76 * How to get signed characters. On machines where signed char works, | 59 60/* 61 * How to get signed characters. On machines where signed char works, |
77 * use it. On machines where signed char doesn't work, char had better | 62 * use it. On machines where signed char doesn't work, char had better |
78 * be signed. 79 */ 80#ifdef NEED_S_CHAR_TYPEDEF 81# if SIZEOF_SIGNED_CHAR 82typedef signed char s_char; 83# else 84typedef char s_char; 85# endif 86 /* XXX: Why is this sequent bit INSIDE this test? */ 87# ifdef sequent 88# undef SO_RCVBUF 89# undef SO_SNDBUF 90# endif 91#endif | 63 * be signed. 64 */ 65#ifdef NEED_S_CHAR_TYPEDEF 66# if SIZEOF_SIGNED_CHAR 67typedef signed char s_char; 68# else 69typedef char s_char; 70# endif 71 /* XXX: Why is this sequent bit INSIDE this test? */ 72# ifdef sequent 73# undef SO_RCVBUF 74# undef SO_SNDBUF 75# endif 76#endif |
77#ifndef TRUE 78# define TRUE 1 79#endif /* TRUE */ 80#ifndef FALSE 81# define FALSE 0 82#endif /* FALSE */ |
|
92 93/* 94 * NTP protocol parameters. See section 3.2.6 of the specification. 95 */ 96#define NTP_VERSION ((u_char)4) /* current version number */ 97#define NTP_OLDVERSION ((u_char)1) /* oldest credible version */ | 83 84/* 85 * NTP protocol parameters. See section 3.2.6 of the specification. 86 */ 87#define NTP_VERSION ((u_char)4) /* current version number */ 88#define NTP_OLDVERSION ((u_char)1) /* oldest credible version */ |
98#define NTP_PORT 123 /* included for non-unix machines */ 99 100/* 101 * Poll interval parameters 102 */ 103#define NTP_UNREACH 10 /* poll unreach threshold */ 104#define NTP_MINPOLL 3 /* log2 min poll interval (8 s) */ 105#define NTP_MINDPOLL 6 /* log2 default min poll (64 s) */ 106#define NTP_MAXDPOLL 10 /* log2 default max poll (~17 m) */ 107#define NTP_MAXPOLL 17 /* log2 max poll interval (~36 h) */ 108#define NTP_RETRY 3 /* max packet retries */ 109#define NTP_MINPKT 2 /* guard time (s) */ 110 111/* 112 * Clock filter algorithm tuning parameters 113 */ 114#define MAXDISPERSE 16. /* max dispersion */ 115#define NTP_SHIFT 8 /* clock filter stages */ | 89#define NTP_PORT 123 /* included for sake of non-unix machines */ 90#define NTP_MAXSTRATUM ((u_char)15) /* max stratum, infinity a la Bellman-Ford */ 91#define NTP_MAXAGE 86400 /* one day in seconds */ 92#define NTP_UNREACH 16 /* poll interval backoff count */ 93#define NTP_MINDPOLL 6 /* log2 default min poll interval (64 s) */ 94#define NTP_MAXDPOLL 10 /* log2 default max poll interval (~17 m) */ 95#define NTP_MINPOLL 4 /* log2 min poll interval (16 s) */ 96#define NTP_MAXPOLL 17 /* log2 max poll interval (~4.5 h) */ 97#define NTP_MINCLOCK 3 /* minimum survivors */ 98#define NTP_CANCLOCK 6 /* minimum candidates */ 99#define NTP_MAXCLOCK 10 /* maximum candidates */ 100#define NTP_WINDOW 8 /* reachability register size */ 101#define NTP_SHIFT 8 /* 8 suitable for crystal time base */ 102#define NTP_MAXKEY 65535 /* maximum authentication key number */ 103#define NTP_MAXSESSION 100 /* maximum entries on session key list */ 104#define NTP_AUTOMAX 12 /* log2 default max session key lifetime */ 105#define KEY_REVOKE 16 /* log2 default key revoke timeout */ |
116#define NTP_FWEIGHT .5 /* clock filter weight */ | 106#define NTP_FWEIGHT .5 /* clock filter weight */ |
117 | 107#define NTP_SWEIGHT .75 /* select weight */ 108#define CLOCK_SGATE 10. /* popcorn spike gate */ 109#define BURST_INTERVAL1 4 /* first interburst interval (log2) */ 110#define BURST_INTERVAL2 1 /* succeeding interburst intervals (log2) */ 111 |
118/* | 112/* |
119 * Selection algorithm tuning parameters | 113 * Operations for jitter (variance) calculations (these use doubles). 114 * Note that we carefully separate the jitter component from the dispersion 115 * component (frequency error plus precision). The frequency error 116 * component is computed as CLOCK_PHI times the difference between the epoch 117 * of the time measurement and the reference time. The precision componen 118 * is computed as the square root of the mean of the squares of a zero- 119 * mean, uniform distribution of unit maximum amplitude. Whether this 120 * makes statistical sense may be arguable. |
120 */ | 121 */ |
121#define NTP_MINCLOCK 3 /* min survivors */ 122#define NTP_MAXCLOCK 10 /* max candidates */ 123#define MINDISPERSE .001 /* min distance */ 124#define MAXDISTANCE 1.5 /* max root distance (select threshold) */ 125#define CLOCK_SGATE 3. /* popcorn spike gate */ 126#define HUFFPUFF 900 /* huff-n'-puff sample interval (s) */ 127#define MAXHOP 2 /* anti-clockhop threshold */ 128#define MAX_TTL 8 /* max ttl mapping vector size */ 129#define BEACON 7200 /* manycast beacon interval */ 130#define NTP_MAXEXTEN 2048 /* max extension field size */ 131#define NTP_ORPHWAIT 300 /* orphan wair (s) */ 132 133/* 134 * Miscellaneous stuff 135 */ 136#define NTP_MAXKEY 65535 /* max authentication key number */ 137#define KEY_TYPE_MD5 NID_md5 /* MD5 digest NID */ 138/* 139 * Limits of things 140 */ 141#define MAXFILENAME 256 /* max length of file name */ 142#define MAXHOSTNAME 512 /* max length of host/node name */ 143#define NTP_MAXSTRLEN 256 /* max string length */ 144 145/* 146 * Operations for jitter calculations (these use doubles). 147 * 148 * Note that we carefully separate the jitter component from the 149 * dispersion component (frequency error plus precision). The frequency 150 * error component is computed as CLOCK_PHI times the difference between 151 * the epoch of the time measurement and the reference time. The 152 * precision component is computed as the square root of the mean of the 153 * squares of a zero-mean, uniform distribution of unit maximum 154 * amplitude. Whether this makes statistical sense may be arguable. 155 */ | |
156#define SQUARE(x) ((x) * (x)) 157#define SQRT(x) (sqrt(x)) 158#define DIFF(x, y) (SQUARE((x) - (y))) | 122#define SQUARE(x) ((x) * (x)) 123#define SQRT(x) (sqrt(x)) 124#define DIFF(x, y) (SQUARE((x) - (y))) |
159#define LOGTOD(a) ldexp(1., (int)(a)) /* log2 to double */ | 125#define LOGTOD(a) ((a) < 0 ? 1. / (1L << -(a)) : \ 126 1L << (int)(a)) /* log2 to double */ |
160#define UNIVAR(x) (SQUARE(.28867513 * LOGTOD(x))) /* std uniform distr */ | 127#define UNIVAR(x) (SQUARE(.28867513 * LOGTOD(x))) /* std uniform distr */ |
161#define ULOGTOD(a) ldexp(1., (int)(a)) /* ulog2 to double */ | 128#define ULOGTOD(a) (1L << (int)(a)) /* ulog2 to double */ 129#define MAXDISPERSE 16. /* max dispersion (square) */ 130#define MINDISPERSE .01 /* min dispersion */ 131#define MAXDISTANCE 1. /* max root distance */ |
162 | 132 |
163#define EVENT_TIMEOUT 0 /* one second, that is */ | 133/* 134 * Loop filter parameters. See section 5.1 of the specification. 135 * 136 * Note that these are appropriate for a crystal time base. If your 137 * system clock is line frequency controlled you should read the 138 * specification for appropriate modifications. 139 */ 140#define CLOCK_PHI 15e-6 /* max frequency wander */ |
164 | 141 |
142#define EVENT_TIMEOUT 0 /* one second, that is */ |
|
165 166/* 167 * The interface structure is used to hold the addresses and socket | 143 144/* 145 * The interface structure is used to hold the addresses and socket |
168 * numbers of each of the local network addresses we are using. 169 * Because "interface" is a reserved word in C++ and has so many 170 * varied meanings, a change to "endpt" (via typedef) is under way. 171 * Eventually the struct tag will change from interface to endpt_tag. 172 * endpt is unrelated to the select algorithm's struct endpoint. | 146 * numbers of each of the interfaces we are using. |
173 */ | 147 */ |
174typedef struct interface endpt; | |
175struct interface { | 148struct interface { |
176 endpt * elink; /* endpt list link */ 177 endpt * mclink; /* per-AF_* multicast list */ 178 void * ioreg_ctx; /* IO registration context */ 179 SOCKET fd; /* socket descriptor */ 180 SOCKET bfd; /* for receiving broadcasts */ 181 u_int32 ifnum; /* endpt instance count */ 182 sockaddr_u sin; /* unicast address */ 183 sockaddr_u mask; /* subnet mask */ 184 sockaddr_u bcast; /* broadcast address */ 185 char name[32]; /* name of interface */ 186 u_short family; /* AF_INET/AF_INET6 */ 187 u_short phase; /* phase in update cycle */ 188 u_int32 flags; /* interface flags */ 189 int last_ttl; /* last TTL specified */ 190 u_int32 addr_refid; /* IPv4 addr or IPv6 hash */ 191 int num_mcast; /* mcast addrs enabled */ 192 u_long starttime; /* current_time at creation */ 193 volatile long received; /* number of incoming packets */ 194 long sent; /* number of outgoing packets */ 195 long notsent; /* number of send failures */ 196 u_int ifindex; /* for IPV6_MULTICAST_IF */ 197 isc_boolean_t ignore_packets; /* listen-read-drop this? */ 198 struct peer * peers; /* list of peers using endpt */ 199 u_int peercnt; /* count of same */ | 149 int fd; /* socket this is opened on */ 150 int bfd; /* socket for receiving broadcasts */ 151 struct sockaddr_in sin; /* interface address */ 152 struct sockaddr_in bcast; /* broadcast address */ 153 struct sockaddr_in mask; /* interface mask */ 154 char name[8]; /* name of interface */ 155 int flags; /* interface flags */ 156 int last_ttl; /* last TTL specified */ 157 volatile long received; /* number of incoming packets */ 158 long sent; /* number of outgoing packets */ 159 long notsent; /* number of send failures */ |
200}; 201 202/* 203 * Flags for interfaces 204 */ | 160}; 161 162/* 163 * Flags for interfaces 164 */ |
205#define INT_UP 0x001 /* Interface is up */ 206#define INT_PPP 0x002 /* Point-to-point interface */ 207#define INT_LOOPBACK 0x004 /* the loopback interface */ 208#define INT_BROADCAST 0x008 /* can broadcast out this interface */ 209#define INT_MULTICAST 0x010 /* can multicast out this interface */ 210#define INT_BCASTOPEN 0x020 /* broadcast receive socket is open */ 211#define INT_MCASTOPEN 0x040 /* multicasting enabled */ 212#define INT_WILDCARD 0x080 /* wildcard interface - usually skipped */ 213#define INT_MCASTIF 0x100 /* bound directly to MCAST address */ 214#define INT_PRIVACY 0x200 /* RFC 4941 IPv6 privacy address */ 215#define INT_BCASTXMIT 0x400 /* socket setup to allow broadcasts */ | 165#define INT_BROADCAST 1 /* can broadcast out this interface */ 166#define INT_BCASTOPEN 2 /* broadcast socket is open */ 167#define INT_LOOPBACK 4 /* the loopback interface */ 168#define INT_MULTICAST 8 /* multicasting enabled */ |
216 217/* | 169 170/* |
218 * Define flasher bits (tests 1 through 11 in packet procedure) | 171 * Define flasher bits (tests 1 through 8 in packet procedure) |
219 * These reveal the state at the last grumble from the peer and are 220 * most handy for diagnosing problems, even if not strictly a state 221 * variable in the spec. These are recorded in the peer structure. | 172 * These reveal the state at the last grumble from the peer and are 173 * most handy for diagnosing problems, even if not strictly a state 174 * variable in the spec. These are recorded in the peer structure. |
222 * 223 * Packet errors | |
224 */ | 175 */ |
225#define TEST1 0X0001 /* duplicate packet */ 226#define TEST2 0x0002 /* bogus packet */ | 176#define TEST1 0x0001 /* duplicate packet received */ 177#define TEST2 0x0002 /* bogus packet received */ |
227#define TEST3 0x0004 /* protocol unsynchronized */ | 178#define TEST3 0x0004 /* protocol unsynchronized */ |
228#define TEST4 0x0008 /* access denied */ 229#define TEST5 0x0010 /* bad authentication */ 230#define TEST6 0x0020 /* bad synch or stratum */ 231#define TEST7 0x0040 /* bad header */ 232#define TEST8 0x0080 /* bad autokey */ 233#define TEST9 0x0100 /* bad crypto */ 234#define PKT_TEST_MASK (TEST1 | TEST2 | TEST3 | TEST4 | TEST5 |\ 235 TEST6 | TEST7 | TEST8 | TEST9) 236/* 237 * Peer errors 238 */ 239#define TEST10 0x0200 /* peer bad synch or stratum */ 240#define TEST11 0x0400 /* peer distance exceeded */ 241#define TEST12 0x0800 /* peer synchronization loop */ 242#define TEST13 0x1000 /* peer unreacable */ 243#define PEER_TEST_MASK (TEST10 | TEST11 | TEST12 | TEST13) | 179#define TEST4 0x0008 /* peer delay/dispersion bounds check */ 180#define TEST5 0x0010 /* peer authentication failed */ 181#define TEST6 0x0020 /* peer clock unsynchronized */ 182#define TEST7 0x0040 /* peer stratum out of bounds */ 183#define TEST8 0x0080 /* root delay/dispersion bounds check */ 184#define TEST9 0x0100 /* peer not authenticated */ 185#define TEST10 0x0200 /* access denied */ |
244 245/* | 186 187/* |
246 * Unused flags 247 */ 248#define TEST14 0x2000 249#define TEST15 0x4000 250#define TEST16 0x8000 251 252/* 253 * The peer structure. Holds state information relating to the guys 254 * we are peering with. Most of this stuff is from section 3.2 of the | 188 * The peer structure. Holds state information relating to the guys 189 * we are peering with. Most of this stuff is from section 3.2 of the |
255 * spec. 256 */ 257struct peer { | 190 * spec. 191 */ 192struct peer { |
258 struct peer *p_link; /* link pointer in free & peer lists */ 259 struct peer *adr_link; /* link pointer in address hash */ 260 struct peer *aid_link; /* link pointer in associd hash */ 261 struct peer *ilink; /* list of peers for interface */ 262 sockaddr_u srcadr; /* address of remote host */ 263 char * hostname; /* if non-NULL, remote name */ 264 struct addrinfo *addrs; /* hostname query result */ 265 struct addrinfo *ai; /* position within addrs */ 266 endpt * dstadr; /* local address */ 267 associd_t associd; /* association ID */ 268 u_char version; /* version number */ 269 u_char hmode; /* local association mode */ 270 u_char hpoll; /* local poll interval */ 271 u_char minpoll; /* min poll interval */ 272 u_char maxpoll; /* max poll interval */ 273 u_int flags; /* association flags */ 274 u_char cast_flags; /* additional flags */ 275 u_char last_event; /* last peer error code */ 276 u_char num_events; /* number of error events */ 277 u_int32 ttl; /* ttl/refclock mode */ 278 char *ident; /* group identifier name */ | 193 struct peer *next; 194 struct peer *ass_next; /* link pointer in associd hash */ 195 struct sockaddr_in srcadr; /* address of remote host */ 196 struct interface *dstadr; /* pointer to address on local host */ 197 struct refclockproc *procptr; /* pointer to reference clock stuff */ 198 u_char leap; /* leap indicator */ 199 u_char hmode; /* association mode with this peer */ 200 u_char pmode; /* peer's association mode */ 201 u_char stratum; /* stratum of remote peer */ 202 s_char precision; /* peer's clock precision */ 203 u_char ppoll; /* peer poll interval */ 204 u_char hpoll; /* local host poll interval */ 205 u_char minpoll; /* min local host poll interval */ 206 u_char maxpoll; /* max local host poll interval */ 207 u_char burst; /* packets remaining in burst */ 208 u_char version; /* version number */ 209 u_int flags; /* peer flags */ 210 u_char cast_flags; /* flags MDF_?CAST */ 211 u_int flash; /* protocol error tally bits */ 212 u_char refclktype; /* reference clock type */ 213 u_char refclkunit; /* reference clock unit number */ 214 u_char sstclktype; /* clock type for system status word */ 215 u_int32 refid; /* peer reference ID */ 216 l_fp reftime; /* update epoch */ 217 u_long keyid; /* current key ID */ 218 u_long pkeyid; /* previous key ID (autokey) */ 219 u_long *keylist; /* session key identifier list */ 220 int keynumber; /* session key identifier number */ 221 u_short associd; /* association ID, a unique integer */ 222 u_char ttl; /* time to live (multicast) */ |
279 | 223 |
280 /* 281 * Variables used by reference clock support 282 */ 283#ifdef REFCLOCK 284 struct refclockproc *procptr; /* refclock structure pointer */ 285 u_char refclktype; /* reference clock type */ 286 u_char refclkunit; /* reference clock unit number */ 287 u_char sstclktype; /* clock type for system status word */ 288#endif /* REFCLOCK */ | 224/* **Start of clear-to-zero area.*** */ 225/* Everything that is cleared to zero goes below here */ 226 u_char valid; /* valid counter */ 227#define clear_to_zero valid 228 double estbdelay; /* broadcast offset */ 229 u_char status; /* peer status */ 230 u_char pollsw; /* what it says */ 231 u_char reach; /* reachability, NTP_WINDOW bits */ 232 u_char unreach; /* unreachable count */ 233 u_short filter_nextpt; /* index into filter shift register */ 234 double filter_delay[NTP_SHIFT]; /* delay part of shift register */ 235 double filter_offset[NTP_SHIFT]; /* offset part of shift register */ 236 double filter_disp[NTP_SHIFT]; /* dispersion part of shift register */ 237 u_long filter_epoch[NTP_SHIFT]; /* epoch part of shift register */ 238 u_char filter_order[NTP_SHIFT]; /* we keep the filter sorted here */ 239 l_fp org; /* originate time stamp */ 240 l_fp rec; /* receive time stamp */ 241 l_fp xmt; /* transmit time stamp */ 242 double offset; /* peer clock offset */ 243 double delay; /* peer roundtrip delay */ 244 double variance; /* peer variance (jitter) */ 245 double disp; /* peer dispersion */ 246 double rootdelay; /* roundtrip delay to primary clock */ 247 double rootdispersion; /* dispersion to primary clock */ 248 u_long epoch; /* reference epoch */ |
289 | 249 |
290 /* 291 * Variables set by received packet 292 */ 293 u_char leap; /* local leap indicator */ 294 u_char pmode; /* remote association mode */ 295 u_char stratum; /* remote stratum */ 296 u_char ppoll; /* remote poll interval */ 297 s_char precision; /* remote clock precision */ 298 double rootdelay; /* roundtrip delay to primary source */ 299 double rootdisp; /* dispersion to primary source */ 300 u_int32 refid; /* remote reference ID */ 301 l_fp reftime; /* update epoch */ 302 303 /* 304 * Variables used by authenticated client 305 */ 306 keyid_t keyid; /* current key ID */ 307#ifdef AUTOKEY 308#define clear_to_zero opcode 309 u_int32 opcode; /* last request opcode */ 310 associd_t assoc; /* peer association ID */ 311 u_int32 crypto; /* peer status word */ 312 EVP_PKEY *pkey; /* public key */ 313 const EVP_MD *digest; /* message digest algorithm */ 314 char *subject; /* certificate subject name */ 315 char *issuer; /* certificate issuer name */ 316 struct cert_info *xinfo; /* issuer certificate */ 317 keyid_t pkeyid; /* previous key ID */ 318 keyid_t hcookie; /* host cookie */ 319 keyid_t pcookie; /* peer cookie */ 320 const struct pkey_info *ident_pkey; /* identity key */ 321 BIGNUM *iffval; /* identity challenge (IFF, GQ, MV) */ 322 const BIGNUM *grpkey; /* identity challenge key (GQ) */ 323 struct value cookval; /* receive cookie values */ 324 struct value recval; /* receive autokey values */ 325 struct exten *cmmd; /* extension pointer */ 326 u_long refresh; /* next refresh epoch */ 327 328 /* 329 * Variables used by authenticated server 330 */ 331 keyid_t *keylist; /* session key ID list */ 332 int keynumber; /* current key number */ 333 struct value encrypt; /* send encrypt values */ 334 struct value sndval; /* send autokey values */ 335#else /* !AUTOKEY follows */ 336#define clear_to_zero status 337#endif /* !AUTOKEY */ 338 339 /* 340 * Ephemeral state variables 341 */ 342 u_char status; /* peer status */ 343 u_char new_status; /* under-construction status */ 344 u_char reach; /* reachability register */ 345 int flash; /* protocol error test tally bits */ 346 u_long epoch; /* reference epoch */ 347 int burst; /* packets remaining in burst */ 348 int retry; /* retry counter */ 349 int flip; /* interleave mode control */ 350 int filter_nextpt; /* index into filter shift register */ 351 double filter_delay[NTP_SHIFT]; /* delay shift register */ 352 double filter_offset[NTP_SHIFT]; /* offset shift register */ 353 double filter_disp[NTP_SHIFT]; /* dispersion shift register */ 354 u_long filter_epoch[NTP_SHIFT]; /* epoch shift register */ 355 u_char filter_order[NTP_SHIFT]; /* filter sort index */ 356 l_fp rec; /* receive time stamp */ 357 l_fp xmt; /* transmit time stamp */ 358 l_fp dst; /* destination timestamp */ 359 l_fp aorg; /* origin timestamp */ 360 l_fp borg; /* alternate origin timestamp */ 361 l_fp bxmt; /* most recent broadcast transmit timestamp */ 362 double offset; /* peer clock offset */ 363 double delay; /* peer roundtrip delay */ 364 double jitter; /* peer jitter (squares) */ 365 double disp; /* peer dispersion */ 366 double xleave; /* interleave delay */ 367 double bias; /* programmed offset bias */ 368 369 /* 370 * Variables used to correct for packet length and asymmetry. 371 */ 372 double t21; /* outbound packet delay */ 373 int t21_bytes; /* outbound packet length */ 374 int t21_last; /* last outbound packet length */ 375 double r21; /* outbound data rate */ 376 double t34; /* inbound packet delay */ 377 int t34_bytes; /* inbound packet length */ 378 double r34; /* inbound data rate */ 379 380 /* 381 * End of clear-to-zero area 382 */ 383 u_long update; /* receive epoch */ | 250/* ***End of clear-to-zero area.*** */ 251/* Everything that is cleared to zero goes above here */ 252 u_long update; /* receive epoch */ |
384#define end_clear_to_zero update | 253#define end_clear_to_zero update |
385 int unreach; /* watchdog counter */ 386 int throttle; /* rate control */ 387 u_long outdate; /* send time last packet */ 388 u_long nextdate; /* send time next packet */ 389 | 254 u_long outdate; /* send time last packet */ 255 u_long nextdate; /* send time next packet */ 256 u_long nextaction; /* peer local activity timeout (refclocks mainly) */ 257 void (*action) P((struct peer *));/* action timeout function */ |
390 /* | 258 /* |
391 * Statistic counters | 259 * statistic counters |
392 */ | 260 */ |
393 u_long timereset; /* time stat counters were reset */ 394 u_long timelastrec; /* last packet received time */ 395 u_long timereceived; /* last (clean) packet received time */ 396 u_long timereachable; /* last reachable/unreachable time */ 397 398 u_long sent; /* packets sent */ 399 u_long received; /* packets received */ 400 u_long processed; /* packets processed */ 401 u_long badauth; /* bad authentication (TEST5) */ 402 u_long badNAK; /* invalid crypto-NAK */ 403 u_long bogusorg; /* bogus origin (TEST2, TEST3) */ 404 u_long oldpkt; /* old duplicate (TEST1) */ 405 u_long seldisptoolarge; /* bad header (TEST6, TEST7) */ 406 u_long selbroken; /* KoD received */ | 261 u_long timereset; /* time stat counters were reset */ 262 u_long sent; /* number of updates sent */ 263 u_long received; /* number of frames received */ 264 u_long timereceived; /* last time a frame received */ 265 u_long timereachable; /* last reachable/unreachable event */ 266 u_long processed; /* processed by the protocol */ 267 u_long badauth; /* bad credentials detected */ 268 u_long bogusorg; /* rejected due to bogus origin */ 269 u_long oldpkt; /* rejected as duplicate packet */ 270 u_long seldisptoolarge; /* too much dispersion for selection */ 271 u_long selbroken; /* broken NTP detected in selection */ 272 u_long seltooold; /* too long since sync in selection */ 273 u_char last_event; /* set to code for last peer error */ 274 u_char num_events; /* num. of events which have occurred */ |
407}; 408 409/* 410 * Values for peer.leap, sys_leap 411 */ 412#define LEAP_NOWARNING 0x0 /* normal, no leap second warning */ 413#define LEAP_ADDSECOND 0x1 /* last minute of day has 61 seconds */ 414#define LEAP_DELSECOND 0x2 /* last minute of day has 59 seconds */ 415#define LEAP_NOTINSYNC 0x3 /* overload, clock is free running */ 416 417/* | 275}; 276 277/* 278 * Values for peer.leap, sys_leap 279 */ 280#define LEAP_NOWARNING 0x0 /* normal, no leap second warning */ 281#define LEAP_ADDSECOND 0x1 /* last minute of day has 61 seconds */ 282#define LEAP_DELSECOND 0x2 /* last minute of day has 59 seconds */ 283#define LEAP_NOTINSYNC 0x3 /* overload, clock is free running */ 284 285/* |
418 * Values for peer mode and packet mode. Only the modes through 419 * MODE_BROADCAST and MODE_BCLIENT appear in the transition 420 * function. MODE_CONTROL and MODE_PRIVATE can appear in packets, 421 * but those never survive to the transition function. 422 * is a 423/ */ 424#define MODE_UNSPEC 0 /* unspecified (old version) */ 425#define MODE_ACTIVE 1 /* symmetric active mode */ 426#define MODE_PASSIVE 2 /* symmetric passive mode */ | 286 * Values for peer.mode 287 */ 288#define MODE_UNSPEC 0 /* unspecified (probably old NTP version) */ 289#define MODE_ACTIVE 1 /* symmetric active */ 290#define MODE_PASSIVE 2 /* symmetric passive */ |
427#define MODE_CLIENT 3 /* client mode */ 428#define MODE_SERVER 4 /* server mode */ 429#define MODE_BROADCAST 5 /* broadcast mode */ | 291#define MODE_CLIENT 3 /* client mode */ 292#define MODE_SERVER 4 /* server mode */ 293#define MODE_BROADCAST 5 /* broadcast mode */ |
430/* 431 * These can appear in packets 432 */ 433#define MODE_CONTROL 6 /* control mode */ 434#define MODE_PRIVATE 7 /* private mode */ 435/* 436 * This is a madeup mode for broadcast client. 437 */ 438#define MODE_BCLIENT 6 /* broadcast client mode */ | 294#define MODE_CONTROL 6 /* control mode packet */ 295#define MODE_PRIVATE 7 /* implementation defined function */ |
439 | 296 |
297#define MODE_BCLIENT 8 /* a pseudo mode, used internally */ 298#define MODE_MCLIENT 9 /* multicast mode, used internally */ 299 |
|
440/* 441 * Values for peer.stratum, sys_stratum 442 */ | 300/* 301 * Values for peer.stratum, sys_stratum 302 */ |
443#define STRATUM_REFCLOCK ((u_char)0) /* default stratum */ | 303#define STRATUM_REFCLOCK ((u_char)0) /* stratum claimed by primary clock */ 304#define STRATUM_PRIMARY ((u_char)1) /* host has a primary clock */ 305#define STRATUM_INFIN ((u_char)NTP_MAXSTRATUM) /* infinity a la Bellman-Ford */ |
444/* A stratum of 0 in the packet is mapped to 16 internally */ 445#define STRATUM_PKT_UNSPEC ((u_char)0) /* unspecified in packet */ | 306/* A stratum of 0 in the packet is mapped to 16 internally */ 307#define STRATUM_PKT_UNSPEC ((u_char)0) /* unspecified in packet */ |
446#define STRATUM_UNSPEC ((u_char)16) /* unspecified */ | 308#define STRATUM_UNSPEC ((u_char)(NTP_MAXSTRATUM+(u_char)1)) /* unspecified */ |
447 448/* | 309 310/* |
449 * Values for peer.flags (u_int) | 311 * Values for peer.flags |
450 */ | 312 */ |
451#define FLAG_CONFIG 0x0001 /* association was configured */ 452#define FLAG_PREEMPT 0x0002 /* preemptable association */ 453#define FLAG_AUTHENTIC 0x0004 /* last message was authentic */ 454#define FLAG_REFCLOCK 0x0008 /* this is actually a reference clock */ 455#define FLAG_BC_VOL 0x0010 /* broadcast client volleying */ 456#define FLAG_PREFER 0x0020 /* prefer peer */ 457#define FLAG_BURST 0x0040 /* burst mode */ 458#define FLAG_PPS 0x0080 /* steered by PPS */ 459#define FLAG_IBURST 0x0100 /* initial burst mode */ 460#define FLAG_NOSELECT 0x0200 /* never select */ 461#define FLAG_TRUE 0x0400 /* force truechimer */ 462#define FLAG_SKEY 0x0800 /* autokey authentication */ 463#define FLAG_XLEAVE 0x1000 /* interleaved protocol */ 464#define FLAG_XB 0x2000 /* interleaved broadcast */ 465#define FLAG_XBOGUS 0x4000 /* interleaved bogus packet */ 466#ifdef OPENSSL 467# define FLAG_ASSOC 0x8000 /* autokey request */ 468#endif /* OPENSSL */ 469#define FLAG_TSTAMP_PPS 0x10000 /* PPS source provides absolute timestamp */ | 313#define FLAG_CONFIG 0x1 /* association was configured */ 314#define FLAG_AUTHENABLE 0x2 /* this guy needs authentication */ 315#define FLAG_MCAST1 0x4 /* multicast client/server mode */ 316#define FLAG_MCAST2 0x8 /* multicast client mode */ 317#define FLAG_AUTHENTIC 0x10 /* last message was authentic */ 318#define FLAG_REFCLOCK 0x20 /* this is actually a reference clock */ 319#define FLAG_SYSPEER 0x40 /* this is one of the selected peers */ 320#define FLAG_PREFER 0x80 /* this is the preferred peer */ 321#define FLAG_BURST 0x100 /* burst mode */ 322#define FLAG_SKEY 0x200 /* autokey authentication */ 323#define FLAG_NOSELECT 0x400 /* this is a "noselect" peer */ |
470 471/* 472 * Definitions for the clear() routine. We use memset() to clear 473 * the parts of the peer structure which go to zero. These are 474 * used to calculate the start address and length of the area. 475 */ 476#define CLEAR_TO_ZERO(p) ((char *)&((p)->clear_to_zero)) 477#define END_CLEAR_TO_ZERO(p) ((char *)&((p)->end_clear_to_zero)) | 324 325/* 326 * Definitions for the clear() routine. We use memset() to clear 327 * the parts of the peer structure which go to zero. These are 328 * used to calculate the start address and length of the area. 329 */ 330#define CLEAR_TO_ZERO(p) ((char *)&((p)->clear_to_zero)) 331#define END_CLEAR_TO_ZERO(p) ((char *)&((p)->end_clear_to_zero)) |
478#define LEN_CLEAR_TO_ZERO(p) (END_CLEAR_TO_ZERO(p) - CLEAR_TO_ZERO(p)) 479#define CRYPTO_TO_ZERO(p) ((char *)&((p)->clear_to_zero)) 480#define END_CRYPTO_TO_ZERO(p) ((char *)&((p)->end_clear_to_zero)) 481#define LEN_CRYPTO_TO_ZERO (END_CRYPTO_TO_ZERO((struct peer *)0) \ 482 - CRYPTO_TO_ZERO((struct peer *)0)) | 332#define LEN_CLEAR_TO_ZERO (END_CLEAR_TO_ZERO((struct peer *)0) \ 333 - CLEAR_TO_ZERO((struct peer *)0)) 334/* 335 * Reference clock identifiers (for pps signal) 336 */ 337#define PPSREFID (u_int32)"PPS " /* used when pps controls stratum>1 */ |
483 484/* 485 * Reference clock types. Added as necessary. 486 */ 487#define REFCLK_NONE 0 /* unknown or missing */ 488#define REFCLK_LOCALCLOCK 1 /* external (e.g., lockclock) */ 489#define REFCLK_GPS_TRAK 2 /* TRAK 8810 GPS Receiver */ 490#define REFCLK_WWV_PST 3 /* PST/Traconex 1020 WWV/H */ | 338 339/* 340 * Reference clock types. Added as necessary. 341 */ 342#define REFCLK_NONE 0 /* unknown or missing */ 343#define REFCLK_LOCALCLOCK 1 /* external (e.g., lockclock) */ 344#define REFCLK_GPS_TRAK 2 /* TRAK 8810 GPS Receiver */ 345#define REFCLK_WWV_PST 3 /* PST/Traconex 1020 WWV/H */ |
491#define REFCLK_SPECTRACOM 4 /* Spectracom (generic) Receivers */ | 346#define REFCLK_WWVB_SPECTRACOM 4 /* Spectracom 8170/Netclock WWVB */ |
492#define REFCLK_TRUETIME 5 /* TrueTime (generic) Receivers */ | 347#define REFCLK_TRUETIME 5 /* TrueTime (generic) Receivers */ |
493#define REFCLK_IRIG_AUDIO 6 /* IRIG-B/W audio decoder */ 494#define REFCLK_CHU_AUDIO 7 /* CHU audio demodulator/decoder */ | 348#define REFCLK_IRIG_AUDIO 6 /* IRIG-B audio decoder */ 349#define REFCLK_CHU 7 /* scratchbuilt CHU (Canada) */ |
495#define REFCLK_PARSE 8 /* generic driver (usually DCF77,GPS,MSF) */ 496#define REFCLK_GPS_MX4200 9 /* Magnavox MX4200 GPS */ 497#define REFCLK_GPS_AS2201 10 /* Austron 2201A GPS */ 498#define REFCLK_GPS_ARBITER 11 /* Arbiter 1088A/B/ GPS */ 499#define REFCLK_IRIG_TPRO 12 /* KSI/Odetics TPRO-S IRIG */ 500#define REFCLK_ATOM_LEITCH 13 /* Leitch CSD 5300 Master Clock */ 501#define REFCLK_MSF_EES 14 /* EES M201 MSF Receiver */ 502#define REFCLK_GPSTM_TRUE 15 /* OLD TrueTime GPS/TM-TMD Receiver */ 503#define REFCLK_IRIG_BANCOMM 16 /* Bancomm GPS/IRIG Interface */ 504#define REFCLK_GPS_DATUM 17 /* Datum Programmable Time System */ | 350#define REFCLK_PARSE 8 /* generic driver (usually DCF77,GPS,MSF) */ 351#define REFCLK_GPS_MX4200 9 /* Magnavox MX4200 GPS */ 352#define REFCLK_GPS_AS2201 10 /* Austron 2201A GPS */ 353#define REFCLK_GPS_ARBITER 11 /* Arbiter 1088A/B/ GPS */ 354#define REFCLK_IRIG_TPRO 12 /* KSI/Odetics TPRO-S IRIG */ 355#define REFCLK_ATOM_LEITCH 13 /* Leitch CSD 5300 Master Clock */ 356#define REFCLK_MSF_EES 14 /* EES M201 MSF Receiver */ 357#define REFCLK_GPSTM_TRUE 15 /* OLD TrueTime GPS/TM-TMD Receiver */ 358#define REFCLK_IRIG_BANCOMM 16 /* Bancomm GPS/IRIG Interface */ 359#define REFCLK_GPS_DATUM 17 /* Datum Programmable Time System */ |
505#define REFCLK_ACTS 18 /* Generic Auto Computer Time Service */ | 360#define REFCLK_NIST_ACTS 18 /* NIST Auto Computer Time Service */ |
506#define REFCLK_WWV_HEATH 19 /* Heath GC1000 WWV/WWVH Receiver */ 507#define REFCLK_GPS_NMEA 20 /* NMEA based GPS clock */ 508#define REFCLK_GPS_VME 21 /* TrueTime GPS-VME Interface */ 509#define REFCLK_ATOM_PPS 22 /* 1-PPS Clock Discipline */ | 361#define REFCLK_WWV_HEATH 19 /* Heath GC1000 WWV/WWVH Receiver */ 362#define REFCLK_GPS_NMEA 20 /* NMEA based GPS clock */ 363#define REFCLK_GPS_VME 21 /* TrueTime GPS-VME Interface */ 364#define REFCLK_ATOM_PPS 22 /* 1-PPS Clock Discipline */ |
510#define REFCLK_PTB_ACTS 23 /* replaced by REFCLK_ACTS */ 511#define REFCLK_USNO 24 /* replaced by REFCLK_ACTS */ | 365#define REFCLK_PTB_ACTS 23 /* PTB Auto Computer Time Service */ 366#define REFCLK_USNO 24 /* Naval Observatory dialup */ |
512#define REFCLK_GPS_HP 26 /* HP 58503A Time/Frequency Receiver */ | 367#define REFCLK_GPS_HP 26 /* HP 58503A Time/Frequency Receiver */ |
513#define REFCLK_ARCRON_MSF 27 /* ARCRON MSF radio clock. */ | 368#define REFCLK_ARCRON_MSF 27 /* ARCRON MSF radio clock. */ |
514#define REFCLK_SHM 28 /* clock attached thru shared memory */ 515#define REFCLK_PALISADE 29 /* Trimble Navigation Palisade GPS */ 516#define REFCLK_ONCORE 30 /* Motorola UT Oncore GPS */ 517#define REFCLK_GPS_JUPITER 31 /* Rockwell Jupiter GPS receiver */ | 369#define REFCLK_SHM 28 /* clock attached thru shared memory */ 370#define REFCLK_PALISADE 29 /* Trimble Navigation Palisade GPS */ 371#define REFCLK_ONCORE 30 /* Motorola UT Oncore GPS */ 372#define REFCLK_GPS_JUPITER 31 /* Rockwell Jupiter GPS receiver */ |
518#define REFCLK_CHRONOLOG 32 /* Chrono-log K WWVB receiver */ 519#define REFCLK_DUMBCLOCK 33 /* Dumb localtime clock */ 520#define REFCLK_ULINK 34 /* Ultralink M320 WWVB receiver */ 521#define REFCLK_PCF 35 /* Conrad parallel port radio clock */ 522#define REFCLK_WWV_AUDIO 36 /* WWV/H audio demodulator/decoder */ 523#define REFCLK_FG 37 /* Forum Graphic GPS */ 524#define REFCLK_HOPF_SERIAL 38 /* hopf DCF77/GPS serial receiver */ 525#define REFCLK_HOPF_PCI 39 /* hopf DCF77/GPS PCI receiver */ 526#define REFCLK_JJY 40 /* JJY receiver */ 527#define REFCLK_TT560 41 /* TrueTime 560 IRIG-B decoder */ 528#define REFCLK_ZYFER 42 /* Zyfer GPStarplus receiver */ 529#define REFCLK_RIPENCC 43 /* RIPE NCC Trimble driver */ 530#define REFCLK_NEOCLOCK4X 44 /* NeoClock4X DCF77 or TDF receiver */ 531#define REFCLK_TSYNCPCI 45 /* Spectracom TSYNC PCI timing board */ 532#define REFCLK_GPSDJSON 46 533#define REFCLK_MAX 46 | 373#define REFCLK_CHRONOLOG 32 /* Chrono-log K WWVB receiver */ 374#define REFCLK_DUMBCLOCK 33 /* Dumb localtime clock */ 375#define REFCLK_ULINK 34 /* Ultralink M320 WWVB receiver */ 376#define REFCLK_MAX 34 /* Grow as needed... */ |
534 | 377 |
378/* 379 * We tell reference clocks from real peers by giving the reference 380 * clocks an address of the form 127.127.t.u, where t is the type and 381 * u is the unit number. We define some of this here since we will need 382 * some sanity checks to make sure this address isn't interpretted as 383 * that of a normal peer. 384 */ 385#define REFCLOCK_ADDR 0x7f7f0000 /* 127.127.0.0 */ 386#define REFCLOCK_MASK 0xffff0000 /* 255.255.0.0 */ |
|
535 | 387 |
388#define ISREFCLOCKADR(srcadr) ((SRCADR(srcadr) & REFCLOCK_MASK) \ 389 == REFCLOCK_ADDR) 390 |
|
536/* | 391/* |
392 * Macro for checking for invalid addresses. This is really, really 393 * gross, but is needed so no one configures a host on net 127 now that 394 * we're encouraging it the the configuration file. 395 */ 396#define LOOPBACKADR 0x7f000001 397#define LOOPNETMASK 0xff000000 398 399#define ISBADADR(srcadr) (((SRCADR(srcadr) & LOOPNETMASK) \ 400 == (LOOPBACKADR & LOOPNETMASK)) \ 401 && (SRCADR(srcadr) != LOOPBACKADR)) 402 403/* 404 * Utilities for manipulating addresses and port numbers 405 */ 406#define NSRCADR(src) ((src)->sin_addr.s_addr) /* address in net byte order */ 407#define NSRCPORT(src) ((src)->sin_port) /* port in net byte order */ 408#define SRCADR(src) (ntohl(NSRCADR((src)))) /* address in host byte order */ 409#define SRCPORT(src) (ntohs(NSRCPORT((src)))) /* host port */ 410 411/* |
|
537 * NTP packet format. The mac field is optional. It isn't really 538 * an l_fp either, but for now declaring it that way is convenient. 539 * See Appendix A in the specification. 540 * 541 * Note that all u_fp and l_fp values arrive in network byte order 542 * and must be converted (except the mac, which isn't, really). 543 */ 544struct pkt { | 412 * NTP packet format. The mac field is optional. It isn't really 413 * an l_fp either, but for now declaring it that way is convenient. 414 * See Appendix A in the specification. 415 * 416 * Note that all u_fp and l_fp values arrive in network byte order 417 * and must be converted (except the mac, which isn't, really). 418 */ 419struct pkt { |
545 u_char li_vn_mode; /* peer leap indicator */ 546 u_char stratum; /* peer stratum */ 547 u_char ppoll; /* peer poll interval */ 548 s_char precision; /* peer clock precision */ 549 u_fp rootdelay; /* roundtrip delay to primary source */ 550 u_fp rootdisp; /* dispersion to primary source*/ 551 u_int32 refid; /* reference id */ 552 l_fp reftime; /* last update time */ 553 l_fp org; /* originate time stamp */ 554 l_fp rec; /* receive time stamp */ 555 l_fp xmt; /* transmit time stamp */ | 420 u_char li_vn_mode; /* contains leap indicator, version and mode */ 421 u_char stratum; /* peer's stratum */ 422 u_char ppoll; /* the peer polling interval */ 423 s_char precision; /* peer clock precision */ 424 u_fp rootdelay; /* distance to primary clock */ 425 u_fp rootdispersion; /* clock dispersion */ 426 u_int32 refid; /* reference clock ID */ 427 l_fp reftime; /* time peer clock was last updated */ 428 l_fp org; /* originate time stamp */ 429 l_fp rec; /* receive time stamp */ 430 l_fp xmt; /* transmit time stamp */ |
556 | 431 |
557#define MIN_V4_PKT_LEN (12 * sizeof(u_int32)) /* min header length */ 558#define LEN_PKT_NOMAC (12 * sizeof(u_int32)) /* min header length */ 559#define MIN_MAC_LEN (1 * sizeof(u_int32)) /* crypto_NAK */ 560#define MAX_MD5_LEN (5 * sizeof(u_int32)) /* MD5 */ 561#define MAX_MAC_LEN (6 * sizeof(u_int32)) /* SHA */ | 432#define MIN_MAC_LEN (sizeof(u_int32) + 8) /* DES */ 433#define MAX_MAC_LEN (sizeof(u_int32) + 16) /* MD5 */ |
562 563 /* 564 * The length of the packet less MAC must be a multiple of 64 | 434 435 /* 436 * The length of the packet less MAC must be a multiple of 64 |
565 * with an RSA modulus and Diffie-Hellman prime of 256 octets 566 * and maximum host name of 128 octets, the maximum autokey 567 * command is 152 octets and maximum autokey response is 460 568 * octets. A packet can contain no more than one command and one 569 * response, so the maximum total extension field length is 864 570 * octets. But, to handle humungus certificates, the bank must 571 * be broke. 572 * 573 * The different definitions of the 'exten' field are here for 574 * the benefit of applications that want to send a packet from 575 * an auto variable in the stack - not using the AUTOKEY version 576 * saves 2KB of stack space. The receive buffer should ALWAYS be 577 * big enough to hold a full extended packet if the extension 578 * fields have to be parsed or skipped. | 437 * bits. For normal private-key cryptography, the cryptosum 438 * covers only the raw NTP header. For autokey cryptography, 439 * the heade is incresed by 64 bits to contain the field length 440 * and private value. |
579 */ | 441 */ |
580#ifdef AUTOKEY 581 u_int32 exten[(NTP_MAXEXTEN + MAX_MAC_LEN) / sizeof(u_int32)]; 582#else /* !AUTOKEY follows */ 583 u_int32 exten[(MAX_MAC_LEN) / sizeof(u_int32)]; 584#endif /* !AUTOKEY */ | 442 u_int32 keyid1; /* key identifier 1 */ 443 u_int32 keyid2; /* key identifier 2 */ 444 u_int32 keyid3; /* key identifier 3 */ 445 u_char mac[MAX_MAC_LEN]; /* mac */ |
585}; 586 587/* | 446}; 447 448/* |
449 * Packets can come in two flavours, one with a mac and one without. 450 */ 451#define LEN_PKT_NOMAC (sizeof(struct pkt) - MAX_MAC_LEN - 3 * sizeof(u_int32)) 452 453/* 454 * Minimum size of packet with a MAC: has to include at least a key number. 455 */ 456#define LEN_PKT_MAC (LEN_PKT_NOMAC + sizeof(u_int32)) 457 458/* |
|
588 * Stuff for extracting things from li_vn_mode 589 */ 590#define PKT_MODE(li_vn_mode) ((u_char)((li_vn_mode) & 0x7)) 591#define PKT_VERSION(li_vn_mode) ((u_char)(((li_vn_mode) >> 3) & 0x7)) 592#define PKT_LEAP(li_vn_mode) ((u_char)(((li_vn_mode) >> 6) & 0x3)) 593 594/* | 459 * Stuff for extracting things from li_vn_mode 460 */ 461#define PKT_MODE(li_vn_mode) ((u_char)((li_vn_mode) & 0x7)) 462#define PKT_VERSION(li_vn_mode) ((u_char)(((li_vn_mode) >> 3) & 0x7)) 463#define PKT_LEAP(li_vn_mode) ((u_char)(((li_vn_mode) >> 6) & 0x3)) 464 465/* |
595 * Stuff for putting things back into li_vn_mode in packets and vn_mode 596 * in ntp_monitor.c's mon_entry. | 466 * Stuff for putting things back into li_vn_mode |
597 */ | 467 */ |
598#define VN_MODE(v, m) ((((v) & 7) << 3) | ((m) & 0x7)) 599#define PKT_LI_VN_MODE(l, v, m) ((((l) & 3) << 6) | VN_MODE((v), (m))) | 468#define PKT_LI_VN_MODE(li, vn, md) \ 469 ((u_char)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7))) |
600 601 602/* 603 * Dealing with stratum. 0 gets mapped to 16 incoming, and back to 0 604 * on output. 605 */ 606#define PKT_TO_STRATUM(s) ((u_char)(((s) == (STRATUM_PKT_UNSPEC)) ?\ 607 (STRATUM_UNSPEC) : (s))) 608 609#define STRATUM_TO_PKT(s) ((u_char)(((s) == (STRATUM_UNSPEC)) ?\ 610 (STRATUM_PKT_UNSPEC) : (s))) 611 | 470 471 472/* 473 * Dealing with stratum. 0 gets mapped to 16 incoming, and back to 0 474 * on output. 475 */ 476#define PKT_TO_STRATUM(s) ((u_char)(((s) == (STRATUM_PKT_UNSPEC)) ?\ 477 (STRATUM_UNSPEC) : (s))) 478 479#define STRATUM_TO_PKT(s) ((u_char)(((s) == (STRATUM_UNSPEC)) ?\ 480 (STRATUM_PKT_UNSPEC) : (s))) 481 |
612/* 613 * Event codes. Used for reporting errors/events to the control module 614 */ 615#define PEER_EVENT 0x080 /* this is a peer event */ 616#define CRPT_EVENT 0x100 /* this is a crypto event */ | |
617 618/* | 482 483/* |
619 * System event codes | 484 * Event codes. Used for reporting errors/events to the control module |
620 */ | 485 */ |
621#define EVNT_UNSPEC 0 /* unspecified */ 622#define EVNT_NSET 1 /* freq not set */ 623#define EVNT_FSET 2 /* freq set */ 624#define EVNT_SPIK 3 /* spike detect */ 625#define EVNT_FREQ 4 /* freq mode */ 626#define EVNT_SYNC 5 /* clock sync */ 627#define EVNT_SYSRESTART 6 /* restart */ 628#define EVNT_SYSFAULT 7 /* panic stop */ 629#define EVNT_NOPEER 8 /* no sys peer */ 630#define EVNT_ARMED 9 /* leap armed */ 631#define EVNT_DISARMED 10 /* leap disarmed */ 632#define EVNT_LEAP 11 /* leap event */ 633#define EVNT_CLOCKRESET 12 /* clock step */ 634#define EVNT_KERN 13 /* kernel event */ 635#define EVNT_TAI 14 /* TAI */ 636#define EVNT_LEAPVAL 15 /* stale leapsecond values */ | 486#define PEER_EVENT 0x80 /* this is a peer event */ |
637 | 487 |
638/* 639 * Peer event codes 640 */ 641#define PEVNT_MOBIL (1 | PEER_EVENT) /* mobilize */ 642#define PEVNT_DEMOBIL (2 | PEER_EVENT) /* demobilize */ 643#define PEVNT_UNREACH (3 | PEER_EVENT) /* unreachable */ 644#define PEVNT_REACH (4 | PEER_EVENT) /* reachable */ 645#define PEVNT_RESTART (5 | PEER_EVENT) /* restart */ 646#define PEVNT_REPLY (6 | PEER_EVENT) /* no reply */ 647#define PEVNT_RATE (7 | PEER_EVENT) /* rate exceeded */ 648#define PEVNT_DENY (8 | PEER_EVENT) /* access denied */ 649#define PEVNT_ARMED (9 | PEER_EVENT) /* leap armed */ 650#define PEVNT_NEWPEER (10 | PEER_EVENT) /* sys peer */ 651#define PEVNT_CLOCK (11 | PEER_EVENT) /* clock event */ 652#define PEVNT_AUTH (12 | PEER_EVENT) /* bad auth */ 653#define PEVNT_POPCORN (13 | PEER_EVENT) /* popcorn */ 654#define PEVNT_XLEAVE (14 | PEER_EVENT) /* interleave mode */ 655#define PEVNT_XERR (15 | PEER_EVENT) /* interleave error */ | 488#define EVNT_UNSPEC 0 489#define EVNT_SYSRESTART 1 490#define EVNT_SYSFAULT 2 491#define EVNT_SYNCCHG 3 492#define EVNT_PEERSTCHG 4 493#define EVNT_CLOCKRESET 5 494#define EVNT_BADDATETIM 6 495#define EVNT_CLOCKEXCPT 7 |
656 | 496 |
497#define EVNT_PEERIPERR (1|PEER_EVENT) 498#define EVNT_PEERAUTH (2|PEER_EVENT) 499#define EVNT_UNREACH (3|PEER_EVENT) 500#define EVNT_REACH (4|PEER_EVENT) 501#define EVNT_PEERCLOCK (5|PEER_EVENT) 502 |
|
657/* 658 * Clock event codes 659 */ | 503/* 504 * Clock event codes 505 */ |
660#define CEVNT_NOMINAL 0 /* unspecified */ 661#define CEVNT_TIMEOUT 1 /* no reply */ 662#define CEVNT_BADREPLY 2 /* bad format */ 663#define CEVNT_FAULT 3 /* fault */ 664#define CEVNT_PROP 4 /* bad signal */ 665#define CEVNT_BADDATE 5 /* bad date */ 666#define CEVNT_BADTIME 6 /* bad time */ | 506#define CEVNT_NOMINAL 0 507#define CEVNT_TIMEOUT 1 508#define CEVNT_BADREPLY 2 509#define CEVNT_FAULT 3 510#define CEVNT_PROP 4 511#define CEVNT_BADDATE 5 512#define CEVNT_BADTIME 6 |
667#define CEVNT_MAX CEVNT_BADTIME 668 669/* 670 * Very misplaced value. Default port through which we send traps. 671 */ 672#define TRAPPORT 18447 673 674 675/* | 513#define CEVNT_MAX CEVNT_BADTIME 514 515/* 516 * Very misplaced value. Default port through which we send traps. 517 */ 518#define TRAPPORT 18447 519 520 521/* |
676 * To speed lookups, peers are hashed by the low order bits of the 677 * remote IP address. These definitions relate to that. | 522 * To speed lookups, peers are hashed by the low order bits of the remote 523 * IP address. These definitions relate to that. |
678 */ | 524 */ |
679#define NTP_HASH_SIZE 128 680#define NTP_HASH_MASK (NTP_HASH_SIZE-1) 681#define NTP_HASH_ADDR(src) (sock_hash(src) & NTP_HASH_MASK) | 525#define HASH_SIZE 32 526#define HASH_MASK (HASH_SIZE-1) 527#define HASH_ADDR(src) ((SRCADR((src))^(SRCADR((src))>>8)) & HASH_MASK) |
682 683/* | 528 529/* |
530 * How we randomize polls. The poll interval is a power of two. 531 * We chose a random value which is between 1/4 and 3/4 of the 532 * poll interval we would normally use and which is an even multiple 533 * of the EVENT_TIMEOUT. The random number routine, given an argument 534 * spread value of n, returns an integer between 0 and (1<<n)-1. This 535 * is shifted by EVENT_TIMEOUT and added to the base value. 536 */ 537#if defined(HAVE_MRAND48) 538#define RANDOM (mrand48()) 539#define SRANDOM(x) (srand48(x)) 540#elif defined(HAVE_RANDOM) 541#define RANDOM (random()) 542#define SRANDOM(x) (srandom(x)) 543#else 544#define RANDOM (0) 545#define SRANDOM(x) (0) 546#endif 547 548#define RANDPOLL(x) ((1 << (x)) - 1 + (RANDOM & 0x3)) 549#define RANDOM_SPREAD(poll) ((poll) - (EVENT_TIMEOUT+1)) 550#define RANDOM_POLL(poll, rval) ((((rval)+1)<<EVENT_TIMEOUT) + (1<<((poll)-2))) 551 552/* |
|
684 * min, min3 and max. Makes it easier to transliterate the spec without 685 * thinking about it. 686 */ 687#define min(a,b) (((a) < (b)) ? (a) : (b)) 688#define max(a,b) (((a) > (b)) ? (a) : (b)) 689#define min3(a,b,c) min(min((a),(b)), (c)) 690 691 --- 6 unchanged lines hidden (view full) --- 698#define PROTO_BROADDELAY 4 699#define PROTO_AUTHDELAY 5 /* (not used) */ 700#define PROTO_MULTICAST_ADD 6 701#define PROTO_MULTICAST_DEL 7 702#define PROTO_NTP 8 703#define PROTO_KERNEL 9 704#define PROTO_MONITOR 10 705#define PROTO_FILEGEN 11 | 553 * min, min3 and max. Makes it easier to transliterate the spec without 554 * thinking about it. 555 */ 556#define min(a,b) (((a) < (b)) ? (a) : (b)) 557#define max(a,b) (((a) > (b)) ? (a) : (b)) 558#define min3(a,b,c) min(min((a),(b)), (c)) 559 560 --- 6 unchanged lines hidden (view full) --- 567#define PROTO_BROADDELAY 4 568#define PROTO_AUTHDELAY 5 /* (not used) */ 569#define PROTO_MULTICAST_ADD 6 570#define PROTO_MULTICAST_DEL 7 571#define PROTO_NTP 8 572#define PROTO_KERNEL 9 573#define PROTO_MONITOR 10 574#define PROTO_FILEGEN 11 |
706#define PROTO_PPS 12 707#define PROTO_CAL 13 708#define PROTO_MINCLOCK 14 709#define PROTO_MAXCLOCK 15 710#define PROTO_MINSANE 16 711#define PROTO_FLOOR 17 712#define PROTO_CEILING 18 713#define PROTO_COHORT 19 714#define PROTO_CALLDELAY 20 715#define PROTO_MINDISP 21 716#define PROTO_MAXDIST 22 717 /* available 23 */ 718#define PROTO_MAXHOP 24 719#define PROTO_BEACON 25 720#define PROTO_ORPHAN 26 721#define PROTO_ORPHWAIT 27 722#define PROTO_MODE7 28 723#define PROTO_UECRYPTO 29 724#define PROTO_UECRYPTONAK 30 725#define PROTO_UEDIGEST 31 726#define PROTO_PCEDIGEST 32 | |
727 728/* 729 * Configuration items for the loop filter 730 */ | 575 576/* 577 * Configuration items for the loop filter 578 */ |
731#define LOOP_DRIFTINIT 1 /* iniitialize frequency */ 732#define LOOP_KERN_CLEAR 2 /* set initial frequency offset */ 733#define LOOP_MAX 3 /* set both step offsets */ 734#define LOOP_MAX_BACK 4 /* set bacward-step offset */ 735#define LOOP_MAX_FWD 5 /* set forward-step offset */ 736#define LOOP_PANIC 6 /* set panic offseet */ 737#define LOOP_PHI 7 /* set dispersion rate */ 738#define LOOP_MINSTEP 8 /* set step timeout */ 739#define LOOP_MINPOLL 9 /* set min poll interval (log2 s) */ 740#define LOOP_ALLAN 10 /* set minimum Allan intercept */ 741#define LOOP_HUFFPUFF 11 /* set huff-n'-puff filter length */ 742#define LOOP_FREQ 12 /* set initial frequency */ 743#define LOOP_CODEC 13 /* set audio codec frequency */ 744#define LOOP_LEAP 14 /* insert leap after second 23:59 */ 745#define LOOP_TICK 15 /* sim. low precision clock */ | 579#define LOOP_DRIFTINIT 1 /* set initial frequency offset */ 580#define LOOP_DRIFTCOMP 2 /* set frequency offset */ 581#define LOOP_PPSDELAY 3 /* set pps delay */ 582#define LOOP_PPSBAUD 4 /* set pps baud rate */ |
746 747/* 748 * Configuration items for the stats printer 749 */ 750#define STATS_FREQ_FILE 1 /* configure drift file */ 751#define STATS_STATSDIR 2 /* directory prefix for stats files */ 752#define STATS_PID_FILE 3 /* configure ntpd PID file */ | 583 584/* 585 * Configuration items for the stats printer 586 */ 587#define STATS_FREQ_FILE 1 /* configure drift file */ 588#define STATS_STATSDIR 2 /* directory prefix for stats files */ 589#define STATS_PID_FILE 3 /* configure ntpd PID file */ |
753#define STATS_LEAP_FILE 4 /* configure ntpd leapseconds file */ | |
754 | 590 |
755#define MJD_1900 15020 /* MJD for 1 Jan 1900 */ | 591#define MJD_1970 40587 /* MJD for 1 Jan 1970 */ |
756 757/* 758 * Default parameters. We use these in the absence of something better. 759 */ | 592 593/* 594 * Default parameters. We use these in the absence of something better. 595 */ |
596#define DEFBROADDELAY 4e-3 /* default broadcast offset */ |
|
760#define INADDR_NTP 0xe0000101 /* NTP multicast address 224.0.1.1 */ | 597#define INADDR_NTP 0xe0000101 /* NTP multicast address 224.0.1.1 */ |
761 | |
762/* 763 * Structure used optionally for monitoring when this is turned on. 764 */ | 598/* 599 * Structure used optionally for monitoring when this is turned on. 600 */ |
765typedef struct mon_data mon_entry; | |
766struct mon_data { | 601struct mon_data { |
767 mon_entry * hash_next; /* next structure in hash list */ 768 DECL_DLIST_LINK(mon_entry, mru);/* MRU list link pointers */ 769 struct interface * lcladr; /* address on which this arrived */ 770 l_fp first; /* first time seen */ 771 l_fp last; /* last time seen */ 772 int leak; /* leaky bucket accumulator */ 773 int count; /* total packet count */ 774 u_short flags; /* restrict flags */ 775 u_char vn_mode; /* packet mode & version */ 776 u_char cast_flags; /* flags MDF_?CAST */ 777 sockaddr_u rmtadr; /* address of remote host */ | 602 struct mon_data *hash_next; /* next structure in hash list */ 603 struct mon_data *mru_next; /* next structure in MRU list */ 604 struct mon_data *mru_prev; /* previous structure in MRU list */ 605 struct mon_data *fifo_next; /* next structure in FIFO list */ 606 struct mon_data *fifo_prev; /* previous structure in FIFO list */ 607 u_long lastdrop; /* last time dropped due to RES_LIMIT*/ 608 u_long lasttime; /* last time data updated */ 609 u_long firsttime; /* time structure initialized */ 610 u_long count; /* count we have seen */ 611 u_int32 rmtadr; /* address of remote host */ 612 struct interface *interface; /* interface on which this arrived */ 613 u_short rmtport; /* remote port last came from */ 614 u_char mode; /* mode of incoming packet */ 615 u_char version; /* version of incoming packet */ 616 u_char cast_flags; /* flags MDF_?CAST */ |
778}; 779 | 617}; 618 |
619#define MDF_UCAST 0x1 /* unicast packet */ 620#define MDF_MCAST 0x2 /* multicast packet */ 621#define MDF_BCAST 0x4 /* broadcast packet */ 622#define MDF_LCAST 0x8 /* local packet */ 623#define MDF_ACAST 0x10 /* manycast packet */ 624 |
|
780/* | 625/* |
781 * Values for cast_flags in mon_entry and struct peer. mon_entry uses 782 * only the first three, MDF_UCAST, MDF_MCAST, and MDF_BCAST. 783 */ 784#define MDF_UCAST 0x01 /* unicast client */ 785#define MDF_MCAST 0x02 /* multicast server */ 786#define MDF_BCAST 0x04 /* broadcast server */ 787#define MDF_POOL 0x08 /* pool client solicitor */ 788#define MDF_ACAST 0x10 /* manycast client solicitor */ 789#define MDF_BCLNT 0x20 /* eph. broadcast/multicast client */ 790#define MDF_UCLNT 0x40 /* preemptible manycast or pool client */ 791/* 792 * In the context of struct peer in ntpd, three of the cast_flags bits 793 * represent configured associations which never receive packets, and 794 * whose reach is always 0: MDF_BCAST, MDF_MCAST, and MDF_ACAST. The 795 * last can be argued as responses are received, but those responses do 796 * not affect the MDF_ACAST association's reach register, rather they 797 * (may) result in mobilizing ephemeral MDF_ACLNT associations. 798 */ 799#define MDF_TXONLY_MASK (MDF_BCAST | MDF_MCAST | MDF_ACAST | MDF_POOL) 800/* 801 * manycastclient-like solicitor association cast_flags bits 802 */ 803#define MDF_SOLICIT_MASK (MDF_ACAST | MDF_POOL) 804/* | |
805 * Values used with mon_enabled to indicate reason for enabling monitoring 806 */ | 626 * Values used with mon_enabled to indicate reason for enabling monitoring 627 */ |
807#define MON_OFF 0x00 /* no monitoring */ 808#define MON_ON 0x01 /* monitoring explicitly enabled */ 809#define MON_RES 0x02 /* implicit monitoring for RES_LIMITED */ | 628#define MON_OFF 0x00 /* no monitoring */ 629#define MON_ON 0x01 /* monitoring explicitly enabled */ 630#define MON_RES 0x02 /* implicit monitoring for RES_LIMITED */ |
810/* 811 * Structure used for restrictlist entries 812 */ | 631/* 632 * Structure used for restrictlist entries 633 */ |
813typedef struct res_addr4_tag { 814 u_int32 addr; /* IPv4 addr (host order) */ 815 u_int32 mask; /* IPv4 mask (host order) */ 816} res_addr4; 817 818typedef struct res_addr6_tag { 819 struct in6_addr addr; /* IPv6 addr (net order) */ 820 struct in6_addr mask; /* IPv6 mask (net order) */ 821} res_addr6; 822 823typedef struct restrict_u_tag restrict_u; 824struct restrict_u_tag { 825 restrict_u * link; /* link to next entry */ 826 u_int32 count; /* number of packets matched */ 827 u_short flags; /* accesslist flags */ 828 u_short mflags; /* match flags */ 829 u_long expire; /* valid until time */ 830 union { /* variant starting here */ 831 res_addr4 v4; 832 res_addr6 v6; 833 } u; | 634struct restrictlist { 635 struct restrictlist *next; /* link to next entry */ 636 u_int32 addr; /* host address (host byte order) */ 637 u_int32 mask; /* mask for address (host byte order) */ 638 u_long count; /* number of packets matched */ 639 u_short flags; /* accesslist flags */ 640 u_short mflags; /* match flags */ |
834}; | 641}; |
835#define V4_SIZEOF_RESTRICT_U (offsetof(restrict_u, u) \ 836 + sizeof(res_addr4)) 837#define V6_SIZEOF_RESTRICT_U (offsetof(restrict_u, u) \ 838 + sizeof(res_addr6)) | |
839 840/* 841 * Access flags 842 */ | 642 643/* 644 * Access flags 645 */ |
843#define RES_IGNORE 0x0001 /* ignore packet */ 844#define RES_DONTSERVE 0x0002 /* access denied */ 845#define RES_DONTTRUST 0x0004 /* authentication required */ 846#define RES_VERSION 0x0008 /* version mismatch */ 847#define RES_NOPEER 0x0010 /* new association denied */ 848#define RES_LIMITED 0x0020 /* packet rate exceeded */ 849#define RES_FLAGS (RES_IGNORE | RES_DONTSERVE |\ 850 RES_DONTTRUST | RES_VERSION |\ 851 RES_NOPEER | RES_LIMITED) | 646#define RES_IGNORE 0x1 /* ignore if matched */ 647#define RES_DONTSERVE 0x2 /* don't give him any time */ 648#define RES_DONTTRUST 0x4 /* don't trust if matched */ 649#define RES_NOQUERY 0x8 /* don't allow queries if matched */ 650#define RES_NOMODIFY 0x10 /* don't allow him to modify server */ 651#define RES_NOPEER 0x20 /* don't allocate memory resources */ 652#define RES_NOTRAP 0x40 /* don't allow him to set traps */ 653#define RES_LPTRAP 0x80 /* traps set by him are low priority */ 654#define RES_LIMITED 0x100 /* limit per net number of clients */ |
852 | 655 |
853#define RES_NOQUERY 0x0040 /* mode 6/7 packet denied */ 854#define RES_NOMODIFY 0x0080 /* mode 6/7 modify denied */ 855#define RES_NOTRAP 0x0100 /* mode 6/7 set trap denied */ 856#define RES_LPTRAP 0x0200 /* mode 6/7 low priority trap */ | 656#define RES_ALLFLAGS \ 657 (RES_IGNORE|RES_DONTSERVE|RES_DONTTRUST|RES_NOQUERY\ 658 |RES_NOMODIFY|RES_NOPEER|RES_NOTRAP|RES_LPTRAP|RES_LIMITED) |
857 | 659 |
858#define RES_KOD 0x0400 /* send kiss of death packet */ 859#define RES_MSSNTP 0x0800 /* enable MS-SNTP authentication */ 860#define RES_FLAKE 0x1000 /* flakeway - drop 10% */ 861#define RES_NOMRULIST 0x2000 /* mode 6 mrulist denied */ 862 863#define RES_ALLFLAGS (RES_FLAGS | RES_NOQUERY | \ 864 RES_NOMODIFY | RES_NOTRAP | \ 865 RES_LPTRAP | RES_KOD | \ 866 RES_MSSNTP | RES_FLAKE | \ 867 RES_NOMRULIST) 868 | |
869/* 870 * Match flags 871 */ | 660/* 661 * Match flags 662 */ |
872#define RESM_INTERFACE 0x1000 /* this is an interface */ 873#define RESM_NTPONLY 0x2000 /* match source port 123 */ 874#define RESM_SOURCE 0x4000 /* from "restrict source" */ | 663#define RESM_INTERFACE 0x1 /* this is an interface */ 664#define RESM_NTPONLY 0x2 /* match ntp port only */ |
875 876/* 877 * Restriction configuration ops 878 */ 879#define RESTRICT_FLAGS 1 /* add flags to restrict entry */ 880#define RESTRICT_UNFLAG 2 /* remove flags from restrict entry */ 881#define RESTRICT_REMOVE 3 /* remove a restrict entry */ | 665 666/* 667 * Restriction configuration ops 668 */ 669#define RESTRICT_FLAGS 1 /* add flags to restrict entry */ 670#define RESTRICT_UNFLAG 2 /* remove flags from restrict entry */ 671#define RESTRICT_REMOVE 3 /* remove a restrict entry */ |
882#define RESTRICT_REMOVEIF 4 /* remove an interface restrict entry */ | |
883 | 672 |
673 |
|
884/* | 674/* |
675 * Experimental alternate selection algorithm identifiers 676 */ 677#define SELECT_1 1 678#define SELECT_2 2 679#define SELECT_3 3 680#define SELECT_4 4 681#define SELECT_5 5 682 683/* |
|
885 * Endpoint structure for the select algorithm 886 */ 887struct endpoint { 888 double val; /* offset of endpoint */ 889 int type; /* interval entry/exit */ 890}; 891 892/* | 684 * Endpoint structure for the select algorithm 685 */ 686struct endpoint { 687 double val; /* offset of endpoint */ 688 int type; /* interval entry/exit */ 689}; 690 691/* |
692 * Defines for association matching 693 */ 694#define AM_MODES 10 /* total number of modes */ 695#define NO_PEER 0 /* action when no peer is found */ 696 697/* |
|
893 * Association matching AM[] return codes 894 */ | 698 * Association matching AM[] return codes 699 */ |
895#define AM_ERR -1 /* error */ 896#define AM_NOMATCH 0 /* no match */ 897#define AM_PROCPKT 1 /* server/symmetric packet */ 898#define AM_BCST 2 /* broadcast packet */ 899#define AM_FXMIT 3 /* client packet */ 900#define AM_MANYCAST 4 /* manycast or pool */ 901#define AM_NEWPASS 5 /* new passive */ 902#define AM_NEWBCL 6 /* new broadcast */ 903#define AM_POSSBCL 7 /* discard broadcast */ | 700#define AM_ERR -1 701#define AM_NOMATCH 0 702#define AM_PROCPKT 1 703#define AM_FXMIT 2 704#define AM_MANYCAST 3 705#define AM_NEWPASS 4 706#define AM_NEWBCL 5 707#define AM_POSSBCL 6 |
904 905/* NetInfo configuration locations */ 906#ifdef HAVE_NETINFO 907#define NETINFO_CONFIG_DIR "/config/ntp" 908#endif 909 | 708 709/* NetInfo configuration locations */ 710#ifdef HAVE_NETINFO 711#define NETINFO_CONFIG_DIR "/config/ntp" 712#endif 713 |
910/* ntpq -c mrulist rows per request limit in ntpd */ 911#define MRU_ROW_LIMIT 256 912/* similar datagrams per response limit for ntpd */ 913#define MRU_FRAGS_LIMIT 128 | |
914#endif /* NTP_H */ | 714#endif /* NTP_H */ |