In the interleaved mode, the remote transmit timestamp of the previous
packet is corrected for the time corrections the source accumulated
since it was captured, as reported in the F323 field. That is right for
servers, which keep their transmit timestamps in the client log, but a
peer in the symmetric active mode slews its saved transmit timestamp
together with its clock. The correction was applied twice, making the
measured delay wrong by the correction and the offset by half of it.

Such a sample is usually rejected by the delay tests, but not if the
correction is comparable to the network delay.

Don't correct the transmit timestamp of packets from active peers.
Extend the 144-monoroot test to check the delay measured by a peer when
the other peer corrects its clock.

Fixes: 2319f72b29a9 ("ntp: add client support for experimental extension field")
---
 ntp_core.c                   |  7 ++++--
 test/simulation/144-monoroot | 41 ++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/ntp_core.c b/ntp_core.c
index 71e2576..49081d3 100644
--- a/ntp_core.c
+++ b/ntp_core.c
@@ -2096,7 +2096,9 @@ process_response(NCR_Instance inst, int saved, 
NTP_Local_Address *local_addr,
        It will correct old measurements kept in sourcestats before accumulating
        the new sample.  In the interleaved mode, cancel the correction out in
        remote timestamps of the previous request and response, which were
-       captured before the source accumulated the new time corrections. */
+       captured before the source accumulated the new time corrections.  A peer
+       in the symmetric active mode slews its saved transmit timestamp with its
+       clock, so the timestamp is already corrected when it is sent. */
     if (ef_mono_root && inst->remote_mono_epoch == 
ntohl(ef_mono_root->mono_epoch) &&
         !UTI_IsZeroNtp64(&ef_mono_root->mono_receive_ts) &&
         !UTI_IsZeroNtp64(&inst->remote_ntp_monorx)) {
@@ -2139,7 +2141,8 @@ process_response(NCR_Instance inst, int saved, 
NTP_Local_Address *local_addr,
         root_dispersion = MAX(pkt_root_dispersion, 
inst->remote_root_dispersion);
       }
       UTI_Ntp64ToTimespec(&message->transmit_ts, &remote_transmit);
-      UTI_AddDoubleToTimespec(&remote_transmit, -mono_doffset, 
&remote_transmit);
+      if (NTP_LVM_TO_MODE(message->lvm) != MODE_ACTIVE)
+        UTI_AddDoubleToTimespec(&remote_transmit, -mono_doffset, 
&remote_transmit);
       UTI_Ntp64ToTimespec(&inst->remote_ntp_tx, &prev_remote_transmit);
       local_receive = inst->local_rx;
     } else {
diff --git a/test/simulation/144-monoroot b/test/simulation/144-monoroot
index d97f30d..c8f0991 100755
--- a/test/simulation/144-monoroot
+++ b/test/simulation/144-monoroot
@@ -52,4 +52,45 @@ for lpoll in 5 6 7; do
        done
 done
 
+# Two peers in the interleaved mode, the second one reaching only the first
+# one.  A small offset correction of the primary server makes the first peer
+# correct its clock by an amount comparable to the network delay, which should
+# not change the delay measured by the second peer.
+clients=2
+peers=2
+limit=4000
+jitter=1e-6
+base_delay=$(cat <<-EOF | tr -d '\n'
+       (+ 1e-3
+          (* -1
+             (+ (* (equal 0.1 from 1) (equal 0.1 to 3))
+                (* (equal 0.1 from 3) (equal 0.1 to 1)))))
+EOF
+)
+primary_time_offset=1e-4
+chronyc_conf="doffset 1e-4"
+client_server_options="minpoll 6 maxpoll 6 xleave extfield F323"
+client_peer_options="minpoll 6 maxpoll 6 xleave extfield F323"
+client_lpeer_options=""
+client_rpeer_options=""
+client_conf="logdir tmp
+log measurements"
+min_sync_time=1
+max_sync_time=1000
+
+run_test || test_fail
+check_chronyd_exit || test_fail
+check_sync || test_fail
+
+test_message 2 1 "checking peer delay:"
+max_delay=$(awk -v peer=$(get_node_name 2) '
+       $3 == peer {
+               split($2, hms, ":")
+               if (hms[1] * 3600 + hms[2] * 60 + hms[3] > 1000 && $13 > max)
+                       max = $13
+       }
+       END { printf "%e\n", max }' tmp/measurements.log)
+test_message 3 0 "$(printf '%.3e' $max_delay)"
+check_stat $max_delay 2e-3 2.02e-3 && test_ok || test_bad || test_fail
+
 test_pass

base-commit: c97d8083cf9a9edc64d53236565916d326d8a109
-- 
2.43.0


-- 
To unsubscribe email [email protected] with "unsubscribe" 
in the subject.
For help email [email protected] with "help" in the 
subject.
Trouble?  Email [email protected].

Reply via email to