1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1991, 2000, 2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* 28*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 29*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 30*7c478bd9Sstevel@tonic-gate * All Rights Reserved 31*7c478bd9Sstevel@tonic-gate * 32*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 33*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 34*7c478bd9Sstevel@tonic-gate * contributors. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #ifndef _NTP_H 38*7c478bd9Sstevel@tonic-gate #define _NTP_H 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 43*7c478bd9Sstevel@tonic-gate extern "C" { 44*7c478bd9Sstevel@tonic-gate #endif 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate /* $Source: /usr/users/louie/ntp/RCS/ntp.h,v $ */ 47*7c478bd9Sstevel@tonic-gate /* $Revision: 3.4.1.5 $ $Date: 89/04/10 15:55:42 $ */ 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate /* 50*7c478bd9Sstevel@tonic-gate * $Log: ntp.h,v $ 51*7c478bd9Sstevel@tonic-gate * Revision 3.4.1.5 89/04/10 15:55:42 louie 52*7c478bd9Sstevel@tonic-gate * Provide default value for number of bits/byte if not defined. Compute the 53*7c478bd9Sstevel@tonic-gate * Window shift mask inside of conditional code on XTAL so we get the correct 54*7c478bd9Sstevel@tonic-gate * value if configured without a crystal controled clock (!!) 55*7c478bd9Sstevel@tonic-gate * 56*7c478bd9Sstevel@tonic-gate * Revision 3.4.1.4 89/03/31 16:34:50 louie 57*7c478bd9Sstevel@tonic-gate * Add bit in flags which allow a peer to be synced to. Changed a char to a bit 58*7c478bd9Sstevel@tonic-gate * field so that it is always signed. 59*7c478bd9Sstevel@tonic-gate * 60*7c478bd9Sstevel@tonic-gate * Revision 3.4.1.3 89/03/29 12:26:18 louie 61*7c478bd9Sstevel@tonic-gate * Removed some unused #defines. Replaced MAXSTRATUM with NTP_INFIN per new 62*7c478bd9Sstevel@tonic-gate * spec. The variable 'mode' in the peer structure has been renamed 'hmode' 63*7c478bd9Sstevel@tonic-gate * per the new spec. 64*7c478bd9Sstevel@tonic-gate * 65*7c478bd9Sstevel@tonic-gate * Revision 3.4.1.2 89/03/22 18:28:18 louie 66*7c478bd9Sstevel@tonic-gate * patch3: Use new RCS headers. 67*7c478bd9Sstevel@tonic-gate * 68*7c478bd9Sstevel@tonic-gate * Revision 3.4.1.1 89/03/20 00:02:53 louie 69*7c478bd9Sstevel@tonic-gate * 1 70*7c478bd9Sstevel@tonic-gate * 71*7c478bd9Sstevel@tonic-gate * Revision 3.4 89/03/17 18:37:00 louie 72*7c478bd9Sstevel@tonic-gate * Latest test release. 73*7c478bd9Sstevel@tonic-gate * 74*7c478bd9Sstevel@tonic-gate * Revision 3.3.1.1 89/03/17 18:23:49 louie 75*7c478bd9Sstevel@tonic-gate * Change CLOCK_FACTOR to be a power of 2. 76*7c478bd9Sstevel@tonic-gate * 77*7c478bd9Sstevel@tonic-gate * Revision 3.3 89/03/15 14:19:36 louie 78*7c478bd9Sstevel@tonic-gate * New baseline for next release. 79*7c478bd9Sstevel@tonic-gate * 80*7c478bd9Sstevel@tonic-gate * Revision 3.2.1.2 89/03/15 13:46:52 louie 81*7c478bd9Sstevel@tonic-gate * The version number for that particular flavor of ntpd <--> ntpdc interaction 82*7c478bd9Sstevel@tonic-gate * is now defined by NTPDC_VERSION. The packet format for the ntpdc program 83*7c478bd9Sstevel@tonic-gate * has changed slightly to improve robustness when dealing with multiple packets 84*7c478bd9Sstevel@tonic-gate * of status data. 85*7c478bd9Sstevel@tonic-gate * 86*7c478bd9Sstevel@tonic-gate * Revision 3.2.1.1 89/03/09 17:11:24 louie 87*7c478bd9Sstevel@tonic-gate * patch1: Updated constants, which were previously in incorrect units. 88*7c478bd9Sstevel@tonic-gate * 89*7c478bd9Sstevel@tonic-gate * Revision 3.2 89/03/07 18:21:45 louie 90*7c478bd9Sstevel@tonic-gate * New version of UNIX NTP daemon and software based on the 6 March 1989 91*7c478bd9Sstevel@tonic-gate * draft of the new NTP protocol specification. This version doesn't 92*7c478bd9Sstevel@tonic-gate * implement authentication, and accepts and send only NTP Version 1 93*7c478bd9Sstevel@tonic-gate * packets. 94*7c478bd9Sstevel@tonic-gate * 95*7c478bd9Sstevel@tonic-gate * Revision 3.1.1.1 89/02/15 08:54:42 louie 96*7c478bd9Sstevel@tonic-gate * *** empty log message *** 97*7c478bd9Sstevel@tonic-gate * 98*7c478bd9Sstevel@tonic-gate * 99*7c478bd9Sstevel@tonic-gate * Revision 3.1 89/01/30 14:43:07 louie 100*7c478bd9Sstevel@tonic-gate * Second UNIX NTP test release. 101*7c478bd9Sstevel@tonic-gate * 102*7c478bd9Sstevel@tonic-gate * Revision 3.0 88/12/12 16:01:07 louie 103*7c478bd9Sstevel@tonic-gate * Test release of new UNIX NTP software. This version should conform to the 104*7c478bd9Sstevel@tonic-gate * revised NTP protocol specification. 105*7c478bd9Sstevel@tonic-gate * 106*7c478bd9Sstevel@tonic-gate */ 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate #ifndef FD_SET 109*7c478bd9Sstevel@tonic-gate #define NFDBITS 32 110*7c478bd9Sstevel@tonic-gate #define FD_SETSIZE 32 111*7c478bd9Sstevel@tonic-gate #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) 112*7c478bd9Sstevel@tonic-gate #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) 113*7c478bd9Sstevel@tonic-gate #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) 114*7c478bd9Sstevel@tonic-gate #define FD_ZERO(p) bzero((char *)(p), sizeof (*(p))) 115*7c478bd9Sstevel@tonic-gate #endif 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate #ifndef NBBY 118*7c478bd9Sstevel@tonic-gate #define NBBY 8 /* number of bits per byte */ 119*7c478bd9Sstevel@tonic-gate #endif 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate #define MAXNETIF 10 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate struct intf { 124*7c478bd9Sstevel@tonic-gate int fd; 125*7c478bd9Sstevel@tonic-gate char *name; 126*7c478bd9Sstevel@tonic-gate struct sockaddr_in sin; 127*7c478bd9Sstevel@tonic-gate struct sockaddr_in bcast; 128*7c478bd9Sstevel@tonic-gate struct sockaddr_in mask; 129*7c478bd9Sstevel@tonic-gate int uses; 130*7c478bd9Sstevel@tonic-gate int if_flags; 131*7c478bd9Sstevel@tonic-gate }; 132*7c478bd9Sstevel@tonic-gate extern struct intf addrs[]; 133*7c478bd9Sstevel@tonic-gate extern int nintf; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /* 136*7c478bd9Sstevel@tonic-gate * Definitions for the masses 137*7c478bd9Sstevel@tonic-gate */ 138*7c478bd9Sstevel@tonic-gate #define JAN_1970 2208988800 /* 1970 - 1900 in seconds */ 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate /* 141*7c478bd9Sstevel@tonic-gate * Daemon specific (ntpd.c) 142*7c478bd9Sstevel@tonic-gate */ 143*7c478bd9Sstevel@tonic-gate #define SHIFT_MASK 0xff /* number of intervals to wait */ 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate #ifndef WAYTOOBIG 146*7c478bd9Sstevel@tonic-gate #define WAYTOOBIG 1000.0 /* Too many seconds to correct, something is */ 147*7c478bd9Sstevel@tonic-gate /* really wrong */ 148*7c478bd9Sstevel@tonic-gate #endif 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate #ifndef XTAL 151*7c478bd9Sstevel@tonic-gate #define XTAL 1 /* crystal controlled clock by default */ 152*7c478bd9Sstevel@tonic-gate #endif 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate #ifndef NTPINITFILE 155*7c478bd9Sstevel@tonic-gate #define NTPINITFILE "/etc/ntp.conf" 156*7c478bd9Sstevel@tonic-gate #endif 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate struct list { 159*7c478bd9Sstevel@tonic-gate struct ntp_peer *head; 160*7c478bd9Sstevel@tonic-gate struct ntp_peer *tail; 161*7c478bd9Sstevel@tonic-gate int members; 162*7c478bd9Sstevel@tonic-gate }; 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate #define STRMCMP(a, cond, b) \ 165*7c478bd9Sstevel@tonic-gate (((a) == UNSPECIFIED ? NTP_INFIN+1 : a) cond \ 166*7c478bd9Sstevel@tonic-gate ((b) == UNSPECIFIED ? NTP_INFIN+1 : (b))) 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate /* 170*7c478bd9Sstevel@tonic-gate * Definitions outlined in the NTP spec 171*7c478bd9Sstevel@tonic-gate */ 172*7c478bd9Sstevel@tonic-gate #define NTP_VERSION 1 173*7c478bd9Sstevel@tonic-gate #define NTP_PORT 123 /* for ref only (see /etc/services) */ 174*7c478bd9Sstevel@tonic-gate #define NTP_INFIN 15 175*7c478bd9Sstevel@tonic-gate #define NTP_MAXAGE 86400 176*7c478bd9Sstevel@tonic-gate #define NTP_MAXSKW 0.01 /* seconds */ 177*7c478bd9Sstevel@tonic-gate #define NTP_MINDIST 0.02 /* seconds */ 178*7c478bd9Sstevel@tonic-gate #define NTP_MINPOLL 6 /* (64) seconds between messages */ 179*7c478bd9Sstevel@tonic-gate #define NTP_MAXPOLL 10 /* (1024) secs to poll */ 180*7c478bd9Sstevel@tonic-gate #define NTP_WINDOW 8 /* size of shift register */ 181*7c478bd9Sstevel@tonic-gate #define NTP_MAXWGT 8 /* maximum allowable dispersion */ 182*7c478bd9Sstevel@tonic-gate #define NTP_MAXLIST 5 /* max size of selection list */ 183*7c478bd9Sstevel@tonic-gate #define NTP_MAXSTRA 2 /* max number of strata in selection list */ 184*7c478bd9Sstevel@tonic-gate #define X_NTP_CANDIDATES 64 /* number of peers to consider when doing */ 185*7c478bd9Sstevel@tonic-gate /* clock selection */ 186*7c478bd9Sstevel@tonic-gate #define NTP_SELECT 0.75 /* weight used to compute dispersion */ 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate #define PEER_MAXDISP 64.0 /* Maximum dispersion */ 189*7c478bd9Sstevel@tonic-gate #define PEER_THRESHOLD 0.5 /* dispersion threshold */ 190*7c478bd9Sstevel@tonic-gate #define PEER_FILTER 0.5 /* filter weight */ 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate #if XTAL == 0 193*7c478bd9Sstevel@tonic-gate #define PEER_SHIFT 4 194*7c478bd9Sstevel@tonic-gate #define NTP_WINDOW_SHIFT_MASK 0x0f 195*7c478bd9Sstevel@tonic-gate #else 196*7c478bd9Sstevel@tonic-gate #define PEER_SHIFT 8 197*7c478bd9Sstevel@tonic-gate #define NTP_WINDOW_SHIFT_MASK 0xff 198*7c478bd9Sstevel@tonic-gate #endif 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate /* 202*7c478bd9Sstevel@tonic-gate * 5.1 Uniform Phase Adjustments 203*7c478bd9Sstevel@tonic-gate * Clock parameters 204*7c478bd9Sstevel@tonic-gate */ 205*7c478bd9Sstevel@tonic-gate #define CLOCK_UPDATE 8 /* update interval (1<<CLOCK_UPDATE secs) */ 206*7c478bd9Sstevel@tonic-gate #if XTAL 207*7c478bd9Sstevel@tonic-gate #define CLOCK_ADJ 2 /* adjustment interval (1<<CLOCK_ADJ secs) */ 208*7c478bd9Sstevel@tonic-gate #define CLOCK_PHASE 8 /* phase shift */ 209*7c478bd9Sstevel@tonic-gate #define CLOCK_MAX 0.128 /* maximum aperture (milliseconds) */ 210*7c478bd9Sstevel@tonic-gate #else 211*7c478bd9Sstevel@tonic-gate #define CLOCK_ADJ 0 212*7c478bd9Sstevel@tonic-gate #define CLOCK_PHASE 6 /* phase shift */ 213*7c478bd9Sstevel@tonic-gate #define CLOCK_MAX 0.512 /* maximum aperture (milliseconds) */ 214*7c478bd9Sstevel@tonic-gate #endif 215*7c478bd9Sstevel@tonic-gate #define CLOCK_FREQ 10 /* frequency shift */ 216*7c478bd9Sstevel@tonic-gate #define CLOCK_TRACK 8 217*7c478bd9Sstevel@tonic-gate #define CLOCK_COMP 4 218*7c478bd9Sstevel@tonic-gate #define CLOCK_FACTOR 18 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate /* 221*7c478bd9Sstevel@tonic-gate * Structure definitions for NTP fixed point values 222*7c478bd9Sstevel@tonic-gate * 223*7c478bd9Sstevel@tonic-gate * 0 1 2 3 224*7c478bd9Sstevel@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 225*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 226*7c478bd9Sstevel@tonic-gate * | Integer Part | 227*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 228*7c478bd9Sstevel@tonic-gate * | Fraction Part | 229*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 230*7c478bd9Sstevel@tonic-gate * 231*7c478bd9Sstevel@tonic-gate * 232*7c478bd9Sstevel@tonic-gate * 0 1 2 3 233*7c478bd9Sstevel@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 234*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 235*7c478bd9Sstevel@tonic-gate * | Integer Part | Fraction Part | 236*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 237*7c478bd9Sstevel@tonic-gate */ 238*7c478bd9Sstevel@tonic-gate struct l_fixedpt { 239*7c478bd9Sstevel@tonic-gate u_long int_part; 240*7c478bd9Sstevel@tonic-gate u_long fraction; 241*7c478bd9Sstevel@tonic-gate }; 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate struct s_fixedpt { 244*7c478bd9Sstevel@tonic-gate u_short int_part; 245*7c478bd9Sstevel@tonic-gate u_short fraction; 246*7c478bd9Sstevel@tonic-gate }; 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate /* 249*7c478bd9Sstevel@tonic-gate * ================= Table 3.3. Packet Variables ================= 250*7c478bd9Sstevel@tonic-gate * 0 1 2 3 251*7c478bd9Sstevel@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 252*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 253*7c478bd9Sstevel@tonic-gate * |LI | VN | Mode| Stratum | Poll | Precision | 254*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 255*7c478bd9Sstevel@tonic-gate * | Synchronizing Distance | 256*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 257*7c478bd9Sstevel@tonic-gate * | Synchronizing Dispersion | 258*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 259*7c478bd9Sstevel@tonic-gate * | Reference Clock Identifier | 260*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 261*7c478bd9Sstevel@tonic-gate * | | 262*7c478bd9Sstevel@tonic-gate * | Reference Timestamp (64 bits) | 263*7c478bd9Sstevel@tonic-gate * | | 264*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 265*7c478bd9Sstevel@tonic-gate * | | 266*7c478bd9Sstevel@tonic-gate * | Originate Timestamp (64 bits) | 267*7c478bd9Sstevel@tonic-gate * | | 268*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 269*7c478bd9Sstevel@tonic-gate * | | 270*7c478bd9Sstevel@tonic-gate * | Receive Timestamp (64 bits) | 271*7c478bd9Sstevel@tonic-gate * | | 272*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 273*7c478bd9Sstevel@tonic-gate * | | 274*7c478bd9Sstevel@tonic-gate * | Transmit Timestamp (64 bits) | 275*7c478bd9Sstevel@tonic-gate * | | 276*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 277*7c478bd9Sstevel@tonic-gate * | Encryption Keyid (32 bits, when A bit set) | 278*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 279*7c478bd9Sstevel@tonic-gate * | | 280*7c478bd9Sstevel@tonic-gate * | Message Authentication Code/MAC (when A bit set) | 281*7c478bd9Sstevel@tonic-gate * | | 282*7c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 283*7c478bd9Sstevel@tonic-gate */ 284*7c478bd9Sstevel@tonic-gate 285*7c478bd9Sstevel@tonic-gate #define MAC_OCTETS_DES 8 286*7c478bd9Sstevel@tonic-gate #define MAC_OCTETS_MD5 16 287*7c478bd9Sstevel@tonic-gate #define MAC_OCTETS_MIN MAC_OCTETS_DES 288*7c478bd9Sstevel@tonic-gate #define MAC_OCTETS_MAX MAC_OCTETS_MD5 289*7c478bd9Sstevel@tonic-gate #define AUTH_OCTETS_V3 (MAC_OCTETS_MAX + sizeof (uint32_t)) 290*7c478bd9Sstevel@tonic-gate 291*7c478bd9Sstevel@tonic-gate struct ntpdata { 292*7c478bd9Sstevel@tonic-gate u_char li_vn_mode; /* contains leap indicator, version and mode */ 293*7c478bd9Sstevel@tonic-gate u_char stratum; /* Stratum level */ 294*7c478bd9Sstevel@tonic-gate u_char ppoll; /* poll value */ 295*7c478bd9Sstevel@tonic-gate int precision:8; 296*7c478bd9Sstevel@tonic-gate struct s_fixedpt distance; 297*7c478bd9Sstevel@tonic-gate struct s_fixedpt dispersion; 298*7c478bd9Sstevel@tonic-gate u_long refid; 299*7c478bd9Sstevel@tonic-gate struct l_fixedpt reftime; 300*7c478bd9Sstevel@tonic-gate struct l_fixedpt org; 301*7c478bd9Sstevel@tonic-gate struct l_fixedpt rec; 302*7c478bd9Sstevel@tonic-gate struct l_fixedpt xmt; 303*7c478bd9Sstevel@tonic-gate uint32_t keyid; 304*7c478bd9Sstevel@tonic-gate u_char mac[MAC_OCTETS_MAX]; 305*7c478bd9Sstevel@tonic-gate }; 306*7c478bd9Sstevel@tonic-gate 307*7c478bd9Sstevel@tonic-gate #define LEN_PKT_NOMAC (sizeof (struct ntpdata) - AUTH_OCTETS_V3) 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate /* 310*7c478bd9Sstevel@tonic-gate * Leap Second Codes (high order two bits) 311*7c478bd9Sstevel@tonic-gate */ 312*7c478bd9Sstevel@tonic-gate #define NO_WARNING 0x00 /* no warning */ 313*7c478bd9Sstevel@tonic-gate #define PLUS_SEC 0x40 /* add a second (61 seconds) */ 314*7c478bd9Sstevel@tonic-gate #define MINUS_SEC 0x80 /* minus a second (59 seconds) */ 315*7c478bd9Sstevel@tonic-gate #define ALARM 0xc0 /* alarm condition (clock unsynchronized) */ 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate /* 318*7c478bd9Sstevel@tonic-gate * Clock Status Bits that Encode Version 319*7c478bd9Sstevel@tonic-gate */ 320*7c478bd9Sstevel@tonic-gate #define NTPVERSION_1 0x08 321*7c478bd9Sstevel@tonic-gate #define VERSIONMASK 0x38 322*7c478bd9Sstevel@tonic-gate #define LEAPMASK 0xc0 323*7c478bd9Sstevel@tonic-gate #define NTPMODEMASK 0x07 324*7c478bd9Sstevel@tonic-gate 325*7c478bd9Sstevel@tonic-gate /* 326*7c478bd9Sstevel@tonic-gate * Code values 327*7c478bd9Sstevel@tonic-gate */ 328*7c478bd9Sstevel@tonic-gate #define MODE_UNSPEC 0 /* unspecified */ 329*7c478bd9Sstevel@tonic-gate #define MODE_SYM_ACT 1 /* symmetric active */ 330*7c478bd9Sstevel@tonic-gate #define MODE_SYM_PAS 2 /* symmetric passive */ 331*7c478bd9Sstevel@tonic-gate #define MODE_CLIENT 3 /* client */ 332*7c478bd9Sstevel@tonic-gate #define MODE_SERVER 4 /* server */ 333*7c478bd9Sstevel@tonic-gate #define MODE_BROADCAST 5 /* broadcast */ 334*7c478bd9Sstevel@tonic-gate #define MODE_CONTROL 6 /* control */ 335*7c478bd9Sstevel@tonic-gate #define MODE_PRIVATE 7 /* private */ 336*7c478bd9Sstevel@tonic-gate 337*7c478bd9Sstevel@tonic-gate /* 338*7c478bd9Sstevel@tonic-gate * Stratum Definitions 339*7c478bd9Sstevel@tonic-gate */ 340*7c478bd9Sstevel@tonic-gate #define UNSPECIFIED 0 341*7c478bd9Sstevel@tonic-gate #define PRIM_REF 1 /* radio clock */ 342*7c478bd9Sstevel@tonic-gate #define INFO_QUERY 62 /* **** THIS implementation dependent **** */ 343*7c478bd9Sstevel@tonic-gate #define INFO_REPLY 63 /* **** THIS implementation dependent **** */ 344*7c478bd9Sstevel@tonic-gate 345*7c478bd9Sstevel@tonic-gate 346*7c478bd9Sstevel@tonic-gate /* ================= table 3.2 Peer Variables ================= */ 347*7c478bd9Sstevel@tonic-gate struct ntp_peer { 348*7c478bd9Sstevel@tonic-gate struct ntp_peer *next, *prev; 349*7c478bd9Sstevel@tonic-gate struct sockaddr_in src; /* both peer.srcadr and peer.srcport */ 350*7c478bd9Sstevel@tonic-gate int flags; /* local flags */ 351*7c478bd9Sstevel@tonic-gate #define PEER_FL_CONFIG 1 352*7c478bd9Sstevel@tonic-gate #define PEER_FL_AUTHENABLE 2 353*7c478bd9Sstevel@tonic-gate #define PEER_FL_SYNC 0x1000 /* peer can bet sync'd to */ 354*7c478bd9Sstevel@tonic-gate #define PEER_FL_BCAST 0x2000 /* broadcast peer */ 355*7c478bd9Sstevel@tonic-gate #define PEER_FL_SELECTED 0x8000 /* actually used by query routine */ 356*7c478bd9Sstevel@tonic-gate 357*7c478bd9Sstevel@tonic-gate int sock; /* index into sockets to derive */ 358*7c478bd9Sstevel@tonic-gate /* peer.dstadr and peer.dstport */ 359*7c478bd9Sstevel@tonic-gate u_char leap; /* receive */ 360*7c478bd9Sstevel@tonic-gate u_char hmode; /* receive */ 361*7c478bd9Sstevel@tonic-gate u_char stratum; /* receive */ 362*7c478bd9Sstevel@tonic-gate u_char ppoll; /* receive */ 363*7c478bd9Sstevel@tonic-gate u_char hpoll; /* poll update */ 364*7c478bd9Sstevel@tonic-gate short precision; /* receive */ 365*7c478bd9Sstevel@tonic-gate struct s_fixedpt distance; /* receive */ 366*7c478bd9Sstevel@tonic-gate struct s_fixedpt dispersion; /* receive */ 367*7c478bd9Sstevel@tonic-gate u_long refid; /* receive */ 368*7c478bd9Sstevel@tonic-gate struct l_fixedpt reftime; /* receive */ 369*7c478bd9Sstevel@tonic-gate struct l_fixedpt org; /* receive, clear */ 370*7c478bd9Sstevel@tonic-gate struct l_fixedpt rec; /* receive, clear */ 371*7c478bd9Sstevel@tonic-gate struct l_fixedpt xmt; /* transmit, clear */ 372*7c478bd9Sstevel@tonic-gate u_long reach; /* receive, transmit, clear */ 373*7c478bd9Sstevel@tonic-gate u_long valid; /* packet, transmit, clear */ 374*7c478bd9Sstevel@tonic-gate u_long timer; /* receive, transmit, poll update */ 375*7c478bd9Sstevel@tonic-gate long stopwatch; /* <<local>> for timing */ 376*7c478bd9Sstevel@tonic-gate /* 377*7c478bd9Sstevel@tonic-gate * first order offsets 378*7c478bd9Sstevel@tonic-gate */ 379*7c478bd9Sstevel@tonic-gate struct filter { 380*7c478bd9Sstevel@tonic-gate short samples; /* <<local>> */ 381*7c478bd9Sstevel@tonic-gate double offset[PEER_SHIFT]; 382*7c478bd9Sstevel@tonic-gate double delay[PEER_SHIFT]; 383*7c478bd9Sstevel@tonic-gate } filter; /* filter, clear */ 384*7c478bd9Sstevel@tonic-gate 385*7c478bd9Sstevel@tonic-gate double estdelay; /* filter */ 386*7c478bd9Sstevel@tonic-gate double estoffset; /* filter */ 387*7c478bd9Sstevel@tonic-gate double estdisp; /* filter */ 388*7c478bd9Sstevel@tonic-gate 389*7c478bd9Sstevel@tonic-gate u_long pkt_sent; /* <<local>> */ 390*7c478bd9Sstevel@tonic-gate u_long pkt_rcvd; /* <<local>> */ 391*7c478bd9Sstevel@tonic-gate u_long pkt_dropped; /* <<local>> */ 392*7c478bd9Sstevel@tonic-gate }; 393*7c478bd9Sstevel@tonic-gate 394*7c478bd9Sstevel@tonic-gate /* ================= table 3.1: System Variables ================= */ 395*7c478bd9Sstevel@tonic-gate 396*7c478bd9Sstevel@tonic-gate struct sysdata { /* procedure */ 397*7c478bd9Sstevel@tonic-gate u_char leap; /* clock update */ 398*7c478bd9Sstevel@tonic-gate u_char stratum; /* clock update */ 399*7c478bd9Sstevel@tonic-gate short precision; /* system */ 400*7c478bd9Sstevel@tonic-gate struct s_fixedpt distance; /* clock update */ 401*7c478bd9Sstevel@tonic-gate struct s_fixedpt dispersion; /* clock update */ 402*7c478bd9Sstevel@tonic-gate u_long refid; /* clock update */ 403*7c478bd9Sstevel@tonic-gate struct l_fixedpt reftime; /* clock update */ 404*7c478bd9Sstevel@tonic-gate int hold; /* clock update */ 405*7c478bd9Sstevel@tonic-gate struct ntp_peer *peer; /* selection */ 406*7c478bd9Sstevel@tonic-gate int maxpeers; /* <<local>> */ 407*7c478bd9Sstevel@tonic-gate u_char filler; /* put here for %&*%$$ SUNs */ 408*7c478bd9Sstevel@tonic-gate }; 409*7c478bd9Sstevel@tonic-gate 410*7c478bd9Sstevel@tonic-gate #define NTPDC_VERSION 2 411*7c478bd9Sstevel@tonic-gate 412*7c478bd9Sstevel@tonic-gate /* 413*7c478bd9Sstevel@tonic-gate * These structures are used to pass information to the ntpdc (control) 414*7c478bd9Sstevel@tonic-gate * program. They are unique to this implementation and not part of the 415*7c478bd9Sstevel@tonic-gate * NTP specification. 416*7c478bd9Sstevel@tonic-gate */ 417*7c478bd9Sstevel@tonic-gate struct clockinfo { 418*7c478bd9Sstevel@tonic-gate u_long net_address; 419*7c478bd9Sstevel@tonic-gate u_long my_address; 420*7c478bd9Sstevel@tonic-gate u_short port; 421*7c478bd9Sstevel@tonic-gate u_short flags; 422*7c478bd9Sstevel@tonic-gate u_long pkt_sent; 423*7c478bd9Sstevel@tonic-gate u_long pkt_rcvd; 424*7c478bd9Sstevel@tonic-gate u_long pkt_dropped; 425*7c478bd9Sstevel@tonic-gate u_long timer; 426*7c478bd9Sstevel@tonic-gate u_char leap; 427*7c478bd9Sstevel@tonic-gate u_char stratum; 428*7c478bd9Sstevel@tonic-gate u_char ppoll; 429*7c478bd9Sstevel@tonic-gate int precision:8; 430*7c478bd9Sstevel@tonic-gate 431*7c478bd9Sstevel@tonic-gate u_char hpoll; 432*7c478bd9Sstevel@tonic-gate u_char filler1; 433*7c478bd9Sstevel@tonic-gate u_short reach; 434*7c478bd9Sstevel@tonic-gate 435*7c478bd9Sstevel@tonic-gate long estdisp; /* scaled by 1000 */ 436*7c478bd9Sstevel@tonic-gate long estdelay; /* in milliseconds */ 437*7c478bd9Sstevel@tonic-gate long estoffset; /* in milliseconds */ 438*7c478bd9Sstevel@tonic-gate u_long refid; 439*7c478bd9Sstevel@tonic-gate struct l_fixedpt reftime; 440*7c478bd9Sstevel@tonic-gate struct info_filter { 441*7c478bd9Sstevel@tonic-gate short index; 442*7c478bd9Sstevel@tonic-gate short filler; 443*7c478bd9Sstevel@tonic-gate long offset[PEER_SHIFT]; /* in milliseconds */ 444*7c478bd9Sstevel@tonic-gate long delay[PEER_SHIFT]; /* in milliseconds */ 445*7c478bd9Sstevel@tonic-gate } info_filter; 446*7c478bd9Sstevel@tonic-gate }; 447*7c478bd9Sstevel@tonic-gate 448*7c478bd9Sstevel@tonic-gate struct ntpinfo { 449*7c478bd9Sstevel@tonic-gate u_char version; 450*7c478bd9Sstevel@tonic-gate u_char type; /* request type (stratum in ntp packets) */ 451*7c478bd9Sstevel@tonic-gate u_char count; /* number of entries in this packet */ 452*7c478bd9Sstevel@tonic-gate u_char seq; /* sequence number of this packet */ 453*7c478bd9Sstevel@tonic-gate 454*7c478bd9Sstevel@tonic-gate u_char npkts; /* total number of packets */ 455*7c478bd9Sstevel@tonic-gate u_char peers; 456*7c478bd9Sstevel@tonic-gate u_char fill3; 457*7c478bd9Sstevel@tonic-gate u_char fill4; 458*7c478bd9Sstevel@tonic-gate }; 459*7c478bd9Sstevel@tonic-gate 460*7c478bd9Sstevel@tonic-gate /* 461*7c478bd9Sstevel@tonic-gate * From usr/src/cmd/xntpd/include/ntp_control.h: 462*7c478bd9Sstevel@tonic-gate * Definition of a mode 6 packet. 463*7c478bd9Sstevel@tonic-gate */ 464*7c478bd9Sstevel@tonic-gate struct ntp_control { 465*7c478bd9Sstevel@tonic-gate u_char li_vn_mode; /* leap, version, mode */ 466*7c478bd9Sstevel@tonic-gate u_char r_m_e_op; /* response, more, error, opcode */ 467*7c478bd9Sstevel@tonic-gate u_short sequence; /* sequence number of request */ 468*7c478bd9Sstevel@tonic-gate u_short status; /* status word for association */ 469*7c478bd9Sstevel@tonic-gate u_short associd; /* association ID */ 470*7c478bd9Sstevel@tonic-gate u_short offset; /* offset of this batch of data */ 471*7c478bd9Sstevel@tonic-gate u_short count; /* count of data in this packet */ 472*7c478bd9Sstevel@tonic-gate u_char data[1]; /* data + auth */ 473*7c478bd9Sstevel@tonic-gate }; 474*7c478bd9Sstevel@tonic-gate 475*7c478bd9Sstevel@tonic-gate #define NTPC_DATA_MAXLEN (480 + AUTH_OCTETS_V3) 476*7c478bd9Sstevel@tonic-gate 477*7c478bd9Sstevel@tonic-gate /* 478*7c478bd9Sstevel@tonic-gate * Decoding for the r_m_e_op field 479*7c478bd9Sstevel@tonic-gate */ 480*7c478bd9Sstevel@tonic-gate #define CTL_RESPONSE 0x80 481*7c478bd9Sstevel@tonic-gate #define CTL_ERROR 0x40 482*7c478bd9Sstevel@tonic-gate #define CTL_MORE 0x20 483*7c478bd9Sstevel@tonic-gate #define CTL_OP_MASK 0x1f 484*7c478bd9Sstevel@tonic-gate 485*7c478bd9Sstevel@tonic-gate /* 486*7c478bd9Sstevel@tonic-gate * Opcodes 487*7c478bd9Sstevel@tonic-gate */ 488*7c478bd9Sstevel@tonic-gate #define CTL_OP_UNSPEC 0 489*7c478bd9Sstevel@tonic-gate #define CTL_OP_READSTAT 1 490*7c478bd9Sstevel@tonic-gate #define CTL_OP_READVAR 2 491*7c478bd9Sstevel@tonic-gate #define CTL_OP_WRITEVAR 3 492*7c478bd9Sstevel@tonic-gate #define CTL_OP_READCLOCK 4 493*7c478bd9Sstevel@tonic-gate #define CTL_OP_WRITECLOCK 5 494*7c478bd9Sstevel@tonic-gate #define CTL_OP_SETTRAP 6 495*7c478bd9Sstevel@tonic-gate #define CTL_OP_ASYNCMSG 7 496*7c478bd9Sstevel@tonic-gate #define CTL_OP_UNSETTRAP 31 497*7c478bd9Sstevel@tonic-gate 498*7c478bd9Sstevel@tonic-gate /* 499*7c478bd9Sstevel@tonic-gate * From usr/src/cmd/xntpd/include/ntp_request.h: 500*7c478bd9Sstevel@tonic-gate * A mode 7 packet is used exchanging data between an NTP server 501*7c478bd9Sstevel@tonic-gate * and a client for purposes other than time synchronization, e.g. 502*7c478bd9Sstevel@tonic-gate * monitoring, statistics gathering and configuration. A mode 7 503*7c478bd9Sstevel@tonic-gate * packet has the following format: 504*7c478bd9Sstevel@tonic-gate */ 505*7c478bd9Sstevel@tonic-gate 506*7c478bd9Sstevel@tonic-gate struct ntp_private { 507*7c478bd9Sstevel@tonic-gate u_char rm_vn_mode; /* response, more, version, mode */ 508*7c478bd9Sstevel@tonic-gate u_char auth_seq; /* key, sequence number */ 509*7c478bd9Sstevel@tonic-gate u_char implementation; /* implementation number */ 510*7c478bd9Sstevel@tonic-gate u_char request; /* request number */ 511*7c478bd9Sstevel@tonic-gate u_short err_nitems; /* error code/number of data items */ 512*7c478bd9Sstevel@tonic-gate u_short mbz_itemsize; /* item size */ 513*7c478bd9Sstevel@tonic-gate char data[1]; /* data area */ 514*7c478bd9Sstevel@tonic-gate }; 515*7c478bd9Sstevel@tonic-gate 516*7c478bd9Sstevel@tonic-gate #define RESP_BIT 0x80 517*7c478bd9Sstevel@tonic-gate #define MORE_BIT 0x40 518*7c478bd9Sstevel@tonic-gate #define INFO_VERSION(rm_vn_mode) ((u_char)(((rm_vn_mode)>>3) & 0x7)) 519*7c478bd9Sstevel@tonic-gate #define INFO_MODE(rm_vn_mode) ((rm_vn_mode) & 0x7) 520*7c478bd9Sstevel@tonic-gate 521*7c478bd9Sstevel@tonic-gate #define AUTH_BIT 0x80 522*7c478bd9Sstevel@tonic-gate #define INFO_SEQ(auth_seq) ((auth_seq) & 0x7f) 523*7c478bd9Sstevel@tonic-gate 524*7c478bd9Sstevel@tonic-gate #define INFO_ERR(err_nitems) ((u_short)((ntohs(err_nitems) >> 12) & 0xf)) 525*7c478bd9Sstevel@tonic-gate #define INFO_NITEMS(err_nitems) ((u_short)(ntohs(err_nitems) & 0xfff)) 526*7c478bd9Sstevel@tonic-gate 527*7c478bd9Sstevel@tonic-gate #define INFO_ITEMSIZE(mbz_itemsize) (ntohs(mbz_itemsize) & 0xfff) 528*7c478bd9Sstevel@tonic-gate 529*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 530*7c478bd9Sstevel@tonic-gate } 531*7c478bd9Sstevel@tonic-gate #endif 532*7c478bd9Sstevel@tonic-gate 533*7c478bd9Sstevel@tonic-gate #endif /* _NTP_H */ 534