10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 23*410Skcpoon * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 290Sstevel@tonic-gate * The Regents of the University of California 300Sstevel@tonic-gate * All Rights Reserved 310Sstevel@tonic-gate * 320Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 330Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 340Sstevel@tonic-gate * contributors. 350Sstevel@tonic-gate */ 360Sstevel@tonic-gate 370Sstevel@tonic-gate #ifndef _NTP_H 380Sstevel@tonic-gate #define _NTP_H 390Sstevel@tonic-gate 400Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 410Sstevel@tonic-gate 420Sstevel@tonic-gate #ifdef __cplusplus 430Sstevel@tonic-gate extern "C" { 440Sstevel@tonic-gate #endif 450Sstevel@tonic-gate 460Sstevel@tonic-gate /* $Source: /usr/users/louie/ntp/RCS/ntp.h,v $ */ 470Sstevel@tonic-gate /* $Revision: 3.4.1.5 $ $Date: 89/04/10 15:55:42 $ */ 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * $Log: ntp.h,v $ 510Sstevel@tonic-gate * Revision 3.4.1.5 89/04/10 15:55:42 louie 520Sstevel@tonic-gate * Provide default value for number of bits/byte if not defined. Compute the 530Sstevel@tonic-gate * Window shift mask inside of conditional code on XTAL so we get the correct 540Sstevel@tonic-gate * value if configured without a crystal controled clock (!!) 550Sstevel@tonic-gate * 560Sstevel@tonic-gate * Revision 3.4.1.4 89/03/31 16:34:50 louie 570Sstevel@tonic-gate * Add bit in flags which allow a peer to be synced to. Changed a char to a bit 580Sstevel@tonic-gate * field so that it is always signed. 590Sstevel@tonic-gate * 600Sstevel@tonic-gate * Revision 3.4.1.3 89/03/29 12:26:18 louie 610Sstevel@tonic-gate * Removed some unused #defines. Replaced MAXSTRATUM with NTP_INFIN per new 620Sstevel@tonic-gate * spec. The variable 'mode' in the peer structure has been renamed 'hmode' 630Sstevel@tonic-gate * per the new spec. 640Sstevel@tonic-gate * 650Sstevel@tonic-gate * Revision 3.4.1.2 89/03/22 18:28:18 louie 660Sstevel@tonic-gate * patch3: Use new RCS headers. 670Sstevel@tonic-gate * 680Sstevel@tonic-gate * Revision 3.4.1.1 89/03/20 00:02:53 louie 690Sstevel@tonic-gate * 1 700Sstevel@tonic-gate * 710Sstevel@tonic-gate * Revision 3.4 89/03/17 18:37:00 louie 720Sstevel@tonic-gate * Latest test release. 730Sstevel@tonic-gate * 740Sstevel@tonic-gate * Revision 3.3.1.1 89/03/17 18:23:49 louie 750Sstevel@tonic-gate * Change CLOCK_FACTOR to be a power of 2. 760Sstevel@tonic-gate * 770Sstevel@tonic-gate * Revision 3.3 89/03/15 14:19:36 louie 780Sstevel@tonic-gate * New baseline for next release. 790Sstevel@tonic-gate * 800Sstevel@tonic-gate * Revision 3.2.1.2 89/03/15 13:46:52 louie 810Sstevel@tonic-gate * The version number for that particular flavor of ntpd <--> ntpdc interaction 820Sstevel@tonic-gate * is now defined by NTPDC_VERSION. The packet format for the ntpdc program 830Sstevel@tonic-gate * has changed slightly to improve robustness when dealing with multiple packets 840Sstevel@tonic-gate * of status data. 850Sstevel@tonic-gate * 860Sstevel@tonic-gate * Revision 3.2.1.1 89/03/09 17:11:24 louie 870Sstevel@tonic-gate * patch1: Updated constants, which were previously in incorrect units. 880Sstevel@tonic-gate * 890Sstevel@tonic-gate * Revision 3.2 89/03/07 18:21:45 louie 900Sstevel@tonic-gate * New version of UNIX NTP daemon and software based on the 6 March 1989 910Sstevel@tonic-gate * draft of the new NTP protocol specification. This version doesn't 920Sstevel@tonic-gate * implement authentication, and accepts and send only NTP Version 1 930Sstevel@tonic-gate * packets. 940Sstevel@tonic-gate * 950Sstevel@tonic-gate * Revision 3.1.1.1 89/02/15 08:54:42 louie 960Sstevel@tonic-gate * *** empty log message *** 970Sstevel@tonic-gate * 980Sstevel@tonic-gate * 990Sstevel@tonic-gate * Revision 3.1 89/01/30 14:43:07 louie 1000Sstevel@tonic-gate * Second UNIX NTP test release. 1010Sstevel@tonic-gate * 1020Sstevel@tonic-gate * Revision 3.0 88/12/12 16:01:07 louie 1030Sstevel@tonic-gate * Test release of new UNIX NTP software. This version should conform to the 1040Sstevel@tonic-gate * revised NTP protocol specification. 1050Sstevel@tonic-gate * 1060Sstevel@tonic-gate */ 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate #ifndef FD_SET 1090Sstevel@tonic-gate #define NFDBITS 32 1100Sstevel@tonic-gate #define FD_SETSIZE 32 1110Sstevel@tonic-gate #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) 1120Sstevel@tonic-gate #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) 1130Sstevel@tonic-gate #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) 1140Sstevel@tonic-gate #define FD_ZERO(p) bzero((char *)(p), sizeof (*(p))) 1150Sstevel@tonic-gate #endif 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate #ifndef NBBY 1180Sstevel@tonic-gate #define NBBY 8 /* number of bits per byte */ 1190Sstevel@tonic-gate #endif 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate #define MAXNETIF 10 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate struct intf { 1240Sstevel@tonic-gate int fd; 1250Sstevel@tonic-gate char *name; 1260Sstevel@tonic-gate struct sockaddr_in sin; 1270Sstevel@tonic-gate struct sockaddr_in bcast; 1280Sstevel@tonic-gate struct sockaddr_in mask; 1290Sstevel@tonic-gate int uses; 1300Sstevel@tonic-gate int if_flags; 1310Sstevel@tonic-gate }; 1320Sstevel@tonic-gate extern struct intf addrs[]; 1330Sstevel@tonic-gate extern int nintf; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate /* 1360Sstevel@tonic-gate * Definitions for the masses 1370Sstevel@tonic-gate */ 138*410Skcpoon #define JAN_1970 2208988800U /* 1970 - 1900 in seconds */ 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * Daemon specific (ntpd.c) 1420Sstevel@tonic-gate */ 1430Sstevel@tonic-gate #define SHIFT_MASK 0xff /* number of intervals to wait */ 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate #ifndef WAYTOOBIG 1460Sstevel@tonic-gate #define WAYTOOBIG 1000.0 /* Too many seconds to correct, something is */ 1470Sstevel@tonic-gate /* really wrong */ 1480Sstevel@tonic-gate #endif 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate #ifndef XTAL 1510Sstevel@tonic-gate #define XTAL 1 /* crystal controlled clock by default */ 1520Sstevel@tonic-gate #endif 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate #ifndef NTPINITFILE 1550Sstevel@tonic-gate #define NTPINITFILE "/etc/ntp.conf" 1560Sstevel@tonic-gate #endif 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate struct list { 1590Sstevel@tonic-gate struct ntp_peer *head; 1600Sstevel@tonic-gate struct ntp_peer *tail; 1610Sstevel@tonic-gate int members; 1620Sstevel@tonic-gate }; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate #define STRMCMP(a, cond, b) \ 1650Sstevel@tonic-gate (((a) == UNSPECIFIED ? NTP_INFIN+1 : a) cond \ 1660Sstevel@tonic-gate ((b) == UNSPECIFIED ? NTP_INFIN+1 : (b))) 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate /* 1700Sstevel@tonic-gate * Definitions outlined in the NTP spec 1710Sstevel@tonic-gate */ 1720Sstevel@tonic-gate #define NTP_VERSION 1 1730Sstevel@tonic-gate #define NTP_PORT 123 /* for ref only (see /etc/services) */ 1740Sstevel@tonic-gate #define NTP_INFIN 15 1750Sstevel@tonic-gate #define NTP_MAXAGE 86400 1760Sstevel@tonic-gate #define NTP_MAXSKW 0.01 /* seconds */ 1770Sstevel@tonic-gate #define NTP_MINDIST 0.02 /* seconds */ 1780Sstevel@tonic-gate #define NTP_MINPOLL 6 /* (64) seconds between messages */ 1790Sstevel@tonic-gate #define NTP_MAXPOLL 10 /* (1024) secs to poll */ 1800Sstevel@tonic-gate #define NTP_WINDOW 8 /* size of shift register */ 1810Sstevel@tonic-gate #define NTP_MAXWGT 8 /* maximum allowable dispersion */ 1820Sstevel@tonic-gate #define NTP_MAXLIST 5 /* max size of selection list */ 1830Sstevel@tonic-gate #define NTP_MAXSTRA 2 /* max number of strata in selection list */ 1840Sstevel@tonic-gate #define X_NTP_CANDIDATES 64 /* number of peers to consider when doing */ 1850Sstevel@tonic-gate /* clock selection */ 1860Sstevel@tonic-gate #define NTP_SELECT 0.75 /* weight used to compute dispersion */ 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate #define PEER_MAXDISP 64.0 /* Maximum dispersion */ 1890Sstevel@tonic-gate #define PEER_THRESHOLD 0.5 /* dispersion threshold */ 1900Sstevel@tonic-gate #define PEER_FILTER 0.5 /* filter weight */ 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate #if XTAL == 0 1930Sstevel@tonic-gate #define PEER_SHIFT 4 1940Sstevel@tonic-gate #define NTP_WINDOW_SHIFT_MASK 0x0f 1950Sstevel@tonic-gate #else 1960Sstevel@tonic-gate #define PEER_SHIFT 8 1970Sstevel@tonic-gate #define NTP_WINDOW_SHIFT_MASK 0xff 1980Sstevel@tonic-gate #endif 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* 2020Sstevel@tonic-gate * 5.1 Uniform Phase Adjustments 2030Sstevel@tonic-gate * Clock parameters 2040Sstevel@tonic-gate */ 2050Sstevel@tonic-gate #define CLOCK_UPDATE 8 /* update interval (1<<CLOCK_UPDATE secs) */ 2060Sstevel@tonic-gate #if XTAL 2070Sstevel@tonic-gate #define CLOCK_ADJ 2 /* adjustment interval (1<<CLOCK_ADJ secs) */ 2080Sstevel@tonic-gate #define CLOCK_PHASE 8 /* phase shift */ 2090Sstevel@tonic-gate #define CLOCK_MAX 0.128 /* maximum aperture (milliseconds) */ 2100Sstevel@tonic-gate #else 2110Sstevel@tonic-gate #define CLOCK_ADJ 0 2120Sstevel@tonic-gate #define CLOCK_PHASE 6 /* phase shift */ 2130Sstevel@tonic-gate #define CLOCK_MAX 0.512 /* maximum aperture (milliseconds) */ 2140Sstevel@tonic-gate #endif 2150Sstevel@tonic-gate #define CLOCK_FREQ 10 /* frequency shift */ 2160Sstevel@tonic-gate #define CLOCK_TRACK 8 2170Sstevel@tonic-gate #define CLOCK_COMP 4 2180Sstevel@tonic-gate #define CLOCK_FACTOR 18 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate /* 2210Sstevel@tonic-gate * Structure definitions for NTP fixed point values 2220Sstevel@tonic-gate * 2230Sstevel@tonic-gate * 0 1 2 3 2240Sstevel@tonic-gate * 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 2250Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2260Sstevel@tonic-gate * | Integer Part | 2270Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2280Sstevel@tonic-gate * | Fraction Part | 2290Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2300Sstevel@tonic-gate * 2310Sstevel@tonic-gate * 2320Sstevel@tonic-gate * 0 1 2 3 2330Sstevel@tonic-gate * 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 2340Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2350Sstevel@tonic-gate * | Integer Part | Fraction Part | 2360Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2370Sstevel@tonic-gate */ 2380Sstevel@tonic-gate struct l_fixedpt { 239*410Skcpoon ulong_t int_part; 240*410Skcpoon ulong_t fraction; 2410Sstevel@tonic-gate }; 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate struct s_fixedpt { 244*410Skcpoon ushort_t int_part; 245*410Skcpoon ushort_t fraction; 2460Sstevel@tonic-gate }; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /* 2490Sstevel@tonic-gate * ================= Table 3.3. Packet Variables ================= 2500Sstevel@tonic-gate * 0 1 2 3 2510Sstevel@tonic-gate * 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 2520Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2530Sstevel@tonic-gate * |LI | VN | Mode| Stratum | Poll | Precision | 2540Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2550Sstevel@tonic-gate * | Synchronizing Distance | 2560Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2570Sstevel@tonic-gate * | Synchronizing Dispersion | 2580Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2590Sstevel@tonic-gate * | Reference Clock Identifier | 2600Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2610Sstevel@tonic-gate * | | 2620Sstevel@tonic-gate * | Reference Timestamp (64 bits) | 2630Sstevel@tonic-gate * | | 2640Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2650Sstevel@tonic-gate * | | 2660Sstevel@tonic-gate * | Originate Timestamp (64 bits) | 2670Sstevel@tonic-gate * | | 2680Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2690Sstevel@tonic-gate * | | 2700Sstevel@tonic-gate * | Receive Timestamp (64 bits) | 2710Sstevel@tonic-gate * | | 2720Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2730Sstevel@tonic-gate * | | 2740Sstevel@tonic-gate * | Transmit Timestamp (64 bits) | 2750Sstevel@tonic-gate * | | 2760Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2770Sstevel@tonic-gate * | Encryption Keyid (32 bits, when A bit set) | 2780Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2790Sstevel@tonic-gate * | | 2800Sstevel@tonic-gate * | Message Authentication Code/MAC (when A bit set) | 2810Sstevel@tonic-gate * | | 2820Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2830Sstevel@tonic-gate */ 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate #define MAC_OCTETS_DES 8 2860Sstevel@tonic-gate #define MAC_OCTETS_MD5 16 2870Sstevel@tonic-gate #define MAC_OCTETS_MIN MAC_OCTETS_DES 2880Sstevel@tonic-gate #define MAC_OCTETS_MAX MAC_OCTETS_MD5 2890Sstevel@tonic-gate #define AUTH_OCTETS_V3 (MAC_OCTETS_MAX + sizeof (uint32_t)) 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate struct ntpdata { 292*410Skcpoon uchar_t li_vn_mode; /* contains leap indicator, version and mode */ 293*410Skcpoon uchar_t stratum; /* Stratum level */ 294*410Skcpoon uchar_t ppoll; /* poll value */ 2950Sstevel@tonic-gate int precision:8; 2960Sstevel@tonic-gate struct s_fixedpt distance; 2970Sstevel@tonic-gate struct s_fixedpt dispersion; 298*410Skcpoon ulong_t refid; 2990Sstevel@tonic-gate struct l_fixedpt reftime; 3000Sstevel@tonic-gate struct l_fixedpt org; 3010Sstevel@tonic-gate struct l_fixedpt rec; 3020Sstevel@tonic-gate struct l_fixedpt xmt; 3030Sstevel@tonic-gate uint32_t keyid; 304*410Skcpoon uchar_t mac[MAC_OCTETS_MAX]; 3050Sstevel@tonic-gate }; 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate #define LEN_PKT_NOMAC (sizeof (struct ntpdata) - AUTH_OCTETS_V3) 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate /* 3100Sstevel@tonic-gate * Leap Second Codes (high order two bits) 3110Sstevel@tonic-gate */ 3120Sstevel@tonic-gate #define NO_WARNING 0x00 /* no warning */ 3130Sstevel@tonic-gate #define PLUS_SEC 0x40 /* add a second (61 seconds) */ 3140Sstevel@tonic-gate #define MINUS_SEC 0x80 /* minus a second (59 seconds) */ 3150Sstevel@tonic-gate #define ALARM 0xc0 /* alarm condition (clock unsynchronized) */ 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate /* 3180Sstevel@tonic-gate * Clock Status Bits that Encode Version 3190Sstevel@tonic-gate */ 3200Sstevel@tonic-gate #define NTPVERSION_1 0x08 3210Sstevel@tonic-gate #define VERSIONMASK 0x38 3220Sstevel@tonic-gate #define LEAPMASK 0xc0 3230Sstevel@tonic-gate #define NTPMODEMASK 0x07 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate /* 3260Sstevel@tonic-gate * Code values 3270Sstevel@tonic-gate */ 3280Sstevel@tonic-gate #define MODE_UNSPEC 0 /* unspecified */ 3290Sstevel@tonic-gate #define MODE_SYM_ACT 1 /* symmetric active */ 3300Sstevel@tonic-gate #define MODE_SYM_PAS 2 /* symmetric passive */ 3310Sstevel@tonic-gate #define MODE_CLIENT 3 /* client */ 3320Sstevel@tonic-gate #define MODE_SERVER 4 /* server */ 3330Sstevel@tonic-gate #define MODE_BROADCAST 5 /* broadcast */ 3340Sstevel@tonic-gate #define MODE_CONTROL 6 /* control */ 3350Sstevel@tonic-gate #define MODE_PRIVATE 7 /* private */ 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate /* 3380Sstevel@tonic-gate * Stratum Definitions 3390Sstevel@tonic-gate */ 3400Sstevel@tonic-gate #define UNSPECIFIED 0 3410Sstevel@tonic-gate #define PRIM_REF 1 /* radio clock */ 3420Sstevel@tonic-gate #define INFO_QUERY 62 /* **** THIS implementation dependent **** */ 3430Sstevel@tonic-gate #define INFO_REPLY 63 /* **** THIS implementation dependent **** */ 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* ================= table 3.2 Peer Variables ================= */ 3470Sstevel@tonic-gate struct ntp_peer { 3480Sstevel@tonic-gate struct ntp_peer *next, *prev; 3490Sstevel@tonic-gate struct sockaddr_in src; /* both peer.srcadr and peer.srcport */ 3500Sstevel@tonic-gate int flags; /* local flags */ 3510Sstevel@tonic-gate #define PEER_FL_CONFIG 1 3520Sstevel@tonic-gate #define PEER_FL_AUTHENABLE 2 3530Sstevel@tonic-gate #define PEER_FL_SYNC 0x1000 /* peer can bet sync'd to */ 3540Sstevel@tonic-gate #define PEER_FL_BCAST 0x2000 /* broadcast peer */ 3550Sstevel@tonic-gate #define PEER_FL_SELECTED 0x8000 /* actually used by query routine */ 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate int sock; /* index into sockets to derive */ 3580Sstevel@tonic-gate /* peer.dstadr and peer.dstport */ 359*410Skcpoon uchar_t leap; /* receive */ 360*410Skcpoon uchar_t hmode; /* receive */ 361*410Skcpoon uchar_t stratum; /* receive */ 362*410Skcpoon uchar_t ppoll; /* receive */ 363*410Skcpoon uchar_t hpoll; /* poll update */ 3640Sstevel@tonic-gate short precision; /* receive */ 3650Sstevel@tonic-gate struct s_fixedpt distance; /* receive */ 3660Sstevel@tonic-gate struct s_fixedpt dispersion; /* receive */ 367*410Skcpoon ulong_t refid; /* receive */ 3680Sstevel@tonic-gate struct l_fixedpt reftime; /* receive */ 3690Sstevel@tonic-gate struct l_fixedpt org; /* receive, clear */ 3700Sstevel@tonic-gate struct l_fixedpt rec; /* receive, clear */ 3710Sstevel@tonic-gate struct l_fixedpt xmt; /* transmit, clear */ 372*410Skcpoon ulong_t reach; /* receive, transmit, clear */ 373*410Skcpoon ulong_t valid; /* packet, transmit, clear */ 374*410Skcpoon ulong_t timer; /* receive, transmit, poll update */ 3750Sstevel@tonic-gate long stopwatch; /* <<local>> for timing */ 3760Sstevel@tonic-gate /* 3770Sstevel@tonic-gate * first order offsets 3780Sstevel@tonic-gate */ 3790Sstevel@tonic-gate struct filter { 3800Sstevel@tonic-gate short samples; /* <<local>> */ 3810Sstevel@tonic-gate double offset[PEER_SHIFT]; 3820Sstevel@tonic-gate double delay[PEER_SHIFT]; 3830Sstevel@tonic-gate } filter; /* filter, clear */ 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate double estdelay; /* filter */ 3860Sstevel@tonic-gate double estoffset; /* filter */ 3870Sstevel@tonic-gate double estdisp; /* filter */ 3880Sstevel@tonic-gate 389*410Skcpoon ulong_t pkt_sent; /* <<local>> */ 390*410Skcpoon ulong_t pkt_rcvd; /* <<local>> */ 391*410Skcpoon ulong_t pkt_dropped; /* <<local>> */ 3920Sstevel@tonic-gate }; 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate /* ================= table 3.1: System Variables ================= */ 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate struct sysdata { /* procedure */ 397*410Skcpoon uchar_t leap; /* clock update */ 398*410Skcpoon uchar_t stratum; /* clock update */ 3990Sstevel@tonic-gate short precision; /* system */ 4000Sstevel@tonic-gate struct s_fixedpt distance; /* clock update */ 4010Sstevel@tonic-gate struct s_fixedpt dispersion; /* clock update */ 402*410Skcpoon ulong_t refid; /* clock update */ 4030Sstevel@tonic-gate struct l_fixedpt reftime; /* clock update */ 4040Sstevel@tonic-gate int hold; /* clock update */ 4050Sstevel@tonic-gate struct ntp_peer *peer; /* selection */ 4060Sstevel@tonic-gate int maxpeers; /* <<local>> */ 407*410Skcpoon uchar_t filler; /* put here for %&*%$$ SUNs */ 4080Sstevel@tonic-gate }; 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate #define NTPDC_VERSION 2 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate /* 4130Sstevel@tonic-gate * These structures are used to pass information to the ntpdc (control) 4140Sstevel@tonic-gate * program. They are unique to this implementation and not part of the 4150Sstevel@tonic-gate * NTP specification. 4160Sstevel@tonic-gate */ 4170Sstevel@tonic-gate struct clockinfo { 418*410Skcpoon ulong_t net_address; 419*410Skcpoon ulong_t my_address; 420*410Skcpoon ushort_t port; 421*410Skcpoon ushort_t flags; 422*410Skcpoon ulong_t pkt_sent; 423*410Skcpoon ulong_t pkt_rcvd; 424*410Skcpoon ulong_t pkt_dropped; 425*410Skcpoon ulong_t timer; 426*410Skcpoon uchar_t leap; 427*410Skcpoon uchar_t stratum; 428*410Skcpoon uchar_t ppoll; 4290Sstevel@tonic-gate int precision:8; 4300Sstevel@tonic-gate 431*410Skcpoon uchar_t hpoll; 432*410Skcpoon uchar_t filler1; 433*410Skcpoon ushort_t reach; 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate long estdisp; /* scaled by 1000 */ 4360Sstevel@tonic-gate long estdelay; /* in milliseconds */ 4370Sstevel@tonic-gate long estoffset; /* in milliseconds */ 438*410Skcpoon ulong_t refid; 4390Sstevel@tonic-gate struct l_fixedpt reftime; 4400Sstevel@tonic-gate struct info_filter { 4410Sstevel@tonic-gate short index; 4420Sstevel@tonic-gate short filler; 4430Sstevel@tonic-gate long offset[PEER_SHIFT]; /* in milliseconds */ 4440Sstevel@tonic-gate long delay[PEER_SHIFT]; /* in milliseconds */ 4450Sstevel@tonic-gate } info_filter; 4460Sstevel@tonic-gate }; 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate struct ntpinfo { 449*410Skcpoon uchar_t version; 450*410Skcpoon uchar_t type; /* request type (stratum in ntp packets) */ 451*410Skcpoon uchar_t count; /* number of entries in this packet */ 452*410Skcpoon uchar_t seq; /* sequence number of this packet */ 4530Sstevel@tonic-gate 454*410Skcpoon uchar_t npkts; /* total number of packets */ 455*410Skcpoon uchar_t peers; 456*410Skcpoon uchar_t fill3; 457*410Skcpoon uchar_t fill4; 4580Sstevel@tonic-gate }; 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate /* 4610Sstevel@tonic-gate * From usr/src/cmd/xntpd/include/ntp_control.h: 4620Sstevel@tonic-gate * Definition of a mode 6 packet. 4630Sstevel@tonic-gate */ 4640Sstevel@tonic-gate struct ntp_control { 465*410Skcpoon uchar_t li_vn_mode; /* leap, version, mode */ 466*410Skcpoon uchar_t r_m_e_op; /* response, more, error, opcode */ 467*410Skcpoon ushort_t sequence; /* sequence number of request */ 468*410Skcpoon ushort_t status; /* status word for association */ 469*410Skcpoon ushort_t associd; /* association ID */ 470*410Skcpoon ushort_t offset; /* offset of this batch of data */ 471*410Skcpoon ushort_t count; /* count of data in this packet */ 472*410Skcpoon uchar_t data[1]; /* data + auth */ 4730Sstevel@tonic-gate }; 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate #define NTPC_DATA_MAXLEN (480 + AUTH_OCTETS_V3) 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate /* 4780Sstevel@tonic-gate * Decoding for the r_m_e_op field 4790Sstevel@tonic-gate */ 4800Sstevel@tonic-gate #define CTL_RESPONSE 0x80 4810Sstevel@tonic-gate #define CTL_ERROR 0x40 4820Sstevel@tonic-gate #define CTL_MORE 0x20 4830Sstevel@tonic-gate #define CTL_OP_MASK 0x1f 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate /* 4860Sstevel@tonic-gate * Opcodes 4870Sstevel@tonic-gate */ 4880Sstevel@tonic-gate #define CTL_OP_UNSPEC 0 4890Sstevel@tonic-gate #define CTL_OP_READSTAT 1 4900Sstevel@tonic-gate #define CTL_OP_READVAR 2 4910Sstevel@tonic-gate #define CTL_OP_WRITEVAR 3 4920Sstevel@tonic-gate #define CTL_OP_READCLOCK 4 4930Sstevel@tonic-gate #define CTL_OP_WRITECLOCK 5 4940Sstevel@tonic-gate #define CTL_OP_SETTRAP 6 4950Sstevel@tonic-gate #define CTL_OP_ASYNCMSG 7 4960Sstevel@tonic-gate #define CTL_OP_UNSETTRAP 31 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate /* 4990Sstevel@tonic-gate * From usr/src/cmd/xntpd/include/ntp_request.h: 5000Sstevel@tonic-gate * A mode 7 packet is used exchanging data between an NTP server 5010Sstevel@tonic-gate * and a client for purposes other than time synchronization, e.g. 5020Sstevel@tonic-gate * monitoring, statistics gathering and configuration. A mode 7 5030Sstevel@tonic-gate * packet has the following format: 5040Sstevel@tonic-gate */ 5050Sstevel@tonic-gate 5060Sstevel@tonic-gate struct ntp_private { 507*410Skcpoon uchar_t rm_vn_mode; /* response, more, version, mode */ 508*410Skcpoon uchar_t auth_seq; /* key, sequence number */ 509*410Skcpoon uchar_t implementation; /* implementation number */ 510*410Skcpoon uchar_t request; /* request number */ 511*410Skcpoon ushort_t err_nitems; /* error code/number of data items */ 512*410Skcpoon ushort_t mbz_itemsize; /* item size */ 5130Sstevel@tonic-gate char data[1]; /* data area */ 5140Sstevel@tonic-gate }; 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate #define RESP_BIT 0x80 5170Sstevel@tonic-gate #define MORE_BIT 0x40 518*410Skcpoon #define INFO_VERSION(rm_vn_mode) ((uchar_t)(((rm_vn_mode)>>3) & 0x7)) 5190Sstevel@tonic-gate #define INFO_MODE(rm_vn_mode) ((rm_vn_mode) & 0x7) 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate #define AUTH_BIT 0x80 5220Sstevel@tonic-gate #define INFO_SEQ(auth_seq) ((auth_seq) & 0x7f) 5230Sstevel@tonic-gate 524*410Skcpoon #define INFO_ERR(err_nitems) ((ushort_t)((ntohs(err_nitems) >> 12) & 0xf)) 525*410Skcpoon #define INFO_NITEMS(err_nitems) ((ushort_t)(ntohs(err_nitems) & 0xfff)) 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate #define INFO_ITEMSIZE(mbz_itemsize) (ntohs(mbz_itemsize) & 0xfff) 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate #ifdef __cplusplus 5300Sstevel@tonic-gate } 5310Sstevel@tonic-gate #endif 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate #endif /* _NTP_H */ 534