]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
refclock: require new samples to have newer timestamp
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 6 Oct 2016 13:21:43 +0000 (15:21 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 21 Nov 2016 11:02:51 +0000 (12:02 +0100)
If all or most SHM/SOCK samples collected in a polling interval had the
same local timestamp, the dispersion could end up as nan, which could
trigger an assert failure later in the code.

Before accumulating a refclock sample, check if the timestamp is newer
than the previous one.

refclock.c

index 7ee1468fa7ab07fe9686ae60872b305ac1d06e39..4439d9c263a05a1f4651cc10cfe824bec045baef 100644 (file)
@@ -505,16 +505,22 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
 static int
 valid_sample_time(RCL_Instance instance, struct timeval *tv)
 {
-  struct timeval raw_time;
-  double diff;
+  struct timeval raw_time, last_sample_time;
+  double diff, last_offset, last_dispersion;
 
   LCL_ReadRawTime(&raw_time);
   UTI_DiffTimevalsToDouble(&diff, &raw_time, tv);
-  if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1)) {
-    DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f tv=%s",
-        UTI_RefidToString(instance->ref_id), diff, UTI_TimevalToString(tv));
+
+  if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1) ||
+      (filter_get_last_sample(&instance->filter, &last_sample_time,
+                              &last_offset, &last_dispersion) &&
+       UTI_CompareTimevals(&last_sample_time, tv) >= 0)) {
+    DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f ts=%s lastts=%s",
+              UTI_RefidToString(instance->ref_id), diff,
+              UTI_TimevalToString(tv), UTI_TimevalToString(&last_sample_time));
     return 0;
   }
+
   return 1;
 }