diff options
author | 2013-09-28 12:18:05 +0000 | |
---|---|---|
committer | 2013-09-28 12:18:05 +0000 | |
commit | b737adba49f9b079ceb16fc38c581f073404153a (patch) | |
tree | e815fbe8a4dbfd399fba1aeeaee17b9347e76ecb | |
parent | Fix the message of uthum(4)'s calibration offset is incorrect (diff) | |
download | wireguard-openbsd-b737adba49f9b079ceb16fc38c581f073404153a.tar.xz wireguard-openbsd-b737adba49f9b079ceb16fc38c581f073404153a.zip |
Resolve the uncertainty in the REFID assignment.
Previously, when there is an even number of offsets, we did the average
of the two middle offets but would set the REFID from one of them.
Instead, we simply select the middle offset with the lowest delay.
diff from Mike Miller <mmiller mgm51 com> (many thanks!)
OK phessler@, henning@
-rw-r--r-- | usr.sbin/ntpd/ntp.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c index 23713fc5e7c..3f85e252576 100644 --- a/usr.sbin/ntpd/ntp.c +++ b/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.117 2011/09/21 15:41:30 phessler Exp $ */ +/* $OpenBSD: ntp.c,v 1.118 2013/09/28 12:18:05 phessler Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -618,18 +618,12 @@ priv_adjtime(void) qsort(offsets, offset_cnt, sizeof(struct ntp_offset *), offset_compare); i = offset_cnt / 2; - if (offset_cnt % 2 == 0) { - offset_median = - (offsets[i - 1]->offset + offsets[i]->offset) / 2; - conf->status.rootdelay = - (offsets[i - 1]->delay + offsets[i]->delay) / 2; - conf->status.stratum = MAX( - offsets[i - 1]->status.stratum, offsets[i]->status.stratum); - } else { - offset_median = offsets[i]->offset; - conf->status.rootdelay = offsets[i]->delay; - conf->status.stratum = offsets[i]->status.stratum; - } + if (offset_cnt % 2 == 0) + if (offsets[i - 1]->delay < offsets[i]->delay) + i -= 1; + offset_median = offsets[i]->offset; + conf->status.rootdelay = offsets[i]->delay; + conf->status.stratum = offsets[i]->status.stratum; conf->status.leap = offsets[i]->status.leap; imsg_compose(ibuf_main, IMSG_ADJTIME, 0, 0, -1, |