Re: [PATCH v6 net-next 4/4] ipv6/udp: Add 4-tuple hash for connected socket

From: Philo Lu
Date: Fri Nov 01 2024 - 07:40:40 EST




On 2024/10/31 20:45, Philo Lu wrote:
Implement ipv6 udp hash4 like that in ipv4. The major difference is that
the hash value should be calculated with udp6_ehashfn(). Besides,
ipv4-mapped ipv6 address is handled before hash() and rehash().

Core procedures of hash/unhash/rehash are same as ipv4, and udpv4 and
udpv6 share the same udptable, so some functions in ipv4 hash4 can also
be shared.

Signed-off-by: Philo Lu <lulie@xxxxxxxxxxxxxxxxx>
Signed-off-by: Cambda Zhu <cambda@xxxxxxxxxxxxxxxxx>
Signed-off-by: Fred Chen <fred.cc@xxxxxxxxxxxxxxx>
Signed-off-by: Yubing Qiu <yubing.qiuyubing@xxxxxxxxxxxxxxx>
---
net/ipv6/udp.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 94 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 1ea99d704e31..64f13f258fca 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -110,8 +110,17 @@ void udp_v6_rehash(struct sock *sk)
u16 new_hash = ipv6_portaddr_hash(sock_net(sk),
&sk->sk_v6_rcv_saddr,
inet_sk(sk)->inet_num);
+ u16 new_hash4;
- udp_lib_rehash(sk, new_hash, 0); /* 4-tuple hash not implemented */
+ if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr)) {
+ new_hash4 = udp_ehashfn(sock_net(sk), sk->sk_rcv_saddr, sk->sk_num,
+ sk->sk_daddr, sk->sk_dport);

Just found udp_ehashfn() used here results in an build error of undefined function.

I think the `ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr)` branch can be moved into udp_lib_rehash() to fix the issue. So in the worst case, we need to calculate the newhash4 twice in ipv6 hash4 rehash, one in udp_v6_rehash() and the other in udp_lib_rehash().

+ } else {
+ new_hash4 = udp6_ehashfn(sock_net(sk), &sk->sk_v6_rcv_saddr, sk->sk_num,
+ &sk->sk_v6_daddr, sk->sk_dport);
+ }
+
+ udp_lib_rehash(sk, new_hash, new_hash4);
}

--
Philo