From f907cc16206f8601d4d7e6f55bbd97d9e79828f3 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 5 Nov 2017 15:39:34 +0900 Subject: [PATCH] timesync: add RootDistanceMaxSec= to timesyncd.conf (#7215) Closes #7211. --- man/timesyncd.conf.xml | 6 ++++++ src/timesync/timesyncd-gperf.gperf | 7 ++++--- src/timesync/timesyncd-manager.c | 8 +++++--- src/timesync/timesyncd-manager.h | 1 + src/timesync/timesyncd.conf.in | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/man/timesyncd.conf.xml b/man/timesyncd.conf.xml index 7c84e80..eb78d7b 100644 --- a/man/timesyncd.conf.xml +++ b/man/timesyncd.conf.xml @@ -101,6 +101,12 @@ is used instead. + + RootDistanceMaxSec= + Maximum acceptable root distance in seconds. + Defaults to 5 seconds. + + diff --git a/src/timesync/timesyncd-gperf.gperf b/src/timesync/timesyncd-gperf.gperf index 29a2cfe..65fae9f 100644 --- a/src/timesync/timesyncd-gperf.gperf +++ b/src/timesync/timesyncd-gperf.gperf @@ -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) diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index eacb10f..e58d819 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -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); diff --git a/src/timesync/timesyncd-manager.h b/src/timesync/timesyncd-manager.h index cf681f6..7550e82 100644 --- a/src/timesync/timesyncd-manager.h +++ b/src/timesync/timesyncd-manager.h @@ -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; diff --git a/src/timesync/timesyncd.conf.in b/src/timesync/timesyncd.conf.in index b6a2ada..2b3c476 100644 --- a/src/timesync/timesyncd.conf.in +++ b/src/timesync/timesyncd.conf.in @@ -14,3 +14,4 @@ [Time] #NTP= #FallbackNTP=@NTP_SERVERS@ +#RootDistanceMaxSec=5 -- 2.7.4