mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 16:35:06 -05:00
manual: check offset sanity
This commit is contained in:
26
manual.c
26
manual.c
@@ -54,6 +54,8 @@ typedef struct {
|
||||
(measured-predicted)) */
|
||||
} Sample;
|
||||
|
||||
#define MIN_SAMPLE_SEPARATION 1.0
|
||||
|
||||
#define MAX_SAMPLES 16
|
||||
|
||||
static Sample samples[16];
|
||||
@@ -174,14 +176,24 @@ int
|
||||
MNL_AcceptTimestamp(struct timeval *ts, long *offset_cs, double *dfreq_ppm, double *new_afreq_ppm)
|
||||
{
|
||||
struct timeval now;
|
||||
double offset;
|
||||
double offset, diff;
|
||||
int i;
|
||||
|
||||
if (enabled) {
|
||||
|
||||
/* Check whether timestamp is within margin of old one */
|
||||
LCL_ReadCookedTime(&now, NULL);
|
||||
|
||||
/* Make sure the provided timestamp is sane and the sample
|
||||
is not too close to the last one */
|
||||
|
||||
if (!UTI_IsTimeOffsetSane(ts, 0.0))
|
||||
return 0;
|
||||
|
||||
if (n_samples) {
|
||||
UTI_DiffTimevalsToDouble(&diff, &now, &samples[n_samples - 1].when);
|
||||
if (diff < MIN_SAMPLE_SEPARATION)
|
||||
return 0;
|
||||
}
|
||||
|
||||
UTI_DiffTimevalsToDouble(&offset, &now, ts);
|
||||
|
||||
/* Check if buffer full up */
|
||||
@@ -258,6 +270,14 @@ MNL_Reset(void)
|
||||
n_samples = 0;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
MNL_IsEnabled(void)
|
||||
{
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
/* Generate report data for the REQ_MANUAL_LIST command/monitoring
|
||||
protocol */
|
||||
|
||||
Reference in New Issue
Block a user