Re: [PATCH net-next] net: ip: lookup the best matched listen socket

From: Eric Dumazet
Date: Thu Jul 31 2025 - 09:02:12 EST


On Thu, Jul 31, 2025 at 5:33 AM Menglong Dong <menglong8.dong@xxxxxxxxx> wrote:
>
> For now, the socket lookup will terminate if the socket is reuse port in
> inet_lhash2_lookup(), which makes the socket is not the best match.
>
> For example, we have socket1 and socket2 both listen on "0.0.0.0:1234",
> but socket1 bind on "eth0". We create socket1 first, and then socket2.
> Then, all connections will goto socket2, which is not expected, as socket1
> has higher priority.
>
> This can cause unexpected behavior if TCP MD5 keys is used, as described
> in Documentation/networking/vrf.rst -> Applications.
>
> Therefor, we lookup the best matched socket first, and then do the reuse
> port logic. This can increase some overhead if there are many reuse port
> socket :/
>
> Signed-off-by: Menglong Dong <dongml2@xxxxxxxxxxxxxxx>

I do not think net-next is open yet ?

It seems this would be net material.

Any way you could provide a test ?

Please CC Martin KaFai Lau <kafai@xxxxxx>, as this was added in :

commit 61b7c691c7317529375f90f0a81a331990b1ec1b
Author: Martin KaFai Lau <kafai@xxxxxx>
Date: Fri Dec 1 12:52:31 2017 -0800

inet: Add a 2nd listener hashtable (port+addr)