154359Sroberto/* 254359Sroberto * ntpdate.h - declarations for the ntpdate and ntptimeset programs 354359Sroberto */ 454359Sroberto 554359Sroberto#include "ntp_malloc.h" 654359Sroberto 7285612Sdelphijextern void loadservers (char *cfgpath); 882498Sroberto 954359Sroberto/* 1054359Sroberto * The server structure is a much simplified version of the 1154359Sroberto * peer structure, for ntpdate's use. Since we always send 1254359Sroberto * in client mode and expect to receive in server mode, this 1354359Sroberto * leaves only a very limited number of things we need to 1454359Sroberto * remember about the server. 1554359Sroberto */ 1654359Srobertostruct server { 1754359Sroberto struct server *next_server; /* next server in build list */ 18285612Sdelphij sockaddr_u srcadr; /* address of remote host */ 1954359Sroberto u_char version; /* version to use */ 2054359Sroberto u_char leap; /* leap indicator */ 2154359Sroberto u_char stratum; /* stratum of remote server */ 2254359Sroberto s_char precision; /* server's clock precision */ 2354359Sroberto u_char trust; /* trustability of the filtered data */ 2454359Sroberto u_fp rootdelay; /* distance from primary clock */ 25285612Sdelphij u_fp rootdisp; /* peer clock dispersion */ 2654359Sroberto u_int32 refid; /* peer reference ID */ 2754359Sroberto l_fp reftime; /* time of peer's last update */ 2854359Sroberto u_long event_time; /* time for next timeout */ 2954359Sroberto u_long last_xmit; /* time of last transmit */ 3054359Sroberto u_short xmtcnt; /* number of packets transmitted */ 3154359Sroberto u_short rcvcnt; /* number of packets received */ 3254359Sroberto u_char reach; /* reachability, NTP_WINDOW bits */ 3354359Sroberto u_short filter_nextpt; /* index into filter shift register */ 3454359Sroberto s_fp filter_delay[NTP_SHIFT]; /* delay part of shift register */ 3554359Sroberto l_fp filter_offset[NTP_SHIFT]; /* offset part of shift register */ 3654359Sroberto s_fp filter_soffset[NTP_SHIFT]; /* offset in s_fp format, for disp */ 3754359Sroberto u_fp filter_error[NTP_SHIFT]; /* error part of shift register */ 3854359Sroberto l_fp org; /* peer's originate time stamp */ 3954359Sroberto l_fp xmt; /* transmit time stamp */ 4054359Sroberto u_fp delay; /* filter estimated delay */ 4154359Sroberto u_fp dispersion; /* filter estimated dispersion */ 4254359Sroberto l_fp offset; /* filter estimated clock offset */ 4354359Sroberto s_fp soffset; /* fp version of above */ 4454359Sroberto}; 4554359Sroberto 4654359Sroberto 4754359Sroberto/* 4854359Sroberto * ntpdate runs everything on a simple, short timeout. It sends a 4954359Sroberto * packet and sets the timeout (by default, to a small value suitable 5054359Sroberto * for a LAN). If it receives a response it sends another request. 5154359Sroberto * If it times out it shifts zeroes into the filter and sends another 5254359Sroberto * request. 5354359Sroberto * 5454359Sroberto * The timer routine is run often (once every 1/5 second currently) 5554359Sroberto * so that time outs are done with reasonable precision. 5654359Sroberto */ 5754359Sroberto#define TIMER_HZ (5) /* 5 per second */ 5854359Sroberto 5954359Sroberto/* 6054359Sroberto * ntpdate will make a long adjustment using adjtime() if the times 6154359Sroberto * are close, or step the time if the times are farther apart. The 6254359Sroberto * following defines what is "close". 6354359Sroberto */ 6454359Sroberto#define NTPDATE_THRESHOLD (FP_SECOND >> 1) /* 1/2 second */ 6554359Sroberto 6682498Sroberto#define NTP_MAXAGE 86400 /* one day in seconds */ 6782498Sroberto 6854359Sroberto/* 6954359Sroberto * When doing adjustments, ntpdate actually overadjusts (currently 7054359Sroberto * by 50%, though this may change). While this will make it take longer 7154359Sroberto * to reach a steady state condition, it will typically result in 7254359Sroberto * the clock keeping more accurate time, on average. The amount of 7354359Sroberto * overshoot is limited. 7454359Sroberto */ 7554359Sroberto#ifdef NOTNOW 7654359Sroberto#define ADJ_OVERSHOOT 1/2 /* this is hard coded */ 7754359Sroberto#endif /* NOTNOW */ 7854359Sroberto#define ADJ_MAXOVERSHOOT 0x10000000 /* 50 ms as a ts fraction */ 7954359Sroberto 8054359Sroberto/* 8154359Sroberto * Since ntpdate isn't aware of some of the things that normally get 8254359Sroberto * put in an NTP packet, we fix some values. 8354359Sroberto */ 8454359Sroberto#define NTPDATE_PRECISION (-6) /* use this precision */ 8554359Sroberto#define NTPDATE_DISTANCE FP_SECOND /* distance is 1 sec */ 8654359Sroberto#define NTPDATE_DISP FP_SECOND /* so is the dispersion */ 8754359Sroberto#define NTPDATE_REFID (0) /* reference ID to use */ 8854359Sroberto#define PEER_MAXDISP (64*FP_SECOND) /* maximum dispersion (fp 64) */ 8954359Sroberto 9054359Sroberto 9154359Sroberto/* 92285612Sdelphij * No less than 2s between requests to a server to stay within ntpd's 93285612Sdelphij * default "discard minimum 1" (and 1s enforcement slop). That is 94285612Sdelphij * enforced only if the nondefault limited restriction is in place, such 95285612Sdelphij * as with "restrict ... limited" and "restrict ... kod limited". 9654359Sroberto */ 97285612Sdelphij#define MINTIMEOUT (1 * TIMER_HZ) /* 1s min. between packets */ 98285612Sdelphij#define DEFTIMEOUT (2 * TIMER_HZ) /* 2s by default */ 9954359Sroberto#define DEFSAMPLES 4 /* get 4 samples per server */ 10054359Sroberto#define DEFPRECISION (-5) /* the precision we claim */ 10154359Sroberto#define DEFMAXPERIOD 60 /* maximum time to wait */ 10254359Sroberto#define DEFMINSERVERS 3 /* minimum responding servers */ 10354359Sroberto#define DEFMINVALID 1 /* mimimum servers with valid time */ 104132451Sroberto 105132451Sroberto/* 106132451Sroberto * Define the max number of sockets we can open 107132451Sroberto */ 108132451Sroberto#define MAX_AF 2 109