From beaaaad16243140d50138f0b9d51cf73ed013b60 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 19 Jan 2017 10:31:58 +0100 Subject: [PATCH] ntp: allow sub-second polling intervals Change the minimum minpoll to -4, but keep the minimum maxpoll at 0 in order to not make it too easy to flood distant servers. --- doc/chrony.conf.adoc | 8 ++++++-- ntp_core.c | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 3ea7287..ddae174 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -68,11 +68,15 @@ options: Although *chronyd* will trim the rate at which it samples the server during normal operation, the user might want to constrain the minimum polling interval. This is always defined as a power of 2, so *minpoll 5* would mean that the -polling interval cannot drop below 32 seconds. The default is 6 (64 seconds). +polling interval cannot drop below 32 seconds. The default is 6 (64 seconds), +the minimum is -4 (1/16th of a second), and the maximum is 24 (6 months). Note +that intervals shorter than 6 (64 seconds) should generally not be used with +public servers on the Internet as their administrators may consider it abuse. *maxpoll* _poll_::: In a similar way, the user might want to constrain the maximum polling interval. Again this is specified as a power of 2, *maxpoll 9* indicates that the polling -interval must stay at or below 512 seconds. The default is 10 (1024 seconds). +interval must stay at or below 512 seconds. The default is 10 (1024 seconds), +the minimum is 0 (1 second), and the maximum is 24 (6 months). *iburst*::: If this option is set, the interval between the first four polls will be 2 seconds instead of _minpoll_. This is useful to quickly get the first update of diff --git a/ntp_core.c b/ntp_core.c index 4a19f29..7055d6c 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -249,7 +249,8 @@ static ARR_Instance broadcasts; #define MAX_MAXDELAYDEVRATIO 1.0e6 /* Minimum and maximum allowed poll interval */ -#define MIN_POLL 0 +#define MIN_MINPOLL -4 +#define MIN_MAXPOLL 0 #define MAX_POLL 24 /* Kiss-o'-Death codes */ @@ -497,12 +498,12 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar result->interleaved = params->interleaved; result->minpoll = params->minpoll; - if (result->minpoll < MIN_POLL) + if (result->minpoll < MIN_MINPOLL) result->minpoll = SRC_DEFAULT_MINPOLL; else if (result->minpoll > MAX_POLL) result->minpoll = MAX_POLL; result->maxpoll = params->maxpoll; - if (result->maxpoll < MIN_POLL) + if (result->maxpoll < MIN_MAXPOLL) result->maxpoll = SRC_DEFAULT_MAXPOLL; else if (result->maxpoll > MAX_POLL) result->maxpoll = MAX_POLL; @@ -765,7 +766,7 @@ get_transmit_delay(NCR_Instance inst, int on_tx, double last_tx) approx the poll interval away */ poll_to_use = inst->local_poll; - delay_time = (double) (1UL<presend_done) delay_time = WARM_UP_DELAY; @@ -783,7 +784,7 @@ get_transmit_delay(NCR_Instance inst, int on_tx, double last_tx) if (poll_to_use < inst->minpoll) poll_to_use = inst->minpoll; - delay_time = (double) (1UL<remote_addr.ip_addr)); /* Back off for a while and stop ongoing burst */ - delay_time += 4 * (1UL << inst->local_poll); + delay_time += 4 * UTI_Log2ToDouble(inst->local_poll); if (inst->opmode == MD_BURST_WAS_OFFLINE || inst->opmode == MD_BURST_WAS_ONLINE) { inst->burst_good_samples_to_go = 0; @@ -2092,7 +2093,7 @@ NCR_TakeSourceOffline(NCR_Instance inst) void NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll) { - if (new_minpoll < MIN_POLL || new_minpoll > MAX_POLL) + if (new_minpoll < MIN_MINPOLL || new_minpoll > MAX_POLL) return; inst->minpoll = new_minpoll; LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new minpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), new_minpoll); @@ -2105,7 +2106,7 @@ NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll) void NCR_ModifyMaxpoll(NCR_Instance inst, int new_maxpoll) { - if (new_maxpoll < MIN_POLL || new_maxpoll > MAX_POLL) + if (new_maxpoll < MIN_MAXPOLL || new_maxpoll > MAX_POLL) return; inst->maxpoll = new_maxpoll; LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new maxpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), new_maxpoll); @@ -2374,7 +2375,7 @@ NCR_AddBroadcastDestination(IPAddr *addr, unsigned short port, int interval) destination->addr.port = port; destination->local_addr.ip_addr.family = IPADDR_UNSPEC; destination->local_addr.sock_fd = NIO_OpenServerSocket(&destination->addr); - destination->interval = CLAMP(1 << MIN_POLL, interval, 1 << MAX_POLL); + destination->interval = CLAMP(1, interval, 1 << MAX_POLL); SCH_AddTimeoutInClass(destination->interval, SAMPLING_SEPARATION, SAMPLING_RANDOMNESS, SCH_NtpBroadcastClass, broadcast_timeout,