diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-06-04 18:58:14 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-06-04 18:58:14 +0000 |
commit | 1c66d151fe023dba10e9c411c4807b319f4bd0a9 (patch) | |
tree | e1c74289d48ae518f113ba6506d132fde43af0bd /usr.sbin/ntpd | |
parent | 013a31ba815ec8341d0dc66e450be005d22c1ab9 (diff) |
Only invalidate stored replies if an adjustment was really made.
ok henning@
Diffstat (limited to 'usr.sbin/ntpd')
-rw-r--r-- | usr.sbin/ntpd/client.c | 13 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntp.c | 67 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntpd.h | 4 |
3 files changed, 43 insertions, 41 deletions
diff --git a/usr.sbin/ntpd/client.c b/usr.sbin/ntpd/client.c index e4b2ea14192..65fad7139b4 100644 --- a/usr.sbin/ntpd/client.c +++ b/usr.sbin/ntpd/client.c @@ -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); } diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c index 0578d22cdf2..4657f6f09c1 100644 --- a/usr.sbin/ntpd/ntp.c +++ b/usr.sbin/ntpd/ntp.c @@ -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 diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h index 788b39358fd..ec7c0a7d2d4 100644 --- a/usr.sbin/ntpd/ntpd.h +++ b/usr.sbin/ntpd/ntpd.h @@ -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); |