Browse Source

Only invalidate stored replies if an adjustment was really made.

ok henning@
OPENBSD_4_0
otto 18 years ago
parent
commit
24fa8ea878
3 changed files with 43 additions and 41 deletions
  1. +6
    -7
      src/usr.sbin/ntpd/client.c
  2. +35
    -32
      src/usr.sbin/ntpd/ntp.c
  3. +2
    -2
      src/usr.sbin/ntpd/ntpd.h

+ 6
- 7
src/usr.sbin/ntpd/client.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: client.c,v 1.68 2006/05/29 20:51:54 ckuethe Exp $ */
/* $OpenBSD: client.c,v 1.69 2006/06/04 18:58:13 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -325,12 +325,11 @@ client_update(struct ntp_peer *p)
return (-1);
memcpy(&p->update, &p->reply[best], sizeof(p->update));
priv_adjtime();
for (i = 0; i < OFFSET_ARRAY_SIZE; i++)
if (p->reply[i].rcvd <= p->reply[best].rcvd)
p->reply[i].good = 0;
if (priv_adjtime() == 0) {
for (i = 0; i < OFFSET_ARRAY_SIZE; i++)
if (p->reply[i].rcvd <= p->reply[best].rcvd)
p->reply[i].good = 0;
}
return (0);
}


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

@ -1,4 +1,4 @@
/* $OpenBSD: ntp.c,v 1.82 2006/06/02 20:45:34 henning Exp $ */
/* $OpenBSD: ntp.c,v 1.83 2006/06/04 18:58:13 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -422,7 +422,7 @@ peer_remove(struct ntp_peer *p)
peer_cnt--;
}
void
int
priv_adjtime(void)
{
struct ntp_peer *p;
@ -435,7 +435,7 @@ priv_adjtime(void)
if (p->trustlevel < TRUSTLEVEL_BADPEER)
continue;
if (!p->update.good)
return;
return (1);
offset_cnt += p->weight;
}
@ -445,6 +445,9 @@ priv_adjtime(void)
offset_cnt += s->weight;
}
if (offset_cnt == 0)
return (1);
if ((offsets = calloc(offset_cnt, sizeof(struct ntp_offset *))) == NULL)
fatal("calloc priv_adjtime");
@ -464,43 +467,43 @@ priv_adjtime(void)
qsort(offsets, offset_cnt, sizeof(struct ntp_offset *), offset_compare);
if (offset_cnt > 0) {
if (offset_cnt > 1 && offset_cnt % 2 == 0) {
offset_median =
(offsets[offset_cnt / 2 - 1]->offset +
offsets[offset_cnt / 2]->offset) / 2;
conf->status.rootdelay =
(offsets[offset_cnt / 2 - 1]->delay +
offsets[offset_cnt / 2]->delay) / 2;
conf->status.stratum = MAX(
offsets[offset_cnt / 2 - 1]->status.stratum,
offsets[offset_cnt / 2]->status.stratum);
} else {
offset_median = offsets[offset_cnt / 2]->offset;
conf->status.rootdelay =
offsets[offset_cnt / 2]->delay;
conf->status.stratum =
offsets[offset_cnt / 2]->status.stratum;
}
conf->status.leap = offsets[offset_cnt / 2]->status.leap;
if (offset_cnt > 1 && offset_cnt % 2 == 0) {
offset_median =
(offsets[offset_cnt / 2 - 1]->offset +
offsets[offset_cnt / 2]->offset) / 2;
conf->status.rootdelay =
(offsets[offset_cnt / 2 - 1]->delay +
offsets[offset_cnt / 2]->delay) / 2;
conf->status.stratum = MAX(
offsets[offset_cnt / 2 - 1]->status.stratum,
offsets[offset_cnt / 2]->status.stratum);
} else {
offset_median = offsets[offset_cnt / 2]->offset;
conf->status.rootdelay =
offsets[offset_cnt / 2]->delay;
conf->status.stratum =
offsets[offset_cnt / 2]->status.stratum;
}
conf->status.leap = offsets[offset_cnt / 2]->status.leap;
imsg_compose(ibuf_main, IMSG_ADJTIME, 0, 0,
&offset_median, sizeof(offset_median));
imsg_compose(ibuf_main, IMSG_ADJTIME, 0, 0,
&offset_median, sizeof(offset_median));
conf->status.reftime = gettime();
conf->status.stratum++; /* one more than selected peer */
update_scale(offset_median);
conf->status.reftime = gettime();
conf->status.stratum++; /* one more than selected peer */
update_scale(offset_median);
conf->status.refid4 =
offsets[offset_cnt / 2]->status.refid4;
conf->status.refid =
offsets[offset_cnt / 2]->status.send_refid;
}
conf->status.refid4 =
offsets[offset_cnt / 2]->status.refid4;
conf->status.refid =
offsets[offset_cnt / 2]->status.send_refid;
free(offsets);
TAILQ_FOREACH(p, &conf->ntp_peers, entry)
p->update.good = 0;
return (0);
}
int


+ 2
- 2
src/usr.sbin/ntpd/ntpd.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.69 2006/05/28 20:39:16 henning Exp $ */
/* $OpenBSD: ntpd.h,v 1.70 2006/06/04 18:58:13 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -241,7 +241,7 @@ void imsg_free(struct imsg *);
/* ntp.c */
pid_t ntp_main(int[2], struct ntpd_conf *);
void priv_adjtime(void);
int priv_adjtime(void);
void priv_settime(double);
void priv_host_dns(char *, u_int32_t);


Loading…
Cancel
Save