]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
udp: add rehash on connect()
authorEric Dumazet <eric.dumazet@gmail.com>
Wed, 8 Sep 2010 05:08:44 +0000 (05:08 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 27 Sep 2010 00:18:14 +0000 (17:18 -0700)
commit749f63ed9bf702e588000f1d1ce6290e6c156289
tree8845c8b3e86aa65405203697ef2e90175d1d8592
parent4275a88aa5891aadb1227631d9e602a1f66f347f
udp: add rehash on connect()

commit 719f835853a92f6090258114a72ffe41f09155cd upstream

commit 30fff923 introduced in linux-2.6.33 (udp: bind() optimisation)
added a secondary hash on UDP, hashed on (local addr, local port).

Problem is that following sequence :

fd = socket(...)
connect(fd, &remote, ...)

not only selects remote end point (address and port), but also sets
local address, while UDP stack stored in secondary hash table the socket
while its local address was INADDR_ANY (or ipv6 equivalent)

Sequence is :
 - autobind() : choose a random local port, insert socket in hash tables
              [while local address is INADDR_ANY]
 - connect() : set remote address and port, change local address to IP
              given by a route lookup.

When an incoming UDP frame comes, if more than 10 sockets are found in
primary hash table, we switch to secondary table, and fail to find
socket because its local address changed.

One solution to this problem is to rehash datagram socket if needed.

We add a new rehash(struct socket *) method in "struct proto", and
implement this method for UDP v4 & v6, using a common helper.

This rehashing only takes care of secondary hash table, since primary
hash (based on local port only) is not changed.

Reported-by: Krzysztof Piotr Oledzki <ole@ans.pl>
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Tested-by: Krzysztof Piotr Oledzki <ole@ans.pl>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/net/sock.h
include/net/udp.h
net/ipv4/datagram.c
net/ipv4/udp.c
net/ipv6/datagram.c
net/ipv6/udp.c