]>
git.saurik.com Git - apple/network_cmds.git/blob - timed.tproj/timed.tproj/globals.h
b3452fcd8e8b6fbd848661ad0061d72ed07d0199
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1985, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * @(#)globals.h 8.1 (Berkeley) 6/6/93
60 #ident "$Revision: 1.1 $"
63 #include <sys/param.h>
65 #include <sys/socket.h>
67 #include <netinet/in.h>
68 #include <arpa/inet.h>
80 #include <protocols/timed.h>
83 #include <sys/clock.h>
84 /* use the constant HZ instead of the function CLK_TCK */
89 #define SECDAY (24*SECHR)
95 /* Best expected round trip for a measurement.
96 * This is essentially the number of milliseconds per CPU tick (CLK_TCK?).
97 * All delays shorter than this are usually reported as 0.
99 #define MIN_ROUND ((1000-1)/CLK_TCK)
102 #define SAMPLEINTVL 240 /* synch() freq for master in sec */
103 #define MAXADJ 20 /* max adjtime() correction in sec */
105 #define MAX_TRIM 3000000 /* max drift in nsec/sec, 0.3% */
106 #define BIG_ADJ (MAX_TRIM/1000*SAMPLEINTVL*2) /* max good adj */
108 #define MINTOUT 360 /* election delays, 6-15 minutes */
111 #define BAD_STATUS (-1)
113 #define UNREACHABLE 2
115 #define HOSTDOWN 0x7fffffff
120 #define MAX_HOPCNT 10 /* max value for tsp_hpcnt */
122 #define LOSTHOST 3 /* forget after this many failures */
124 #define VALID_RANGE (MAXADJ*1000) /* good times in milliseconds */
125 #define GOOD_RANGE (MIN_ROUND*2)
126 #define VGOOD_RANGE (MIN_ROUND-1)
130 * Global and per-network states.
132 #define NOMASTER 0 /* no good master */
136 #define ALL (SLAVE|MASTER|IGNORE)
137 #define SUBMASTER (SLAVE|MASTER)
139 #define NHOSTS 1013 /* max of hosts controlled by timed
140 * This must be a prime number.
143 struct hosttbl
*h_bak
; /* hash chain */
144 struct hosttbl
*h_fwd
;
145 struct hosttbl
*l_bak
; /* "sequential" list */
146 struct hosttbl
*l_fwd
;
148 struct sockaddr_in addr
;
149 char name
[MAXHOSTNAMELEN
+1];
150 u_char head
; /* 1=head of hash chain */
151 u_char good
; /* 0=trusted host, for averaging */
152 u_char noanswer
; /* count of failures to answer */
153 u_char need_set
; /* need a SETTIME */
158 /* closed hash table with internal chaining */
159 extern struct hosttbl hosttbl
[NHOSTS
+1];
160 #define self hosttbl[0]
161 #define hostname (self.name)
165 struct netinfo
*next
;
168 struct in_addr my_addr
;
169 struct sockaddr_in dest_addr
; /* broadcast addr or point-point */
171 struct timeval slvwait
; /* delay before sending our time */
172 int quit_count
; /* recent QUITs */
177 #define tvtomsround(tv) ((tv).tv_sec*1000 + ((tv).tv_usec + 500)/1000)
179 extern struct netinfo
*nettab
;
183 extern struct sockaddr_in from
;
184 extern struct timeval from_when
; /* when the last msg arrived */
185 extern u_short sequence
; /* TSP message sequence number */
186 extern struct netinfo
*fromnet
, *slavenet
;
188 extern long delay1
, delay2
;
189 extern int nslavenets
; /* nets were I could be a slave */
190 extern int nmasternets
; /* nets were I could be a master */
191 extern int nignorednets
; /* ignored nets */
192 extern int nnets
; /* nets I am connected to */
195 #define trace_msg(msg) {if (trace) fprintf(fd, msg);}
197 #define trace_sendto_err(addr) { \
198 int st_errno = errno; \
199 syslog(LOG_ERR, "%s %d: sendto %s: %m", \
200 __FILE__, __LINE__, inet_ntoa(addr)); \
202 fprintf(fd, "%s %d: sendto %s: %d", __FILE__, __LINE__, \
203 inet_ntoa(addr), st_errno); \
207 # define max(a,b) (a<b ? b : a)
208 # define min(a,b) (a>b ? b : a)
209 # define abs(x) (x>=0 ? x : -(x))