summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@cvs.openbsd.org>2005-01-28 12:37:21 +0000
committerDarren Tucker <dtucker@cvs.openbsd.org>2005-01-28 12:37:21 +0000
commit0dcb4b3a6285e3cc2e96ba56db5f830a086696f7 (patch)
treebcb9b6dfa39e2a9d2955d2c0041914eb730cbb59
parent465bbdbb932e2bcc8b931a52f960a60c9d745788 (diff)
Simplify interval scaling and randomize query intervals; ok henning@
-rw-r--r--usr.sbin/ntpd/client.c6
-rw-r--r--usr.sbin/ntpd/ntp.c26
-rw-r--r--usr.sbin/ntpd/ntpd.h3
3 files changed, 21 insertions, 14 deletions
diff --git a/usr.sbin/ntpd/client.c b/usr.sbin/ntpd/client.c
index 938afbabb18..ac3bcea279f 100644
--- a/usr.sbin/ntpd/client.c
+++ b/usr.sbin/ntpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.54 2005/01/28 12:01:32 dtucker Exp $ */
+/* $OpenBSD: client.c,v 1.55 2005/01/28 12:37:20 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -242,9 +242,9 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
p->reply[p->shift].status.stratum = msg.stratum;
if (p->trustlevel < TRUSTLEVEL_PATHETIC)
- interval = INTERVAL_QUERY_PATHETIC;
+ interval = scale_interval(INTERVAL_QUERY_PATHETIC);
else if (p->trustlevel < TRUSTLEVEL_AGRESSIVE)
- interval = INTERVAL_QUERY_AGRESSIVE;
+ interval = scale_interval(INTERVAL_QUERY_AGRESSIVE);
else
interval = scale_interval(INTERVAL_QUERY_NORMAL);
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c
index be0c2666051..cabe54ab8ea 100644
--- a/usr.sbin/ntpd/ntp.c
+++ b/usr.sbin/ntpd/ntp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntp.c,v 1.48 2005/01/27 14:44:00 dtucker Exp $ */
+/* $OpenBSD: ntp.c,v 1.49 2005/01/28 12:37:20 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -143,7 +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;
+ conf->scale = 1;
log_info("ntp engine ready");
@@ -465,22 +465,30 @@ update_scale(double offset)
offset = -offset;
if (offset > QSCALE_OFF_MAX)
- conf->scale = QSCALE_FACTOR;
+ conf->scale = 1;
else if (offset < QSCALE_OFF_MIN)
- conf->scale = QSCALE_FACTOR * QSCALE_OFF_MAX / QSCALE_OFF_MIN;
+ conf->scale = QSCALE_OFF_MAX / QSCALE_OFF_MIN;
else
- conf->scale = QSCALE_FACTOR * QSCALE_OFF_MAX / offset;
+ conf->scale = QSCALE_OFF_MAX / offset;
}
time_t
scale_interval(time_t requested)
{
- return (requested * conf->scale / QSCALE_FACTOR);
+ time_t interval, r;
+
+ interval = requested * conf->scale;
+ r = arc4random() % MAX(5, interval / 10);
+ return (interval + r);
}
-
+
time_t
-error_interval(void)
+error_interval(void)
{
- return (INTERVAL_QUERY_PATHETIC * QSCALE_OFF_MAX / QSCALE_OFF_MIN);
+ time_t interval, r;
+
+ interval = INTERVAL_QUERY_PATHETIC * QSCALE_OFF_MAX / QSCALE_OFF_MIN;
+ r = arc4random() % (interval / 10);
+ return (interval + r);
}
diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h
index ed69d2bd3eb..2bea573d1e3 100644
--- a/usr.sbin/ntpd/ntpd.h
+++ b/usr.sbin/ntpd/ntpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.h,v 1.50 2005/01/27 14:44:00 dtucker Exp $ */
+/* $OpenBSD: ntpd.h,v 1.51 2005/01/28 12:37:20 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -51,7 +51,6 @@
#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