ntp: suggest clients to increase their polling interval
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.
This commit is contained in:
parent
c5735ebfe9
commit
018a1c42b0
3 changed files with 21 additions and 2 deletions
13
clientlog.c
13
clientlog.c
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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. */
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue