From: Miroslav Lichvar Date: Tue, 28 Jun 2016 13:27:44 +0000 (+0200) Subject: ntp: add offset option X-Git-Tag: 3.0-pre1~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6cd558398ae7a6742eb6db0e8acf6e312071d890;p=thirdparty%2Fchrony.git ntp: add offset option Add offset option to the server/pool/peer directive. It specifies a correction which will be applied to offsets measured with the NTP source. It's particularly useful to compensate for a known asymmetry in network delay or timestamping errors. --- diff --git a/client.c b/client.c index d3494f20..8050b90c 100644 --- a/client.c +++ b/client.c @@ -1083,6 +1083,8 @@ process_cmd_add_server_or_peer(CMD_Request *msg, char *line) opt_name = "maxsources"; else if (data.params.min_stratum != SRC_DEFAULT_MINSTRATUM) opt_name = "minstratum"; + else if (data.params.offset != 0.0) + opt_name = "offset"; else if (data.params.poll_target != SRC_DEFAULT_POLLTARGET) opt_name = "polltarget"; else if (data.params.version != NTP_VERSION) diff --git a/cmdparse.c b/cmdparse.c index e358b444..121a0454 100644 --- a/cmdparse.c +++ b/cmdparse.c @@ -63,6 +63,7 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src) src->params.max_delay = SRC_DEFAULT_MAXDELAY; src->params.max_delay_ratio = SRC_DEFAULT_MAXDELAYRATIO; src->params.max_delay_dev_ratio = SRC_DEFAULT_MAXDELAYDEVRATIO; + src->params.offset = 0.0; hostname = line; line = CPS_SplitWord(line); @@ -123,6 +124,9 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src) } else if (!strcasecmp(cmd, "minstratum")) { if (sscanf(line, "%d%n", &src->params.min_stratum, &n) != 1) return 0; + } else if (!strcasecmp(cmd, "offset")) { + if (sscanf(line, "%lf%n", &src->params.offset, &n) != 1) + return 0; } else if (!strcasecmp(cmd, "port")) { if (sscanf(line, "%hu%n", &src->port, &n) != 1) return 0; diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 5fb68a33..fcfefdb6 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -116,6 +116,13 @@ 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 the previous measurements that is greater than the specified ratio, it will be rejected. The default is 10.0. +*offset* _offset_::: +This option specifies a correction (in seconds) which will be applied to +offsets measured with this source. It's particularly useful to compensate for a +known asymmetry in network delay or timestamping errors. For example, if +packets sent to the source were on average delayed by 100 microseconds more +than packets sent from the source back, the correction would be -0.00005 (-50 +microseconds). The default is 0.0. *minsamples* _samples_::: Set the minimum number of samples kept for this source. This overrides the <> directive. diff --git a/ntp_core.c b/ntp_core.c index 79426937..fe894f9d 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -119,6 +119,9 @@ struct NCR_Instance_Record { double max_delay_dev_ratio; /* Maximum ratio of increase in delay / stddev */ + double offset_correction; /* Correction applied to measured offset + (e.g. for asymmetry in network delay) */ + int do_auth; /* Flag indicating whether we authenticate packets we send to this machine (if it's serving us or @@ -481,6 +484,7 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar result->max_delay = params->max_delay; result->max_delay_ratio = params->max_delay_ratio; result->max_delay_dev_ratio = params->max_delay_dev_ratio; + result->offset_correction = params->offset; result->auto_offline = params->auto_offline; result->poll_target = params->poll_target; @@ -1310,7 +1314,10 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins /* Calculate offset. Following the NTP definition, this is negative if we are fast of the remote source. */ UTI_DiffTimevalsToDouble(&offset, &remote_average, &local_average); - + + /* Apply configured correction */ + offset += inst->offset_correction; + /* We treat the time of the sample as being midway through the local measurement period. An analysis assuming constant relative frequency and zero network delay shows this is the only possible diff --git a/srcparams.h b/srcparams.h index 42a1555b..6714fe7f 100644 --- a/srcparams.h +++ b/srcparams.h @@ -47,6 +47,7 @@ typedef struct { double max_delay; double max_delay_ratio; double max_delay_dev_ratio; + double offset; } SourceParameters; #define SRC_DEFAULT_PORT 123