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.
This commit is contained in:
Miroslav Lichvar 2017-01-19 10:31:58 +01:00
parent 4e78975909
commit beaaaad162
2 changed files with 16 additions and 11 deletions

View file

@ -68,11 +68,15 @@ options:
Although *chronyd* will trim the rate at which it samples the server during 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. 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 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_::: *maxpoll* _poll_:::
In a similar way, the user might want to constrain the maximum polling interval. 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 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*::: *iburst*:::
If this option is set, the interval between the first four polls will be 2 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 seconds instead of _minpoll_. This is useful to quickly get the first update of

View file

@ -249,7 +249,8 @@ static ARR_Instance broadcasts;
#define MAX_MAXDELAYDEVRATIO 1.0e6 #define MAX_MAXDELAYDEVRATIO 1.0e6
/* Minimum and maximum allowed poll interval */ /* Minimum and maximum allowed poll interval */
#define MIN_POLL 0 #define MIN_MINPOLL -4
#define MIN_MAXPOLL 0
#define MAX_POLL 24 #define MAX_POLL 24
/* Kiss-o'-Death codes */ /* 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->interleaved = params->interleaved;
result->minpoll = params->minpoll; result->minpoll = params->minpoll;
if (result->minpoll < MIN_POLL) if (result->minpoll < MIN_MINPOLL)
result->minpoll = SRC_DEFAULT_MINPOLL; result->minpoll = SRC_DEFAULT_MINPOLL;
else if (result->minpoll > MAX_POLL) else if (result->minpoll > MAX_POLL)
result->minpoll = MAX_POLL; result->minpoll = MAX_POLL;
result->maxpoll = params->maxpoll; result->maxpoll = params->maxpoll;
if (result->maxpoll < MIN_POLL) if (result->maxpoll < MIN_MAXPOLL)
result->maxpoll = SRC_DEFAULT_MAXPOLL; result->maxpoll = SRC_DEFAULT_MAXPOLL;
else if (result->maxpoll > MAX_POLL) else if (result->maxpoll > MAX_POLL)
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 */ approx the poll interval away */
poll_to_use = inst->local_poll; poll_to_use = inst->local_poll;
delay_time = (double) (1UL<<poll_to_use); delay_time = UTI_Log2ToDouble(poll_to_use);
if (inst->presend_done) if (inst->presend_done)
delay_time = WARM_UP_DELAY; 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) if (poll_to_use < inst->minpoll)
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 /* If the remote stratum is higher than ours, try to lock on the
peer's polling to minimize our response time by slightly extending 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)); UTI_IPToString(&inst->remote_addr.ip_addr));
/* Back off for a while and stop ongoing burst */ /* 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) { if (inst->opmode == MD_BURST_WAS_OFFLINE || inst->opmode == MD_BURST_WAS_ONLINE) {
inst->burst_good_samples_to_go = 0; inst->burst_good_samples_to_go = 0;
@ -2092,7 +2093,7 @@ NCR_TakeSourceOffline(NCR_Instance inst)
void void
NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll) 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; return;
inst->minpoll = new_minpoll; inst->minpoll = new_minpoll;
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new minpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), 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 void
NCR_ModifyMaxpoll(NCR_Instance inst, int new_maxpoll) 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; return;
inst->maxpoll = new_maxpoll; inst->maxpoll = new_maxpoll;
LOG(LOGS_INFO, LOGF_NtpCore, "Source %s new maxpoll %d", UTI_IPToString(&inst->remote_addr.ip_addr), 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->addr.port = port;
destination->local_addr.ip_addr.family = IPADDR_UNSPEC; destination->local_addr.ip_addr.family = IPADDR_UNSPEC;
destination->local_addr.sock_fd = NIO_OpenServerSocket(&destination->addr); 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_AddTimeoutInClass(destination->interval, SAMPLING_SEPARATION, SAMPLING_RANDOMNESS,
SCH_NtpBroadcastClass, broadcast_timeout, SCH_NtpBroadcastClass, broadcast_timeout,