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