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_debug.h" 9 #include "ntp_select.h" 10 #include "ntp_malloc.h" 11 #include "ntp_refclock.h" 12 #include "recvbuff.h" 13 14 15 /* ntp_config.c */ 16 extern void getconfig P((int, char **)); 17 18 /* ntp_config.c */ 19 extern void ctl_clr_stats P((void)); 20 extern int ctlclrtrap P((struct sockaddr_storage *, struct interface *, int)); 21 extern u_short ctlpeerstatus P((struct peer *)); 22 extern int ctlsettrap P((struct sockaddr_storage *, struct interface *, int, int)); 23 extern u_short ctlsysstatus P((void)); 24 extern void init_control P((void)); 25 extern void process_control P((struct recvbuf *, int)); 26 extern void report_event P((int, struct peer *)); 27 28 extern double fabs P((double)); 29 extern double sqrt P((double)); 30 31 /* ntp_control.c */ 32 /* 33 * Structure for translation tables between internal system 34 * variable indices and text format. 35 */ 36 struct ctl_var { 37 u_short code; 38 u_short flags; 39 char *text; 40 }; 41 /* 42 * Flag values 43 */ 44 #define CAN_READ 0x01 45 #define CAN_WRITE 0x02 46 47 #define DEF 0x20 48 #define PADDING 0x40 49 #define EOV 0x80 50 51 #define RO (CAN_READ) 52 #define WO (CAN_WRITE) 53 #define RW (CAN_READ|CAN_WRITE) 54 55 extern char * add_var P((struct ctl_var **, u_long, u_short)); 56 extern void free_varlist P((struct ctl_var *)); 57 extern void set_var P((struct ctl_var **, const char *, u_long, u_short)); 58 extern void set_sys_var P((const char *, u_long, u_short)); 59 60 /* ntp_intres.c */ 61 extern void ntp_res_name P((struct sockaddr_storage, u_short)); 62 extern void ntp_res_recv P((void)); 63 extern void ntp_intres P((void)); 64 65 /* ntp_io.c */ 66 typedef struct interface_info { 67 struct interface *interface; 68 u_char action; 69 } interface_info_t; 70 71 typedef void (*interface_receiver_t)(void *, interface_info_t *); 72 73 extern volatile int disable_dynamic_updates; 74 75 extern void interface_enumerate P((interface_receiver_t, void *)); 76 extern struct interface *findinterface P((struct sockaddr_storage *)); 77 extern struct interface *findbcastinter P((struct sockaddr_storage *)); 78 extern void enable_broadcast P((struct interface *, struct sockaddr_storage *)); 79 extern void enable_multicast_if P((struct interface *, struct sockaddr_storage *)); 80 extern void interface_dump P((struct interface *)); 81 82 extern void interface_update P((interface_receiver_t, void *)); 83 extern void init_io P((void)); 84 extern void input_handler P((l_fp *)); 85 extern void io_clr_stats P((void)); 86 extern void io_setbclient P((void)); 87 extern void io_unsetbclient P((void)); 88 extern void io_multicast_add P((struct sockaddr_storage)); 89 extern void io_multicast_del P((struct sockaddr_storage)); 90 extern void kill_asyncio P((int)); 91 extern void sendpkt P((struct sockaddr_storage *, struct interface *, int, struct pkt *, int)); 92 #ifdef DEBUG 93 extern void collect_timing P((struct recvbuf *, const char *, int, l_fp *)); 94 #endif 95 #ifdef HAVE_SIGNALED_IO 96 extern void wait_for_signal P((void)); 97 extern void unblock_io_and_alarm P((void)); 98 extern void block_io_and_alarm P((void)); 99 #define UNBLOCK_IO_AND_ALARM() unblock_io_and_alarm() 100 #define BLOCK_IO_AND_ALARM() block_io_and_alarm() 101 #else 102 #define UNBLOCK_IO_AND_ALARM() 103 #define BLOCK_IO_AND_ALARM() 104 #endif 105 106 /* ntp_leap.c */ 107 extern void init_leap P((void)); 108 extern void leap_process P((void)); 109 extern int leap_setleap P((int, int)); 110 /* 111 * there seems to be a bug in the IRIX 4 compiler which prevents 112 * u_char from beeing used in prototyped functions. 113 * This is also true AIX compiler. 114 * So give up and define it to be int. WLJ 115 */ 116 extern int leap_actual P((int)); 117 118 /* ntp_loopfilter.c */ 119 extern void init_loopfilter P((void)); 120 extern int local_clock P((struct peer *, double)); 121 extern void adj_host_clock P((void)); 122 extern void loop_config P((int, double)); 123 extern void huffpuff P((void)); 124 extern u_long sys_clocktime; 125 extern u_long sys_tai; 126 127 /* ntp_monitor.c */ 128 extern void init_mon P((void)); 129 extern void mon_start P((int)); 130 extern void mon_stop P((int)); 131 extern int ntp_monitor P((struct recvbuf *)); 132 extern void ntp_monclearinterface P((struct interface *interface)); 133 134 /* ntp_peer.c */ 135 extern void init_peer P((void)); 136 extern struct peer *findexistingpeer P((struct sockaddr_storage *, struct peer *, int)); 137 extern struct peer *findpeer P((struct sockaddr_storage *, struct interface *, int, int *)); 138 extern struct peer *findpeerbyassoc P((u_int)); 139 extern void set_peerdstadr P((struct peer *peer, struct interface *interface)); 140 extern struct peer *newpeer P((struct sockaddr_storage *, struct interface *, int, int, int, int, u_int, u_char, int, keyid_t)); 141 extern void peer_all_reset P((void)); 142 extern void peer_clr_stats P((void)); 143 extern struct peer *peer_config P((struct sockaddr_storage *, struct interface *, int, int, int, int, u_int, int, keyid_t, u_char *)); 144 extern void peer_reset P((struct peer *)); 145 extern int peer_unconfig P((struct sockaddr_storage *, struct interface *, int)); 146 extern void refresh_all_peerinterfaces P((void)); 147 extern void unpeer P((struct peer *)); 148 extern void clear_all P((void)); 149 150 #ifdef OPENSSL 151 extern void expire_all P((void)); 152 #endif /* OPENSSL */ 153 extern struct peer *findmanycastpeer P((struct recvbuf *)); 154 155 /* ntp_crypto.c */ 156 #ifdef OPENSSL 157 extern int crypto_recv P((struct peer *, struct recvbuf *)); 158 extern int crypto_xmit P((struct pkt *, struct sockaddr_storage *, int, struct exten *, keyid_t)); 159 extern keyid_t session_key P((struct sockaddr_storage *, struct sockaddr_storage *, keyid_t, keyid_t, u_long)); 160 extern int make_keylist P((struct peer *, struct interface *)); 161 extern void key_expire P((struct peer *)); 162 extern void crypto_update P((void)); 163 extern void crypto_config P((int, char *)); 164 extern void crypto_setup P((void)); 165 extern u_int crypto_ident P((struct peer *)); 166 extern struct exten *crypto_args P((struct peer *, u_int, char *)); 167 extern int crypto_public P((struct peer *, u_char *, u_int)); 168 extern void value_free P((struct value *)); 169 extern char *iffpar_file; 170 extern EVP_PKEY *iffpar_pkey; 171 extern char *gqpar_file; 172 extern EVP_PKEY *gqpar_pkey; 173 extern char *mvpar_file; 174 extern EVP_PKEY *mvpar_pkey; 175 extern struct value tai_leap; 176 #endif /* OPENSSL */ 177 178 /* ntp_proto.c */ 179 extern void transmit P((struct peer *)); 180 extern void receive P((struct recvbuf *)); 181 extern void peer_crypto_clear P((struct peer *peer)); 182 extern void peer_clear P((struct peer *, char *)); 183 extern void process_packet P((struct peer *, struct pkt *)); 184 extern void clock_select P((void)); 185 extern void kod_proto P((void)); 186 187 /* 188 * there seems to be a bug in the IRIX 4 compiler which prevents 189 * u_char from beeing used in prototyped functions. 190 * This is also true AIX compiler. 191 * So give up and define it to be int. WLJ 192 */ 193 extern void poll_update P((struct peer *, int)); 194 195 extern void clear P((struct peer *)); 196 extern void clock_filter P((struct peer *, double, double, double)); 197 extern void init_proto P((void)); 198 extern void proto_config P((int, u_long, double, struct sockaddr_storage*)); 199 extern void proto_clr_stats P((void)); 200 201 #ifdef REFCLOCK 202 /* ntp_refclock.c */ 203 extern int refclock_newpeer P((struct peer *)); 204 extern void refclock_unpeer P((struct peer *)); 205 extern void refclock_receive P((struct peer *)); 206 extern void refclock_transmit P((struct peer *)); 207 extern void init_refclock P((void)); 208 #endif /* REFCLOCK */ 209 210 /* ntp_request.c */ 211 extern void init_request P((void)); 212 extern void process_private P((struct recvbuf *, int)); 213 214 /* ntp_restrict.c */ 215 extern void init_restrict P((void)); 216 extern int restrictions P((struct sockaddr_storage *, int)); 217 extern void hack_restrict P((int, struct sockaddr_storage *, struct sockaddr_storage *, int, int)); 218 219 /* ntp_timer.c */ 220 extern void init_timer P((void)); 221 extern void reinit_timer P((void)); 222 extern void timer P((void)); 223 extern void timer_clr_stats P((void)); 224 extern void timer_interfacetimeout P((u_long)); 225 extern volatile int interface_interval; 226 227 #ifdef OPENSSL 228 extern char *sys_hostname; 229 extern l_fp sys_revoketime; 230 #endif /* OPENSSL */ 231 232 /* ntp_util.c */ 233 extern void init_util P((void)); 234 extern void write_stats P((void)); 235 extern void stats_config P((int, const char *)); 236 extern void record_peer_stats P((struct sockaddr_storage *, int, double, double, double, double)); 237 extern void record_loop_stats P((double, double, double, double, int)); 238 extern void record_clock_stats P((struct sockaddr_storage *, const char *)); 239 extern void record_raw_stats P((struct sockaddr_storage *, struct sockaddr_storage *, l_fp *, l_fp *, l_fp *, l_fp *)); 240 extern void record_sys_stats P((void)); 241 extern void record_crypto_stats P((struct sockaddr_storage *, const char *)); 242 #ifdef DEBUG 243 extern void record_timing_stats P((const char *)); 244 #endif 245 extern int sock_hash P((struct sockaddr_storage *)); 246 extern double old_drift; 247 248 /* 249 * Variable declarations for ntpd. 250 */ 251 252 /* ntp_config.c */ 253 extern char const * progname; 254 extern char *sys_phone[]; /* ACTS phone numbers */ 255 #if defined(HAVE_SCHED_SETSCHEDULER) 256 extern int config_priority_override; 257 extern int config_priority; 258 #endif 259 260 /* ntp_control.c */ 261 extern int num_ctl_traps; 262 extern keyid_t ctl_auth_keyid; /* keyid used for authenticating write requests */ 263 264 /* 265 * Statistic counters to keep track of requests and responses. 266 */ 267 extern u_long ctltimereset; /* time stats reset */ 268 extern u_long numctlreq; /* number of requests we've received */ 269 extern u_long numctlbadpkts; /* number of bad control packets */ 270 extern u_long numctlresponses; /* number of resp packets sent with data */ 271 extern u_long numctlfrags; /* number of fragments sent */ 272 extern u_long numctlerrors; /* number of error responses sent */ 273 extern u_long numctltooshort; /* number of too short input packets */ 274 extern u_long numctlinputresp; /* number of responses on input */ 275 extern u_long numctlinputfrag; /* number of fragments on input */ 276 extern u_long numctlinputerr; /* number of input pkts with err bit set */ 277 extern u_long numctlbadoffset; /* number of input pkts with nonzero offset */ 278 extern u_long numctlbadversion; /* number of input pkts with unknown version */ 279 extern u_long numctldatatooshort; /* data too short for count */ 280 extern u_long numctlbadop; /* bad op code found in packet */ 281 extern u_long numasyncmsgs; /* number of async messages we've sent */ 282 283 /* ntp_intres.c */ 284 extern keyid_t req_keyid; /* request keyid */ 285 extern char * req_file; /* name of the file with configuration info */ 286 #ifdef SYS_WINNT 287 extern HANDLE ResolverEventHandle; 288 #else 289 extern int resolver_pipe_fd[2]; /* used to let the resolver process alert the parent process */ 290 #endif /* SYS_WINNT */ 291 292 /* 293 * Other statistics of possible interest 294 */ 295 extern volatile u_long packets_dropped; /* total number of packets dropped on reception */ 296 extern volatile u_long packets_ignored; /* packets received on wild card interface */ 297 extern volatile u_long packets_received;/* total number of packets received */ 298 extern u_long packets_sent; /* total number of packets sent */ 299 extern u_long packets_notsent; /* total number of packets which couldn't be sent */ 300 301 extern volatile u_long handler_calls; /* number of calls to interrupt handler */ 302 extern volatile u_long handler_pkts; /* number of pkts received by handler */ 303 extern u_long io_timereset; /* time counters were reset */ 304 305 /* 306 * Interface stuff 307 */ 308 extern struct interface *any_interface; /* default ipv4 interface */ 309 extern struct interface *any6_interface;/* default ipv6 interface */ 310 extern struct interface *loopback_interface; /* loopback interface */ 311 312 /* 313 * File descriptor masks etc. for call to select 314 */ 315 extern fd_set activefds; 316 extern int maxactivefd; 317 318 /* ntp_loopfilter.c */ 319 extern double drift_comp; /* clock frequency (s/s) */ 320 extern double clock_stability; /* clock stability (s/s) */ 321 extern double clock_max; /* max offset before step (s) */ 322 extern double clock_panic; /* max offset before panic (s) */ 323 extern double clock_phi; /* dispersion rate (s/s) */ 324 extern double clock_minstep; /* step timeout (s) */ 325 extern u_long pps_control; /* last pps sample time */ 326 #ifdef KERNEL_PLL 327 extern int pll_status; /* status bits for kernel pll */ 328 #endif /* KERNEL_PLL */ 329 330 /* 331 * Clock state machine control flags 332 */ 333 extern int ntp_enable; /* clock discipline enabled */ 334 extern int pll_control; /* kernel support available */ 335 extern int kern_enable; /* kernel support enabled */ 336 extern int pps_enable; /* kernel PPS discipline enabled */ 337 extern int ext_enable; /* external clock enabled */ 338 extern int cal_enable; /* refclock calibrate enable */ 339 extern int allow_panic; /* allow panic correction */ 340 extern int mode_ntpdate; /* exit on first clock set */ 341 extern int peer_ntpdate; /* count of ntpdate peers */ 342 343 /* 344 * Clock state machine variables 345 */ 346 extern u_char sys_poll; /* system poll interval (log2 s) */ 347 extern int state; /* clock discipline state */ 348 extern int tc_counter; /* poll-adjust counter */ 349 extern u_long last_time; /* time of last clock update (s) */ 350 extern double last_offset; /* last clock offset (s) */ 351 extern double allan_xpt; /* Allan intercept (s) */ 352 extern double clock_jitter; /* clock jitter (s) */ 353 extern double sys_jitter; /* system jitter (s) */ 354 355 /* ntp_monitor.c */ 356 extern struct mon_data mon_mru_list; 357 extern struct mon_data mon_fifo_list; 358 extern int mon_enabled; 359 360 /* ntp_peer.c */ 361 extern struct peer *peer_hash[]; /* peer hash table */ 362 extern int peer_hash_count[]; /* count of peers in each bucket */ 363 extern struct peer *assoc_hash[]; /* association ID hash table */ 364 extern int assoc_hash_count[]; 365 extern int peer_free_count; 366 367 /* 368 * Miscellaneous statistic counters which may be queried. 369 */ 370 extern u_long peer_timereset; /* time stat counters were zeroed */ 371 extern u_long findpeer_calls; /* number of calls to findpeer */ 372 extern u_long assocpeer_calls; /* number of calls to findpeerbyassoc */ 373 extern u_long peer_allocations; /* number of allocations from the free list */ 374 extern u_long peer_demobilizations; /* number of structs freed to free list */ 375 extern int total_peer_structs; /* number of peer structs in circulation */ 376 extern int peer_associations; /* mobilized associations */ 377 extern int peer_preempt; /* preemptable associations */ 378 /* ntp_proto.c */ 379 /* 380 * System variables are declared here. See Section 3.2 of the 381 * specification. 382 */ 383 extern u_char sys_leap; /* system leap indicator */ 384 extern u_char sys_stratum; /* stratum of system */ 385 extern s_char sys_precision; /* local clock precision */ 386 extern double sys_rootdelay; /* distance to current sync source */ 387 extern double sys_rootdispersion; /* dispersion of system clock */ 388 extern u_int32 sys_refid; /* reference source for local clock */ 389 extern l_fp sys_reftime; /* time we were last updated */ 390 extern struct peer *sys_peer; /* our current peer */ 391 extern struct peer *sys_pps; /* our current PPS peer */ 392 extern struct peer *sys_prefer; /* our cherished peer */ 393 extern u_long sys_automax; /* maximum session key lifetime */ 394 395 /* 396 * Nonspecified system state variables. 397 */ 398 extern int sys_bclient; /* we set our time to broadcasts */ 399 extern double sys_bdelay; /* broadcast client default delay */ 400 extern int sys_authenticate; /* requre authentication for config */ 401 extern l_fp sys_authdelay; /* authentication delay */ 402 extern keyid_t sys_private; /* private value for session seed */ 403 extern int sys_manycastserver; /* respond to manycast client pkts */ 404 extern int sys_minclock; /* minimum survivors */ 405 extern int sys_minsane; /* minimum candidates */ 406 extern int sys_floor; /* cluster stratum floor */ 407 extern int sys_ceiling; /* cluster stratum ceiling */ 408 extern u_char sys_ttl[]; /* ttl mapping vector */ 409 extern int sys_ttlmax; /* max ttl mapping vector index */ 410 extern int leap_next; /* leap consensus */ 411 412 /* 413 * Statistics counters 414 */ 415 extern u_long sys_stattime; /* time when we started recording */ 416 extern u_long sys_restricted; /* restricted packets */ 417 extern u_long sys_oldversionpkt; /* old version packets */ 418 extern u_long sys_newversionpkt; /* new version packets */ 419 extern u_long sys_unknownversion; /* don't know version packets */ 420 extern u_long sys_badlength; /* bad length or format */ 421 extern u_long sys_processed; /* packets processed */ 422 extern u_long sys_badauth; /* bad authentication */ 423 extern u_long sys_limitrejected; /* rate limit exceeded */ 424 extern u_long sys_received; /* packets received */ 425 426 /* ntp_refclock.c */ 427 #ifdef REFCLOCK 428 #ifdef PPS 429 extern int fdpps; /* pps file descriptor */ 430 #endif /* PPS */ 431 #endif 432 433 /* ntp_request.c */ 434 extern keyid_t info_auth_keyid; /* keyid used to authenticate requests */ 435 436 /* ntp_restrict.c */ 437 extern struct restrictlist *restrictlist; /* the ipv4 restriction list */ 438 extern struct restrictlist6 *restrictlist6; /* the ipv6 restriction list */ 439 extern u_long res_min_interval; 440 extern u_long res_avg_interval; 441 extern u_long mon_age; /* monitor preempt age */ 442 443 /* ntp_timer.c */ 444 extern volatile int alarm_flag; /* alarm flag */ 445 extern u_char sys_revoke; /* keys revoke timeout (log2 s) */ 446 extern volatile u_long alarm_overflow; 447 extern u_long current_time; /* current time (s) */ 448 extern u_long timer_timereset; 449 extern u_long timer_overflows; 450 extern u_long timer_xmtcalls; 451 452 /* ntp_util.c */ 453 extern int stats_control; /* write stats to fileset? */ 454 extern int stats_write_period; /* # of seconds between writes. */ 455 extern double stats_write_tolerance; 456 457 /* ntpd.c */ 458 extern volatile int debug; /* debugging flag */ 459 extern int nofork; /* no-fork flag */ 460 extern int initializing; /* initializing flag */ 461 #ifdef HAVE_DROPROOT 462 extern int droproot; /* flag: try to drop root privileges after startup */ 463 extern char *user; /* user to switch to */ 464 extern char *group; /* group to switch to */ 465 extern char *chrootdir; /* directory to chroot to */ 466 #endif 467 468 /* refclock_conf.c */ 469 #ifdef REFCLOCK 470 extern struct refclock *refclock_conf[]; /* refclock configuration table */ 471 extern u_char num_refclock_conf; 472 #endif 473