summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/ntpd/client.c28
-rw-r--r--usr.sbin/ntpd/ntp.c34
-rw-r--r--usr.sbin/ntpd/ntpd.h8
3 files changed, 43 insertions, 27 deletions
diff --git a/usr.sbin/ntpd/client.c b/usr.sbin/ntpd/client.c
index 139cd309779..0016488a604 100644
--- a/usr.sbin/ntpd/client.c
+++ b/usr.sbin/ntpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.52 2005/01/27 10:32:29 dtucker Exp $ */
+/* $OpenBSD: client.c,v 1.53 2005/01/27 14:44:00 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -43,20 +43,6 @@ set_deadline(struct ntp_peer *p, time_t t)
p->next = 0;
}
-time_t
-scale_interval(time_t requested, double offset)
-{
- if (offset < 0)
- offset = -offset;
-
- if (offset > QSCALE_OFF_MAX)
- return (requested);
- else if (offset < QSCALE_OFF_MIN)
- return (requested * (QSCALE_OFF_MAX / QSCALE_OFF_MIN));
- else
- return (requested * (QSCALE_OFF_MAX / offset));
-}
-
int
client_peer_init(struct ntp_peer *p)
{
@@ -128,7 +114,7 @@ client_query(struct ntp_peer *p)
int tos = IPTOS_LOWDELAY;
if (p->addr == NULL && client_nextaddr(p) == -1) {
- set_next(p, INTERVAL_QUERY_PATHETIC);
+ set_next(p, error_interval());
return (-1);
}
@@ -142,7 +128,7 @@ client_query(struct ntp_peer *p)
if (errno == ECONNREFUSED || errno == ENETUNREACH ||
errno == EHOSTUNREACH) {
client_nextaddr(p);
- set_next(p, INTERVAL_QUERY_PATHETIC);
+ set_next(p, error_interval());
return (-1);
} else
fatal("client_query connect");
@@ -197,8 +183,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
errno == ENETDOWN || errno == ECONNREFUSED) {
log_warn("recvfrom %s",
log_sockaddr((struct sockaddr *)&p->addr->ss));
- interval = scale_interval(INTERVAL_QUERY_PATHETIC, 0.0);
- set_next(p, interval);
+ set_next(p, error_interval());
return (0);
} else
fatal("recvfrom");
@@ -214,7 +199,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
if ((msg.status & LI_ALARM) == LI_ALARM || msg.stratum == 0 ||
msg.stratum > NTP_MAXSTRATUM) {
- interval = scale_interval(INTERVAL_QUERY_PATHETIC, 0.0);
+ interval = error_interval();
set_next(p, interval);
log_info("reply from %s: not synced, next query %ds",
log_sockaddr((struct sockaddr *)&p->addr->ss), interval);
@@ -260,8 +245,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
else if (p->trustlevel < TRUSTLEVEL_AGRESSIVE)
interval = INTERVAL_QUERY_AGRESSIVE;
else
- interval = scale_interval(INTERVAL_QUERY_NORMAL,
- p->reply[p->shift].offset);
+ interval = scale_interval(INTERVAL_QUERY_NORMAL);
set_next(p, interval);
p->state = STATE_REPLY_RECEIVED;
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c
index 76ef10c5e24..be0c2666051 100644
--- a/usr.sbin/ntpd/ntp.c
+++ b/usr.sbin/ntpd/ntp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntp.c,v 1.47 2005/01/27 10:32:29 dtucker Exp $ */
+/* $OpenBSD: ntp.c,v 1.48 2005/01/27 14:44:00 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -143,6 +143,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
b = 1000000000 / tp.tv_nsec; /* convert to Hz */
for (a = 0; b > 1; a--, b >>= 1);
conf->status.precision = a;
+ conf->scale = QSCALE_FACTOR;
log_info("ntp engine ready");
@@ -199,8 +200,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
if (p->deadline > 0 && p->deadline < nextaction)
nextaction = p->deadline;
if (p->deadline > 0 && p->deadline <= time(NULL)) {
- timeout = scale_interval(
- INTERVAL_QUERY_PATHETIC, 0.0);
+ timeout = error_interval();
log_debug("no reply from %s received in time, "
"next query %ds", log_sockaddr(
(struct sockaddr *)&p->addr->ss), timeout);
@@ -412,6 +412,7 @@ priv_adjtime(void)
conf->status.reftime = gettime();
conf->status.leap = LI_NOWARNING;
conf->status.stratum++; /* one more than selected peer */
+ update_scale(offset_median);
if (peers[offset_cnt / 2]->addr->ss.ss_family == AF_INET)
conf->status.refid = ((struct sockaddr_in *)
@@ -456,3 +457,30 @@ priv_host_dns(char *name, u_int32_t peerid)
dlen = strlen(name) + 1;
imsg_compose(ibuf_main, IMSG_HOST_DNS, peerid, 0, name, dlen);
}
+
+void
+update_scale(double offset)
+{
+ if (offset < 0)
+ offset = -offset;
+
+ if (offset > QSCALE_OFF_MAX)
+ conf->scale = QSCALE_FACTOR;
+ else if (offset < QSCALE_OFF_MIN)
+ conf->scale = QSCALE_FACTOR * QSCALE_OFF_MAX / QSCALE_OFF_MIN;
+ else
+ conf->scale = QSCALE_FACTOR * QSCALE_OFF_MAX / offset;
+}
+
+time_t
+scale_interval(time_t requested)
+{
+ return (requested * conf->scale / QSCALE_FACTOR);
+}
+
+time_t
+error_interval(void)
+{
+ return (INTERVAL_QUERY_PATHETIC * QSCALE_OFF_MAX / QSCALE_OFF_MIN);
+}
+
diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h
index 64ddb9a18e7..ed69d2bd3eb 100644
--- a/usr.sbin/ntpd/ntpd.h
+++ b/usr.sbin/ntpd/ntpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.h,v 1.49 2005/01/27 10:32:29 dtucker Exp $ */
+/* $OpenBSD: ntpd.h,v 1.50 2005/01/27 14:44:00 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -51,6 +51,7 @@
#define QSCALE_OFF_MIN 0.05
#define QSCALE_OFF_MAX 0.50
+#define QSCALE_FACTOR 1000
#define QUERYTIME_MAX 15 /* single query might take n secs max */
#define OFFSET_ARRAY_SIZE 8
@@ -122,6 +123,7 @@ struct ntpd_conf {
u_int8_t listen_all;
u_int8_t settime;
u_int8_t debug;
+ u_int32_t scale;
};
struct buf {
@@ -237,7 +239,9 @@ int client_addr_init(struct ntp_peer *);
int client_nextaddr(struct ntp_peer *);
int client_query(struct ntp_peer *);
int client_dispatch(struct ntp_peer *, u_int8_t);
-time_t scale_interval(time_t, double);
+void update_scale(double);
+time_t scale_interval(time_t);
+time_t error_interval(void);
void set_next(struct ntp_peer *, time_t);
/* util.c */