1 /* $OpenBSD: ntpd.h,v 1.52 2005/02/02 18:57:09 henning Exp $ */
4 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <sys/queue.h>
24 #include <netinet/in.h>
25 #include <netinet/in_systm.h>
26 #include <netinet/ip.h>
27 #include <arpa/inet.h>
33 #define NTPD_USER "_ntp"
34 #define CONFFILE "/etc/ntpd.conf"
36 #define READ_BUF_SIZE 65535
38 #define NTPD_OPT_VERBOSE 0x0001
39 #define NTPD_OPT_VERBOSE2 0x0002
41 #define INTERVAL_QUERY_NORMAL 30 /* sync to peers every n secs */
42 #define INTERVAL_QUERY_PATHETIC 60
43 #define INTERVAL_QUERY_AGRESSIVE 5
45 #define TRUSTLEVEL_BADPEER 6
46 #define TRUSTLEVEL_PATHETIC 2
47 #define TRUSTLEVEL_AGRESSIVE 8
48 #define TRUSTLEVEL_MAX 10
50 #define MAX_SERVERS_DNS 8
52 #define QSCALE_OFF_MIN 0.05
53 #define QSCALE_OFF_MAX 0.50
55 #define QUERYTIME_MAX 15 /* single query might take n secs max */
56 #define OFFSET_ARRAY_SIZE 8
57 #define SETTIME_MIN_OFFSET 180 /* min offset for settime at start */
58 #define LOG_NEGLIGEE 128 /* negligible drift to not log (ms) */
67 TAILQ_ENTRY(listen_addr) entry;
68 struct sockaddr_storage sa;
73 struct ntp_addr *next;
74 struct sockaddr_storage ss;
77 struct ntp_addr_wrap {
85 double rootdispersion;
95 struct ntp_status status;
104 TAILQ_ENTRY(ntp_peer) entry;
105 struct ntp_addr_wrap addr_head;
106 struct ntp_addr *addr;
107 struct ntp_query *query;
108 struct ntp_offset reply[OFFSET_ARRAY_SIZE];
109 struct ntp_offset update;
110 enum client_state state;
120 TAILQ_HEAD(listen_addrs, listen_addr) listen_addrs;
121 TAILQ_HEAD(ntp_peers, ntp_peer) ntp_peers;
122 struct ntp_status status;
130 TAILQ_ENTRY(buf) entries;
138 TAILQ_HEAD(bufs, buf) bufs;
145 u_char buf[READ_BUF_SIZE];
151 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
152 #define MAX_IMSGSIZE 8192
183 void vlog(int, const char *, va_list);
184 void log_warn(const char *, ...);
185 void log_warnx(const char *, ...);
186 void log_info(const char *, ...);
187 void log_debug(const char *, ...);
188 void fatal(const char *);
189 void fatalx(const char *);
190 const char * log_sockaddr(struct sockaddr *);
193 struct buf *buf_open(size_t);
194 int buf_add(struct buf *, void *, size_t);
195 int buf_close(struct msgbuf *, struct buf *);
196 void buf_free(struct buf *);
197 void msgbuf_init(struct msgbuf *);
198 void msgbuf_clear(struct msgbuf *);
199 int msgbuf_write(struct msgbuf *);
202 void imsg_init(struct imsgbuf *, int);
203 int imsg_read(struct imsgbuf *);
204 int imsg_get(struct imsgbuf *, struct imsg *);
205 int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
207 struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
209 int imsg_add(struct buf *, void *, u_int16_t);
210 int imsg_close(struct imsgbuf *, struct buf *);
211 void imsg_free(struct imsg *);
214 pid_t ntp_main(int[2], struct ntpd_conf *);
215 void priv_adjtime(void);
216 void priv_settime(double);
217 void priv_host_dns(char *, u_int32_t);
220 int parse_config(const char *, struct ntpd_conf *);
223 int host(const char *, struct ntp_addr **);
224 int host_dns(const char *, struct ntp_addr **);
225 struct ntp_peer *new_peer(void);
228 int ntp_getmsg(char *, ssize_t, struct ntp_msg *);
229 int ntp_sendmsg(int, struct sockaddr *, struct ntp_msg *, ssize_t, int);
232 int setup_listeners(struct servent *, struct ntpd_conf *, u_int *);
233 int ntp_reply(int, struct sockaddr *, struct ntp_msg *, int);
234 int server_dispatch(int, struct ntpd_conf *);
237 int client_peer_init(struct ntp_peer *);
238 int client_addr_init(struct ntp_peer *);
239 int client_nextaddr(struct ntp_peer *);
240 int client_query(struct ntp_peer *);
241 int client_dispatch(struct ntp_peer *, u_int8_t);
242 void client_log_error(struct ntp_peer *, const char *, int);
243 void update_scale(double);
244 time_t scale_interval(time_t);
245 time_t error_interval(void);
246 void set_next(struct ntp_peer *, time_t);
249 double gettime(void);
250 void d_to_tv(double, struct timeval *);
251 double lfp_to_d(struct l_fixedpt);
252 struct l_fixedpt d_to_lfp(double);
253 double sfp_to_d(struct s_fixedpt);
254 struct s_fixedpt d_to_sfp(double);