]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
socket: add support for Linux timestamping transmit IDs
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Nov 2025 10:14:35 +0000 (11:14 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 18 Nov 2025 14:50:54 +0000 (15:50 +0100)
Add a new field to the SCK_Message structure to enable setting and
getting of the Linux timestamping transmit IDs enabled by the
SOF_TIMESTAMPING_OPT_ID socket option. The ID can be set for each packet
individually by the SCM_TS_OPT_ID control message (supported on Linux
6.13 and newer).

This will allow procesing of transmit timestamps without extracting data
from the data-link frames.

socket.c
socket.h

index a01ad74cfc018268581d2b5330d94fbaed391557..ec1a5973f0175bc6a7b694f7a99f7def48d1d675 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -850,6 +850,7 @@ init_message_nonaddress(SCK_Message *message)
   message->timestamp.if_index = INVALID_IF_INDEX;
   message->timestamp.l2_length = 0;
   message->timestamp.tx_flags = 0;
+  message->timestamp.tx_id = 0;
 
   message->descriptor = INVALID_SOCK_FD;
 }
@@ -1020,6 +1021,8 @@ process_header(struct msghdr *msg, int msg_length, int sock_fd, int flags,
         log_message(sock_fd, 1, message, "Unexpected extended error in", NULL);
         r = 0;
       }
+
+      message->timestamp.tx_id = err.ee_data;
     }
 #endif
     else if (match_cmsg(cmsg, SOL_SOCKET, SCM_RIGHTS, 0)) {
@@ -1251,6 +1254,19 @@ send_message(int sock_fd, SCK_Message *message, int flags)
 
     *ts_tx_flags = message->timestamp.tx_flags;
   }
+
+#ifdef SCM_TS_OPT_ID
+  if (message->timestamp.tx_id != 0) {
+    uint32_t *tx_id;
+
+    tx_id = add_control_message(&msg, SOL_SOCKET, SCM_TS_OPT_ID,
+                                sizeof (*tx_id), sizeof (cmsg_buf));
+    if (!tx_id)
+      return 0;
+
+    *tx_id = message->timestamp.tx_id;
+  }
+#endif
 #endif
 
   if (flags & SCK_FLAG_MSG_DESCRIPTOR) {
index 99192c140712f5923625981623d68d3eb49085c7..ec2114dca63c8dffdf8630b6ad9eee472e469412 100644 (file)
--- a/socket.h
+++ b/socket.h
@@ -67,6 +67,7 @@ typedef struct {
     int if_index;
     int l2_length;
     int tx_flags;
+    uint32_t tx_id;
   } timestamp;
 
   int descriptor;