]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tcp: avoid dst->ops->check() call in tcp_v{4,6}_do_rcv()
authorEric Dumazet <edumazet@google.com>
Fri, 6 Mar 2026 15:43:22 +0000 (15:43 +0000)
committerJakub Kicinski <kuba@kernel.org>
Tue, 10 Mar 2026 01:52:56 +0000 (18:52 -0700)
If incoming skb dst matches the socket cached one,
there is no need to call again dst->ops->check().

Network layer already validated the skb dst for us,
usually from tcp_v{4,6}_early_demux().

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260306154322.1086539-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/tcp_ipv4.c
net/ipv6/tcp_ipv6.c

index f27995a6456198866ec2f9860b18d911e8dc1bcd..2ea8253b737ab7908490e4690828f19e2caed9dd 100644 (file)
@@ -1855,7 +1855,7 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
 
                sock_rps_save_rxhash(sk, skb);
                sk_mark_napi_id(sk, skb);
-               if (dst) {
+               if (dst && unlikely(dst != skb_dst(skb))) {
                        if (sk->sk_rx_dst_ifindex != skb->skb_iif ||
                            !INDIRECT_CALL_1(dst->ops->check, ipv4_dst_check,
                                             dst, 0)) {
index 164dceb842af767d93d0a2389564f543b2ba2fbf..074b83c9a551fafa52972a41506cdaf5299e24bd 100644 (file)
@@ -1596,7 +1596,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
 
                sock_rps_save_rxhash(sk, skb);
                sk_mark_napi_id(sk, skb);
-               if (dst) {
+               if (dst && unlikely(dst != skb_dst(skb))) {
                        if (sk->sk_rx_dst_ifindex != skb->skb_iif ||
                            INDIRECT_CALL_1(dst->ops->check, ip6_dst_check,
                                            dst, sk->sk_rx_dst_cookie) == NULL) {