ntpd.h revision 309007
1/* 2 * ntpd.h - Prototypes and external variables for ntpd. 3 * 4 * Note the first half is primarily function prototypes, type 5 * declarations, and preprocessor macros, with variables declared 6 * primarily in the second half. 7 * 8 * Each half is further divided into sections for each source file. 9 */ 10 11#include "ntp.h" 12#include "ntp_stdlib.h" 13#include "ntp_syslog.h" 14#include "ntp_debug.h" 15#include "ntp_syslog.h" 16#include "ntp_select.h" 17#include "ntp_malloc.h" 18#include "ntp_refclock.h" 19#include "ntp_intres.h" 20#include "recvbuff.h" 21 22/* 23 * First half: ntpd types, functions, macros 24 * ----------------------------------------- 25 */ 26 27/* 28 * macro for debugging output - cut down on #ifdef pollution. 29 * 30 * DPRINTF() is for use by ntpd only, and compiles away to nothing 31 * without DEBUG (configure --disable-debugging). 32 * 33 * TRACE() is similar for libntp and utilities, which retain full 34 * debug capability even when compiled without DEBUG. 35 * 36 * The calling convention is not attractive: 37 * DPRINTF(debuglevel, (fmt, ...)); 38 * DPRINTF(2, ("shows #ifdef DEBUG and if debug >= %d\n", 2)); 39 */ 40#ifdef DEBUG 41# define DPRINTF(lvl, arg) \ 42 do { \ 43 if (debug >= (lvl)) \ 44 mprintf arg; \ 45 } while (0) 46#else 47# define DPRINTF(lvl, arg) do {} while (0) 48#endif 49 50 51/* nt_clockstuff.c */ 52#ifdef SYS_WINNT 53extern void win_time_stepped(void); 54#endif 55 56/* ntp_config.c */ 57#define TAI_1972 10 /* initial TAI offset (s) */ 58extern char *keysdir; /* crypto keys and leaptable directory */ 59extern char * saveconfigdir; /* ntpq saveconfig output directory */ 60 61extern void getconfig (int, char **); 62extern void ctl_clr_stats (void); 63extern int ctlclrtrap (sockaddr_u *, struct interface *, int); 64extern u_short ctlpeerstatus (struct peer *); 65extern int ctlsettrap (sockaddr_u *, struct interface *, int, int); 66extern u_short ctlsysstatus (void); 67extern void init_control (void); 68extern void process_control (struct recvbuf *, int); 69extern void report_event (int, struct peer *, const char *); 70extern int mprintf_event (int, struct peer *, const char *, ...) 71 NTP_PRINTF(3, 4); 72 73/* ntp_control.c */ 74/* 75 * Structure for translation tables between internal system 76 * variable indices and text format. 77 */ 78struct ctl_var { 79 u_short code; 80 u_short flags; 81 const char *text; 82}; 83/* 84 * Flag values 85 */ 86#define CAN_READ 0x01 87#define CAN_WRITE 0x02 88 89#define DEF 0x20 90#define PADDING 0x40 91#define EOV 0x80 92 93#define RO (CAN_READ) 94#define WO (CAN_WRITE) 95#define RW (CAN_READ|CAN_WRITE) 96 97extern char * add_var (struct ctl_var **, u_long, u_short); 98extern void free_varlist (struct ctl_var *); 99extern void set_var (struct ctl_var **, const char *, u_long, u_short); 100extern void set_sys_var (const char *, u_long, u_short); 101extern const char * get_ext_sys_var(const char *tag); 102 103/* ntp_io.c */ 104typedef struct interface_info { 105 endpt * ep; 106 u_char action; 107} interface_info_t; 108 109typedef void (*interface_receiver_t) (void *, interface_info_t *); 110 111extern void interface_enumerate (interface_receiver_t, void *); 112extern endpt * getinterface (sockaddr_u *, u_int32); 113extern endpt * select_peerinterface (struct peer *, sockaddr_u *, 114 endpt *); 115extern endpt * findinterface (sockaddr_u *); 116extern endpt * findbcastinter (sockaddr_u *); 117extern void enable_broadcast (endpt *, sockaddr_u *); 118extern void enable_multicast_if (endpt *, sockaddr_u *); 119extern void interface_update (interface_receiver_t, void *); 120#ifndef HAVE_IO_COMPLETION_PORT 121extern void io_handler (void); 122#endif 123extern void init_io (void); 124extern void io_open_sockets (void); 125extern void io_clr_stats (void); 126extern void io_setbclient (void); 127extern void io_unsetbclient (void); 128extern void io_multicast_add(sockaddr_u *); 129extern void io_multicast_del(sockaddr_u *); 130extern void sendpkt (sockaddr_u *, struct interface *, int, struct pkt *, int); 131#ifdef DEBUG 132extern void collect_timing (struct recvbuf *, const char *, int, l_fp *); 133#endif 134#ifdef HAVE_SIGNALED_IO 135extern void wait_for_signal (void); 136extern void unblock_io_and_alarm (void); 137extern void block_io_and_alarm (void); 138# define UNBLOCK_IO_AND_ALARM() unblock_io_and_alarm() 139# define BLOCK_IO_AND_ALARM() block_io_and_alarm() 140#else 141# define UNBLOCK_IO_AND_ALARM() do {} while (0) 142# define BLOCK_IO_AND_ALARM() do {} while (0) 143#endif 144#define latoa(pif) localaddrtoa(pif) 145extern const char * localaddrtoa(endpt *); 146 147/* ntp_loopfilter.c */ 148extern void init_loopfilter(void); 149extern int local_clock(struct peer *, double); 150extern void adj_host_clock(void); 151extern void loop_config(int, double); 152extern void select_loop(int); 153extern void huffpuff(void); 154extern u_long sys_clocktime; 155extern u_int sys_tai; 156extern int freq_cnt; 157 158/* ntp_monitor.c */ 159#define MON_HASH_SIZE ((size_t)1U << mon_hash_bits) 160#define MON_HASH_MASK (MON_HASH_SIZE - 1) 161#define MON_HASH(addr) (sock_hash(addr) & MON_HASH_MASK) 162extern void init_mon (void); 163extern void mon_start (int); 164extern void mon_stop (int); 165extern u_short ntp_monitor (struct recvbuf *, u_short); 166extern void mon_clearinterface(endpt *interface); 167 168/* ntp_peer.c */ 169extern void init_peer (void); 170extern struct peer *findexistingpeer(sockaddr_u *, const char *, 171 struct peer *, int, u_char); 172extern struct peer *findpeer (struct recvbuf *, int, int *); 173extern struct peer *findpeerbyassoc(associd_t); 174extern void set_peerdstadr (struct peer *, endpt *); 175extern struct peer *newpeer (sockaddr_u *, const char *, 176 endpt *, u_char, u_char, 177 u_char, u_char, u_int, u_char, u_int32, 178 keyid_t, const char *); 179extern void peer_all_reset (void); 180extern void peer_clr_stats (void); 181extern struct peer *peer_config(sockaddr_u *, const char *, 182 endpt *, u_char, u_char, 183 u_char, u_char, u_int, u_int32, 184 keyid_t, const char *); 185extern void peer_reset (struct peer *); 186extern void refresh_all_peerinterfaces(void); 187extern void unpeer (struct peer *); 188extern void clear_all (void); 189extern int score_all (struct peer *); 190extern struct peer *findmanycastpeer(struct recvbuf *); 191extern void peer_cleanup (void); 192 193/* ntp_crypto.c */ 194#ifdef AUTOKEY 195extern int crypto_recv (struct peer *, struct recvbuf *); 196extern int crypto_xmit (struct peer *, struct pkt *, 197 struct recvbuf *, int, 198 struct exten *, keyid_t); 199extern keyid_t session_key (sockaddr_u *, sockaddr_u *, keyid_t, 200 keyid_t, u_long); 201extern int make_keylist (struct peer *, struct interface *); 202extern void key_expire (struct peer *); 203extern void crypto_update (void); 204extern void crypto_update_taichange(void); 205extern void crypto_config (int, char *); 206extern void crypto_setup (void); 207extern u_int crypto_ident (struct peer *); 208extern struct exten *crypto_args (struct peer *, u_int, associd_t, char *); 209extern int crypto_public (struct peer *, u_char *, u_int); 210extern void value_free (struct value *); 211extern char *iffpar_file; 212extern EVP_PKEY *iffpar_pkey; 213extern char *gqpar_file; 214extern EVP_PKEY *gqpar_pkey; 215extern char *mvpar_file; 216extern EVP_PKEY *mvpar_pkey; 217extern struct value tai_leap; 218#endif /* AUTOKEY */ 219 220/* ntp_proto.c */ 221extern void transmit (struct peer *); 222extern void receive (struct recvbuf *); 223extern void peer_clear (struct peer *, const char *); 224extern void process_packet (struct peer *, struct pkt *, u_int); 225extern void clock_select (void); 226extern void set_sys_leap (u_char); 227 228extern u_long leapsec; /* seconds to next leap (proximity class) */ 229extern int leapdif; /* TAI difference step at next leap second*/ 230extern int sys_orphan; 231extern double sys_mindisp; 232extern double sys_maxdist; 233 234extern char *sys_ident; /* identity scheme */ 235extern void poll_update (struct peer *, u_char); 236 237extern void clear (struct peer *); 238extern void clock_filter (struct peer *, double, double, double); 239extern void init_proto (void); 240extern void set_sys_tick_precision(double); 241extern void proto_config (int, u_long, double, sockaddr_u *); 242extern void proto_clr_stats (void); 243 244/* ntp_refclock.c */ 245#ifdef REFCLOCK 246extern int refclock_newpeer (struct peer *); 247extern void refclock_unpeer (struct peer *); 248extern void refclock_receive (struct peer *); 249extern void refclock_transmit (struct peer *); 250extern void init_refclock (void); 251#endif /* REFCLOCK */ 252 253/* ntp_request.c */ 254extern void init_request (void); 255extern void process_private (struct recvbuf *, int); 256extern void reset_auth_stats(void); 257 258/* ntp_restrict.c */ 259extern void init_restrict (void); 260extern u_short restrictions (sockaddr_u *); 261extern void hack_restrict (int, sockaddr_u *, sockaddr_u *, 262 u_short, u_short, u_long); 263extern void restrict_source (sockaddr_u *, int, u_long); 264 265/* ntp_timer.c */ 266extern void init_timer (void); 267extern void reinit_timer (void); 268extern void timer (void); 269extern void timer_clr_stats (void); 270extern void timer_interfacetimeout (u_long); 271extern volatile int interface_interval; 272extern u_long orphwait; /* orphan wait time */ 273#ifdef AUTOKEY 274extern char *sys_hostname; /* host name */ 275extern char *sys_groupname; /* group name */ 276extern char *group_name; /* group name */ 277extern u_long sys_revoke; /* keys revoke timeout */ 278extern u_long sys_automax; /* session key timeout */ 279#endif /* AUTOKEY */ 280 281/* ntp_util.c */ 282extern void init_util (void); 283extern void write_stats (void); 284extern void stats_config (int, const char *); 285extern void record_peer_stats (sockaddr_u *, int, double, double, double, double); 286extern void record_proto_stats (char *); 287extern void record_loop_stats (double, double, double, double, int); 288extern void record_clock_stats (sockaddr_u *, const char *); 289extern int mprintf_clock_stats(sockaddr_u *, const char *, ...) 290 NTP_PRINTF(2, 3); 291extern void record_raw_stats (sockaddr_u *srcadr, sockaddr_u *dstadr, l_fp *t1, l_fp *t2, l_fp *t3, l_fp *t4, int leap, int version, int mode, int stratum, int ppoll, int precision, double root_delay, double root_dispersion, u_int32 refid); 292extern void check_leap_file (int is_daily_check, u_int32 ntptime, const time_t * systime); 293extern void record_crypto_stats (sockaddr_u *, const char *); 294#ifdef DEBUG 295extern void record_timing_stats (const char *); 296#endif 297extern char * fstostr(time_t); /* NTP timescale seconds */ 298 299/* ntpd.c */ 300extern void parse_cmdline_opts(int *, char ***); 301/* 302 * Signals we catch for debugging. 303 */ 304#define MOREDEBUGSIG SIGUSR1 305#define LESSDEBUGSIG SIGUSR2 306/* 307 * Signals which terminate us gracefully. 308 */ 309#ifndef SYS_WINNT 310# define SIGDIE1 SIGHUP 311# define SIGDIE2 SIGINT 312# define SIGDIE3 SIGQUIT 313# define SIGDIE4 SIGTERM 314#endif /* SYS_WINNT */ 315 316 317/* 318 * Last half: ntpd variables 319 * ------------------------- 320 */ 321 322/* ntp_config.c */ 323extern char const * progname; 324extern char *sys_phone[]; /* ACTS phone numbers */ 325#if defined(HAVE_SCHED_SETSCHEDULER) 326extern int config_priority_override; 327extern int config_priority; 328#endif 329extern char *ntp_signd_socket; 330extern struct config_tree_tag *cfg_tree_history; 331 332#ifdef BC_LIST_FRAMEWORK_NOT_YET_USED 333/* 334 * backwards compatibility flags 335 */ 336typedef struct bc_entry_tag { 337 int token; 338 int enabled; 339} bc_entry; 340 341extern bc_entry bc_list[]; 342#endif 343 344/* ntp_control.c */ 345extern int num_ctl_traps; 346extern keyid_t ctl_auth_keyid; /* keyid used for authenticating write requests */ 347 348/* 349 * Statistic counters to keep track of requests and responses. 350 */ 351extern u_long ctltimereset; /* time stats reset */ 352extern u_long numctlreq; /* number of requests we've received */ 353extern u_long numctlbadpkts; /* number of bad control packets */ 354extern u_long numctlresponses; /* number of resp packets sent with data */ 355extern u_long numctlfrags; /* number of fragments sent */ 356extern u_long numctlerrors; /* number of error responses sent */ 357extern u_long numctltooshort; /* number of too short input packets */ 358extern u_long numctlinputresp; /* number of responses on input */ 359extern u_long numctlinputfrag; /* number of fragments on input */ 360extern u_long numctlinputerr; /* number of input pkts with err bit set */ 361extern u_long numctlbadoffset; /* number of input pkts with nonzero offset */ 362extern u_long numctlbadversion; /* number of input pkts with unknown version */ 363extern u_long numctldatatooshort; /* data too short for count */ 364extern u_long numctlbadop; /* bad op code found in packet */ 365extern u_long numasyncmsgs; /* number of async messages we've sent */ 366 367/* 368 * Other statistics of possible interest 369 */ 370extern volatile u_long packets_dropped; /* total number of packets dropped on reception */ 371extern volatile u_long packets_ignored; /* packets received on wild card interface */ 372extern volatile u_long packets_received;/* total number of packets received */ 373extern u_long packets_sent; /* total number of packets sent */ 374extern u_long packets_notsent; /* total number of packets which couldn't be sent */ 375 376extern volatile u_long handler_calls; /* number of calls to interrupt handler */ 377extern volatile u_long handler_pkts; /* number of pkts received by handler */ 378extern u_long io_timereset; /* time counters were reset */ 379 380/* ntp_io.c */ 381extern int disable_dynamic_updates; 382extern u_int sys_ifnum; /* next .ifnum to assign */ 383extern endpt * any_interface; /* IPv4 wildcard */ 384extern endpt * any6_interface; /* IPv6 wildcard */ 385extern endpt * loopback_interface; /* IPv4 loopback for refclocks */ 386extern endpt * ep_list; /* linked list */ 387 388/* ntp_loopfilter.c */ 389extern double drift_comp; /* clock frequency (s/s) */ 390extern double clock_stability; /* clock stability (s/s) */ 391extern double clock_max_back; /* max backward offset before step (s) */ 392extern double clock_max_fwd; /* max forward offset before step (s) */ 393extern double clock_panic; /* max offset before panic (s) */ 394extern double clock_phi; /* dispersion rate (s/s) */ 395extern double clock_minstep; /* step timeout (s) */ 396extern double clock_codec; /* codec frequency */ 397#ifdef KERNEL_PLL 398extern int pll_status; /* status bits for kernel pll */ 399#endif /* KERNEL_PLL */ 400 401/* 402 * Clock state machine control flags 403 */ 404extern int ntp_enable; /* clock discipline enabled */ 405extern int pll_control; /* kernel support available */ 406extern int kern_enable; /* kernel support enabled */ 407extern int hardpps_enable; /* kernel PPS discipline enabled */ 408extern int ext_enable; /* external clock enabled */ 409extern int cal_enable; /* refclock calibrate enable */ 410extern int allow_panic; /* allow panic correction (-g) */ 411extern int enable_panic_check; /* Can we check allow_panic's state? */ 412extern int force_step_once; /* always step time once at startup (-G) */ 413extern int mode_ntpdate; /* exit on first clock set (-q) */ 414extern int peer_ntpdate; /* count of ntpdate peers */ 415 416/* 417 * Clock state machine variables 418 */ 419extern u_char sys_poll; /* system poll interval (log2 s) */ 420extern int state; /* clock discipline state */ 421extern int tc_counter; /* poll-adjust counter */ 422extern u_long last_time; /* time of last clock update (s) */ 423extern double last_offset; /* last clock offset (s) */ 424extern u_char allan_xpt; /* Allan intercept (log2 s) */ 425extern double clock_jitter; /* clock jitter (s) */ 426extern double sys_offset; /* system offset (s) */ 427extern double sys_jitter; /* system jitter (s) */ 428 429/* ntp_monitor.c */ 430extern u_char mon_hash_bits; /* log2 size of hash table */ 431extern mon_entry ** mon_hash; /* MRU hash table */ 432extern mon_entry mon_mru_list; /* mru listhead */ 433extern u_int mon_enabled; /* MON_OFF (0) or other MON_* */ 434extern u_int mru_alloc; /* mru list + free list count */ 435extern u_int mru_entries; /* mru list count */ 436extern u_int mru_peakentries; /* highest mru_entries */ 437extern u_int mru_initalloc; /* entries to preallocate */ 438extern u_int mru_incalloc; /* allocation batch factor */ 439extern u_int mru_mindepth; /* preempt above this */ 440extern int mru_maxage; /* for entries older than */ 441extern u_int mru_maxdepth; /* MRU size hard limit */ 442extern int mon_age; /* preemption limit */ 443 444/* ntp_peer.c */ 445extern struct peer *peer_hash[NTP_HASH_SIZE]; /* peer hash table */ 446extern int peer_hash_count[NTP_HASH_SIZE]; /* count of in each bucket */ 447extern struct peer *assoc_hash[NTP_HASH_SIZE]; /* association ID hash table */ 448extern int assoc_hash_count[NTP_HASH_SIZE];/* count of in each bucket */ 449extern struct peer *peer_list; /* peer structures list */ 450extern int peer_count; /* count in peer_list */ 451extern int peer_free_count; /* count in peer_free */ 452 453/* 454 * Miscellaneous statistic counters which may be queried. 455 */ 456extern u_long peer_timereset; /* time stat counters were zeroed */ 457extern u_long findpeer_calls; /* number of calls to findpeer */ 458extern u_long assocpeer_calls; /* number of calls to findpeerbyassoc */ 459extern u_long peer_allocations; /* number of allocations from the free list */ 460extern u_long peer_demobilizations; /* number of structs freed to free list */ 461extern int total_peer_structs; /* number of peer structs in circulation */ 462extern int peer_associations; /* mobilized associations */ 463extern int peer_preempt; /* preemptable associations */ 464 465/* ntp_proto.c */ 466/* 467 * System variables are declared here. See Section 3.2 of the 468 * specification. 469 */ 470extern u_char sys_leap; /* system leap indicator */ 471extern u_char sys_stratum; /* system stratum */ 472extern s_char sys_precision; /* local clock precision */ 473extern double sys_rootdelay; /* roundtrip delay to primary source */ 474extern double sys_rootdisp; /* dispersion to primary source */ 475extern u_int32 sys_refid; /* reference id */ 476extern l_fp sys_reftime; /* last update time */ 477extern struct peer *sys_peer; /* current peer */ 478 479/* 480 * Nonspecified system state variables. 481 */ 482extern int sys_bclient; /* we set our time to broadcasts */ 483extern double sys_bdelay; /* broadcast client default delay */ 484extern int sys_authenticate; /* requre authentication for config */ 485extern l_fp sys_authdelay; /* authentication delay */ 486extern u_char sys_bcpollbstep; /* broadcast poll backstep gate */ 487extern u_long sys_epoch; /* last clock update time */ 488extern keyid_t sys_private; /* private value for session seed */ 489extern int sys_manycastserver; /* respond to manycast client pkts */ 490extern int sys_minclock; /* minimum survivors */ 491extern int sys_minsane; /* minimum candidates */ 492extern int sys_floor; /* cluster stratum floor */ 493extern int sys_ceiling; /* cluster stratum ceiling */ 494extern u_char sys_ttl[MAX_TTL]; /* ttl mapping vector */ 495extern int sys_ttlmax; /* max ttl mapping vector index */ 496 497/* 498 * Statistics counters 499 */ 500extern u_long sys_stattime; /* time since reset */ 501extern u_long sys_received; /* packets received */ 502extern u_long sys_processed; /* packets for this host */ 503extern u_long sys_restricted; /* restricted packets */ 504extern u_long sys_newversion; /* current version */ 505extern u_long sys_oldversion; /* old version */ 506extern u_long sys_restricted; /* access denied */ 507extern u_long sys_badlength; /* bad length or format */ 508extern u_long sys_badauth; /* bad authentication */ 509extern u_long sys_declined; /* declined */ 510extern u_long sys_limitrejected; /* rate exceeded */ 511extern u_long sys_kodsent; /* KoD sent */ 512 513/* ntp_request.c */ 514extern keyid_t info_auth_keyid; /* keyid used to authenticate requests */ 515extern u_long auth_timereset; 516 517/* ntp_restrict.c */ 518extern restrict_u * restrictlist4; /* IPv4 restriction list */ 519extern restrict_u * restrictlist6; /* IPv6 restriction list */ 520extern int ntp_minpkt; 521extern u_char ntp_minpoll; 522 523/* ntp_scanner.c */ 524extern u_int32 conf_file_sum; /* Simple sum of characters */ 525 526/* ntp_signd.c */ 527#ifdef HAVE_NTP_SIGND 528extern void send_via_ntp_signd(struct recvbuf *, int, keyid_t, int, 529 struct pkt *); 530#endif 531 532/* ntp_timer.c */ 533extern volatile int alarm_flag; /* alarm flag */ 534extern volatile u_long alarm_overflow; 535extern u_long current_time; /* seconds since startup */ 536extern u_long timer_timereset; 537extern u_long timer_overflows; 538extern u_long timer_xmtcalls; 539extern int leap_sec_in_progress; 540#ifdef LEAP_SMEAR 541extern struct leap_smear_info leap_smear; 542extern int leap_smear_intv; 543#endif 544#ifdef SYS_WINNT 545HANDLE WaitableTimerHandle; 546#endif 547 548/* ntp_util.c */ 549extern char statsdir[MAXFILENAME]; 550extern int stats_control; /* write stats to fileset? */ 551extern int stats_write_period; /* # of seconds between writes. */ 552extern double stats_write_tolerance; 553extern double wander_threshold; 554 555/* ntpd.c */ 556extern int nofork; /* no-fork flag */ 557extern int initializing; /* initializing flag */ 558#ifdef HAVE_DROPROOT 559extern int droproot; /* flag: try to drop root privileges after startup */ 560extern int root_dropped; /* root has been dropped */ 561extern char *user; /* user to switch to */ 562extern char *group; /* group to switch to */ 563extern const char *chrootdir; /* directory to chroot() to */ 564#endif 565#ifdef HAVE_WORKING_FORK 566extern int waitsync_fd_to_close; /* -w/--wait-sync */ 567#endif 568 569/* ntservice.c */ 570#ifdef SYS_WINNT 571extern int accept_wildcard_if_for_winnt; 572#endif 573 574/* refclock_conf.c */ 575#ifdef REFCLOCK 576/* refclock configuration table */ 577extern struct refclock * const refclock_conf[]; 578extern u_char num_refclock_conf; 579#endif 580 581