17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*2e3b6467Skcpoon * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 297c478bd9Sstevel@tonic-gate * The Regents of the University of California 307c478bd9Sstevel@tonic-gate * All Rights Reserved 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 337c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 347c478bd9Sstevel@tonic-gate * contributors. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifndef _NTP_H 387c478bd9Sstevel@tonic-gate #define _NTP_H 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #ifdef __cplusplus 417c478bd9Sstevel@tonic-gate extern "C" { 427c478bd9Sstevel@tonic-gate #endif 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* $Source: /usr/users/louie/ntp/RCS/ntp.h,v $ */ 457c478bd9Sstevel@tonic-gate /* $Revision: 3.4.1.5 $ $Date: 89/04/10 15:55:42 $ */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * $Log: ntp.h,v $ 497c478bd9Sstevel@tonic-gate * Revision 3.4.1.5 89/04/10 15:55:42 louie 507c478bd9Sstevel@tonic-gate * Provide default value for number of bits/byte if not defined. Compute the 517c478bd9Sstevel@tonic-gate * Window shift mask inside of conditional code on XTAL so we get the correct 527c478bd9Sstevel@tonic-gate * value if configured without a crystal controled clock (!!) 537c478bd9Sstevel@tonic-gate * 547c478bd9Sstevel@tonic-gate * Revision 3.4.1.4 89/03/31 16:34:50 louie 557c478bd9Sstevel@tonic-gate * Add bit in flags which allow a peer to be synced to. Changed a char to a bit 567c478bd9Sstevel@tonic-gate * field so that it is always signed. 577c478bd9Sstevel@tonic-gate * 587c478bd9Sstevel@tonic-gate * Revision 3.4.1.3 89/03/29 12:26:18 louie 597c478bd9Sstevel@tonic-gate * Removed some unused #defines. Replaced MAXSTRATUM with NTP_INFIN per new 607c478bd9Sstevel@tonic-gate * spec. The variable 'mode' in the peer structure has been renamed 'hmode' 617c478bd9Sstevel@tonic-gate * per the new spec. 627c478bd9Sstevel@tonic-gate * 637c478bd9Sstevel@tonic-gate * Revision 3.4.1.2 89/03/22 18:28:18 louie 647c478bd9Sstevel@tonic-gate * patch3: Use new RCS headers. 657c478bd9Sstevel@tonic-gate * 667c478bd9Sstevel@tonic-gate * Revision 3.4.1.1 89/03/20 00:02:53 louie 677c478bd9Sstevel@tonic-gate * 1 687c478bd9Sstevel@tonic-gate * 697c478bd9Sstevel@tonic-gate * Revision 3.4 89/03/17 18:37:00 louie 707c478bd9Sstevel@tonic-gate * Latest test release. 717c478bd9Sstevel@tonic-gate * 727c478bd9Sstevel@tonic-gate * Revision 3.3.1.1 89/03/17 18:23:49 louie 737c478bd9Sstevel@tonic-gate * Change CLOCK_FACTOR to be a power of 2. 747c478bd9Sstevel@tonic-gate * 757c478bd9Sstevel@tonic-gate * Revision 3.3 89/03/15 14:19:36 louie 767c478bd9Sstevel@tonic-gate * New baseline for next release. 777c478bd9Sstevel@tonic-gate * 787c478bd9Sstevel@tonic-gate * Revision 3.2.1.2 89/03/15 13:46:52 louie 797c478bd9Sstevel@tonic-gate * The version number for that particular flavor of ntpd <--> ntpdc interaction 807c478bd9Sstevel@tonic-gate * is now defined by NTPDC_VERSION. The packet format for the ntpdc program 817c478bd9Sstevel@tonic-gate * has changed slightly to improve robustness when dealing with multiple packets 827c478bd9Sstevel@tonic-gate * of status data. 837c478bd9Sstevel@tonic-gate * 847c478bd9Sstevel@tonic-gate * Revision 3.2.1.1 89/03/09 17:11:24 louie 857c478bd9Sstevel@tonic-gate * patch1: Updated constants, which were previously in incorrect units. 867c478bd9Sstevel@tonic-gate * 877c478bd9Sstevel@tonic-gate * Revision 3.2 89/03/07 18:21:45 louie 887c478bd9Sstevel@tonic-gate * New version of UNIX NTP daemon and software based on the 6 March 1989 897c478bd9Sstevel@tonic-gate * draft of the new NTP protocol specification. This version doesn't 907c478bd9Sstevel@tonic-gate * implement authentication, and accepts and send only NTP Version 1 917c478bd9Sstevel@tonic-gate * packets. 927c478bd9Sstevel@tonic-gate * 937c478bd9Sstevel@tonic-gate * Revision 3.1.1.1 89/02/15 08:54:42 louie 947c478bd9Sstevel@tonic-gate * *** empty log message *** 957c478bd9Sstevel@tonic-gate * 967c478bd9Sstevel@tonic-gate * 977c478bd9Sstevel@tonic-gate * Revision 3.1 89/01/30 14:43:07 louie 987c478bd9Sstevel@tonic-gate * Second UNIX NTP test release. 997c478bd9Sstevel@tonic-gate * 1007c478bd9Sstevel@tonic-gate * Revision 3.0 88/12/12 16:01:07 louie 1017c478bd9Sstevel@tonic-gate * Test release of new UNIX NTP software. This version should conform to the 1027c478bd9Sstevel@tonic-gate * revised NTP protocol specification. 1037c478bd9Sstevel@tonic-gate * 1047c478bd9Sstevel@tonic-gate */ 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #ifndef FD_SET 1077c478bd9Sstevel@tonic-gate #define NFDBITS 32 1087c478bd9Sstevel@tonic-gate #define FD_SETSIZE 32 1097c478bd9Sstevel@tonic-gate #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) 1107c478bd9Sstevel@tonic-gate #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) 1117c478bd9Sstevel@tonic-gate #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) 1127c478bd9Sstevel@tonic-gate #define FD_ZERO(p) bzero((char *)(p), sizeof (*(p))) 1137c478bd9Sstevel@tonic-gate #endif 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate #ifndef NBBY 1167c478bd9Sstevel@tonic-gate #define NBBY 8 /* number of bits per byte */ 1177c478bd9Sstevel@tonic-gate #endif 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate #define MAXNETIF 10 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate struct intf { 1227c478bd9Sstevel@tonic-gate int fd; 1237c478bd9Sstevel@tonic-gate char *name; 1247c478bd9Sstevel@tonic-gate struct sockaddr_in sin; 1257c478bd9Sstevel@tonic-gate struct sockaddr_in bcast; 1267c478bd9Sstevel@tonic-gate struct sockaddr_in mask; 1277c478bd9Sstevel@tonic-gate int uses; 1287c478bd9Sstevel@tonic-gate int if_flags; 1297c478bd9Sstevel@tonic-gate }; 1307c478bd9Sstevel@tonic-gate extern struct intf addrs[]; 1317c478bd9Sstevel@tonic-gate extern int nintf; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * Definitions for the masses 1357c478bd9Sstevel@tonic-gate */ 136*2e3b6467Skcpoon #define JAN_1970 2208988800U /* 1970 - 1900 in seconds */ 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * Daemon specific (ntpd.c) 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate #define SHIFT_MASK 0xff /* number of intervals to wait */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #ifndef WAYTOOBIG 1447c478bd9Sstevel@tonic-gate #define WAYTOOBIG 1000.0 /* Too many seconds to correct, something is */ 1457c478bd9Sstevel@tonic-gate /* really wrong */ 1467c478bd9Sstevel@tonic-gate #endif 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate #ifndef XTAL 1497c478bd9Sstevel@tonic-gate #define XTAL 1 /* crystal controlled clock by default */ 1507c478bd9Sstevel@tonic-gate #endif 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate #ifndef NTPINITFILE 1537c478bd9Sstevel@tonic-gate #define NTPINITFILE "/etc/ntp.conf" 1547c478bd9Sstevel@tonic-gate #endif 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate struct list { 1577c478bd9Sstevel@tonic-gate struct ntp_peer *head; 1587c478bd9Sstevel@tonic-gate struct ntp_peer *tail; 1597c478bd9Sstevel@tonic-gate int members; 1607c478bd9Sstevel@tonic-gate }; 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate #define STRMCMP(a, cond, b) \ 1637c478bd9Sstevel@tonic-gate (((a) == UNSPECIFIED ? NTP_INFIN+1 : a) cond \ 1647c478bd9Sstevel@tonic-gate ((b) == UNSPECIFIED ? NTP_INFIN+1 : (b))) 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * Definitions outlined in the NTP spec 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate #define NTP_VERSION 1 1717c478bd9Sstevel@tonic-gate #define NTP_PORT 123 /* for ref only (see /etc/services) */ 1727c478bd9Sstevel@tonic-gate #define NTP_INFIN 15 1737c478bd9Sstevel@tonic-gate #define NTP_MAXAGE 86400 1747c478bd9Sstevel@tonic-gate #define NTP_MAXSKW 0.01 /* seconds */ 1757c478bd9Sstevel@tonic-gate #define NTP_MINDIST 0.02 /* seconds */ 1767c478bd9Sstevel@tonic-gate #define NTP_MINPOLL 6 /* (64) seconds between messages */ 1777c478bd9Sstevel@tonic-gate #define NTP_MAXPOLL 10 /* (1024) secs to poll */ 1787c478bd9Sstevel@tonic-gate #define NTP_WINDOW 8 /* size of shift register */ 1797c478bd9Sstevel@tonic-gate #define NTP_MAXWGT 8 /* maximum allowable dispersion */ 1807c478bd9Sstevel@tonic-gate #define NTP_MAXLIST 5 /* max size of selection list */ 1817c478bd9Sstevel@tonic-gate #define NTP_MAXSTRA 2 /* max number of strata in selection list */ 1827c478bd9Sstevel@tonic-gate #define X_NTP_CANDIDATES 64 /* number of peers to consider when doing */ 1837c478bd9Sstevel@tonic-gate /* clock selection */ 1847c478bd9Sstevel@tonic-gate #define NTP_SELECT 0.75 /* weight used to compute dispersion */ 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate #define PEER_MAXDISP 64.0 /* Maximum dispersion */ 1877c478bd9Sstevel@tonic-gate #define PEER_THRESHOLD 0.5 /* dispersion threshold */ 1887c478bd9Sstevel@tonic-gate #define PEER_FILTER 0.5 /* filter weight */ 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate #if XTAL == 0 1917c478bd9Sstevel@tonic-gate #define PEER_SHIFT 4 1927c478bd9Sstevel@tonic-gate #define NTP_WINDOW_SHIFT_MASK 0x0f 1937c478bd9Sstevel@tonic-gate #else 1947c478bd9Sstevel@tonic-gate #define PEER_SHIFT 8 1957c478bd9Sstevel@tonic-gate #define NTP_WINDOW_SHIFT_MASK 0xff 1967c478bd9Sstevel@tonic-gate #endif 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * 5.1 Uniform Phase Adjustments 2017c478bd9Sstevel@tonic-gate * Clock parameters 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate #define CLOCK_UPDATE 8 /* update interval (1<<CLOCK_UPDATE secs) */ 2047c478bd9Sstevel@tonic-gate #if XTAL 2057c478bd9Sstevel@tonic-gate #define CLOCK_ADJ 2 /* adjustment interval (1<<CLOCK_ADJ secs) */ 2067c478bd9Sstevel@tonic-gate #define CLOCK_PHASE 8 /* phase shift */ 2077c478bd9Sstevel@tonic-gate #define CLOCK_MAX 0.128 /* maximum aperture (milliseconds) */ 2087c478bd9Sstevel@tonic-gate #else 2097c478bd9Sstevel@tonic-gate #define CLOCK_ADJ 0 2107c478bd9Sstevel@tonic-gate #define CLOCK_PHASE 6 /* phase shift */ 2117c478bd9Sstevel@tonic-gate #define CLOCK_MAX 0.512 /* maximum aperture (milliseconds) */ 2127c478bd9Sstevel@tonic-gate #endif 2137c478bd9Sstevel@tonic-gate #define CLOCK_FREQ 10 /* frequency shift */ 2147c478bd9Sstevel@tonic-gate #define CLOCK_TRACK 8 2157c478bd9Sstevel@tonic-gate #define CLOCK_COMP 4 2167c478bd9Sstevel@tonic-gate #define CLOCK_FACTOR 18 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate /* 2197c478bd9Sstevel@tonic-gate * Structure definitions for NTP fixed point values 2207c478bd9Sstevel@tonic-gate * 2217c478bd9Sstevel@tonic-gate * 0 1 2 3 2227c478bd9Sstevel@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 2237c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2247c478bd9Sstevel@tonic-gate * | Integer Part | 2257c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2267c478bd9Sstevel@tonic-gate * | Fraction Part | 2277c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2287c478bd9Sstevel@tonic-gate * 2297c478bd9Sstevel@tonic-gate * 2307c478bd9Sstevel@tonic-gate * 0 1 2 3 2317c478bd9Sstevel@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 2327c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2337c478bd9Sstevel@tonic-gate * | Integer Part | Fraction Part | 2347c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2357c478bd9Sstevel@tonic-gate */ 2367c478bd9Sstevel@tonic-gate struct l_fixedpt { 237*2e3b6467Skcpoon ulong_t int_part; 238*2e3b6467Skcpoon ulong_t fraction; 2397c478bd9Sstevel@tonic-gate }; 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate struct s_fixedpt { 242*2e3b6467Skcpoon ushort_t int_part; 243*2e3b6467Skcpoon ushort_t fraction; 2447c478bd9Sstevel@tonic-gate }; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * ================= Table 3.3. Packet Variables ================= 2487c478bd9Sstevel@tonic-gate * 0 1 2 3 2497c478bd9Sstevel@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 2507c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2517c478bd9Sstevel@tonic-gate * |LI | VN | Mode| Stratum | Poll | Precision | 2527c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2537c478bd9Sstevel@tonic-gate * | Synchronizing Distance | 2547c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2557c478bd9Sstevel@tonic-gate * | Synchronizing Dispersion | 2567c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2577c478bd9Sstevel@tonic-gate * | Reference Clock Identifier | 2587c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2597c478bd9Sstevel@tonic-gate * | | 2607c478bd9Sstevel@tonic-gate * | Reference Timestamp (64 bits) | 2617c478bd9Sstevel@tonic-gate * | | 2627c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2637c478bd9Sstevel@tonic-gate * | | 2647c478bd9Sstevel@tonic-gate * | Originate Timestamp (64 bits) | 2657c478bd9Sstevel@tonic-gate * | | 2667c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2677c478bd9Sstevel@tonic-gate * | | 2687c478bd9Sstevel@tonic-gate * | Receive Timestamp (64 bits) | 2697c478bd9Sstevel@tonic-gate * | | 2707c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2717c478bd9Sstevel@tonic-gate * | | 2727c478bd9Sstevel@tonic-gate * | Transmit Timestamp (64 bits) | 2737c478bd9Sstevel@tonic-gate * | | 2747c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2757c478bd9Sstevel@tonic-gate * | Encryption Keyid (32 bits, when A bit set) | 2767c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2777c478bd9Sstevel@tonic-gate * | | 2787c478bd9Sstevel@tonic-gate * | Message Authentication Code/MAC (when A bit set) | 2797c478bd9Sstevel@tonic-gate * | | 2807c478bd9Sstevel@tonic-gate * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2817c478bd9Sstevel@tonic-gate */ 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate #define MAC_OCTETS_DES 8 2847c478bd9Sstevel@tonic-gate #define MAC_OCTETS_MD5 16 2857c478bd9Sstevel@tonic-gate #define MAC_OCTETS_MIN MAC_OCTETS_DES 2867c478bd9Sstevel@tonic-gate #define MAC_OCTETS_MAX MAC_OCTETS_MD5 2877c478bd9Sstevel@tonic-gate #define AUTH_OCTETS_V3 (MAC_OCTETS_MAX + sizeof (uint32_t)) 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate struct ntpdata { 290*2e3b6467Skcpoon uchar_t li_vn_mode; /* contains leap indicator, version and mode */ 291*2e3b6467Skcpoon uchar_t stratum; /* Stratum level */ 292*2e3b6467Skcpoon uchar_t ppoll; /* poll value */ 2937c478bd9Sstevel@tonic-gate int precision:8; 2947c478bd9Sstevel@tonic-gate struct s_fixedpt distance; 2957c478bd9Sstevel@tonic-gate struct s_fixedpt dispersion; 296*2e3b6467Skcpoon ulong_t refid; 2977c478bd9Sstevel@tonic-gate struct l_fixedpt reftime; 2987c478bd9Sstevel@tonic-gate struct l_fixedpt org; 2997c478bd9Sstevel@tonic-gate struct l_fixedpt rec; 3007c478bd9Sstevel@tonic-gate struct l_fixedpt xmt; 3017c478bd9Sstevel@tonic-gate uint32_t keyid; 302*2e3b6467Skcpoon uchar_t mac[MAC_OCTETS_MAX]; 3037c478bd9Sstevel@tonic-gate }; 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate #define LEN_PKT_NOMAC (sizeof (struct ntpdata) - AUTH_OCTETS_V3) 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate /* 3087c478bd9Sstevel@tonic-gate * Leap Second Codes (high order two bits) 3097c478bd9Sstevel@tonic-gate */ 3107c478bd9Sstevel@tonic-gate #define NO_WARNING 0x00 /* no warning */ 3117c478bd9Sstevel@tonic-gate #define PLUS_SEC 0x40 /* add a second (61 seconds) */ 3127c478bd9Sstevel@tonic-gate #define MINUS_SEC 0x80 /* minus a second (59 seconds) */ 3137c478bd9Sstevel@tonic-gate #define ALARM 0xc0 /* alarm condition (clock unsynchronized) */ 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate /* 3167c478bd9Sstevel@tonic-gate * Clock Status Bits that Encode Version 3177c478bd9Sstevel@tonic-gate */ 3187c478bd9Sstevel@tonic-gate #define NTPVERSION_1 0x08 3197c478bd9Sstevel@tonic-gate #define VERSIONMASK 0x38 3207c478bd9Sstevel@tonic-gate #define LEAPMASK 0xc0 3217c478bd9Sstevel@tonic-gate #define NTPMODEMASK 0x07 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate /* 3247c478bd9Sstevel@tonic-gate * Code values 3257c478bd9Sstevel@tonic-gate */ 3267c478bd9Sstevel@tonic-gate #define MODE_UNSPEC 0 /* unspecified */ 3277c478bd9Sstevel@tonic-gate #define MODE_SYM_ACT 1 /* symmetric active */ 3287c478bd9Sstevel@tonic-gate #define MODE_SYM_PAS 2 /* symmetric passive */ 3297c478bd9Sstevel@tonic-gate #define MODE_CLIENT 3 /* client */ 3307c478bd9Sstevel@tonic-gate #define MODE_SERVER 4 /* server */ 3317c478bd9Sstevel@tonic-gate #define MODE_BROADCAST 5 /* broadcast */ 3327c478bd9Sstevel@tonic-gate #define MODE_CONTROL 6 /* control */ 3337c478bd9Sstevel@tonic-gate #define MODE_PRIVATE 7 /* private */ 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate /* 3367c478bd9Sstevel@tonic-gate * Stratum Definitions 3377c478bd9Sstevel@tonic-gate */ 3387c478bd9Sstevel@tonic-gate #define UNSPECIFIED 0 3397c478bd9Sstevel@tonic-gate #define PRIM_REF 1 /* radio clock */ 3407c478bd9Sstevel@tonic-gate #define INFO_QUERY 62 /* **** THIS implementation dependent **** */ 3417c478bd9Sstevel@tonic-gate #define INFO_REPLY 63 /* **** THIS implementation dependent **** */ 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate /* ================= table 3.2 Peer Variables ================= */ 3457c478bd9Sstevel@tonic-gate struct ntp_peer { 3467c478bd9Sstevel@tonic-gate struct ntp_peer *next, *prev; 3477c478bd9Sstevel@tonic-gate struct sockaddr_in src; /* both peer.srcadr and peer.srcport */ 3487c478bd9Sstevel@tonic-gate int flags; /* local flags */ 3497c478bd9Sstevel@tonic-gate #define PEER_FL_CONFIG 1 3507c478bd9Sstevel@tonic-gate #define PEER_FL_AUTHENABLE 2 3517c478bd9Sstevel@tonic-gate #define PEER_FL_SYNC 0x1000 /* peer can bet sync'd to */ 3527c478bd9Sstevel@tonic-gate #define PEER_FL_BCAST 0x2000 /* broadcast peer */ 3537c478bd9Sstevel@tonic-gate #define PEER_FL_SELECTED 0x8000 /* actually used by query routine */ 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate int sock; /* index into sockets to derive */ 3567c478bd9Sstevel@tonic-gate /* peer.dstadr and peer.dstport */ 357*2e3b6467Skcpoon uchar_t leap; /* receive */ 358*2e3b6467Skcpoon uchar_t hmode; /* receive */ 359*2e3b6467Skcpoon uchar_t stratum; /* receive */ 360*2e3b6467Skcpoon uchar_t ppoll; /* receive */ 361*2e3b6467Skcpoon uchar_t hpoll; /* poll update */ 3627c478bd9Sstevel@tonic-gate short precision; /* receive */ 3637c478bd9Sstevel@tonic-gate struct s_fixedpt distance; /* receive */ 3647c478bd9Sstevel@tonic-gate struct s_fixedpt dispersion; /* receive */ 365*2e3b6467Skcpoon ulong_t refid; /* receive */ 3667c478bd9Sstevel@tonic-gate struct l_fixedpt reftime; /* receive */ 3677c478bd9Sstevel@tonic-gate struct l_fixedpt org; /* receive, clear */ 3687c478bd9Sstevel@tonic-gate struct l_fixedpt rec; /* receive, clear */ 3697c478bd9Sstevel@tonic-gate struct l_fixedpt xmt; /* transmit, clear */ 370*2e3b6467Skcpoon ulong_t reach; /* receive, transmit, clear */ 371*2e3b6467Skcpoon ulong_t valid; /* packet, transmit, clear */ 372*2e3b6467Skcpoon ulong_t timer; /* receive, transmit, poll update */ 3737c478bd9Sstevel@tonic-gate long stopwatch; /* <<local>> for timing */ 3747c478bd9Sstevel@tonic-gate /* 3757c478bd9Sstevel@tonic-gate * first order offsets 3767c478bd9Sstevel@tonic-gate */ 3777c478bd9Sstevel@tonic-gate struct filter { 3787c478bd9Sstevel@tonic-gate short samples; /* <<local>> */ 3797c478bd9Sstevel@tonic-gate double offset[PEER_SHIFT]; 3807c478bd9Sstevel@tonic-gate double delay[PEER_SHIFT]; 3817c478bd9Sstevel@tonic-gate } filter; /* filter, clear */ 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate double estdelay; /* filter */ 3847c478bd9Sstevel@tonic-gate double estoffset; /* filter */ 3857c478bd9Sstevel@tonic-gate double estdisp; /* filter */ 3867c478bd9Sstevel@tonic-gate 387*2e3b6467Skcpoon ulong_t pkt_sent; /* <<local>> */ 388*2e3b6467Skcpoon ulong_t pkt_rcvd; /* <<local>> */ 389*2e3b6467Skcpoon ulong_t pkt_dropped; /* <<local>> */ 3907c478bd9Sstevel@tonic-gate }; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate /* ================= table 3.1: System Variables ================= */ 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate struct sysdata { /* procedure */ 395*2e3b6467Skcpoon uchar_t leap; /* clock update */ 396*2e3b6467Skcpoon uchar_t stratum; /* clock update */ 3977c478bd9Sstevel@tonic-gate short precision; /* system */ 3987c478bd9Sstevel@tonic-gate struct s_fixedpt distance; /* clock update */ 3997c478bd9Sstevel@tonic-gate struct s_fixedpt dispersion; /* clock update */ 400*2e3b6467Skcpoon ulong_t refid; /* clock update */ 4017c478bd9Sstevel@tonic-gate struct l_fixedpt reftime; /* clock update */ 4027c478bd9Sstevel@tonic-gate int hold; /* clock update */ 4037c478bd9Sstevel@tonic-gate struct ntp_peer *peer; /* selection */ 4047c478bd9Sstevel@tonic-gate int maxpeers; /* <<local>> */ 405*2e3b6467Skcpoon uchar_t filler; /* put here for %&*%$$ SUNs */ 4067c478bd9Sstevel@tonic-gate }; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate #define NTPDC_VERSION 2 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate /* 4117c478bd9Sstevel@tonic-gate * These structures are used to pass information to the ntpdc (control) 4127c478bd9Sstevel@tonic-gate * program. They are unique to this implementation and not part of the 4137c478bd9Sstevel@tonic-gate * NTP specification. 4147c478bd9Sstevel@tonic-gate */ 4157c478bd9Sstevel@tonic-gate struct clockinfo { 416*2e3b6467Skcpoon ulong_t net_address; 417*2e3b6467Skcpoon ulong_t my_address; 418*2e3b6467Skcpoon ushort_t port; 419*2e3b6467Skcpoon ushort_t flags; 420*2e3b6467Skcpoon ulong_t pkt_sent; 421*2e3b6467Skcpoon ulong_t pkt_rcvd; 422*2e3b6467Skcpoon ulong_t pkt_dropped; 423*2e3b6467Skcpoon ulong_t timer; 424*2e3b6467Skcpoon uchar_t leap; 425*2e3b6467Skcpoon uchar_t stratum; 426*2e3b6467Skcpoon uchar_t ppoll; 4277c478bd9Sstevel@tonic-gate int precision:8; 4287c478bd9Sstevel@tonic-gate 429*2e3b6467Skcpoon uchar_t hpoll; 430*2e3b6467Skcpoon uchar_t filler1; 431*2e3b6467Skcpoon ushort_t reach; 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate long estdisp; /* scaled by 1000 */ 4347c478bd9Sstevel@tonic-gate long estdelay; /* in milliseconds */ 4357c478bd9Sstevel@tonic-gate long estoffset; /* in milliseconds */ 436*2e3b6467Skcpoon ulong_t refid; 4377c478bd9Sstevel@tonic-gate struct l_fixedpt reftime; 4387c478bd9Sstevel@tonic-gate struct info_filter { 4397c478bd9Sstevel@tonic-gate short index; 4407c478bd9Sstevel@tonic-gate short filler; 4417c478bd9Sstevel@tonic-gate long offset[PEER_SHIFT]; /* in milliseconds */ 4427c478bd9Sstevel@tonic-gate long delay[PEER_SHIFT]; /* in milliseconds */ 4437c478bd9Sstevel@tonic-gate } info_filter; 4447c478bd9Sstevel@tonic-gate }; 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate struct ntpinfo { 447*2e3b6467Skcpoon uchar_t version; 448*2e3b6467Skcpoon uchar_t type; /* request type (stratum in ntp packets) */ 449*2e3b6467Skcpoon uchar_t count; /* number of entries in this packet */ 450*2e3b6467Skcpoon uchar_t seq; /* sequence number of this packet */ 4517c478bd9Sstevel@tonic-gate 452*2e3b6467Skcpoon uchar_t npkts; /* total number of packets */ 453*2e3b6467Skcpoon uchar_t peers; 454*2e3b6467Skcpoon uchar_t fill3; 455*2e3b6467Skcpoon uchar_t fill4; 4567c478bd9Sstevel@tonic-gate }; 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate /* 4597c478bd9Sstevel@tonic-gate * From usr/src/cmd/xntpd/include/ntp_control.h: 4607c478bd9Sstevel@tonic-gate * Definition of a mode 6 packet. 4617c478bd9Sstevel@tonic-gate */ 4627c478bd9Sstevel@tonic-gate struct ntp_control { 463*2e3b6467Skcpoon uchar_t li_vn_mode; /* leap, version, mode */ 464*2e3b6467Skcpoon uchar_t r_m_e_op; /* response, more, error, opcode */ 465*2e3b6467Skcpoon ushort_t sequence; /* sequence number of request */ 466*2e3b6467Skcpoon ushort_t status; /* status word for association */ 467*2e3b6467Skcpoon ushort_t associd; /* association ID */ 468*2e3b6467Skcpoon ushort_t offset; /* offset of this batch of data */ 469*2e3b6467Skcpoon ushort_t count; /* count of data in this packet */ 470*2e3b6467Skcpoon uchar_t data[1]; /* data + auth */ 4717c478bd9Sstevel@tonic-gate }; 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate #define NTPC_DATA_MAXLEN (480 + AUTH_OCTETS_V3) 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate /* 4767c478bd9Sstevel@tonic-gate * Decoding for the r_m_e_op field 4777c478bd9Sstevel@tonic-gate */ 4787c478bd9Sstevel@tonic-gate #define CTL_RESPONSE 0x80 4797c478bd9Sstevel@tonic-gate #define CTL_ERROR 0x40 4807c478bd9Sstevel@tonic-gate #define CTL_MORE 0x20 4817c478bd9Sstevel@tonic-gate #define CTL_OP_MASK 0x1f 4827c478bd9Sstevel@tonic-gate 4837c478bd9Sstevel@tonic-gate /* 4847c478bd9Sstevel@tonic-gate * Opcodes 4857c478bd9Sstevel@tonic-gate */ 4867c478bd9Sstevel@tonic-gate #define CTL_OP_UNSPEC 0 4877c478bd9Sstevel@tonic-gate #define CTL_OP_READSTAT 1 4887c478bd9Sstevel@tonic-gate #define CTL_OP_READVAR 2 4897c478bd9Sstevel@tonic-gate #define CTL_OP_WRITEVAR 3 4907c478bd9Sstevel@tonic-gate #define CTL_OP_READCLOCK 4 4917c478bd9Sstevel@tonic-gate #define CTL_OP_WRITECLOCK 5 4927c478bd9Sstevel@tonic-gate #define CTL_OP_SETTRAP 6 4937c478bd9Sstevel@tonic-gate #define CTL_OP_ASYNCMSG 7 4947c478bd9Sstevel@tonic-gate #define CTL_OP_UNSETTRAP 31 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate /* 4977c478bd9Sstevel@tonic-gate * From usr/src/cmd/xntpd/include/ntp_request.h: 4987c478bd9Sstevel@tonic-gate * A mode 7 packet is used exchanging data between an NTP server 4997c478bd9Sstevel@tonic-gate * and a client for purposes other than time synchronization, e.g. 5007c478bd9Sstevel@tonic-gate * monitoring, statistics gathering and configuration. A mode 7 5017c478bd9Sstevel@tonic-gate * packet has the following format: 5027c478bd9Sstevel@tonic-gate */ 5037c478bd9Sstevel@tonic-gate 5047c478bd9Sstevel@tonic-gate struct ntp_private { 505*2e3b6467Skcpoon uchar_t rm_vn_mode; /* response, more, version, mode */ 506*2e3b6467Skcpoon uchar_t auth_seq; /* key, sequence number */ 507*2e3b6467Skcpoon uchar_t implementation; /* implementation number */ 508*2e3b6467Skcpoon uchar_t request; /* request number */ 509*2e3b6467Skcpoon ushort_t err_nitems; /* error code/number of data items */ 510*2e3b6467Skcpoon ushort_t mbz_itemsize; /* item size */ 5117c478bd9Sstevel@tonic-gate char data[1]; /* data area */ 5127c478bd9Sstevel@tonic-gate }; 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate #define RESP_BIT 0x80 5157c478bd9Sstevel@tonic-gate #define MORE_BIT 0x40 516*2e3b6467Skcpoon #define INFO_VERSION(rm_vn_mode) ((uchar_t)(((rm_vn_mode)>>3) & 0x7)) 5177c478bd9Sstevel@tonic-gate #define INFO_MODE(rm_vn_mode) ((rm_vn_mode) & 0x7) 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate #define AUTH_BIT 0x80 5207c478bd9Sstevel@tonic-gate #define INFO_SEQ(auth_seq) ((auth_seq) & 0x7f) 5217c478bd9Sstevel@tonic-gate 522*2e3b6467Skcpoon #define INFO_ERR(err_nitems) ((ushort_t)((ntohs(err_nitems) >> 12) & 0xf)) 523*2e3b6467Skcpoon #define INFO_NITEMS(err_nitems) ((ushort_t)(ntohs(err_nitems) & 0xfff)) 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate #define INFO_ITEMSIZE(mbz_itemsize) (ntohs(mbz_itemsize) & 0xfff) 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate #ifdef __cplusplus 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate #endif 5307c478bd9Sstevel@tonic-gate 5317c478bd9Sstevel@tonic-gate #endif /* _NTP_H */ 532