mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-05 20:45:06 -05:00
util: add support for other NTP eras
NTP timestamps use only 32 bits to count seconds and the current NTP era ends in 2036. Add support for converting NTP timestamps from other NTP eras on systems with 64-bit time_t. The earliest assumed NTP time is set by the configure script (by default to 50 years before the date of the build) and earlier NTP timestamps underflow to the following NTP era.
This commit is contained in:
25
ntp_core.c
25
ntp_core.c
@@ -258,10 +258,35 @@ do_size_checks(void)
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
static void
|
||||
do_time_checks(void)
|
||||
{
|
||||
#ifdef HAVE_LONG_TIME_T
|
||||
/* Check that time before NTP_ERA_SPLIT underflows correctly */
|
||||
|
||||
struct timeval tv1 = {NTP_ERA_SPLIT, 1}, tv2 = {NTP_ERA_SPLIT - 1, 1};
|
||||
NTP_int64 ntv1, ntv2;
|
||||
int r;
|
||||
|
||||
UTI_TimevalToInt64(&tv1, &ntv1, 0);
|
||||
UTI_TimevalToInt64(&tv2, &ntv2, 0);
|
||||
UTI_Int64ToTimeval(&ntv1, &tv1);
|
||||
UTI_Int64ToTimeval(&ntv2, &tv2);
|
||||
|
||||
r = tv1.tv_sec == NTP_ERA_SPLIT &&
|
||||
tv1.tv_sec + (1ULL << 32) - 1 == tv2.tv_sec;
|
||||
|
||||
assert(r);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
void
|
||||
NCR_Initialise(void)
|
||||
{
|
||||
do_size_checks();
|
||||
do_time_checks();
|
||||
|
||||
logfileid = CNF_GetLogMeasurements() ? LOG_FileOpen("measurements",
|
||||
" Date (UTC) Time IP Address L St 1234 abc 5678 LP RP Score Offset Peer del. Peer disp. Root del. Root disp.")
|
||||
|
||||
Reference in New Issue
Block a user