diff --git a/conf.c b/conf.c index d0f002c..a5e2d25 100644 --- a/conf.c +++ b/conf.c @@ -1771,11 +1771,10 @@ CNF_AddInitSources(void) /* Get the default NTP params */ CPS_ParseNTPSourceAdd(dummy_hostname, &cps_source); - /* Add the address as an offline iburst server */ + /* Add the address as a server specified with the iburst option */ ntp_addr.ip_addr = *(IPAddr *)ARR_GetElement(init_sources, i); ntp_addr.port = cps_source.port; cps_source.params.iburst = 1; - cps_source.params.connectivity = SRC_OFFLINE; NSR_AddSource(&ntp_addr, NTP_SERVER, &cps_source.params, NULL); } diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 0f4d74c..5658af0 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -82,13 +82,13 @@ interval should stay at or below 9 (512 seconds). The default is 10 (1024 seconds), the minimum is -6 (1/64th of a second), and the maximum is 24 (6 months). *iburst*::: -With this option, the interval between the first four requests sent to the -server will be 2 seconds or less instead of the interval specified by the -*minpoll* option, which allows *chronyd* to make the first update of the clock -shortly after start. +With this option, *chronyd* will start with a burst of 4-8 requests in order to +make the first update of the clock sooner. It will also repeat the burst every +time the source is switched from the offline state to online with the +<> command in *chronyc*. *burst*::: -With this option, *chronyd* will shorten the interval between up to four -requests to 2 seconds or less when it cannot get a good measurement from the +With this option, *chronyd* will send a burst of up to 4 requests when it +cannot get a good measurement from the server. The number of requests in the burst is limited by the current polling interval to keep the average interval at or above the minimum interval, i.e. the current interval needs to be at least two times longer than the minimum diff --git a/ntp_core.c b/ntp_core.c index 53c9ae1..e71c93f 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -78,6 +78,7 @@ struct NCR_Instance_Record { SCH_TimeoutID tx_timeout_id; /* Timeout ID for next transmission */ int tx_suspended; /* Boolean indicating we can't transmit yet */ + int auto_iburst; /* If 1, initiate a burst when going online */ int auto_burst; /* If 1, initiate a burst on each poll */ int auto_offline; /* If 1, automatically go offline when requests cannot be sent */ @@ -297,6 +298,7 @@ static void transmit_timeout(void *arg); static double get_transmit_delay(NCR_Instance inst, int on_tx, double last_tx); static double get_separation(int poll); static int parse_packet(NTP_Packet *packet, int length, NTP_PacketInfo *info); +static void set_connectivity(NCR_Instance inst, SRC_Connectivity connectivity); /* ================================================== */ @@ -555,6 +557,7 @@ NCR_CreateInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, result->max_delay_ratio = CLAMP(0.0, params->max_delay_ratio, MAX_MAXDELAYRATIO); result->max_delay_dev_ratio = CLAMP(0.0, params->max_delay_dev_ratio, MAX_MAXDELAYDEVRATIO); result->offset_correction = params->offset; + result->auto_iburst = params->iburst; result->auto_burst = params->burst; result->auto_offline = params->auto_offline; result->poll_target = params->poll_target; @@ -596,9 +599,7 @@ NCR_CreateInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, result->rx_timeout_id = 0; result->tx_timeout_id = 0; result->tx_suspended = 1; - result->opmode = params->connectivity == SRC_ONLINE || - (params->connectivity == SRC_MAYBE_ONLINE && - NIO_IsServerConnectable(remote_addr)) ? MD_ONLINE : MD_OFFLINE; + result->opmode = MD_OFFLINE; result->local_poll = result->minpoll; result->poll_score = 0.0; zero_local_timestamp(&result->local_tx); @@ -608,9 +609,7 @@ NCR_CreateInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, NCR_ResetInstance(result); - if (params->iburst) { - NCR_InitiateSampleBurst(result, IBURST_GOOD_SAMPLES, IBURST_TOTAL_SAMPLES); - } + set_connectivity(result, params->connectivity); return result; } @@ -2257,13 +2256,9 @@ NCR_SlewTimes(NCR_Instance inst, struct timespec *when, double dfreq, double dof /* ================================================== */ -void -NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity) +static void +set_connectivity(NCR_Instance inst, SRC_Connectivity connectivity) { - char *s; - - s = UTI_IPToString(&inst->remote_addr.ip_addr); - if (connectivity == SRC_MAYBE_ONLINE) connectivity = NIO_IsServerConnectable(&inst->remote_addr) ? SRC_ONLINE : SRC_OFFLINE; @@ -2274,17 +2269,17 @@ NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity) /* Nothing to do */ break; case MD_OFFLINE: - LOG(LOGS_INFO, "Source %s online", s); inst->opmode = MD_ONLINE; NCR_ResetInstance(inst); start_initial_timeout(inst); + if (inst->auto_iburst) + NCR_InitiateSampleBurst(inst, IBURST_GOOD_SAMPLES, IBURST_TOTAL_SAMPLES); break; case MD_BURST_WAS_ONLINE: /* Will revert */ break; case MD_BURST_WAS_OFFLINE: inst->opmode = MD_BURST_WAS_ONLINE; - LOG(LOGS_INFO, "Source %s online", s); break; default: assert(0); @@ -2293,14 +2288,12 @@ NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity) case SRC_OFFLINE: switch (inst->opmode) { case MD_ONLINE: - LOG(LOGS_INFO, "Source %s offline", s); take_offline(inst); break; case MD_OFFLINE: break; case MD_BURST_WAS_ONLINE: inst->opmode = MD_BURST_WAS_OFFLINE; - LOG(LOGS_INFO, "Source %s offline", s); break; case MD_BURST_WAS_OFFLINE: break; @@ -2315,6 +2308,26 @@ NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity) /* ================================================== */ +void +NCR_SetConnectivity(NCR_Instance inst, SRC_Connectivity connectivity) +{ + OperatingMode prev_opmode; + int was_online, is_online; + + prev_opmode = inst->opmode; + + set_connectivity(inst, connectivity); + + /* Report an important change */ + was_online = prev_opmode == MD_ONLINE || prev_opmode == MD_BURST_WAS_ONLINE; + is_online = inst->opmode == MD_ONLINE || inst->opmode == MD_BURST_WAS_ONLINE; + if (was_online != is_online) + LOG(LOGS_INFO, "Source %s %s", + UTI_IPToString(&inst->remote_addr.ip_addr), is_online ? "online" : "offline"); +} + +/* ================================================== */ + void NCR_ModifyMinpoll(NCR_Instance inst, int new_minpoll) { diff --git a/sources.c b/sources.c index 9fc5a0e..91d6a08 100644 --- a/sources.c +++ b/sources.c @@ -439,7 +439,7 @@ special_mode_end(void) if (!sources[i]->active) continue; - /* Don't expect more updates than from an offline iburst NTP source */ + /* Don't expect more updates than the initial burst of an NTP source */ if (sources[i]->reachability_size >= SOURCE_REACH_BITS - 1) continue;