2 * Copyright (c) 1985, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)globals.h 8.1 (Berkeley) 6/6/93
34 * $FreeBSD: src/usr.sbin/timed/timed/globals.h,v 1.5 2000/03/03 13:01:56 shin Exp $
37 #include <sys/param.h>
39 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <arpa/inet.h>
55 #include <protocols/timed.h>
58 #include <sys/clock.h>
59 /* use the constant HZ instead of the function CLK_TCK */
64 #define SECDAY (24*SECHR)
69 /* Best expected round trip for a measurement.
70 * This is essentially the number of milliseconds per CPU tick (CLK_TCK?).
71 * All delays shorter than this are usually reported as 0.
73 #define MIN_ROUND ((1000-1)/CLK_TCK)
76 #define SAMPLEINTVL 240 /* synch() freq for master in sec */
77 #define MAXADJ 20 /* max adjtime() correction in sec */
79 #define MAX_TRIM 3000000 /* max drift in nsec/sec, 0.3% */
80 #define BIG_ADJ (MAX_TRIM/1000*SAMPLEINTVL*2) /* max good adj */
82 #define MINTOUT 360 /* election delays, 6-15 minutes */
85 #define BAD_STATUS (-1)
89 #define HOSTDOWN 0x7fffffff
94 #define MAX_HOPCNT 10 /* max value for tsp_hpcnt */
96 #define LOSTHOST 3 /* forget after this many failures */
98 #define VALID_RANGE (MAXADJ*1000) /* good times in milliseconds */
99 #define GOOD_RANGE (MIN_ROUND*2)
100 #define VGOOD_RANGE (MIN_ROUND-1)
104 * Global and per-network states.
106 #define NOMASTER 0 /* no good master */
110 #define ALL (SLAVE|MASTER|IGNORE)
111 #define SUBMASTER (SLAVE|MASTER)
113 #define NHOSTS 1013 /* max of hosts controlled by timed
114 * This must be a prime number.
117 struct hosttbl *h_bak; /* hash chain */
118 struct hosttbl *h_fwd;
119 struct hosttbl *l_bak; /* "sequential" list */
120 struct hosttbl *l_fwd;
122 struct sockaddr_in addr;
123 char name[MAXHOSTNAMELEN];
124 u_char head; /* 1=head of hash chain */
125 u_char good; /* 0=trusted host, for averaging */
126 u_char noanswer; /* count of failures to answer */
127 u_char need_set; /* need a SETTIME */
132 /* closed hash table with internal chaining */
133 extern struct hosttbl hosttbl[NHOSTS+1];
134 #define self hosttbl[0]
135 #define hostname (self.name)
139 struct netinfo *next;
142 struct in_addr my_addr;
143 struct sockaddr_in dest_addr; /* broadcast addr or point-point */
145 struct timeval slvwait; /* delay before sending our time */
146 int quit_count; /* recent QUITs */
151 #define tvtomsround(tv) ((tv).tv_sec*1000 + ((tv).tv_usec + 500)/1000)
153 extern struct netinfo *nettab;
157 extern struct sockaddr_in from;
158 extern struct timeval from_when; /* when the last msg arrived */
159 extern u_short sequence; /* TSP message sequence number */
160 extern struct netinfo *fromnet, *slavenet;
162 extern long delay1, delay2;
163 extern int nslavenets; /* nets were I could be a slave */
164 extern int nmasternets; /* nets were I could be a master */
165 extern int nignorednets; /* ignored nets */
166 extern int nnets; /* nets I am connected to */
169 #define trace_msg(msg) {if (trace) fprintf(fd, msg);}
171 #define trace_sendto_err(addr) { \
172 int st_errno = errno; \
173 syslog(LOG_ERR, "%s %d: sendto %s: %m", \
174 __FILE__, __LINE__, inet_ntoa(addr)); \
176 fprintf(fd, "%s %d: sendto %s: %d", __FILE__, __LINE__, \
177 inet_ntoa(addr), st_errno); \
181 # define max(a,b) (a<b ? b : a)
182 # define min(a,b) (a>b ? b : a)
183 # define abs(x) (x>=0 ? x : -(x))