]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: add offset option
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 28 Jun 2016 13:27:44 +0000 (15:27 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 28 Jun 2016 13:40:58 +0000 (15:40 +0200)
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.

client.c
cmdparse.c
doc/chrony.conf.adoc
ntp_core.c
srcparams.h

index d3494f20b007dc8a90302ad6bccc780f95d86229..8050b90cba62e5487b2a635be08d344048236594 100644 (file)
--- 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)
index e358b444220d2e8bbc21b0f68f62100cbe49e6c9..121a0454fe6955e08b700b10466ca493691927c0 100644 (file)
@@ -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;
index 5fb68a33327f8b45696a1070e446009af313c2a1..fcfefdb61544c5b4e16361ff84f48fce9714e73e 100644 (file)
@@ -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
 <<minsamples,*minsamples*>> directive.
index 79426937d405cfa796fc523da9966d4f5378f54f..fe894f9d430412966b0f52c4e8e7a4733ceaacd0 100644 (file)
@@ -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
index 42a1555b0c9c3d509ef89609515bc70c642b9552..6714fe7f4a8eaeba1fe54622a9c3f2588e3affd6 100644 (file)
@@ -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