mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 22:45:07 -05:00
Add support for SO_TIMESTAMP control messages
SO_TIMESTAMP messages contain kernel time stamps for received packets, this should improve accuracy and avoid the impact of CPU scheduling latencies.
This commit is contained in:
20
ntp_io.c
20
ntp_io.c
@@ -119,6 +119,12 @@ NIO_Initialise(void)
|
|||||||
/* Don't quit - we might survive anyway */
|
/* Don't quit - we might survive anyway */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Enable receiving of timestamp control messages */
|
||||||
|
if (setsockopt(sock_fd, SOL_SOCKET, SO_TIMESTAMP, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not set timestamp socket options");
|
||||||
|
/* Don't quit - we might survive anyway */
|
||||||
|
}
|
||||||
|
|
||||||
/* We want the local IP info too */
|
/* We want the local IP info too */
|
||||||
if (setsockopt(sock_fd, IPPROTO_IP, IP_PKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
if (setsockopt(sock_fd, IPPROTO_IP, IP_PKTINFO, (char *)&on_off, sizeof(on_off)) < 0) {
|
||||||
LOG(LOGS_ERR, LOGF_NtpIO, "Could not request packet info using socket option");
|
LOG(LOGS_ERR, LOGF_NtpIO, "Could not request packet info using socket option");
|
||||||
@@ -233,6 +239,20 @@ read_from_socket(void *anything)
|
|||||||
memcpy(&ipi, CMSG_DATA(cmsg), sizeof(ipi));
|
memcpy(&ipi, CMSG_DATA(cmsg), sizeof(ipi));
|
||||||
remote_addr.local_ip_addr = ntohl(ipi.ipi_spec_dst.s_addr);
|
remote_addr.local_ip_addr = ntohl(ipi.ipi_spec_dst.s_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_TIMESTAMP) {
|
||||||
|
struct timeval tv;
|
||||||
|
double correction;
|
||||||
|
|
||||||
|
memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv));
|
||||||
|
correction = LCL_GetOffsetCorrection(&tv);
|
||||||
|
UTI_AddDoubleToTimeval(&tv, correction, &tv);
|
||||||
|
#if 0
|
||||||
|
UTI_DiffTimevalsToDouble(&correction, &now, &tv);
|
||||||
|
LOG(LOGS_INFO, LOGF_NtpIO, "timestamp diff: %f", correction);
|
||||||
|
#endif
|
||||||
|
now = tv;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == NTP_NORMAL_PACKET_SIZE) {
|
if (status == NTP_NORMAL_PACKET_SIZE) {
|
||||||
|
|||||||
Reference in New Issue
Block a user