)
{
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;
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 {
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;
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;
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 */
} else if (enable_local_stratum) {
- *is_synchronised = 1;
+ *is_synchronised = 0;
*stratum = local_stratum;
*ref_id = NTP_REFID_LOCAL;
/* ================================================== */
-int
-REF_IsLocalActive(void)
-{
- return !are_we_synchronised && enable_local_stratum;
-}
-
-/* ================================================== */
-
#define LEAP_SECOND_CLOSE 5
int REF_IsLeapSecondClose(void)
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 */