mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 18:05:06 -05:00
samplefilt: check for non-increasing sample times
Adopt the check from the refclock code to check also samples from NTP.
This commit is contained in:
24
samplefilt.c
24
samplefilt.c
@@ -102,9 +102,30 @@ SPF_DestroyInstance(SPF_Instance filter)
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
/* Check that samples times are strictly increasing */
|
||||
|
||||
static int
|
||||
check_sample(SPF_Instance filter, NTP_Sample *sample)
|
||||
{
|
||||
if (filter->used <= 0)
|
||||
return 1;
|
||||
|
||||
if (UTI_CompareTimespecs(&filter->samples[filter->last].time, &sample->time) >= 0) {
|
||||
DEBUG_LOG("filter non-increasing sample time %s", UTI_TimespecToString(&sample->time));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
SPF_AccumulateSample(SPF_Instance filter, NTP_Sample *sample)
|
||||
{
|
||||
if (!check_sample(filter, sample))
|
||||
return 0;
|
||||
|
||||
filter->index++;
|
||||
filter->index %= filter->max_samples;
|
||||
filter->last = filter->index;
|
||||
@@ -116,6 +137,7 @@ SPF_AccumulateSample(SPF_Instance filter, NTP_Sample *sample)
|
||||
DEBUG_LOG("filter sample %d t=%s offset=%.9f peer_disp=%.9f",
|
||||
filter->index, UTI_TimespecToString(&sample->time),
|
||||
sample->offset, sample->peer_dispersion);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
Reference in New Issue
Block a user