xref: /freebsd/contrib/ntp/include/ntpd.h (revision 17d6c636720d00f77e5d098daf4c278f89d84f7b)
1 /*
2  * ntpd.h - Prototypes for ntpd.
3  */
4 
5 #include "ntp_syslog.h"
6 #include "ntp_fp.h"
7 #include "ntp.h"
8 #include "ntp_select.h"
9 #include "ntp_malloc.h"
10 #include "ntp_refclock.h"
11 #include "recvbuff.h"
12 
13 #define MAXINTERFACES	512
14 #define MAXFILENAME	128	/* maximum length of a file name */
15 
16 #ifdef SYS_WINNT
17 #define exit service_exit
18 extern	void	service_exit	(int);
19 /*	declare the service threads */
20 void	service_main	(DWORD, LPTSTR *);
21 void	service_ctrl	(DWORD);
22 void	worker_thread	(void *);
23 #define sleep(x) Sleep((DWORD) x * 1000 /* milliseconds */ );
24 #else
25 #define closesocket close
26 #endif /* SYS_WINNT */
27 
28 /* ntp_config.c */
29 extern	void	getconfig	P((int, char **));
30 
31 /* ntp_config.c */
32 extern	void	ctl_clr_stats	P((void));
33 extern	int	ctlclrtrap	P((struct sockaddr_in *, struct interface *, int));
34 extern	u_short ctlpeerstatus	P((struct peer *));
35 extern	int	ctlsettrap	P((struct sockaddr_in *, struct interface *, int, int));
36 extern	u_short ctlsysstatus	P((void));
37 extern	void	init_control	P((void));
38 extern	void	process_control P((struct recvbuf *, int));
39 extern	void	report_event	P((int, struct peer *));
40 
41 extern	double	fabs		P((double));
42 extern	double	sqrt		P((double));
43 
44 /* ntp_control.c */
45 /*
46  * Structure for translation tables between internal system
47  * variable indices and text format.
48  */
49 struct ctl_var {
50 	u_short code;
51 	u_short flags;
52 	char *text;
53 };
54 /*
55  * Flag values
56  */
57 #define	CAN_READ	0x01
58 #define	CAN_WRITE	0x02
59 
60 #define DEF		0x20
61 #define	PADDING		0x40
62 #define	EOV		0x80
63 
64 #define	RO	(CAN_READ)
65 #define	WO	(CAN_WRITE)
66 #define	RW	(CAN_READ|CAN_WRITE)
67 
68 extern  char *  add_var P((struct ctl_var **, unsigned long, int));
69 extern  void    free_varlist P((struct ctl_var *));
70 extern  void    set_var P((struct ctl_var **, const char *, unsigned long, int));
71 extern  void    set_sys_var P((char *, unsigned long, int));
72 
73 /* ntp_intres.c */
74 extern	void	ntp_res_name	P((u_int32, u_short));
75 extern	void	ntp_res_recv	P((void));
76 extern	void	ntp_intres	P((void));
77 
78 /* ntp_io.c */
79 extern	struct interface *findinterface P((struct sockaddr_in *));
80 extern  struct interface *findbcastinter P((struct sockaddr_in *));
81 
82 extern	void	init_io 	P((void));
83 extern	void	input_handler	P((l_fp *));
84 extern	void	io_clr_stats	P((void));
85 extern	void	io_setbclient	P((void));
86 extern	void	io_unsetbclient P((void));
87 extern	void	io_multicast_add P((u_int32));
88 extern	void	io_multicast_del P((u_int32));
89 extern	void	kill_asyncio	 P((void));
90 
91 extern	void	sendpkt 	P((struct sockaddr_in *, struct interface *, int, struct pkt *, int));
92 #ifdef HAVE_SIGNALED_IO
93 extern	void	wait_for_signal P((void));
94 extern	void	unblock_io_and_alarm P((void));
95 extern	void	block_io_and_alarm P((void));
96 #endif
97 
98 /* ntp_leap.c */
99 extern	void	init_leap	P((void));
100 extern	void	leap_process	P((void));
101 extern	int 	leap_setleap	P((int, int));
102 /*
103  * there seems to be a bug in the IRIX 4 compiler which prevents
104  * u_char from beeing used in prototyped functions.
105  * This is also true AIX compiler.
106  * So give up and define it to be int. WLJ
107  */
108 extern	int	leap_actual P((int));
109 
110 /* ntp_loopfilter.c */
111 extern	void	init_loopfilter P((void));
112 extern	int 	local_clock P((struct peer *, double, double));
113 extern	void	adj_host_clock	P((void));
114 extern	void	loop_config P((int, double));
115 extern	void	huffpuff	P((void));
116 
117 /* ntp_monitor.c */
118 extern	void	init_mon	P((void));
119 extern	void	mon_start	P((int));
120 extern	void	mon_stop	P((int));
121 extern	void	ntp_monitor P((struct recvbuf *));
122 
123 /* ntp_peer.c */
124 extern	void	init_peer	P((void));
125 extern	struct peer *findexistingpeer P((struct sockaddr_in *, struct peer *, int));
126 extern	struct peer *findpeer	P((struct sockaddr_in *, struct interface *, int, int, int *));
127 extern	struct peer *findpeerbyassoc P((u_int));
128 extern	struct peer *newpeer	P((struct sockaddr_in *, struct interface *, int, int, int, int, u_int, u_int, int, keyid_t));
129 extern	void	peer_all_reset	P((void));
130 extern	void	peer_clr_stats	P((void));
131 extern	struct peer *peer_config P((struct sockaddr_in *, struct interface *, int, int, int, int, u_int, int, keyid_t, u_char *));
132 extern	void	peer_reset	P((struct peer *));
133 extern	int 	peer_unconfig	P((struct sockaddr_in *, struct interface *, int));
134 extern	void	unpeer		P((struct peer *));
135 extern	void	clear_all	P((void));
136 #ifdef AUTOKEY
137 extern	void	expire_all	P((void));
138 #endif /* AUTOKEY */
139 extern	struct	peer *findmanycastpeer	P((struct recvbuf *));
140 extern	void	resetmanycast	P((void));
141 
142 /* ntp_proto.c */
143 extern	void	transmit	P((struct peer *));
144 extern	void	receive 	P((struct recvbuf *));
145 extern	void	peer_clear	P((struct peer *));
146 extern	void 	process_packet	P((struct peer *, struct pkt *, l_fp *));
147 extern	void	clock_select	P((void));
148 
149 /*
150  * there seems to be a bug in the IRIX 4 compiler which prevents
151  * u_char from beeing used in prototyped functions.
152  * This is also true AIX compiler.
153  * So give up and define it to be int. WLJ
154  */
155 extern	void	poll_update P((struct peer *, int));
156 
157 extern	void	clear		P((struct peer *));
158 extern	void	clock_filter	P((struct peer *, double, double, double));
159 extern	void	init_proto	P((void));
160 extern	void	proto_config	P((int, u_long, double));
161 extern	void	proto_clr_stats P((void));
162 
163 #ifdef	REFCLOCK
164 /* ntp_refclock.c */
165 extern	int	refclock_newpeer P((struct peer *));
166 extern	void	refclock_unpeer P((struct peer *));
167 extern	void	refclock_receive P((struct peer *));
168 extern	void	refclock_transmit P((struct peer *));
169 extern	void	init_refclock	P((void));
170 #endif	/* REFCLOCK */
171 
172 /* ntp_request.c */
173 extern	void	init_request	P((void));
174 extern	void	process_private P((struct recvbuf *, int));
175 
176 /* ntp_restrict.c */
177 extern	void	init_restrict	P((void));
178 extern	int 	restrictions	P((struct sockaddr_in *));
179 extern	void	hack_restrict	P((int, struct sockaddr_in *, struct sockaddr_in *, int, int));
180 
181 /* ntp_timer.c */
182 extern	void	init_timer	P((void));
183 extern	void	timer		P((void));
184 extern	void	timer_clr_stats P((void));
185 #ifdef AUTOKEY
186 extern	char	*sys_hostname;
187 extern	l_fp	sys_revoketime;
188 #endif /* AUTOKEY */
189 
190 /* ntp_util.c */
191 extern	void	init_util	P((void));
192 extern	void	hourly_stats	P((void));
193 extern	void	stats_config	P((int, char *));
194 extern	void	record_peer_stats P((struct sockaddr_in *, int, double, double, double, double));
195 extern	void	record_loop_stats P((double, double, double, double, int));
196 extern	void	record_clock_stats P((struct sockaddr_in *, const char *));
197 extern	void	record_raw_stats P((struct sockaddr_in *, struct sockaddr_in *, l_fp *, l_fp *, l_fp *, l_fp *));
198 
199 /*
200  * Variable declarations for ntpd.
201  */
202 
203 /* ntp_config.c */
204 extern char const *	progname;
205 extern char	sys_phone[][MAXDIAL];	/* ACTS phone numbers */
206 extern char	pps_device[];		/* PPS device name */
207 #if defined(HAVE_SCHED_SETSCHEDULER)
208 extern int	config_priority_override;
209 extern int	config_priority;
210 #endif
211 
212 /* ntp_control.c */
213 struct ctl_trap;
214 extern struct ctl_trap ctl_trap[];
215 extern int	num_ctl_traps;
216 extern keyid_t	ctl_auth_keyid;		/* keyid used for authenticating write requests */
217 
218 /*
219  * Statistic counters to keep track of requests and responses.
220  */
221 extern u_long	ctltimereset;		/* time stats reset */
222 extern u_long	numctlreq;		/* number of requests we've received */
223 extern u_long	numctlbadpkts;		/* number of bad control packets */
224 extern u_long	numctlresponses; 	/* number of resp packets sent with data */
225 extern u_long	numctlfrags; 		/* number of fragments sent */
226 extern u_long	numctlerrors;		/* number of error responses sent */
227 extern u_long	numctltooshort;		/* number of too short input packets */
228 extern u_long	numctlinputresp; 	/* number of responses on input */
229 extern u_long	numctlinputfrag; 	/* number of fragments on input */
230 extern u_long	numctlinputerr;		/* number of input pkts with err bit set */
231 extern u_long	numctlbadoffset; 	/* number of input pkts with nonzero offset */
232 extern u_long	numctlbadversion;	/* number of input pkts with unknown version */
233 extern u_long	numctldatatooshort;	/* data too short for count */
234 extern u_long	numctlbadop; 		/* bad op code found in packet */
235 extern u_long	numasyncmsgs;		/* number of async messages we've sent */
236 
237 /* ntp_intres.c */
238 extern keyid_t	req_keyid;		/* request keyid */
239 extern char *	req_file;		/* name of the file with configuration info */
240 
241 /*
242  * Other statistics of possible interest
243  */
244 extern volatile u_long packets_dropped;	/* total number of packets dropped on reception */
245 extern volatile u_long packets_ignored;	/* packets received on wild card interface */
246 extern volatile u_long packets_received;/* total number of packets received */
247 extern u_long	packets_sent;		/* total number of packets sent */
248 extern u_long	packets_notsent; 	/* total number of packets which couldn't be sent */
249 
250 extern volatile u_long handler_calls;	/* number of calls to interrupt handler */
251 extern volatile u_long handler_pkts;	/* number of pkts received by handler */
252 extern u_long	io_timereset;		/* time counters were reset */
253 
254 /*
255  * Interface stuff
256  */
257 extern struct interface *any_interface;	/* default interface */
258 extern struct interface *loopback_interface; /* loopback interface */
259 
260 /*
261  * File descriptor masks etc. for call to select
262  */
263 extern fd_set	activefds;
264 extern int	maxactivefd;
265 
266 /* ntp_loopfilter.c */
267 extern double	drift_comp;		/* clock frequency (s/s) */
268 extern double	clock_stability;	/* clock stability (s/s) */
269 extern double	clock_max;		/* max offset before step (s) */
270 extern double	clock_panic;		/* max offset before panic (s) */
271 extern double	clock_phi;		/* dispersion rate (s/s) */
272 extern double	clock_minstep;		/* step timeout (s) */
273 extern u_long	pps_control;		/* last pps sample time */
274 #ifdef KERNEL_PLL
275 extern int	pll_status;		/* status bits for kernel pll */
276 #endif /* KERNEL_PLL */
277 
278 /*
279  * Clock state machine control flags
280  */
281 extern int	ntp_enable;		/* clock discipline enabled */
282 extern int	pll_control;		/* kernel support available */
283 extern int	kern_enable;		/* kernel support enabled */
284 extern int	pps_enable;		/* kernel PPS discipline enabled */
285 extern int	ext_enable;		/* external clock enabled */
286 extern int	cal_enable;		/* refclock calibrate enable */
287 extern int	allow_step;		/* allow step correction */
288 extern int	allow_panic;		/* allow panic correction */
289 extern int	mode_ntpdate;		/* exit on first clock set */
290 extern int	peer_ntpdate;		/* count of ntpdate peers */
291 
292 /*
293  * Clock state machine variables
294  */
295 extern u_char	sys_poll;		/* system poll interval (log2 s) */
296 extern u_char	sys_minpoll;		/* min system poll interval (log2 s) */
297 extern int	state;			/* clock discipline state */
298 extern int	tc_counter;		/* poll-adjust counter */
299 extern u_long	last_time;		/* time of last clock update (s) */
300 extern double	last_offset;		/* last clock offset (s) */
301 extern double	allan_xpt;		/* Allan intercept (s) */
302 extern double	sys_error;		/* system RMS error (s) */
303 extern double	sys_jitter;		/* system RMS jitter (s) */
304 
305 /* ntp_monitor.c */
306 extern struct mon_data mon_mru_list;
307 extern struct mon_data mon_fifo_list;
308 extern int	mon_enabled;
309 
310 /* ntp_peer.c */
311 extern struct peer *peer_hash[];	/* peer hash table */
312 extern int	peer_hash_count[];	/* count of peers in each bucket */
313 extern struct peer *assoc_hash[];	/* association ID hash table */
314 extern int	assoc_hash_count[];
315 extern int	peer_free_count;
316 
317 /*
318  * Miscellaneous statistic counters which may be queried.
319  */
320 extern u_long	peer_timereset;		/* time stat counters were zeroed */
321 extern u_long	findpeer_calls;		/* number of calls to findpeer */
322 extern u_long	assocpeer_calls;	/* number of calls to findpeerbyassoc */
323 extern u_long	peer_allocations;	/* number of allocations from the free list */
324 extern u_long	peer_demobilizations;	/* number of structs freed to free list */
325 extern int	total_peer_structs;	/* number of peer structs in circulation */
326 extern int	peer_associations;	/* number of active associations */
327 
328 /* ntp_proto.c */
329 /*
330  * System variables are declared here.	See Section 3.2 of the
331  * specification.
332  */
333 extern u_char	sys_leap;		/* system leap indicator */
334 extern u_char	sys_stratum;		/* stratum of system */
335 extern s_char	sys_precision;		/* local clock precision */
336 extern double	sys_rootdelay;		/* distance to current sync source */
337 extern double	sys_rootdispersion;	/* dispersion of system clock */
338 extern u_int32	sys_refid;		/* reference source for local clock */
339 extern l_fp	sys_reftime;		/* time we were last updated */
340 extern struct peer *sys_peer;		/* our current peer */
341 extern struct peer *sys_prefer;		/* our cherished peer */
342 extern u_long	sys_automax;		/* maximum session key lifetime */
343 
344 /*
345  * Nonspecified system state variables.
346  */
347 extern int	sys_bclient;		/* we set our time to broadcasts */
348 extern double	sys_bdelay; 		/* broadcast client default delay */
349 extern int	sys_authenticate;	/* requre authentication for config */
350 extern l_fp	sys_authdelay;		/* authentication delay */
351 extern keyid_t	sys_private;		/* private value for session seed */
352 extern int	sys_manycastserver;	/* 1 => respond to manycast client pkts */
353 
354 /*
355  * Statistics counters
356  */
357 extern u_long	sys_stattime;		/* time when we started recording */
358 extern u_long	sys_badstratum; 	/* packets with invalid stratum */
359 extern u_long	sys_oldversionpkt;	/* old version packets received */
360 extern u_long	sys_newversionpkt;	/* new version packets received */
361 extern u_long	sys_unknownversion;	/* don't know version packets */
362 extern u_long	sys_badlength;		/* packets with bad length */
363 extern u_long	sys_processed;		/* packets processed */
364 extern u_long	sys_badauth;		/* packets dropped because of auth */
365 extern u_long	sys_limitrejected;	/* pkts rejected due to client count per net */
366 
367 /* ntp_refclock.c */
368 #ifdef REFCLOCK
369 #if defined(PPS) || defined(HAVE_PPSAPI)
370 extern int	fdpps;			/* pps file descriptor */
371 #endif /* PPS */
372 #endif
373 
374 /* ntp_request.c */
375 extern keyid_t	info_auth_keyid;	/* keyid used to authenticate requests */
376 
377 /* ntp_restrict.c */
378 extern struct restrictlist *restrictlist; /* the restriction list */
379 extern u_long	client_limit;
380 extern u_long	client_limit_period;
381 
382 /* ntp_timer.c */
383 extern volatile int alarm_flag;		/* alarm flag */
384 extern u_long	sys_revoke;		/* keys revoke timeout */
385 extern volatile u_long alarm_overflow;
386 extern u_long	current_time;		/* current time (s) */
387 extern u_long	timer_timereset;
388 extern u_long	timer_overflows;
389 extern u_long	timer_xmtcalls;
390 
391 /* ntp_util.c */
392 extern int	stats_control;		/* write stats to fileset? */
393 
394 /* ntpd.c */
395 extern volatile int debug;		/* debugging flag */
396 extern int	nofork;			/* no-fork flag */
397 extern int 	initializing;		/* initializing flag */
398 
399 /* refclock_conf.c */
400 #ifdef REFCLOCK
401 extern struct refclock *refclock_conf[]; /* refclock configuration table */
402 extern u_char	num_refclock_conf;
403 #endif
404