1: /* $Source: /usr/src/new/ntp/ntp.h,v $ $Revision: 3.4.1.8 $ $Date: 95/01/27 17:22:14 $ */
   2: 
   3: /*
   4:  *  $Log:	ntp.h,v $
   5:  * Revision 3.4.1.9 2000/04/11 20:55:00 sms
   6:  * Remove short name hacks - 2.11BSD has long variable names.
   7:  *
   8:  * Revision 3.4.1.8  95/01/27  17:20:14  sms
   9:  * Fix name 'struct clockinfo' name collision with sysctl.h by renaming our
  10:  * structure xclockinfo.
  11:  *
  12:  * Revision 3.4.1.7  89/05/18  18:22:14  louie
  13:  * A few extra diddles in ntp.h for the reference clock feature.
  14:  *
  15:  * Revision 3.4.1.6  89/05/03  15:11:06  louie
  16:  * Specify default file for drift value and more peer flag definitions to
  17:  * reflect various stages of clock selection critera.
  18:  *
  19:  * Revision 3.4.1.5  89/04/10  15:55:42  louie
  20:  * Provide default value for number of bits/byte if not defined.  Compute the
  21:  * Window shift mask inside of conditional code on XTAL so we get the correct
  22:  * value if configured without a crystal controled clock (!!)
  23:  *
  24:  * Revision 3.4.1.4  89/03/31  16:34:50  louie
  25:  * Add bit in flags which allow a peer to be synced to.  Changed a char to a bit
  26:  * field so that it is always signed.
  27:  *
  28:  * Revision 3.4.1.3  89/03/29  12:26:18  louie
  29:  * Removed some unused #defines.  Replaced MAXSTRATUM with NTP_INFIN per new
  30:  * spec.  The variable 'mode' in the peer structure has been renamed 'hmode'
  31:  * per the new spec.
  32:  *
  33:  * Revision 3.4.1.2  89/03/22  18:28:18  louie
  34:  * patch3: Use new RCS headers.
  35:  *
  36:  * Revision 3.4.1.1  89/03/20  00:02:53  louie
  37:  * 1
  38:  *
  39:  * Revision 3.4  89/03/17  18:37:00  louie
  40:  * Latest test release.
  41:  *
  42:  * Revision 3.3.1.1  89/03/17  18:23:49  louie
  43:  * Change CLOCK_FACTOR to be a power of 2.
  44:  *
  45:  * Revision 3.3  89/03/15  14:19:36  louie
  46:  * New baseline for next release.
  47:  *
  48:  * Revision 3.2.1.2  89/03/15  13:46:52  louie
  49:  * The version number for that particular flavor of ntpd <--> ntpdc interaction
  50:  * is now defined by NTPDC_VERSION.  The packet format for the ntpdc program
  51:  * has changed slightly to improve robustness when dealing with multiple packets
  52:  * of status data.
  53:  *
  54:  * Revision 3.2.1.1  89/03/09  17:11:24  louie
  55:  * patch1: Updated constants, which were previously in incorrect units.
  56:  *
  57:  * Revision 3.2  89/03/07  18:21:45  louie
  58:  * New version of UNIX NTP daemon and software based on the 6 March 1989
  59:  * draft of the new NTP protocol specification.  This version doesn't
  60:  * implement authentication, and accepts and send only NTP Version 1
  61:  * packets.
  62:  *
  63:  * Revision 3.1.1.1  89/02/15  08:54:42  louie
  64:  * *** empty log message ***
  65:  *
  66:  *
  67:  * Revision 3.1  89/01/30  14:43:07  louie
  68:  * Second UNIX NTP test release.
  69:  *
  70:  * Revision 3.0  88/12/12  16:01:07  louie
  71:  * Test release of new UNIX NTP software.  This version should conform to the
  72:  * revised NTP protocol specification.
  73:  *
  74:  */
  75: 
  76: #ifndef FD_SET
  77: #define NFDBITS     32
  78: #define FD_SETSIZE  32
  79: #define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  80: #define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  81: #define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  82: #define FD_ZERO(p)  bzero((char *)(p), sizeof(*(p)))
  83: #endif
  84: 
  85: #ifndef NBBY
  86: #define NBBY    8   /* number of bits per byte */
  87: #endif
  88: 
  89: #define MAXNETIF    10
  90: 
  91: struct intf {
  92:     int fd;
  93:     char *name;
  94:     struct sockaddr_in sin;
  95:     struct sockaddr_in bcast;
  96:     struct sockaddr_in mask;
  97:     int uses;
  98:     int if_flags;
  99: };
 100: extern struct intf addrs[];
 101: extern int nintf;
 102: 
 103: /*
 104:  *  Definitions for the masses
 105:  */
 106: #define JAN_1970    2208988800  /* 1970 - 1900 in seconds */
 107: 
 108: /*
 109:  *  Daemon specific (ntpd.c)
 110:  */
 111: #define SHIFT_MASK  0xff    /* number of intervals to wait */
 112: 
 113: #ifndef WAYTOOBIG
 114: #define WAYTOOBIG   1000.0  /* Too many seconds to correct, something is
 115: 				 * really wrong */
 116: #endif
 117: 
 118: #ifndef XTAL
 119: #define XTAL    1   /* crystal controlled clock by default */
 120: #endif
 121: 
 122: #ifndef NTPINITFILE
 123: #define NTPINITFILE "/etc/ntp.conf"
 124: #endif
 125: #ifndef NTPDRIFTCOMP
 126: #define NTPDRIFTCOMP    "/etc/ntp.drift"
 127: #endif
 128: 
 129: struct list {
 130:     struct ntp_peer *head;
 131:     struct ntp_peer *tail;
 132:     int members;
 133: };
 134: 
 135: #define STRMCMP(a, cond, b) \
 136:     (((a) == UNSPECIFIED ? NTP_INFIN+1 : a) cond \
 137:      ((b) == UNSPECIFIED ? NTP_INFIN+1 : (b)))
 138: 
 139: 
 140: /*
 141:  *  Definitions outlined in the NTP spec
 142:  */
 143: #define NTP_VERSION 1
 144: #define NTP_PORT    123 /* for ref only (see /etc/services) */
 145: #define NTP_INFIN   15
 146: #define NTP_MAXAGE  86400
 147: #define NTP_MAXSKW  0.01    /* seconds */
 148: #define NTP_MINDIST 0.02    /* seconds */
 149: #ifdef  REFCLOCK
 150: #define NTP_REFMAXSKW   0.001   /* seconds (for REFCLOCKs) */
 151: #define NTP_REFMINDIST  0.001   /* seconds (for REFCLOCKs) */
 152: #endif
 153: #define NTP_MINPOLL 6   /* (64) seconds between messages */
 154: #define NTP_MAXPOLL 10  /* (1024) secs to poll */
 155: #define NTP_WINDOW  8   /* size of shift register */
 156: #define NTP_MAXWGT  8   /* maximum allowable dispersion */
 157: #define NTP_MAXLIST 5   /* max size of selection list */
 158: #define NTP_MAXSTRA 2   /* max number of strata in selection list */
 159: #define X_NTP_CANDIDATES 64 /* number of peers to consider when doing
 160: 				   clock selection */
 161: #define NTP_SELECT  0.75    /* weight used to compute dispersion */
 162: 
 163: #define PEER_MAXDISP    64.0    /* Maximum dispersion  */
 164: #define PEER_THRESHOLD  0.5 /* dispersion threshold */
 165: #define PEER_FILTER 0.5 /* filter weight */
 166: 
 167: #if XTAL == 0
 168: #define PEER_SHIFT  4
 169: #define NTP_WINDOW_SHIFT_MASK 0x0f
 170: #else
 171: #define PEER_SHIFT  8
 172: #define NTP_WINDOW_SHIFT_MASK 0xff
 173: #endif
 174: 
 175: 
 176: /*
 177:  *  5.1 Uniform Phase Adjustments
 178:  *  Clock parameters
 179:  */
 180: #define CLOCK_UPDATE    8   /* update interval (1<<CLOCK_UPDATE secs) */
 181: #if XTAL
 182: #define CLOCK_ADJ   2   /* adjustment interval (1<<CLOCK_ADJ secs) */
 183: #define CLOCK_PHASE 8   /* phase shift */
 184: #define CLOCK_MAX   0.128   /* maximum aperture (milliseconds) */
 185: #else
 186: #define CLOCK_ADJ   0
 187: #define CLOCK_PHASE 6   /* phase shift */
 188: #define CLOCK_MAX   0.512   /* maximum aperture (milliseconds) */
 189: #endif
 190: #define CLOCK_FREQ  10  /* frequency shift */
 191: #define CLOCK_TRACK 8
 192: #define CLOCK_COMP  4
 193: #define CLOCK_FACTOR    18
 194: 
 195: /*
 196:  * Structure definitions for NTP fixed point values
 197:  *
 198:  *    0			  1		      2			  3
 199:  *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 200:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 201:  *   |			       Integer Part			     |
 202:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 203:  *   |			       Fraction Part			     |
 204:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 205:  *
 206:  *    0			  1		      2			  3
 207:  *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 208:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 209:  *   |		  Integer Part	     |	   Fraction Part	     |
 210:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 211: */
 212: struct l_fixedpt {
 213:     u_long int_part;
 214:     u_long fraction;
 215: };
 216: 
 217: struct s_fixedpt {
 218:     u_short int_part;
 219:     u_short fraction;
 220: };
 221: 
 222: /*  =================  Table 3.3. Packet Variables   ================= */
 223: /*
 224:  *    0			  1		      2			  3
 225:  *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 226:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 227:  *   |LI | VN  | Mode|	  Stratum    |	    Poll     |	 Precision   |
 228:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 229:  *   |			   Synchronizing Distance		     |
 230:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 231:  *   |			  Synchronizing Dispersion		     |
 232:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 233:  *   |			Reference Clock Identifier		     |
 234:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 235:  *   |								     |
 236:  *   |		       Reference Timestamp (64 bits)		     |
 237:  *   |								     |
 238:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 239:  *   |								     |
 240:  *   |		       Originate Timestamp (64 bits)		     |
 241:  *   |								     |
 242:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 243:  *   |								     |
 244:  *   |			Receive Timestamp (64 bits)		     |
 245:  *   |								     |
 246:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 247:  *   |								     |
 248:  *   |			Transmit Timestamp (64 bits)		     |
 249:  *   |								     |
 250:  *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 251: */
 252: struct ntpdata {
 253:     u_char status;      /* status of local clock and leap info */
 254:     u_char stratum;     /* Stratum level */
 255:     u_char ppoll;       /* poll value */
 256:     char   precision;
 257:     struct s_fixedpt distance;
 258:     struct s_fixedpt dispersion;
 259:     u_long refid;
 260:     struct l_fixedpt reftime;
 261:     struct l_fixedpt org;
 262:     struct l_fixedpt rec;
 263:     struct l_fixedpt xmt;
 264: };
 265: /*
 266:  *	Leap Second Codes (high order two bits)
 267:  */
 268: #define NO_WARNING  0x00    /* no warning */
 269: #define PLUS_SEC    0x40    /* add a second (61 seconds) */
 270: #define MINUS_SEC   0x80    /* minus a second (59 seconds) */
 271: #define ALARM       0xc0    /* alarm condition (clock unsynchronized) */
 272: 
 273: /*
 274:  *	Clock Status Bits that Encode Version
 275:  */
 276: #define NTPVERSION_1    0x08
 277: #define VERSIONMASK 0x38
 278: #define LEAPMASK    0xc0
 279: #define MODEMASK    0x07
 280: 
 281: /*
 282:  *	Code values
 283:  */
 284: #define MODE_UNSPEC 0   /* unspecified */
 285: #define MODE_SYM_ACT    1   /* symmetric active */
 286: #define MODE_SYM_PAS    2   /* symmetric passive */
 287: #define MODE_CLIENT 3   /* client */
 288: #define MODE_SERVER 4   /* server */
 289: #define MODE_BROADCAST  5   /* broadcast */
 290: #define MODE_RES1   6   /* reserved */
 291: #define MODE_RES2   7   /* reserved */
 292: 
 293: /*
 294:  *	Stratum Definitions
 295:  */
 296: #define UNSPECIFIED 0
 297: #define PRIM_REF    1   /* radio clock */
 298: #define INFO_QUERY  62  /* **** THIS implementation dependent **** */
 299: #define INFO_REPLY  63  /* **** THIS implementation dependent **** */
 300: 
 301: 
 302: /* =================  table 3.2 Peer Variables	================= */
 303: struct ntp_peer {
 304:     struct ntp_peer *next, *prev;
 305:     struct sockaddr_in src;     /* both peer.srcadr and
 306: 					   peer.srcport */
 307:     int flags;          /* local flags */
 308: #define PEER_FL_CONFIG      1
 309: #define PEER_FL_AUTHENABLE  2
 310: #define PEER_FL_SANE        0x0100  /* sane peer */
 311: #define PEER_FL_CANDIDATE   0x0200  /* candidate peer */
 312: #define PEER_FL_SYNC        0x1000  /* peer can bet sync'd to */
 313: #define PEER_FL_BCAST       0x2000  /* broadcast peer */
 314: #define PEER_FL_REFCLOCK    0x4000  /* peer is a local reference clock */
 315: #define PEER_FL_SELECTED    0x8000  /* actually used by query routine */
 316: 
 317:     int sock;           /* index into sockets to derive
 318: 					   peer.dstadr and peer.dstport */
 319:     u_char  leap;           /* receive */
 320:     u_char  hmode;          /* receive */
 321:     u_char  stratum;        /* receive */
 322:     u_char  ppoll;          /* receive */
 323:     u_char  hpoll;          /* poll update */
 324:     short   precision;      /* receive */
 325:     struct  s_fixedpt distance; /* receive */
 326:     struct  s_fixedpt dispersion;   /* receive */
 327:     u_long  refid;          /* receive */
 328:     struct  l_fixedpt reftime;  /* receive */
 329:     struct  l_fixedpt org;      /* receive, clear */
 330:     struct  l_fixedpt rec;      /* receive, clear */
 331:     struct  l_fixedpt xmt;      /* transmit, clear */
 332:     u_long  reach;          /* receive, transmit, clear */
 333:     u_long  valid;          /* packet, transmit, clear */
 334:     u_long  timer;          /* receive, transmit, poll update */
 335:     long    stopwatch;      /* <<local>> for timing */
 336:     /*
 337: 	 * first order offsets
 338: 	 */
 339:     struct  filter {
 340:         short samples;      /* <<local>> */
 341:         double offset[PEER_SHIFT];
 342:         double delay[PEER_SHIFT];
 343:     } filter;           /* filter, clear */
 344: 
 345:     double  estdelay;       /* filter */
 346:     double  estoffset;      /* filter */
 347:     double  estdisp;        /* filter */
 348: 
 349:     u_long  pkt_sent;       /* <<local>> */
 350:     u_long  pkt_rcvd;       /* <<local>> */
 351:     u_long  pkt_dropped;        /* <<local>> */
 352: };
 353: 
 354: /* ================= table 3.1:  System Variables ================= */
 355: 
 356: struct sysdata {            /* procedure */
 357:     u_char leap;            /* clock update */
 358:     u_char stratum;         /* clock update */
 359:     short precision;        /* system */
 360:     struct s_fixedpt distance;  /* clock update */
 361:     struct s_fixedpt dispersion;    /* clock update */
 362:     u_long refid;           /* clock update */
 363:     struct l_fixedpt reftime;   /* clock update */
 364:     int hold;           /* clock update */
 365:     struct ntp_peer *peer;      /* selection */
 366:     int maxpeers;           /* <<local>> */
 367:     u_char filler;      /* put here for %&*%$$ SUNs */
 368: };
 369: 
 370: #define NTPDC_VERSION   2
 371: 
 372: /*
 373:  *  These structures are used to pass information to the ntpdc (control)
 374:  *  program.  They are unique to this implementation and not part of the
 375:  *  NTP specification.
 376:  */
 377: struct xclockinfo {
 378:     u_long net_address;
 379:     u_long my_address;
 380:     u_short port;
 381:     u_short flags;
 382:     u_long pkt_sent;
 383:     u_long pkt_rcvd;
 384:     u_long pkt_dropped;
 385:     u_long timer;
 386:     u_char leap;
 387:     u_char stratum;
 388:     u_char ppoll;
 389:     char   precision;
 390: 
 391:     u_char hpoll;
 392:     u_char filler1;
 393:     u_short reach;
 394: 
 395:     long    estdisp;            /* scaled by 1000 */
 396:     long    estdelay;           /* in milliseconds */
 397:     long    estoffset;          /* in milliseconds */
 398:     u_long refid;
 399:     struct l_fixedpt reftime;
 400:     struct info_filter {
 401:         short index;
 402:         short filler;
 403:         long offset[PEER_SHIFT];    /* in milliseconds */
 404:         long delay[PEER_SHIFT];     /* in milliseconds */
 405:     } info_filter;
 406: };
 407: 
 408: struct ntpinfo {
 409:     u_char version;
 410:     u_char type;        /* request type (stratum in ntp packets) */
 411:     u_char count;       /* number of entries in this packet */
 412:     u_char seq;     /* sequence number of this packet */
 413: 
 414:     u_char npkts;       /* total number of packets */
 415:     u_char peers;
 416:     u_char fill3;
 417:     u_char fill4;
 418: };

Defined struct's

filter defined in line 339; never used
info_filter defined in line 400; never used
intf defined in line 91; used 4 times
l_fixedpt defined in line 212; used 36 times
list defined in line 129; used 8 times
ntp_peer defined in line 303; used 78 times
ntpdata defined in line 252; used 28 times
ntpinfo defined in line 408; used 8 times
s_fixedpt defined in line 217; used 18 times
xclockinfo defined in line 377; used 14 times

Defined macros

CLOCK_ADJ defined in line 186; used 11 times
CLOCK_COMP defined in line 192; used 1 times
CLOCK_FACTOR defined in line 193; used 1 times
CLOCK_FREQ defined in line 190; used 1 times
CLOCK_MAX defined in line 188; used 2 times
CLOCK_PHASE defined in line 187; used 1 times
CLOCK_TRACK defined in line 191; used 1 times
CLOCK_UPDATE defined in line 180; never used
FD_CLR defined in line 80; never used
FD_ISSET defined in line 81; used 2 times
FD_SET defined in line 79; used 5 times
INFO_QUERY defined in line 298; used 3 times
INFO_REPLY defined in line 299; used 4 times
JAN_1970 defined in line 106; used 8 times
MAXNETIF defined in line 89; never used
MINUS_SEC defined in line 270; never used
MODE_RES1 defined in line 290; never used
MODE_RES2 defined in line 291; never used
MODE_SERVER defined in line 288; used 1 times
MODE_UNSPEC defined in line 284; never used
NBBY defined in line 86; used 3 times
NFDBITS defined in line 77; used 6 times
NO_WARNING defined in line 268; used 1 times
NTPDC_VERSION defined in line 370; used 3 times
NTPDRIFTCOMP defined in line 126; used 2 times
NTPINITFILE defined in line 123; used 2 times
NTP_INFIN defined in line 145; used 3 times
NTP_MAXAGE defined in line 146; used 5 times
NTP_MAXLIST defined in line 157; used 2 times
NTP_MAXPOLL defined in line 154; used 3 times
NTP_MAXSKW defined in line 147; used 3 times
NTP_MAXSTRA defined in line 158; used 1 times
NTP_MAXWGT defined in line 156; used 2 times
NTP_MINDIST defined in line 148; used 2 times
NTP_MINPOLL defined in line 153; used 14 times
NTP_REFMAXSKW defined in line 150; used 1 times
NTP_REFMINDIST defined in line 151; used 1 times
NTP_SELECT defined in line 161; used 1 times
NTP_VERSION defined in line 143; never used
PEER_FILTER defined in line 165; used 1 times
PEER_FL_AUTHENABLE defined in line 309; used 2 times
PEER_SHIFT defined in line 171; used 19 times
PEER_THRESHOLD defined in line 164; used 1 times
PLUS_SEC defined in line 269; never used
PRIM_REF defined in line 297; never used
SHIFT_MASK defined in line 111; used 2 times
STRMCMP defined in line 135; used 2 times
UNSPECIFIED defined in line 296; used 3 times
VERSIONMASK defined in line 277; used 3 times
WAYTOOBIG defined in line 114; used 3 times
XTAL defined in line 119; used 4 times
X_NTP_CANDIDATES defined in line 159; used 2 times

Usage of this include

Last modified: 2000-04-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2691
Valid CSS Valid XHTML 1.0 Strict