diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 612bc00..6b65445 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -115,8 +115,7 @@ round-trip delay of 0.3 seconds or more should be ignored. The default value is This option is similar to the maxdelay option above. *chronyd* keeps a record of the minimum round-trip delay amongst the previous measurements that it has buffered. If a measurement has a round trip delay that is greater than the -maxdelayratio times the minimum delay, it will be rejected. This option does -not work in the *peer* directive. +maxdelayratio times the minimum delay, it will be rejected. *maxdelaydevratio* _ratio_::: If a measurement has a ratio of the increase in the round-trip delay from the minimum delay amongst the previous measurements to the standard deviation of diff --git a/ntp_core.c b/ntp_core.c index af47516..d73111f 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -1325,6 +1325,30 @@ check_packet_auth(NTP_Packet *pkt, int length, /* ================================================== */ +static int +check_delay_ratio(NCR_Instance inst, SST_Stats stats, + struct timespec *sample_time, double delay) +{ + double last_sample_ago, predicted_offset, min_delay, skew, std_dev; + double max_delay; + + if (inst->max_delay_ratio < 1.0 || + !SST_GetDelayTestData(stats, sample_time, &last_sample_ago, + &predicted_offset, &min_delay, &skew, &std_dev)) + return 1; + + max_delay = min_delay * inst->max_delay_ratio + + last_sample_ago * (skew + LCL_GetMaxClockError()); + + if (delay <= max_delay) + return 1; + + DEBUG_LOG("maxdelayratio: delay=%e max_delay=%e", delay, max_delay); + return 0; +} + +/* ================================================== */ + static int check_delay_dev_ratio(NCR_Instance inst, SST_Stats stats, struct timespec *sample_time, double offset, double delay) @@ -1582,9 +1606,7 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr, /* Test B requires in client mode that the ratio of the round trip delay to the minimum one currently in the stats data register is less than an administrator-defined value */ - testB = inst->max_delay_ratio <= 1.0 || - !(inst->mode == MODE_CLIENT && - (delay - dispersion) / SST_MinRoundTripDelay(stats) > inst->max_delay_ratio); + testB = check_delay_ratio(inst, stats, &sample_time, delay); /* Test C requires that the ratio of the increase in delay from the minimum one in the stats data register to the standard deviation of the offsets diff --git a/test/simulation/118-maxdelay b/test/simulation/118-maxdelay index 18fcdfa..22b9a50 100755 --- a/test/simulation/118-maxdelay +++ b/test/simulation/118-maxdelay @@ -18,7 +18,7 @@ check_source_selection || test_fail check_packet_interval || test_fail check_sync || test_fail -for client_server_options in "maxpoll 6 maxdelay 2e-5" "maxpoll 6 maxdelayratio 1.001"; do +for client_server_options in "maxpoll 6 maxdelay 2e-5"; do run_test || test_fail check_chronyd_exit || test_fail check_packet_interval || test_fail