Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipv6: change inet6_sk_rebuild_header() to use inet->cork.fl.u.ip6

TCP v6 spends a good amount of time rebuilding a fresh fl6 at each
transmit in inet6_csk_xmit()/inet6_csk_route_socket().

TCP v4 caches the information in inet->cork.fl.u.ip4 instead.

This patch is a first step converting IPv6 to the same strategy:

Before this patch inet6_sk_rebuild_header() only validated/rebuilt
a dst. Automatic variable @fl6 content was lost.

After this patch inet6_sk_rebuild_header() also initializes
inet->cork.fl.u.ip6, which can be reused in the future.

This makes inet6_sk_rebuild_header() very similar to
inet_sk_rebuild_header().

Also remove the EXPORT_SYMBOL_GPL(), inet6_sk_rebuild_header()
is not called from any module.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260204163035.4123817-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
85d05e28 047c5265

+26 -29
+26 -29
net/ipv6/af_inet6.c
··· 824 824 int inet6_sk_rebuild_header(struct sock *sk) 825 825 { 826 826 struct ipv6_pinfo *np = inet6_sk(sk); 827 + struct inet_sock *inet = inet_sk(sk); 828 + struct in6_addr *final_p, final; 827 829 struct dst_entry *dst; 830 + struct flowi6 *fl6; 828 831 829 832 dst = __sk_dst_check(sk, np->dst_cookie); 833 + if (dst) 834 + return 0; 830 835 831 - if (!dst) { 832 - struct inet_sock *inet = inet_sk(sk); 833 - struct in6_addr *final_p, final; 834 - struct flowi6 fl6; 836 + fl6 = &inet->cork.fl.u.ip6; 837 + memset(fl6, 0, sizeof(*fl6)); 838 + fl6->flowi6_proto = sk->sk_protocol; 839 + fl6->daddr = sk->sk_v6_daddr; 840 + fl6->saddr = np->saddr; 841 + fl6->flowlabel = np->flow_label; 842 + fl6->flowi6_oif = sk->sk_bound_dev_if; 843 + fl6->flowi6_mark = sk->sk_mark; 844 + fl6->fl6_dport = inet->inet_dport; 845 + fl6->fl6_sport = inet->inet_sport; 846 + fl6->flowi6_uid = sk_uid(sk); 847 + security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6)); 835 848 836 - memset(&fl6, 0, sizeof(fl6)); 837 - fl6.flowi6_proto = sk->sk_protocol; 838 - fl6.daddr = sk->sk_v6_daddr; 839 - fl6.saddr = np->saddr; 840 - fl6.flowlabel = np->flow_label; 841 - fl6.flowi6_oif = sk->sk_bound_dev_if; 842 - fl6.flowi6_mark = sk->sk_mark; 843 - fl6.fl6_dport = inet->inet_dport; 844 - fl6.fl6_sport = inet->inet_sport; 845 - fl6.flowi6_uid = sk_uid(sk); 846 - security_sk_classify_flow(sk, flowi6_to_flowi_common(&fl6)); 849 + rcu_read_lock(); 850 + final_p = fl6_update_dst(fl6, rcu_dereference(np->opt), &final); 851 + rcu_read_unlock(); 847 852 848 - rcu_read_lock(); 849 - final_p = fl6_update_dst(&fl6, rcu_dereference(np->opt), 850 - &final); 851 - rcu_read_unlock(); 852 - 853 - dst = ip6_dst_lookup_flow(sock_net(sk), sk, &fl6, final_p); 854 - if (IS_ERR(dst)) { 855 - sk->sk_route_caps = 0; 856 - WRITE_ONCE(sk->sk_err_soft, -PTR_ERR(dst)); 857 - return PTR_ERR(dst); 858 - } 859 - 860 - ip6_dst_store(sk, dst, false, false); 853 + dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p); 854 + if (IS_ERR(dst)) { 855 + sk->sk_route_caps = 0; 856 + WRITE_ONCE(sk->sk_err_soft, -PTR_ERR(dst)); 857 + return PTR_ERR(dst); 861 858 } 862 859 860 + ip6_dst_store(sk, dst, false, false); 863 861 return 0; 864 862 } 865 - EXPORT_SYMBOL_GPL(inet6_sk_rebuild_header); 866 863 867 864 bool ipv6_opt_accepted(const struct sock *sk, const struct sk_buff *skb, 868 865 const struct inet6_skb_parm *opt)