Skip to content

Commit 97d7ae6

Browse files
edumazetkuba-moo
authored andcommitted
tcp: inet6_csk_xmit() optimization
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>
1 parent a6eee39 commit 97d7ae6

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

net/ipv6/inet6_connection_sock.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ static struct dst_entry *inet6_csk_route_socket(struct sock *sk,
8181
final_p = fl6_update_dst(fl6, rcu_dereference(np->opt), &np->final);
8282
rcu_read_unlock();
8383

84-
dst = __sk_dst_check(sk, np->dst_cookie);
85-
if (!dst) {
86-
dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
84+
dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
85+
86+
if (!IS_ERR(dst))
87+
ip6_dst_store(sk, dst, false, false);
8788

88-
if (!IS_ERR(dst))
89-
ip6_dst_store(sk, dst, false, false);
90-
}
9189
return dst;
9290
}
9391

@@ -98,20 +96,22 @@ int inet6_csk_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl_unused
9896
struct dst_entry *dst;
9997
int res;
10098

101-
dst = inet6_csk_route_socket(sk, fl6);
102-
if (IS_ERR(dst)) {
103-
WRITE_ONCE(sk->sk_err_soft, -PTR_ERR(dst));
104-
sk->sk_route_caps = 0;
105-
kfree_skb(skb);
106-
return PTR_ERR(dst);
99+
dst = __sk_dst_check(sk, np->dst_cookie);
100+
if (unlikely(!dst)) {
101+
dst = inet6_csk_route_socket(sk, fl6);
102+
if (IS_ERR(dst)) {
103+
WRITE_ONCE(sk->sk_err_soft, -PTR_ERR(dst));
104+
sk->sk_route_caps = 0;
105+
kfree_skb(skb);
106+
return PTR_ERR(dst);
107+
}
108+
/* Restore final destination back after routing done */
109+
fl6->daddr = sk->sk_v6_daddr;
107110
}
108111

109112
rcu_read_lock();
110113
skb_dst_set_noref(skb, dst);
111114

112-
/* Restore final destination back after routing done */
113-
fl6->daddr = sk->sk_v6_daddr;
114-
115115
res = ip6_xmit(sk, skb, fl6, sk->sk_mark, rcu_dereference(np->opt),
116116
np->tclass, READ_ONCE(sk->sk_priority));
117117
rcu_read_unlock();

0 commit comments

Comments
 (0)