From: Eric Dumazet <eric.dumazet@gmail.com>
To: Gaspar Chilingarov <gasparch@gmail.com>
Cc: Daniel Baluta <daniel.baluta@gmail.com>, netdev <netdev@vger.kernel.org>
Subject: Re: 'tcp: bind() fix when many ports are bound' problem
Date: Tue, 04 Jan 2011 12:22:52 +0100 [thread overview]
Message-ID: <1294140172.3579.81.camel@edumazet-laptop> (raw)
In-Reply-To: <AANLkTinNcds1EAnWXOX6wAjg+wv4O=Xd65hHEGWoGos8@mail.gmail.com>
Le mardi 04 janvier 2011 à 13:12 +0400, Gaspar Chilingarov a écrit :
> Hi there!
>
> Well, that looks strange.
>
> On my own side I've just put workaround (manually binding to all ports
> in sequence :)
> and moved production code to FreeBSD as it has better scalable network stack.
>
> I can see the potential problem with that bind() problem on highly
> loaded DNS servers/resolvers which establish tons of outgoing UDP
> connections.
>
> In some cases that connections could fail and as not receiving the
> answer it is normal condition for DNS this will go totally unnoticed.
>
> I don't think anyone will hit this bug in production environment
> except the very high load applications.
Dont mix TCP and UDP, they are not the same.
Problem with TCP is you can have TIME_WAIT sockets, disallowing a port
to be reused. Not with UDP.
The connect() [without a previous bind()], or a sendto() [without a
previous bind()] problem is more an API problem.
When kernel autobinds an UDP socket [to get a local IP/port], there is a
problem on the selection of the local address : It must be ANY_ADDR
(0.0.0.0)
While for TCP, the IP address wont change for the whole session.
Problem is : The port can really be random, while the local address
comes from routing tables. To reach one destination, we usually use one
pref IP address, even if many are available.
If you dont bind() a socket before sending an UDP frame, kernel cannot
assume the local IP address wont change later (for other sent frames, if
routing takes another path), so must use the ANY address for the port
selection done in autobind. Max 2^16-1 choices.
If you have 100 IP addresses on your machine, it doesnt change this ANY
selection [for UDP] at all.
If you need more than 2^16 local endpoints and you have more than one
external IP address, the only portable way is to use bind() yourself and
manage a pool of [tuples]. Well, this is not true for some old OSes
(Solaris 2.5.1 comes to mind with TCP sockets)
next prev parent reply other threads:[~2011-01-04 11:22 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-04 8:53 'tcp: bind() fix when many ports are bound' problem Daniel Baluta
2011-01-04 9:12 ` Gaspar Chilingarov
2011-01-04 11:22 ` Eric Dumazet [this message]
2011-01-05 9:00 ` Daniel Baluta
2011-01-11 11:14 ` [PATCH] tcp: disallow bind() to reuse addr/port Eric Dumazet
2011-01-11 13:04 ` Daniel Baluta
2011-01-11 22:03 ` David Miller
2011-04-27 17:37 ` George B.
2011-04-27 17:40 ` Eric Dumazet
2011-04-27 17:54 ` George B.
2011-04-27 18:02 ` Eric Dumazet
2011-04-27 18:45 ` George B.
2011-04-27 17:36 ` 'tcp: bind() fix when many ports are bound' problem George B.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1294140172.3579.81.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=daniel.baluta@gmail.com \
--cc=gasparch@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox