Re: [RFC PATCHv2 net-next 1/3] net/udp: Add a new struct for hash2 slot

From: Philo Lu
Date: Tue Sep 24 2024 - 22:57:48 EST



On 2024/9/24 20:51, Gur Stavi wrote:
@@ -224,13 +224,12 @@ struct sock *__udp6_lib_lookup(const struct net *net,
struct sk_buff *skb)
{
unsigned short hnum = ntohs(dport);
- unsigned int hash2, slot2;
struct udp_hslot *hslot2;
struct sock *result, *sk;
+ unsigned int hash2;

hash2 = ipv6_portaddr_hash(net, daddr, hnum);
- slot2 = hash2 & udptable->mask;
- hslot2 = &udptable->hash2[slot2];
+ hslot2 = udp_hashslot2(udptable, hash2);


Why not minimize the code change by using udptable->hash2[slot2].hslot?
Especially since later you do it in __udp6_lib_mcast_deliver.
I think that many developers would find usage of C primitives more
readable.

Yes I can use udptable->hash2[slot2].hslot. But I prefer the udp_hashslot2() helper, because I found I have to add ".hslot" at many places, while most of them look exactly what udp_hashslot2() does. I think replacing them may get the codes simpler and benefit future coding.

Some places like __udp6_lib_mcast_deliver() get hslot2 differently from udp_hashslot2(), so just appending ".hslot" to avoid functionality change.

Thanks.
--
Philo