Re: [PATCH v3] udp reuseport: fix packet of same flow hashed to different socket
From: Eric Dumazet
Date: Sun Jun 12 2016 - 11:33:01 EST
On Sun, 2016-06-12 at 20:43 +0800, Su Xuemin wrote:
> From: "Su, Xuemin" <suxm@xxxxxxxxxxxxxxxxxx>
...
> Signed-off-by: Su, Xuemin <suxm@xxxxxxxxxxxxxxxxxx>
> Signed-off-by: Eric Dumazet <edumazet@xxxxxxxxxx>
> ---
First, I want to thank you for this very high quality submission,
especially if this is your first linux kernel patch.
I have one additional comment to make :
> if (score > badness) {
> reuseport = sk->sk_reuseport;
> @@ -556,14 +510,20 @@ struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
> daddr, hnum, dif,
> hslot2, slot2, skb);
> if (!result) {
> + unsigned int old = hash2;
> hash2 = udp4_portaddr_hash(net, htonl(INADDR_ANY), hnum);
> +
> + /* avoid search the same slot again. */
> + if (unlikely(old == hash2))
> + return result;
> +
Technically speaking, what matters is the slot, not the hash value
(32bit)
So I would save in old, slot2
> slot2 = hash2 & udptable->mask;
And here perform the check
if (unlikely(slot2 != old_slot))
return result;
> hslot2 = &udptable->hash2[slot2];
> if (hslot->count < hslot2->count)
> goto begin;
(Same remark applies in IPv6)
Thanks !