]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: add support for SO_TIMESTAMPNS socket option
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 18 Aug 2016 13:39:14 +0000 (15:39 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 19 Aug 2016 11:55:20 +0000 (13:55 +0200)
Enable the SO_TIMESTAMPNS option to get kernel timestamps in nanosecond
resolution.

ntp_io.c
sys_linux.c

index 9aa4785fd2e98f91aa2a3c3691dea20439551348..e1f165527983d816fbc0adb879f14d3cdd0e9535 100644 (file)
--- a/ntp_io.c
+++ b/ntp_io.c
@@ -202,6 +202,10 @@ prepare_socket(int family, int port_number, int client_only)
 
 #ifdef SO_TIMESTAMP
   /* Enable receiving of timestamp control messages */
+#ifdef SO_TIMESTAMPNS
+  /* Try nanosecond resolution first */
+  if (setsockopt(sock_fd, SOL_SOCKET, SO_TIMESTAMPNS, (char *)&on_off, sizeof(on_off)) < 0)
+#endif
   if (setsockopt(sock_fd, SOL_SOCKET, SO_TIMESTAMP, (char *)&on_off, sizeof(on_off)) < 0) {
     LOG(LOGS_ERR, LOGF_NtpIO, "Could not set %s socket option", "SO_TIMESTAMP");
     /* Don't quit - we might survive anyway */
@@ -597,6 +601,15 @@ process_receive(struct msghdr *hdr, int length, int sock_fd)
       LCL_CookTime(&ts, &now, &now_err);
     }
 #endif
+
+#ifdef SO_TIMESTAMPNS
+    if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_TIMESTAMPNS) {
+      struct timespec ts;
+
+      memcpy(&ts, CMSG_DATA(cmsg), sizeof (ts));
+      LCL_CookTime(&ts, &now, &now_err);
+    }
+#endif
   }
 
   DEBUG_LOG(LOGF_NtpIO, "Received %d bytes from %s:%d to %s fd %d",
index dd8529be9d7a29f07585e45bc892c68551ffa39e..c4f5c14a77de2dada8a8c6d5534b4ca916aa05cf 100644 (file)
@@ -493,7 +493,7 @@ SYS_Linux_EnableSystemCallFilter(int level)
     { SOL_IPV6, IPV6_V6ONLY }, { SOL_IPV6, IPV6_RECVPKTINFO },
 #endif
     { SOL_SOCKET, SO_BROADCAST }, { SOL_SOCKET, SO_REUSEADDR },
-    { SOL_SOCKET, SO_TIMESTAMP },
+    { SOL_SOCKET, SO_TIMESTAMP }, { SOL_SOCKET, SO_TIMESTAMPNS },
   };
 
   const static int fcntls[] = { F_GETFD, F_SETFD };