summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-07-05 22:12:54 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-07-05 22:12:54 +0000
commit3de5171cc6d6cdb3c739120dc65c9e647c79d1b1 (patch)
tree79e2916e7df3406a45e365b7005ff3ce4026adcf /usr.sbin
parentc8fc69a63dbfc17fd6b74d184c14f3d77732b2b3 (diff)
keep last 8 offset,delay pairs - we'll need them for the clock filters later.
for now, average over those to adjust the local clock.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ntpd/client.c14
-rw-r--r--usr.sbin/ntpd/ntp.c16
-rw-r--r--usr.sbin/ntpd/ntpd.h13
3 files changed, 26 insertions, 17 deletions
diff --git a/usr.sbin/ntpd/client.c b/usr.sbin/ntpd/client.c
index 8b97f9f82ee..2e300e1656a 100644
--- a/usr.sbin/ntpd/client.c
+++ b/usr.sbin/ntpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.6 2004/07/05 20:41:34 henning Exp $ */
+/* $OpenBSD: client.c,v 1.7 2004/07/05 22:12:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -135,14 +135,20 @@ client_dispatch(struct ntp_peer *p)
T2 = lfp_to_d(msg.rectime);
T3 = lfp_to_d(msg.xmttime);
- p->offset = ((T2 - T1) + (T3 - T4)) / 2;
- p->delay = (T2 - T1) - (T3 - T4);
+ p->offset[p->shift] = ((T2 - T1) + (T3 - T4)) / 2;
+ p->delay[p->shift] = (T2 - T1) - (T3 - T4);
p->state = STATE_REPLY_RECEIVED;
p->next = time(NULL) + INTERVAL_QUERY;
p->deadline = 0;
- log_debug("reply received: offset %f delay %f", p->offset, p->delay);
+ log_debug("reply received: offset %f delay %f", p->offset[p->shift],
+ p->delay[p->shift]);
+
+ if (++p->shift >= OFFSET_ARRAY_SIZE) {
+ p->shift = 0;
+ p->valid = 1;
+ }
return (0);
}
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c
index dadc76c2be9..9f4a980a7f5 100644
--- a/usr.sbin/ntpd/ntp.c
+++ b/usr.sbin/ntpd/ntp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntp.c,v 1.10 2004/07/05 07:46:16 henning Exp $ */
+/* $OpenBSD: ntp.c,v 1.11 2004/07/05 22:12:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -285,21 +285,21 @@ ntp_adjtime(struct ntpd_conf *conf)
struct ntp_peer *p;
double offset_median = 0;
int offset_cnt = 0;
+ u_int8_t idx;
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
- if (p->state == STATE_NONE)
+ if (!p->valid)
continue;
- offset_median += p->offset;
- offset_cnt++;
+ for (idx = 0; idx < OFFSET_ARRAY_SIZE; idx++) {
+ offset_median += p->offset[idx];
+ offset_cnt++;
+ }
}
offset_median /= offset_cnt;
- if (offset_median >= 0.001 || offset_median <= 0.001) {
+ if (offset_median >= 0.001 || offset_median <= 0.001)
imsg_compose(&ibuf_main, IMSG_ADJTIME, 0,
&offset_median, sizeof(offset_median));
- TAILQ_FOREACH(p, &conf->ntp_peers, entry)
- p->offset = 0;
- }
}
diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h
index 4d321821b05..ea0833929d0 100644
--- a/usr.sbin/ntpd/ntpd.h
+++ b/usr.sbin/ntpd/ntpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.h,v 1.11 2004/07/05 20:41:35 henning Exp $ */
+/* $OpenBSD: ntpd.h,v 1.12 2004/07/05 22:12:53 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -37,8 +37,9 @@
#define NTPD_OPT_VERBOSE2 0x0002
#define INTERVAL_ADJTIME 120 /* call adjtime every n seconds */
-#define INTERVAL_QUERY 60 /* sync with peers every n seconds */
-#define QUERYTIME_MAX 30 /* single query might take n secs max */
+#define INTERVAL_QUERY 30 /* sync with peers every n seconds */
+#define QUERYTIME_MAX 15 /* single query might take n secs max */
+#define OFFSET_ARRAY_SIZE 8
enum client_state {
STATE_NONE,
@@ -59,8 +60,10 @@ struct ntp_peer {
enum client_state state;
time_t next;
time_t deadline;
- double offset;
- double delay;
+ double offset[OFFSET_ARRAY_SIZE];
+ double delay[OFFSET_ARRAY_SIZE];
+ u_int8_t shift;
+ u_int8_t valid;
};
struct ntpd_conf {