dump_packet_cmsg -- Allow to receive timestamp data

A socket may support receiving timestamps from the
kernel (see net/socket.c:__sock_recv_timestamp
in the kernel), so simply pass up this data to
userspace.

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>

(cherry picked from commit 1ecd757bf23831d1574e1dca0566dbe26e0fcb49)
Ahmed Elaidy:
- ported as a standalone commit (was previously squashed into the
  unix-sockets ucred support); only the SOL_SOCKET timestamp handling
  is kept, the netlink pktinfo part of the original is not ported here.
Signed-off-by: Ahmed Elaidy <elaidya225@gmail.com>
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@futurfusion.io>
This commit is contained in:
Cyrill Gorcunov 2026-06-25 22:11:38 +03:00 committed by Alexander Mikhalitsyn
parent abc025016b
commit eee7477515

View file

@ -207,14 +207,22 @@ static int dump_packet_cmsg(struct msghdr *mh, SkPacketEntry *pe, int flags)
continue;
}
if (ch->cmsg_len == CMSG_LEN(sizeof(struct ucred)) &&
ch->cmsg_type == SCM_CREDENTIALS &&
ch->cmsg_level == SOL_SOCKET) {
struct ucred *ucred = (struct ucred *)CMSG_DATA(ch);
if (ch->cmsg_level == SOL_SOCKET) {
if (ch->cmsg_len == CMSG_LEN(sizeof(struct ucred)) &&
ch->cmsg_type == SCM_CREDENTIALS) {
struct ucred *ucred = (struct ucred *)CMSG_DATA(ch);
if (dump_sk_creds(ucred, pe, flags))
return -1;
continue;
if (dump_sk_creds(ucred, pe, flags))
return -1;
continue;
} else if (ch->cmsg_type == SCM_TIMESTAMP ||
ch->cmsg_type == SCM_TIMESTAMPNS ||
ch->cmsg_type == SCM_TIMESTAMPING) {
/*
* Allow to receive timestamps from the kernel.
*/
continue;
}
}
pr_err("cmsg: len %lu type %d level %d\n",