From: Eric Dumazet <redacted>
Date: Fri, 26 Aug 2022 08:40:49 -0700
On Thu, Aug 25, 2022 at 5:07 PM Kuniyuki Iwashima [off-list ref] wrote:
quoted
We will soon introduce an optional per-netns ehash.
This means we cannot use the global sk->sk_prot->h.hashinfo
to fetch a TCP hashinfo.
Instead, set NULL to sk->sk_prot->h.hashinfo for TCP and get
a proper hashinfo from net->ipv4.tcp_death_row->hashinfo.
Note that we need not use sk->sk_prot->h.hashinfo if DCCP is
disabled.
Signed-off-by: Kuniyuki Iwashima <redacted>
---
include/net/inet_hashtables.h | 10 ++++++++++
net/ipv4/af_inet.c | 2 +-
net/ipv4/inet_connection_sock.c | 6 +++---
net/ipv4/inet_hashtables.c | 14 +++++++-------
net/ipv4/tcp_ipv4.c | 2 +-
net/ipv6/tcp_ipv6.c | 2 +-
6 files changed, 23 insertions(+), 13 deletions(-)
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index 44a419b9e3d5..2c866112433e 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -170,6 +170,16 @@ struct inet_hashinfo {
struct inet_listen_hashbucket *lhash2;
};
+static inline struct inet_hashinfo *inet_get_hashinfo(const struct sock *sk)
+{
+#if IS_ENABLED(CONFIG_IP_DCCP)
+ return sk->sk_prot->h.hashinfo ? :
+ sock_net(sk)->ipv4.tcp_death_row->hashinfo;
+#else
+ return sock_net(sk)->ipv4.tcp_death_row->hashinfo;
+#endif
+}
If the sk_prot->h.hashinfo must disappear, I would rather add a new
inet->hashinfo field
return inet_sk(sk)->hashinfo
Conceptually, the pointer no longer belongs to sk_prot, and not in struct net,
otherwise you should name this helper tcp_or_dccp_get_hashinfo() to avoid
any temptation to use it for other inet protocol.
That makes sense.
To keep the series simple, I'll use tcp_or_dccp_get_hashinfo() in v2 and
post follow-up patch to add inet_sk(sk)->hashinfo, which needs a little
bit more work/test I think.
Thank you!