Skip to content

Commit

Permalink
udp: ipv4: do not waste time in __udp4_lib_mcast_demux_lookup
Browse files Browse the repository at this point in the history
Its too easy to add thousand of UDP sockets on a particular bucket,
and slow down an innocent multicast receiver.

Early demux is supposed to be an optimization, we should avoid spending
too much time in it.

It is interesting to note __udp4_lib_demux_lookup() only tries to
match first socket in the chain.

10 is the threshold we already have in __udp4_lib_lookup() to switch
to secondary hash.

Fixes: 421b388 ("udp: ipv4: Add udp early demux")
Signed-off-by: Eric Dumazet <[email protected]>
Reported-by: David Held <[email protected]>
Cc: Shawn Bohrer <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Eric Dumazet authored and davem330 committed Jun 13, 2014
1 parent 2853af6 commit 63c6f81
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/ipv4/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,10 @@ static struct sock *__udp4_lib_mcast_demux_lookup(struct net *net,
unsigned int count, slot = udp_hashfn(net, hnum, udp_table.mask);
struct udp_hslot *hslot = &udp_table.hash[slot];

/* Do not bother scanning a too big list */
if (hslot->count > 10)
return NULL;

rcu_read_lock();
begin:
count = 0;
Expand Down

0 comments on commit 63c6f81

Please sign in to comment.