Clients sockets are closed immediately after receiving valid response.
Don't wait for the first early HW TX timestamp to enable waiting for
late timestamps. It may take a long time or never come if the HW/driver
is consistently slow. It's a chicken and egg problem.
Instead, simply check if HW timestamping is enabled on at least one
interface. Responses from NTP sources on other interfaces will always be
saved (for 1 millisecond by default).
SPF_Instance filter;
int filter_count;
- /* Flag indicating HW transmit timestamps are expected */
- int had_hw_tx_timestamp;
-
/* Response waiting for a HW transmit timestamp of the request */
struct SavedResponse *saved_response;
if (instance->filter)
SPF_DropSamples(instance->filter);
instance->filter_count = 0;
-
- instance->had_hw_tx_timestamp = 0;
}
/* ================================================== */
response to the request, when at least one good response has already been
accepted to avoid incorrectly confirming a tentative source. */
if (valid_packet && synced_packet && !saved && !inst->valid_rx &&
- inst->had_hw_tx_timestamp && inst->local_tx.source != NTP_TS_HARDWARE &&
+ NIO_IsHwTsEnabled() && inst->local_tx.source != NTP_TS_HARDWARE &&
inst->report.total_good_count > 0) {
if (save_response(inst, local_addr, rx_ts, message, info))
return 1;
message);
if (tx_ts->source == NTP_TS_HARDWARE) {
- inst->had_hw_tx_timestamp = 1;
-
if (has_saved_response(inst))
process_saved_response(inst);
}
/* ================================================== */
+int
+NIO_IsHwTsEnabled(void)
+{
+#ifdef HAVE_LINUX_TIMESTAMPING
+ return NIO_Linux_IsHwTsEnabled();
+#else
+ return 0;
+#endif
+}
+
+/* ================================================== */
+
int
NIO_OpenClientSocket(NTP_Remote_Address *remote_addr)
{
/* Function to finalise the module */
extern void NIO_Finalise(void);
+/* Function to check if HW timestamping is enabled on any interface */
+extern int NIO_IsHwTsEnabled(void);
+
/* Function to obtain a socket for sending client packets */
extern int NIO_OpenClientSocket(NTP_Remote_Address *remote_addr);
/* ================================================== */
+int
+NIO_Linux_IsHwTsEnabled(void)
+{
+ return ARR_GetSize(interfaces) > 0;
+}
+
+/* ================================================== */
+
int
NIO_Linux_SetTimestampSocketOptions(int sock_fd, int client_only, int *events)
{
extern void NIO_Linux_Finalise(void);
+extern int NIO_Linux_IsHwTsEnabled(void);
+
extern int NIO_Linux_SetTimestampSocketOptions(int sock_fd, int client_only, int *events);
extern int NIO_Linux_ProcessMessage(SCK_Message *message, NTP_Local_Address *local_addr,
static NTP_Packet req_buffer, res_buffer;
static int req_length, res_length;
+#define NIO_IsHwTsEnabled() 1
#define NIO_OpenServerSocket(addr) ((addr)->ip_addr.family != IPADDR_UNSPEC ? 100 : 0)
#define NIO_CloseServerSocket(fd) assert(fd == 100)
#define NIO_OpenClientSocket(addr) ((addr)->ip_addr.family != IPADDR_UNSPEC ? 101 : 0)
}
if (late_hwts) {
- inst->had_hw_tx_timestamp = 1;
inst->report.total_good_count++;
} else {
- if (random() % 2)
- inst->had_hw_tx_timestamp = 0;
- else
- inst->report.total_good_count = 0;
+ inst->report.total_good_count = 0;
}
}