From 9d257760caa4db42e79e726075fef9c7cb9ed40a Mon Sep 17 00:00:00 2001 From: phessler <> Date: Sat, 28 Sep 2013 12:18:05 +0000 Subject: [PATCH] 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 (many thanks!) OK phessler@, henning@ --- src/usr.sbin/ntpd/ntp.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c index 23713fc5..3f85e252 100644 --- a/src/usr.sbin/ntpd/ntp.c +++ b/src/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 @@ -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,