From 6a79771898e518cf98242d56084f1db26ecca73e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 1 Dec 2021 09:11:09 +0100 Subject: [PATCH] ntp: check for zero timestamp in initial TX timeout Calculate the delay since the previous transmission only if the TX timestamp is actually set. This removes an unnecessary delay when starting at the Unix epoch in 1970 (e.g. in a test). --- ntp_core.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ntp_core.c b/ntp_core.c index 2cffd6c..6c3ba76 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -493,11 +493,16 @@ start_initial_timeout(NCR_Instance inst) /* In case the offline period was too short, adjust the delay to keep the interval between packets at least as long as the current polling interval */ - SCH_GetLastEventTime(&now, NULL, NULL); - last_tx = UTI_DiffTimespecsToDouble(&now, &inst->local_tx.ts); - if (last_tx < 0.0) - last_tx = 0.0; - delay = get_transmit_delay(inst, 0, 0.0) - last_tx; + if (!UTI_IsZeroTimespec(&inst->local_tx.ts)) { + SCH_GetLastEventTime(&now, NULL, NULL); + last_tx = UTI_DiffTimespecsToDouble(&now, &inst->local_tx.ts); + if (last_tx < 0.0) + last_tx = 0.0; + delay = get_transmit_delay(inst, 0, 0.0) - last_tx; + } else { + delay = 0.0; + } + if (delay < INITIAL_DELAY) delay = INITIAL_DELAY;