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