]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: allow sub-second polling intervals
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 19 Jan 2017 09:31:58 +0000 (10:31 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 23 Jan 2017 14:58:55 +0000 (15:58 +0100)
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
ntp_core.c

index 3ea7287d7cc20e78ed2c49d24a446912c1fb5f7c..ddae1740ea4c41fe7551e853818a725376964110 100644 (file)
@@ -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
index 4a19f2983f9cc91b1aa04278a28e22cba556aa24..7055d6ce48251101743f7da66ba6c729b61b5f93 100644 (file)
@@ -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<<poll_to_use);
+          delay_time = UTI_Log2ToDouble(poll_to_use);
           if (inst->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<<poll_to_use);
+          delay_time = UTI_Log2ToDouble(poll_to_use);
 
           /* If the remote stratum is higher than ours, try to lock on the
              peer's polling to minimize our response time by slightly extending
@@ -1622,7 +1623,7 @@ receive_packet(NCR_Instance inst, NTP_Local_Address *local_addr,
             UTI_IPToString(&inst->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,