4 * ntpd.h - Prototypes for ntpd.
7 #include "ntp_syslog.h"
10 #include "ntp_debug.h"
11 #include "ntp_select.h"
12 #include "ntp_malloc.h"
13 #include "ntp_refclock.h"
18 #define TAI_1972 10 /* initial TAI offset (s) */
19 extern char *keysdir
; /* crypto keys and leaptable directory */
20 extern char * saveconfigdir
; /* ntpq saveconfig output directory */
22 extern void getconfig (int, char **);
23 extern void ctl_clr_stats (void);
24 extern int ctlclrtrap (sockaddr_u
*, struct interface
*, int);
25 extern u_short
ctlpeerstatus (struct peer
*);
26 extern int ctlsettrap (sockaddr_u
*, struct interface
*, int, int);
27 extern u_short
ctlsysstatus (void);
28 extern void init_control (void);
29 extern void init_logging (char const *, int);
30 extern void setup_logfile (void);
31 extern void process_control (struct recvbuf
*, int);
32 extern void report_event (int, struct peer
*, const char *);
36 * Structure for translation tables between internal system
37 * variable indices and text format.
48 #define CAN_WRITE 0x02
55 #define WO (CAN_WRITE)
56 #define RW (CAN_READ|CAN_WRITE)
58 extern char * add_var (struct ctl_var
**, u_long
, u_short
);
59 extern void free_varlist (struct ctl_var
*);
60 extern void set_var (struct ctl_var
**, const char *, u_long
, u_short
);
61 extern void set_sys_var (const char *, u_long
, u_short
);
64 extern void ntp_res_name (sockaddr_u
, u_short
);
65 extern void ntp_res_recv (void);
66 extern void ntp_intres (void);
68 extern unsigned WINAPI
ntp_intres_thread (void *);
72 typedef struct interface_info
{
73 struct interface
* interface
;
77 typedef void (*interface_receiver_t
) (void *, interface_info_t
*);
79 extern int disable_dynamic_updates
;
81 extern void interface_enumerate (interface_receiver_t
, void *);
82 extern struct interface
*findinterface (sockaddr_u
*);
83 extern struct interface
*findbcastinter(sockaddr_u
*);
84 extern void enable_broadcast (struct interface
*, sockaddr_u
*);
85 extern void enable_multicast_if (struct interface
*, sockaddr_u
*);
86 extern void interface_update (interface_receiver_t
, void *);
88 extern void init_io (void);
89 extern void io_open_sockets (void);
90 extern void input_handler (l_fp
*);
91 extern void io_clr_stats (void);
92 extern void io_setbclient (void);
93 extern void io_unsetbclient (void);
94 extern void io_multicast_add(sockaddr_u
*);
95 extern void io_multicast_del(sockaddr_u
*);
96 extern void sendpkt (sockaddr_u
*, struct interface
*, int, struct pkt
*, int);
98 extern void kill_asyncio (int);
101 extern void collect_timing (struct recvbuf
*, const char *, int, l_fp
*);
103 #ifdef HAVE_SIGNALED_IO
104 extern void wait_for_signal (void);
105 extern void unblock_io_and_alarm (void);
106 extern void block_io_and_alarm (void);
107 #define UNBLOCK_IO_AND_ALARM() unblock_io_and_alarm()
108 #define BLOCK_IO_AND_ALARM() block_io_and_alarm()
110 #define UNBLOCK_IO_AND_ALARM()
111 #define BLOCK_IO_AND_ALARM()
114 /* ntp_loopfilter.c */
115 extern void init_loopfilter(void);
116 extern int local_clock(struct peer
*, double);
117 extern void adj_host_clock(void);
118 extern void loop_config(int, double);
119 extern void huffpuff(void);
120 extern u_long sys_clocktime
;
121 extern u_int sys_tai
;
124 extern void init_mon (void);
125 extern void mon_start (int);
126 extern void mon_stop (int);
127 extern int ntp_monitor (struct recvbuf
*, int);
128 extern void ntp_monclearinterface (struct interface
*interface
);
131 extern void init_peer (void);
132 extern struct peer
*findexistingpeer (sockaddr_u
*, struct peer
*, int);
133 extern struct peer
*findpeer (sockaddr_u
*, struct interface
*, int, int *);
134 extern struct peer
*findpeerbyassoc (u_int
);
135 extern void set_peerdstadr (struct peer
*peer
, struct interface
*interface
);
136 extern struct peer
*newpeer (sockaddr_u
*, struct interface
*, int, int, int, int, u_int
, u_char
, int, keyid_t
);
137 extern void peer_all_reset (void);
138 extern void peer_clr_stats (void);
139 extern struct peer
*peer_config (sockaddr_u
*, struct interface
*, int, int, int, int, u_int
, int, keyid_t
, u_char
*);
140 extern void peer_reset (struct peer
*);
141 extern void refresh_all_peerinterfaces (void);
142 extern void unpeer (struct peer
*);
143 extern void clear_all (void);
144 extern int score_all (struct peer
*);
145 extern struct peer
*findmanycastpeer (struct recvbuf
*);
149 extern int crypto_recv (struct peer
*, struct recvbuf
*);
150 extern int crypto_xmit (struct peer
*, struct pkt
*,
151 struct recvbuf
*, int,
152 struct exten
*, keyid_t
);
153 extern keyid_t
session_key (sockaddr_u
*, sockaddr_u
*, keyid_t
,
155 extern int make_keylist (struct peer
*, struct interface
*);
156 extern void key_expire (struct peer
*);
157 extern void crypto_update (void);
158 extern void crypto_config (int, char *);
159 extern void crypto_setup (void);
160 extern u_int
crypto_ident (struct peer
*);
161 extern struct exten
*crypto_args (struct peer
*, u_int
, associd_t
, char *);
162 extern int crypto_public (struct peer
*, u_char
*, u_int
);
163 extern void value_free (struct value
*);
164 extern char *iffpar_file
;
165 extern EVP_PKEY
*iffpar_pkey
;
166 extern char *gqpar_file
;
167 extern EVP_PKEY
*gqpar_pkey
;
168 extern char *mvpar_file
;
169 extern EVP_PKEY
*mvpar_pkey
;
170 extern struct value tai_leap
;
174 extern void transmit (struct peer
*);
175 extern void receive (struct recvbuf
*);
176 extern void peer_clear (struct peer
*, char *);
177 extern void process_packet (struct peer
*, struct pkt
*, u_int
);
178 extern void clock_select (void);
180 extern int leap_tai
; /* TAI at next leap */
181 extern u_long leap_sec
; /* next scheduled leap from file */
182 extern u_long leap_peers
; /* next scheduled leap from peers */
183 extern u_long leapsec
; /* seconds to next leap */
184 extern u_long leap_expire
; /* leap information expiration */
185 extern int sys_orphan
;
186 extern double sys_mindisp
;
187 extern double sys_maxdist
;
190 * there seems to be a bug in the IRIX 4 compiler which prevents
191 * u_char from beeing used in prototyped functions.
192 * This is also true AIX compiler.
193 * So give up and define it to be int. WLJ
195 extern void poll_update (struct peer
*, int);
197 extern void clear (struct peer
*);
198 extern void clock_filter (struct peer
*, double, double, double);
199 extern void init_proto (void);
200 extern void proto_config (int, u_long
, double, sockaddr_u
*);
201 extern void proto_clr_stats (void);
205 extern int refclock_newpeer (struct peer
*);
206 extern void refclock_unpeer (struct peer
*);
207 extern void refclock_receive (struct peer
*);
208 extern void refclock_transmit (struct peer
*);
209 extern void init_refclock (void);
210 #endif /* REFCLOCK */
213 extern void init_request (void);
214 extern void process_private (struct recvbuf
*, int);
217 extern void init_restrict (void);
218 extern int restrictions (sockaddr_u
*);
219 extern void hack_restrict (int, sockaddr_u
*, sockaddr_u
*, int, int);
222 extern void init_timer (void);
223 extern void reinit_timer (void);
224 extern void timer (void);
225 extern void timer_clr_stats (void);
226 extern void timer_interfacetimeout (u_long
);
227 extern volatile int interface_interval
;
229 extern char *sys_hostname
; /* host name */
230 extern char *sys_groupname
; /* group name */
231 extern char *group_name
; /* group name */
232 extern u_long sys_revoke
; /* keys revoke timeout */
233 extern u_long sys_automax
; /* session key timeout */
237 extern void init_util (void);
238 extern void write_stats (void);
239 extern void stats_config (int, const char *);
240 extern void record_peer_stats (sockaddr_u
*, int, double, double, double, double);
241 extern void record_proto_stats (char *);
242 extern void record_loop_stats (double, double, double, double, int);
243 extern void record_clock_stats (sockaddr_u
*, const char *);
244 extern void record_raw_stats (sockaddr_u
*, sockaddr_u
*, l_fp
*, l_fp
*, l_fp
*, l_fp
*);
245 extern u_long
leap_month(u_long
);
246 extern void record_crypto_stats (sockaddr_u
*, const char *);
248 extern void record_timing_stats (const char *);
250 extern u_short
sock_hash (sockaddr_u
*);
251 extern char * fstostr(time_t); /* NTP timescale seconds */
252 extern double old_drift
;
253 extern int drift_file_sw
;
254 extern double wander_threshold
;
255 extern double wander_resid
;
258 * Variable declarations for ntpd.
261 extern char const * progname
;
262 extern char *sys_phone
[]; /* ACTS phone numbers */
263 #if defined(HAVE_SCHED_SETSCHEDULER)
264 extern int config_priority_override
;
265 extern int config_priority
;
267 extern char *ntp_signd_socket
;
268 extern struct config_tree
*cfg_tree_history
;
270 #ifdef BC_LIST_FRAMEWORK_NOT_YET_USED
272 * backwards compatibility flags
274 typedef struct bc_entry_tag
{
279 extern bc_entry bc_list
[];
283 extern int num_ctl_traps
;
284 extern keyid_t ctl_auth_keyid
; /* keyid used for authenticating write requests */
287 * Statistic counters to keep track of requests and responses.
289 extern u_long ctltimereset
; /* time stats reset */
290 extern u_long numctlreq
; /* number of requests we've received */
291 extern u_long numctlbadpkts
; /* number of bad control packets */
292 extern u_long numctlresponses
; /* number of resp packets sent with data */
293 extern u_long numctlfrags
; /* number of fragments sent */
294 extern u_long numctlerrors
; /* number of error responses sent */
295 extern u_long numctltooshort
; /* number of too short input packets */
296 extern u_long numctlinputresp
; /* number of responses on input */
297 extern u_long numctlinputfrag
; /* number of fragments on input */
298 extern u_long numctlinputerr
; /* number of input pkts with err bit set */
299 extern u_long numctlbadoffset
; /* number of input pkts with nonzero offset */
300 extern u_long numctlbadversion
; /* number of input pkts with unknown version */
301 extern u_long numctldatatooshort
; /* data too short for count */
302 extern u_long numctlbadop
; /* bad op code found in packet */
303 extern u_long numasyncmsgs
; /* number of async messages we've sent */
306 extern keyid_t req_keyid
; /* request keyid */
307 extern int req_keytype
; /* OpenSSL NID such as NID_md5 */
308 extern size_t req_hashlen
; /* digest size for req_keytype */
309 extern char * req_file
; /* name of the file with configuration info */
311 extern HANDLE ResolverEventHandle
;
313 extern int resolver_pipe_fd
[2]; /* used to let the resolver process alert the parent process */
314 #endif /* SYS_WINNT */
317 * Other statistics of possible interest
319 extern volatile u_long packets_dropped
; /* total number of packets dropped on reception */
320 extern volatile u_long packets_ignored
; /* packets received on wild card interface */
321 extern volatile u_long packets_received
;/* total number of packets received */
322 extern u_long packets_sent
; /* total number of packets sent */
323 extern u_long packets_notsent
; /* total number of packets which couldn't be sent */
325 extern volatile u_long handler_calls
; /* number of calls to interrupt handler */
326 extern volatile u_long handler_pkts
; /* number of pkts received by handler */
327 extern u_long io_timereset
; /* time counters were reset */
332 extern struct interface
*any_interface
; /* default ipv4 interface */
333 extern struct interface
*any6_interface
;/* default ipv6 interface */
334 extern struct interface
*loopback_interface
; /* loopback interface */
337 * File descriptor masks etc. for call to select
339 extern fd_set activefds
;
340 extern int maxactivefd
;
342 /* ntp_loopfilter.c */
343 extern double drift_comp
; /* clock frequency (s/s) */
344 extern double clock_stability
; /* clock stability (s/s) */
345 extern double clock_max
; /* max offset before step (s) */
346 extern double clock_panic
; /* max offset before panic (s) */
347 extern double clock_phi
; /* dispersion rate (s/s) */
348 extern double clock_minstep
; /* step timeout (s) */
349 extern double clock_codec
; /* codec frequency */
351 extern int pll_status
; /* status bits for kernel pll */
352 #endif /* KERNEL_PLL */
355 * Clock state machine control flags
357 extern int ntp_enable
; /* clock discipline enabled */
358 extern int pll_control
; /* kernel support available */
359 extern int kern_enable
; /* kernel support enabled */
360 extern int pps_enable
; /* kernel PPS discipline enabled */
361 extern int ext_enable
; /* external clock enabled */
362 extern int cal_enable
; /* refclock calibrate enable */
363 extern int allow_panic
; /* allow panic correction */
364 extern int mode_ntpdate
; /* exit on first clock set */
365 extern int peer_ntpdate
; /* count of ntpdate peers */
368 * Clock state machine variables
370 extern u_char sys_poll
; /* system poll interval (log2 s) */
371 extern int state
; /* clock discipline state */
372 extern int tc_counter
; /* poll-adjust counter */
373 extern u_long last_time
; /* time of last clock update (s) */
374 extern double last_offset
; /* last clock offset (s) */
375 extern u_char allan_xpt
; /* Allan intercept (log2 s) */
376 extern double clock_jitter
; /* clock jitter (s) */
377 extern double sys_offset
; /* system offset (s) */
378 extern double sys_jitter
; /* system jitter (s) */
381 extern struct mon_data mon_mru_list
;
382 extern struct mon_data mon_fifo_list
;
383 extern int mon_enabled
;
386 extern struct peer
*peer_hash
[]; /* peer hash table */
387 extern int peer_hash_count
[]; /* count of peers in each bucket */
388 extern struct peer
*assoc_hash
[]; /* association ID hash table */
389 extern int assoc_hash_count
[];
390 extern int peer_free_count
;
393 * Miscellaneous statistic counters which may be queried.
395 extern u_long peer_timereset
; /* time stat counters were zeroed */
396 extern u_long findpeer_calls
; /* number of calls to findpeer */
397 extern u_long assocpeer_calls
; /* number of calls to findpeerbyassoc */
398 extern u_long peer_allocations
; /* number of allocations from the free list */
399 extern u_long peer_demobilizations
; /* number of structs freed to free list */
400 extern int total_peer_structs
; /* number of peer structs in circulation */
401 extern int peer_associations
; /* mobilized associations */
402 extern int peer_preempt
; /* preemptable associations */
405 * System variables are declared here. See Section 3.2 of the
408 extern u_char sys_leap
; /* system leap indicator */
409 extern u_char sys_stratum
; /* system stratum */
410 extern s_char sys_precision
; /* local clock precision */
411 extern double sys_rootdelay
; /* roundtrip delay to primary source */
412 extern double sys_rootdisp
; /* dispersion to primary source */
413 extern u_int32 sys_refid
; /* reference id */
414 extern l_fp sys_reftime
; /* last update time */
415 extern struct peer
*sys_peer
; /* current peer */
418 * Nonspecified system state variables.
420 extern int sys_bclient
; /* we set our time to broadcasts */
421 extern double sys_bdelay
; /* broadcast client default delay */
422 extern int sys_authenticate
; /* requre authentication for config */
423 extern l_fp sys_authdelay
; /* authentication delay */
424 extern keyid_t sys_private
; /* private value for session seed */
425 extern int sys_manycastserver
; /* respond to manycast client pkts */
426 extern int sys_minclock
; /* minimum survivors */
427 extern int sys_minsane
; /* minimum candidates */
428 extern int sys_floor
; /* cluster stratum floor */
429 extern int sys_ceiling
; /* cluster stratum ceiling */
430 extern u_char sys_ttl
[MAX_TTL
]; /* ttl mapping vector */
431 extern int sys_ttlmax
; /* max ttl mapping vector index */
434 * Statistics counters
436 extern u_long sys_stattime
; /* time since reset */
437 extern u_long sys_received
; /* packets received */
438 extern u_long sys_processed
; /* packets for this host */
439 extern u_long sys_restricted
; /* restricted packets */
440 extern u_long sys_newversion
; /* current version */
441 extern u_long sys_oldversion
; /* old version */
442 extern u_long sys_restricted
; /* access denied */
443 extern u_long sys_badlength
; /* bad length or format */
444 extern u_long sys_badauth
; /* bad authentication */
445 extern u_long sys_declined
; /* declined */
446 extern u_long sys_limitrejected
; /* rate exceeded */
447 extern u_long sys_kodsent
; /* KoD sent */
452 extern int fdpps
; /* pps file descriptor */
457 extern keyid_t info_auth_keyid
; /* keyid used to authenticate requests */
460 extern struct restrictlist
*restrictlist
; /* the ipv4 restriction list */
461 extern struct restrictlist6
*restrictlist6
; /* the ipv6 restriction list */
462 extern int ntp_minpkt
;
463 extern int ntp_minpoll
;
464 extern int mon_age
; /* monitor preempt age */
467 extern volatile int alarm_flag
; /* alarm flag */
468 extern volatile u_long alarm_overflow
;
469 extern u_long current_time
; /* current time (s) */
470 extern u_long timer_timereset
;
471 extern u_long timer_overflows
;
472 extern u_long timer_xmtcalls
;
475 extern int stats_control
; /* write stats to fileset? */
476 extern int stats_write_period
; /* # of seconds between writes. */
477 extern double stats_write_tolerance
;
480 extern volatile int debug
; /* debugging flag */
481 extern int nofork
; /* no-fork flag */
482 extern int initializing
; /* initializing flag */
484 extern int droproot
; /* flag: try to drop root privileges after startup */
485 extern char *user
; /* user to switch to */
486 extern char *group
; /* group to switch to */
487 extern const char *chrootdir
; /* directory to chroot to */
490 /* refclock_conf.c */
492 extern struct refclock
*refclock_conf
[]; /* refclock configuration table */
493 extern u_char num_refclock_conf
;
497 #ifdef HAVE_NTP_SIGND
500 struct recvbuf
*rbufp
, /* receive packet pointer */