Thread (12 messages) 12 messages, 2 authors, 2026-05-28
COLD55d

[PATCH net-next v2 5/6] bpf: enable bpf timestamping rx in TCP layer

From: Jason Xing <hidden>
Date: 2026-05-21 13:53:48
Also in: bpf
Subsystem: networking [general], networking [tcp], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Neal Cardwell, Linus Torvalds

From: Jason Xing <kernelxing@tencent.com>

Add two if statements to accurately isolate bpf timestamping and so
timestamping. They can work respectively.

As to so_timestamping, only add a loose condition via report flags
to avoid duplicate strict checks that is done in tcp_recv_timestamp()
and performance impact. If the loose condition is hit,
tcp_recv_timestamp() is able to handle the exact case and doesn't
hamper the existing timestamping feature.

Make it work in TCP protocol.

Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
 net/ipv4/tcp.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 21ece4c71612..7ad3561dc8cd 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2353,6 +2353,16 @@ void tcp_recv_timestamp(struct msghdr *msg, const struct sock *sk,
 	int new_tstamp = sock_flag(sk, SOCK_TSTAMP_NEW);
 	u32 tsflags = READ_ONCE(sk->sk_tsflags);
 
+	if (cgroup_bpf_enabled(CGROUP_SOCK_OPS) &&
+	    SK_BPF_CB_FLAG_TEST(sk, SK_BPF_CB_RX_TIMESTAMPING))
+		bpf_skops_rx_timestamping((struct sock *)sk, tss,
+					  BPF_SOCK_OPS_TSTAMP_RCV_CB);
+
+	if (!sock_flag(sk, SOCK_RCVTSTAMP) &&
+	    !(tsflags & SOF_TIMESTAMPING_SOFTWARE) &&
+	    !(tsflags & SOF_TIMESTAMPING_RAW_HARDWARE))
+		return;
+
 	if (tss->ts[0]) {
 		if (sock_flag(sk, SOCK_RCVTSTAMP)) {
 			struct timespec64 tv = ktime_to_timespec64(tss->ts[0]);
-- 
2.43.7
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help