]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tcp: inet6_csk_xmit() optimization
authorEric Dumazet <edumazet@google.com>
Fri, 6 Feb 2026 17:34:26 +0000 (17:34 +0000)
committerJakub Kicinski <kuba@kernel.org>
Wed, 11 Feb 2026 04:57:50 +0000 (20:57 -0800)
After prior patches, inet6_csk_xmit() can reuse inet->cork.fl.u.ip6
if __sk_dst_check() returns a valid dst.

Otherwise call inet6_csk_route_socket() to refresh inet->cork.fl.u.ip6
content and get a new dst.

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

index b6c4123aa0aeb803afdf807d8683156b710df2f6..11fc2f7de2fe981ddb48dc008bf7fd4ae1e4e2f6 100644 (file)
@@ -81,13 +81,11 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk,
        final_p = fl6_update_dst(fl6, rcu_dereference(np->opt), &np->final);
        rcu_read_unlock();
 
-       dst = __sk_dst_check(sk, np->dst_cookie);
-       if (!dst) {
-               dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
+       dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
+
+       if (!IS_ERR(dst))
+               ip6_dst_store(sk, dst, false, false);
 
-               if (!IS_ERR(dst))
-                       ip6_dst_store(sk, dst, false, false);
-       }
        return dst;
 }
 
@@ -98,20 +96,22 @@ int inet6_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl_unused
        struct dst_entry *dst;
        int res;
 
-       dst = inet6_csk_route_socket(sk, fl6);
-       if (IS_ERR(dst)) {
-               WRITE_ONCE(sk->sk_err_soft, -PTR_ERR(dst));
-               sk->sk_route_caps = 0;
-               kfree_skb(skb);
-               return PTR_ERR(dst);
+       dst = __sk_dst_check(sk, np->dst_cookie);
+       if (unlikely(!dst)) {
+               dst = inet6_csk_route_socket(sk, fl6);
+               if (IS_ERR(dst)) {
+                       WRITE_ONCE(sk->sk_err_soft, -PTR_ERR(dst));
+                       sk->sk_route_caps = 0;
+                       kfree_skb(skb);
+                       return PTR_ERR(dst);
+               }
+               /* Restore final destination back after routing done */
+               fl6->daddr = sk->sk_v6_daddr;
        }
 
        rcu_read_lock();
        skb_dst_set_noref(skb, dst);
 
-       /* Restore final destination back after routing done */
-       fl6->daddr = sk->sk_v6_daddr;
-
        res = ip6_xmit(sk, skb, fl6, sk->sk_mark, rcu_dereference(np->opt),
                       np->tclass, READ_ONCE(sk->sk_priority));
        rcu_read_unlock();