1 /* $OpenBSD: src/usr.sbin/ntpd/ntpd.h,v 1.47 2004/12/09 20:24:46 mickey 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 QSCALE_OFF_MIN 0.05
51 #define QSCALE_OFF_MAX 0.50
53 #define QUERYTIME_MAX 15 /* single query might take n secs max */
54 #define OFFSET_ARRAY_SIZE 8
55 #define SETTIME_MIN_OFFSET 180 /* min offset for settime at start */
56 #define LOG_NEGLIGEE 128 /* negligible drift to not log (ms) */
65 TAILQ_ENTRY(listen_addr) entry;
66 struct sockaddr_storage sa;
71 struct ntp_addr *next;
72 struct sockaddr_storage ss;
75 struct ntp_addr_wrap {
83 double rootdispersion;
93 struct ntp_status status;
102 TAILQ_ENTRY(ntp_peer) entry;
103 struct ntp_addr_wrap addr_head;
104 struct ntp_addr *addr;
105 struct ntp_query *query;
106 struct ntp_offset reply[OFFSET_ARRAY_SIZE];
107 struct ntp_offset update;
108 enum client_state state;
117 TAILQ_HEAD(listen_addrs, listen_addr) listen_addrs;
118 TAILQ_HEAD(ntp_peers, ntp_peer) ntp_peers;
119 struct ntp_status status;
126 TAILQ_ENTRY(buf) entries;
134 TAILQ_HEAD(bufs, buf) bufs;
141 u_char buf[READ_BUF_SIZE];
147 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
148 #define MAX_IMSGSIZE 8192
179 void vlog(int, const char *, va_list);
180 void log_warn(const char *, ...);
181 void log_warnx(const char *, ...);
182 void log_info(const char *, ...);
183 void log_debug(const char *, ...);
184 void fatal(const char *);
185 void fatalx(const char *);
186 const char * log_sockaddr(struct sockaddr *);
189 struct buf *buf_open(ssize_t);
190 int buf_add(struct buf *, void *, ssize_t);
191 int buf_close(struct msgbuf *, struct buf *);
192 void buf_free(struct buf *);
193 void msgbuf_init(struct msgbuf *);
194 void msgbuf_clear(struct msgbuf *);
195 int msgbuf_write(struct msgbuf *);
198 void imsg_init(struct imsgbuf *, int);
199 int imsg_read(struct imsgbuf *);
200 int imsg_get(struct imsgbuf *, struct imsg *);
201 int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
203 struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
205 int imsg_add(struct buf *, void *, u_int16_t);
206 int imsg_close(struct imsgbuf *, struct buf *);
207 void imsg_free(struct imsg *);
210 pid_t ntp_main(int[2], struct ntpd_conf *);
211 void priv_adjtime(void);
212 void priv_settime(double);
213 void priv_host_dns(char *, u_int32_t);
216 int parse_config(const char *, struct ntpd_conf *);
219 int host(const char *, struct ntp_addr **);
220 int host_dns(const char *, struct ntp_addr **);
221 struct ntp_peer *new_peer(void);
224 int ntp_getmsg(char *, ssize_t, struct ntp_msg *);
225 int ntp_sendmsg(int, struct sockaddr *, struct ntp_msg *, ssize_t, int);
228 int setup_listeners(struct servent *, struct ntpd_conf *, u_int *);
229 int ntp_reply(int, struct sockaddr *, struct ntp_msg *, int);
230 int server_dispatch(int, struct ntpd_conf *);
233 int client_peer_init(struct ntp_peer *);
234 int client_addr_init(struct ntp_peer *);
235 int client_nextaddr(struct ntp_peer *);
236 int client_query(struct ntp_peer *);
237 int client_dispatch(struct ntp_peer *, u_int8_t);
240 double gettime(void);
241 void d_to_tv(double, struct timeval *);
242 double lfp_to_d(struct l_fixedpt);
243 struct l_fixedpt d_to_lfp(double);
244 double sfp_to_d(struct s_fixedpt);
245 struct s_fixedpt d_to_sfp(double);