timesync: add RootDistanceMaxSec= to timesyncd.conf (#7215)
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 5 Nov 2017 06:39:34 +0000 (15:39 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 5 Nov 2017 06:39:34 +0000 (07:39 +0100)
Closes #7211.

man/timesyncd.conf.xml
src/timesync/timesyncd-gperf.gperf
src/timesync/timesyncd-manager.c
src/timesync/timesyncd-manager.h
src/timesync/timesyncd.conf.in

index 7c84e80..eb78d7b 100644 (file)
         is used instead.</para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><varname>RootDistanceMaxSec=</varname></term>
+        <listitem><para>Maximum acceptable root distance in seconds.
+        Defaults to 5 seconds.</para></listitem>
+      </varlistentry>
+
     </variablelist>
   </refsect1>
 
index 29a2cfe..65fae9f 100644 (file)
@@ -14,6 +14,7 @@ struct ConfigPerfItem;
 %struct-type
 %includes
 %%
-Time.NTP,           config_parse_servers, SERVER_SYSTEM,   0
-Time.Servers,       config_parse_servers, SERVER_SYSTEM,   0
-Time.FallbackNTP,   config_parse_servers, SERVER_FALLBACK, 0
+Time.NTP,                 config_parse_servers, SERVER_SYSTEM,   0
+Time.Servers,             config_parse_servers, SERVER_SYSTEM,   0
+Time.FallbackNTP,         config_parse_servers, SERVER_FALLBACK, 0
+Time.RootDistanceMaxSec,  config_parse_sec,     0,               offsetof(Manager, max_root_distance_usec)
index eacb10f..e58d819 100644 (file)
@@ -80,8 +80,8 @@
 #define NTP_FIELD_MODE(f)               ((f) & 7)
 #define NTP_FIELD(l, v, m)              (((l) << 6) | ((v) << 3) | (m))
 
-/* Maximum acceptable root distance in seconds. */
-#define NTP_MAX_ROOT_DISTANCE           5.0
+/* Maximum acceptable root distance in microseconds. */
+#define NTP_MAX_ROOT_DISTANCE           (5 * USEC_PER_SEC)
 
 /* Maximum number of missed replies before selecting another source. */
 #define NTP_MAX_MISSED_REPLIES          2
@@ -588,7 +588,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
         }
 
         root_distance = ntp_ts_short_to_d(&ntpmsg.root_delay) / 2 + ntp_ts_short_to_d(&ntpmsg.root_dispersion);
-        if (root_distance > NTP_MAX_ROOT_DISTANCE) {
+        if (root_distance > (double) m->max_root_distance_usec / (double) USEC_PER_SEC) {
                 log_debug("Server has too large root distance. Disconnecting.");
                 return manager_connect(m);
         }
@@ -1124,6 +1124,8 @@ int manager_new(Manager **ret) {
         if (!m)
                 return -ENOMEM;
 
+        m->max_root_distance_usec = NTP_MAX_ROOT_DISTANCE;
+
         m->server_socket = m->clock_watch_fd = -1;
 
         RATELIMIT_INIT(m->ratelimit, RATELIMIT_INTERVAL_USEC, RATELIMIT_BURST);
index cf681f6..7550e82 100644 (file)
@@ -76,6 +76,7 @@ struct Manager {
         } samples[8];
         unsigned int samples_idx;
         double samples_jitter;
+        usec_t max_root_distance_usec;
 
         /* last change */
         bool jumped;
index b6a2ada..2b3c476 100644 (file)
@@ -14,3 +14,4 @@
 [Time]
 #NTP=
 #FallbackNTP=@NTP_SERVERS@
+#RootDistanceMaxSec=5