OSDN Git Service

net: udp: prefer listeners bound to an address
authorPeter Oskolkov <posk@google.com>
Wed, 12 Dec 2018 21:15:33 +0000 (13:15 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 14 Dec 2018 23:55:20 +0000 (15:55 -0800)
commit4cdeeee9252af1ba50482f91d615f326365306bd
tree62cc2eca1cfed387c81af3053e04b50339e316a4
parent8e2ea53a83dfb4b892ba35ddd9e78e6091202fa6
net: udp: prefer listeners bound to an address

A relatively common use case is to have several IPs configured
on a host, and have different listeners for each of them. We would
like to add a "catch all" listener on addr_any, to match incoming
connections not served by any of the listeners bound to a specific
address.

However, port-only lookups can match addr_any sockets when sockets
listening on specific addresses are present if so_reuseport flag
is set. This patch eliminates lookups into port-only hashtable,
as lookups by (addr,port) tuple are easily available.

In addition, compute_score() is tweaked to _not_ match
addr_any sockets to specific addresses, as hash collisions
could result in the unwanted behavior described above.

Tested: the patch compiles; full test in the last patch in this
patchset. Existing reuseport_* selftests also pass.

Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Peter Oskolkov <posk@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/udp.c