From 4d7eb2f7a66f99c8bd09d5e7b9d0d92159ce2c85 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 23 Nov 2016 12:45:11 +0100 Subject: [PATCH] ntp: don't reset polling interval when switching to/from online This allows chronyd to ramp up the polling interval even when the source is frequently switched between the online and offline modes. --- ntp_core.c | 11 ++++++++--- ntp_core.h | 3 +++ ntp_sources.c | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ntp_core.c b/ntp_core.c index e234499..b41affb 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -553,6 +553,7 @@ NCR_GetInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type, SourcePar result->tx_suspended = 1; result->opmode = params->online ? MD_ONLINE : MD_OFFLINE; result->local_poll = result->minpoll; + result->poll_score = 0.0; UTI_ZeroTimespec(&result->local_tx.ts); result->local_tx.err = 0.0; result->local_tx.source = NTP_TS_DAEMON; @@ -605,7 +606,6 @@ NCR_ResetInstance(NCR_Instance instance) instance->tx_count = 0; instance->presend_done = 0; - instance->poll_score = 0.0; instance->remote_poll = 0; instance->remote_stratum = 0; @@ -619,7 +619,13 @@ NCR_ResetInstance(NCR_Instance instance) UTI_ZeroTimespec(&instance->local_rx.ts); instance->local_rx.err = 0.0; instance->local_rx.source = NTP_TS_DAEMON; +} +/* ================================================== */ + +void +NCR_ResetPoll(NCR_Instance instance) +{ if (instance->local_poll != instance->minpoll) { instance->local_poll = instance->minpoll; @@ -634,9 +640,8 @@ NCR_ResetInstance(NCR_Instance instance) void NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr) { + NCR_ResetInstance(inst); inst->remote_addr = *remote_addr; - inst->tx_count = 0; - inst->presend_done = 0; if (inst->mode == MODE_CLIENT) close_client_socket(inst); diff --git a/ntp_core.h b/ntp_core.h index 4d0c214..699cb83 100644 --- a/ntp_core.h +++ b/ntp_core.h @@ -70,6 +70,9 @@ extern void NCR_StartInstance(NCR_Instance instance); /* Reset an instance */ extern void NCR_ResetInstance(NCR_Instance inst); +/* Reset polling interval of an instance */ +extern void NCR_ResetPoll(NCR_Instance instance); + /* Change the remote address of an instance */ extern void NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr); diff --git a/ntp_sources.c b/ntp_sources.c index 00f922b..835599f 100644 --- a/ntp_sources.c +++ b/ntp_sources.c @@ -851,6 +851,7 @@ slew_sources(struct timespec *raw, if (record->remote_addr) { if (change_type == LCL_ChangeUnknownStep) { NCR_ResetInstance(record->data); + NCR_ResetPoll(record->data); } else { NCR_SlewTimes(record->data, cooked, dfreq, doffset); }