1 /* $OpenBSD: src/usr.sbin/ntpd/ntpd.h,v 1.41 2004/10/22 21:17:37 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>
23 #include <netinet/in.h>
24 #include <netinet/in_systm.h>
25 #include <netinet/ip.h>
26 #include <arpa/inet.h>
32 #define NTPD_USER "_ntp"
33 #define CONFFILE "/etc/ntpd.conf"
35 #define READ_BUF_SIZE 65535
37 #define NTPD_OPT_VERBOSE 0x0001
38 #define NTPD_OPT_VERBOSE2 0x0002
40 #define INTERVAL_QUERY_NORMAL 30 /* sync to peers every n secs */
41 #define INTERVAL_QUERY_PATHETIC 60
42 #define INTERVAL_QUERY_AGRESSIVE 5
44 #define TRUSTLEVEL_BADPEER 6
45 #define TRUSTLEVEL_PATHETIC 2
46 #define TRUSTLEVEL_AGRESSIVE 8
48 #define QSCALE_OFF_MIN 0.05
49 #define QSCALE_OFF_MAX 0.50
51 #define QUERYTIME_MAX 15 /* single query might take n secs max */
52 #define OFFSET_ARRAY_SIZE 8
53 #define SETTIME_MIN_OFFSET 180 /* min offset for settime at start */
62 TAILQ_ENTRY(listen_addr) entry;
63 struct sockaddr_storage sa;
68 struct ntp_addr *next;
69 struct sockaddr_storage ss;
72 struct ntp_addr_wrap {
82 double rootdispersion;
95 struct ntp_status status;
99 TAILQ_ENTRY(ntp_peer) entry;
101 struct ntp_addr_wrap addr_head;
102 struct ntp_addr *addr;
103 struct ntp_query *query;
104 enum client_state state;
107 struct ntp_offset reply[OFFSET_ARRAY_SIZE];
108 struct ntp_offset update;
114 TAILQ_HEAD(listen_addrs, listen_addr) listen_addrs;
115 TAILQ_HEAD(ntp_peers, ntp_peer) ntp_peers;
119 struct ntp_status status;
123 TAILQ_ENTRY(buf) entries;
133 TAILQ_HEAD(bufs, buf) bufs;
137 u_char buf[READ_BUF_SIZE];
144 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
145 #define MAX_IMSGSIZE 8192
176 void vlog(int, const char *, va_list);
177 void log_warn(const char *, ...);
178 void log_warnx(const char *, ...);
179 void log_info(const char *, ...);
180 void log_debug(const char *, ...);
181 void fatal(const char *);
182 void fatalx(const char *);
183 const char * log_sockaddr(struct sockaddr *);
186 struct buf *buf_open(ssize_t);
187 int buf_add(struct buf *, void *, ssize_t);
188 int buf_close(struct msgbuf *, struct buf *);
189 void buf_free(struct buf *);
190 void msgbuf_init(struct msgbuf *);
191 void msgbuf_clear(struct msgbuf *);
192 int msgbuf_write(struct msgbuf *);
195 void imsg_init(struct imsgbuf *, int);
196 int imsg_read(struct imsgbuf *);
197 int imsg_get(struct imsgbuf *, struct imsg *);
198 int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
200 struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
202 int imsg_add(struct buf *, void *, u_int16_t);
203 int imsg_close(struct imsgbuf *, struct buf *);
204 void imsg_free(struct imsg *);
207 pid_t ntp_main(int[2], struct ntpd_conf *);
208 void ntp_adjtime(void);
209 void ntp_settime(double);
210 void ntp_host_dns(char *, u_int32_t);
213 int parse_config(char *, struct ntpd_conf *);
216 int host(const char *, struct ntp_addr **);
217 int host_dns(const char *, struct ntp_addr **);
218 struct ntp_peer *new_peer(void);
221 int ntp_getmsg(char *, ssize_t, struct ntp_msg *);
222 int ntp_sendmsg(int, struct sockaddr *, struct ntp_msg *, ssize_t, int);
225 int setup_listeners(struct servent *, struct ntpd_conf *, u_int *);
226 int ntp_reply(int, struct sockaddr *, struct ntp_msg *, int);
227 int server_dispatch(int, struct ntpd_conf *);
230 int client_peer_init(struct ntp_peer *);
231 int client_addr_init(struct ntp_peer *);
232 int client_nextaddr(struct ntp_peer *);
233 int client_query(struct ntp_peer *);
234 int client_dispatch(struct ntp_peer *, u_int8_t);
237 double gettime(void);
238 void d_to_tv(double, struct timeval *);
239 double lfp_to_d(struct l_fixedpt);
240 struct l_fixedpt d_to_lfp(double);
241 double sfp_to_d(struct s_fixedpt);
242 struct s_fixedpt d_to_sfp(double);