From: Miroslav Lichvar Date: Thu, 13 Nov 2025 10:14:35 +0000 (+0100) Subject: socket: add support for Linux timestamping transmit IDs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4507359952b466f23ea3e5de4409e7610b927c8c;p=thirdparty%2Fchrony.git socket: add support for Linux timestamping transmit IDs 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. --- diff --git a/socket.c b/socket.c index a01ad74c..ec1a5973 100644 --- 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) { diff --git a/socket.h b/socket.h index 99192c14..ec2114dc 100644 --- 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;