From 2aab6a85a456854219d76f8a20ccb790877d4aa2 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Fri, 8 Apr 2016 16:10:02 +0200 Subject: [PATCH] reference: return real sync status in REF_GetReferenceParams() If local reference is active, return normal leap, but unsynchronised status. Update the callers of the function to work with the leap directly and not change their behaviour. REF_IsLocalActive() is no longer needed. --- ntp_core.c | 12 +++--------- refclock.c | 12 +++++++----- reference.c | 10 +--------- reference.h | 1 - 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/ntp_core.c b/ntp_core.c index 8f3c3e8..3d3a612 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -801,7 +801,7 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */ ) { NTP_Packet message; - int leap, auth_len, length, ret, precision; + int auth_len, length, ret, precision; struct timeval local_receive, local_transmit; NTP_int64 ts_fuzz; @@ -823,7 +823,7 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */ if (my_mode == MODE_CLIENT) { /* Don't reveal local time or state of the clock in client packets */ precision = 32; - are_we_synchronised = leap_status = our_stratum = our_ref_id = 0; + leap_status = our_stratum = our_ref_id = 0; our_ref_time.tv_sec = our_ref_time.tv_usec = 0; our_root_delay = our_root_dispersion = 0.0; } else { @@ -859,14 +859,8 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */ local_receive = *local_rx; } - if (are_we_synchronised) { - leap = (int) leap_status; - } else { - leap = LEAP_Unsynchronised; - } - /* Generate transmit packet */ - message.lvm = NTP_LVM(leap, version, my_mode); + message.lvm = NTP_LVM(leap_status, version, my_mode); /* Stratum 16 and larger are invalid */ if (our_stratum < NTP_MAX_STRATUM) { message.stratum = our_stratum; diff --git a/refclock.c b/refclock.c index 86c0de2..59765f8 100644 --- a/refclock.c +++ b/refclock.c @@ -470,15 +470,16 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second) double root_delay, root_dispersion, distance; uint32_t ref_id; - /* Ignore the pulse if we are not well synchronized */ + /* Ignore the pulse if we are not well synchronized and the local + reference is not active */ REF_GetReferenceParams(&cooked_time, &is_synchronised, &leap, &stratum, &ref_id, &ref_time, &root_delay, &root_dispersion); distance = fabs(root_delay) / 2 + root_dispersion; - if (!is_synchronised || distance >= 0.5 / rate) { + if (leap == LEAP_Unsynchronised || distance >= 0.5 / rate) { DEBUG_LOG(LOGF_Refclock, "refclock pulse ignored second=%.9f sync=%d dist=%.9f", - second, is_synchronised, distance); + second, leap != LEAP_Unsynchronised, distance); /* Drop also all stored samples */ filter_reset(&instance->filter); return 0; @@ -528,9 +529,10 @@ pps_stratum(RCL_Instance instance, struct timeval *tv) REF_GetReferenceParams(tv, &is_synchronised, &leap, &stratum, &ref_id, &ref_time, &root_delay, &root_dispersion); - /* Don't change our stratum if local stratum is active + /* Don't change our stratum if the local reference is active or this is the current source */ - if (ref_id == instance->ref_id || REF_IsLocalActive()) + if (ref_id == instance->ref_id || + (!is_synchronised && leap != LEAP_Unsynchronised)) return stratum - 1; /* Or the current source is another PPS refclock */ diff --git a/reference.c b/reference.c index dfc851d..ff73dbb 100644 --- a/reference.c +++ b/reference.c @@ -1223,7 +1223,7 @@ REF_GetReferenceParams } else if (enable_local_stratum) { - *is_synchronised = 1; + *is_synchronised = 0; *stratum = local_stratum; *ref_id = NTP_REFID_LOCAL; @@ -1331,14 +1331,6 @@ REF_DisableLocal(void) /* ================================================== */ -int -REF_IsLocalActive(void) -{ - return !are_we_synchronised && enable_local_stratum; -} - -/* ================================================== */ - #define LEAP_SECOND_CLOSE 5 int REF_IsLeapSecondClose(void) diff --git a/reference.h b/reference.h index d146ec5..e4387b0 100644 --- a/reference.h +++ b/reference.h @@ -179,7 +179,6 @@ extern void REF_ModifyMakestep(int limit, double threshold); extern void REF_EnableLocal(int stratum, double distance, int orphan); extern void REF_DisableLocal(void); -extern int REF_IsLocalActive(void); /* Check if current raw or cooked time is close to a leap second and is better to discard any measurements */