Browse Source

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.
OPENBSD_3_6
henning 20 years ago
parent
commit
e490cc8936
3 changed files with 26 additions and 17 deletions
  1. +10
    -4
      src/usr.sbin/ntpd/client.c
  2. +8
    -8
      src/usr.sbin/ntpd/ntp.c
  3. +8
    -5
      src/usr.sbin/ntpd/ntpd.h

+ 10
- 4
src/usr.sbin/ntpd/client.c View File

@ -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);
}

+ 8
- 8
src/usr.sbin/ntpd/ntp.c View File

@ -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;
}
}

+ 8
- 5
src/usr.sbin/ntpd/ntpd.h View File

@ -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 {


Loading…
Cancel
Save