]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: suggest clients to increase their polling interval
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 16 Jun 2017 10:16:17 +0000 (12:16 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 27 Jun 2017 13:29:01 +0000 (15:29 +0200)
When the poll value in a client request is smaller than the server's NTP
rate limiting interval, set poll in the response to the rate limiting
interval to suggest the client to increase its polling interval.

This follows ntpd as a server. No current client implementation seems to
be increasing its interval by the poll, but it may change in the future.

clientlog.c
clientlog.h
ntp_core.c

index 63d932e7b5f2f702c05b61fa8a0e24a5007f9d01..5288fa8d118ded5c61a11a3bf608468d81c7e157 100644 (file)
@@ -128,6 +128,9 @@ static int cmd_leak_rate;
 /* Flag indicating whether the last response was dropped */
 #define FLAG_NTP_DROPPED 0x1
 
+/* NTP limit interval in log2 */
+static int ntp_limit_interval;
+
 /* Flag indicating whether facility is turned on or not */
 static int active;
 
@@ -309,11 +312,13 @@ CLG_Initialise(void)
   ntp_tokens_per_packet = cmd_tokens_per_packet = 0;
   ntp_token_shift = cmd_token_shift = 0;
   ntp_leak_rate = cmd_leak_rate = 0;
+  ntp_limit_interval = MIN_LIMIT_INTERVAL;
 
   if (CNF_GetNTPRateLimit(&interval, &burst, &leak_rate)) {
     set_bucket_params(interval, burst, &max_ntp_tokens, &ntp_tokens_per_packet,
                       &ntp_token_shift);
     ntp_leak_rate = CLAMP(MIN_LEAK_RATE, leak_rate, MAX_LEAK_RATE);
+    ntp_limit_interval = CLAMP(MIN_LIMIT_INTERVAL, interval, MAX_LIMIT_INTERVAL);
   }
 
   if (CNF_GetCommandRateLimit(&interval, &burst, &leak_rate)) {
@@ -606,6 +611,14 @@ void CLG_GetNtpTimestamps(int index, NTP_int64 **rx_ts, NTP_int64 **tx_ts)
 
 /* ================================================== */
 
+int
+CLG_GetNtpMinPoll(void)
+{
+  return ntp_limit_interval;
+}
+
+/* ================================================== */
+
 int
 CLG_GetNumberOfIndices(void)
 {
index 337b4d8270b9359fa8ff7067193633cf879941b9..552c7671b1c552fc2b2926884fc0967858b0b8e9 100644 (file)
@@ -39,6 +39,7 @@ extern int CLG_LogCommandAccess(IPAddr *client, struct timespec *now);
 extern int CLG_LimitNTPResponseRate(int index);
 extern int CLG_LimitCommandResponseRate(int index);
 extern void CLG_GetNtpTimestamps(int index, NTP_int64 **rx_ts, NTP_int64 **tx_ts);
+extern int CLG_GetNtpMinPoll(void);
 
 /* And some reporting functions, for use by chronyc. */
 
index becb797cf144ed813620808bc4ce16a2e55f7042..fc63c68127e430c6a863808343761100d87b6bdb 100644 (file)
@@ -1860,7 +1860,7 @@ NCR_ProcessRxUnknown(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_a
   NTP_Mode pkt_mode, my_mode;
   NTP_int64 *local_ntp_rx, *local_ntp_tx;
   NTP_Local_Timestamp local_tx, *tx_ts;
-  int valid_auth, log_index, interleaved;
+  int valid_auth, log_index, interleaved, poll;
   AuthenticationMode auth_mode;
   uint32_t key_id;
 
@@ -1947,8 +1947,13 @@ NCR_ProcessRxUnknown(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_a
     }
   }
 
+  /* Suggest the client to increase its polling interval if it indicates
+     the interval is shorter than the rate limiting interval */
+  poll = CLG_GetNtpMinPoll();
+  poll = MAX(poll, message->poll);
+
   /* Send a reply */
-  transmit_packet(my_mode, interleaved, message->poll, NTP_LVM_TO_VERSION(message->lvm),
+  transmit_packet(my_mode, interleaved, poll, NTP_LVM_TO_VERSION(message->lvm),
                   auth_mode, key_id, &message->receive_ts, &message->transmit_ts,
                   rx_ts, tx_ts, local_ntp_rx, NULL, remote_addr, local_addr);