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 struct ctl_trap; 230 extern struct ctl_trap ctl_trap[]; 231 extern int num_ctl_traps; 232 extern keyid_t ctl_auth_keyid; /* keyid used for authenticating write requests */ 233 234 /* 235 * Statistic counters to keep track of requests and responses. 236 */ 237 extern u_long ctltimereset; /* time stats reset */ 238 extern u_long numctlreq; /* number of requests we've received */ 239 extern u_long numctlbadpkts; /* number of bad control packets */ 240 extern u_long numctlresponses; /* number of resp packets sent with data */ 241 extern u_long numctlfrags; /* number of fragments sent */ 242 extern u_long numctlerrors; /* number of error responses sent */ 243 extern u_long numctltooshort; /* number of too short input packets */ 244 extern u_long numctlinputresp; /* number of responses on input */ 245 extern u_long numctlinputfrag; /* number of fragments on input */ 246 extern u_long numctlinputerr; /* number of input pkts with err bit set */ 247 extern u_long numctlbadoffset; /* number of input pkts with nonzero offset */ 248 extern u_long numctlbadversion; /* number of input pkts with unknown version */ 249 extern u_long numctldatatooshort; /* data too short for count */ 250 extern u_long numctlbadop; /* bad op code found in packet */ 251 extern u_long numasyncmsgs; /* number of async messages we've sent */ 252 253 /* ntp_intres.c */ 254 extern keyid_t req_keyid; /* request keyid */ 255 extern char * req_file; /* name of the file with configuration info */ 256 257 /* 258 * Other statistics of possible interest 259 */ 260 extern volatile u_long packets_dropped; /* total number of packets dropped on reception */ 261 extern volatile u_long packets_ignored; /* packets received on wild card interface */ 262 extern volatile u_long packets_received;/* total number of packets received */ 263 extern u_long packets_sent; /* total number of packets sent */ 264 extern u_long packets_notsent; /* total number of packets which couldn't be sent */ 265 266 extern volatile u_long handler_calls; /* number of calls to interrupt handler */ 267 extern volatile u_long handler_pkts; /* number of pkts received by handler */ 268 extern u_long io_timereset; /* time counters were reset */ 269 270 /* 271 * Interface stuff 272 */ 273 extern struct interface *any_interface; /* default ipv4 interface */ 274 extern struct interface *any6_interface;/* default ipv6 interface */ 275 extern struct interface *loopback_interface; /* loopback interface */ 276 277 /* 278 * File descriptor masks etc. for call to select 279 */ 280 extern fd_set activefds; 281 extern int maxactivefd; 282 283 /* ntp_loopfilter.c */ 284 extern double drift_comp; /* clock frequency (s/s) */ 285 extern double clock_stability; /* clock stability (s/s) */ 286 extern double clock_max; /* max offset before step (s) */ 287 extern double clock_panic; /* max offset before panic (s) */ 288 extern double clock_phi; /* dispersion rate (s/s) */ 289 extern double clock_minstep; /* step timeout (s) */ 290 extern u_long pps_control; /* last pps sample time */ 291 #ifdef KERNEL_PLL 292 extern int pll_status; /* status bits for kernel pll */ 293 #endif /* KERNEL_PLL */ 294 295 /* 296 * Clock state machine control flags 297 */ 298 extern int ntp_enable; /* clock discipline enabled */ 299 extern int pll_control; /* kernel support available */ 300 extern int kern_enable; /* kernel support enabled */ 301 extern int pps_enable; /* kernel PPS discipline enabled */ 302 extern int ext_enable; /* external clock enabled */ 303 extern int cal_enable; /* refclock calibrate enable */ 304 extern int allow_panic; /* allow panic correction */ 305 extern int mode_ntpdate; /* exit on first clock set */ 306 extern int peer_ntpdate; /* count of ntpdate peers */ 307 extern int forground_process; /* run the process in the forground */ 308 309 /* 310 * Clock state machine variables 311 */ 312 extern u_char sys_poll; /* system poll interval (log2 s) */ 313 extern int state; /* clock discipline state */ 314 extern int tc_counter; /* poll-adjust counter */ 315 extern u_long last_time; /* time of last clock update (s) */ 316 extern double last_offset; /* last clock offset (s) */ 317 extern double allan_xpt; /* Allan intercept (s) */ 318 extern double sys_error; /* system RMS error (s) */ 319 extern double sys_jitter; /* system RMS jitter (s) */ 320 321 /* ntp_monitor.c */ 322 extern struct mon_data mon_mru_list; 323 extern struct mon_data mon_fifo_list; 324 extern int mon_enabled; 325 326 /* ntp_peer.c */ 327 extern struct peer *peer_hash[]; /* peer hash table */ 328 extern int peer_hash_count[]; /* count of peers in each bucket */ 329 extern struct peer *assoc_hash[]; /* association ID hash table */ 330 extern int assoc_hash_count[]; 331 extern int peer_free_count; 332 333 /* 334 * Miscellaneous statistic counters which may be queried. 335 */ 336 extern u_long peer_timereset; /* time stat counters were zeroed */ 337 extern u_long findpeer_calls; /* number of calls to findpeer */ 338 extern u_long assocpeer_calls; /* number of calls to findpeerbyassoc */ 339 extern u_long peer_allocations; /* number of allocations from the free list */ 340 extern u_long peer_demobilizations; /* number of structs freed to free list */ 341 extern int total_peer_structs; /* number of peer structs in circulation */ 342 extern int peer_associations; /* number of active associations */ 343 344 /* ntp_proto.c */ 345 /* 346 * System variables are declared here. See Section 3.2 of the 347 * specification. 348 */ 349 extern u_char sys_leap; /* system leap indicator */ 350 extern u_char sys_stratum; /* stratum of system */ 351 extern s_char sys_precision; /* local clock precision */ 352 extern double sys_rootdelay; /* distance to current sync source */ 353 extern double sys_rootdispersion; /* dispersion of system clock */ 354 extern u_int32 sys_refid; /* reference source for local clock */ 355 extern l_fp sys_reftime; /* time we were last updated */ 356 extern struct peer *sys_peer; /* our current peer */ 357 extern struct peer *sys_prefer; /* our cherished peer */ 358 extern u_long sys_automax; /* maximum session key lifetime */ 359 360 /* 361 * Nonspecified system state variables. 362 */ 363 extern int sys_bclient; /* we set our time to broadcasts */ 364 extern double sys_bdelay; /* broadcast client default delay */ 365 extern int sys_authenticate; /* requre authentication for config */ 366 extern l_fp sys_authdelay; /* authentication delay */ 367 extern keyid_t sys_private; /* private value for session seed */ 368 extern int sys_manycastserver; /* respond to manycast client pkts */ 369 extern int sys_minclock; /* minimum survivors */ 370 extern int sys_minsane; /* minimum candidates */ 371 extern int sys_floor; /* cluster stratum floor */ 372 extern int sys_ceiling; /* cluster stratum ceiling */ 373 extern u_char sys_ttl[]; /* ttl mapping vector */ 374 extern int sys_ttlmax; /* max ttl mapping vector index */ 375 376 /* 377 * Statistics counters 378 */ 379 extern u_long sys_stattime; /* time when we started recording */ 380 extern u_long sys_restricted; /* restricted packets */ 381 extern u_long sys_oldversionpkt; /* old version packets */ 382 extern u_long sys_newversionpkt; /* new version packets */ 383 extern u_long sys_unknownversion; /* don't know version packets */ 384 extern u_long sys_badlength; /* bad length or format */ 385 extern u_long sys_processed; /* packets processed */ 386 extern u_long sys_badauth; /* bad authentication */ 387 extern u_long sys_limitrejected; /* rate limit exceeded */ 388 extern u_long sys_received; /* packets received */ 389 390 /* ntp_refclock.c */ 391 #ifdef REFCLOCK 392 #if defined(PPS) || defined(HAVE_PPSAPI) 393 extern int fdpps; /* pps file descriptor */ 394 #endif /* PPS */ 395 #endif 396 397 /* ntp_request.c */ 398 extern keyid_t info_auth_keyid; /* keyid used to authenticate requests */ 399 400 /* ntp_restrict.c */ 401 extern struct restrictlist *restrictlist; /* the ipv4 restriction list */ 402 extern struct restrictlist6 *restrictlist6; /* the ipv6 restriction list */ 403 extern u_long res_min_interval; 404 extern u_long res_avg_interval; 405 extern u_long mon_age; /* monitor preempt age */ 406 407 /* ntp_timer.c */ 408 extern volatile int alarm_flag; /* alarm flag */ 409 extern u_char sys_revoke; /* keys revoke timeout (log2 s) */ 410 extern volatile u_long alarm_overflow; 411 extern u_long current_time; /* current time (s) */ 412 extern u_long timer_timereset; 413 extern u_long timer_overflows; 414 extern u_long timer_xmtcalls; 415 416 /* ntp_util.c */ 417 extern int stats_control; /* write stats to fileset? */ 418 419 /* ntpd.c */ 420 extern volatile int debug; /* debugging flag */ 421 extern int nofork; /* no-fork flag */ 422 extern int initializing; /* initializing flag */ 423 #ifdef HAVE_CLOCKCTL 424 extern char *user; /* user to switch to */ 425 extern char *group; /* group to switch to */ 426 extern char *chrootdir; /* directory to chroot to */ 427 #endif 428 429 /* refclock_conf.c */ 430 #ifdef REFCLOCK 431 extern struct refclock *refclock_conf[]; /* refclock configuration table */ 432 extern u_char num_refclock_conf; 433 #endif 434