From: Dan Kegel <dank@kegel.com>
To: Mika Liljeberg <Mika.Liljeberg@welho.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] tcp_v4_get_port() and ephemeral ports
Date: Sun, 30 Sep 2001 13:37:37 -0700 [thread overview]
Message-ID: <3BB78291.F8732D4@kegel.com> (raw)
In-Reply-To: <3BB75EB4.3268D3FC@kegel.com> <3BB7676C.1213CC84@welho.com>
Mika Liljeberg wrote:
>
> Dan Kegel wrote:
>
> > So far, I've found an implementation of getifaddrs() that makes it
> > easy to retrieve the list of local IP addresses, and modified my
> > benchmark to assign a different local ip address to each user;
> > the users use bind() with that address and a zero port number,
> > and expect the system to assign a port.
> [...]
> > It's tempting to patch tcp_v4_get_port() to check
> > sk->rcv_saddr, and if it's nonzero, allow the
> > same ephemeral port number to be reused on different interfaces.
> [...]
> > Can anyone comment on the wisdom of such a change?
>
> Hi Dan,
Thanks for the reply!
> It shouldn't break anything as far as I can see. However, patching the
> kernel simply to accommodate a benchmark does not seem the right thing
> to do. Since your client is already binding the source address, why not
> simply bind the port as well? You can easily loop the whole 64K range if
> you want. ... I don't see any reason to
> modify the kernel for this, particularly as it wouldn't really help port
> exhaustion in real-life situations.
Depends on what you mean by real-life situations. If you actually
need to handle over ten thousand outgoing connections, this change
could indeed help relieve port exhaustion. Think of web spiders
or web caches on gigabit/sec links.
Perhaps one could go further, and have the kernel pick an ip address as
well; that would make the app even easier to code. That means
changing connect() rather than bind(). It looks like the ip address for
ephemeral connect() is picked by tcp_v4_connect / ip_route_connect /
ip_route_output / ip_route_output_key / ip_route_output_slow / inet_select_addr().
inet_select_addr() calls for_primary_ifa to iterate through the devices,
so it doesn't pick up aliases. Making this pick an alias at random
is kind of a gross thought. I suppose there could be a socket option
SO_PREFER_ALIASES, and make it pick an alias 'at random'. That's a change
I'd rather not make, since it looks like socket option space is about used up.
> Or you could even pick a completely empty port range and bind
> each client socket with the SO_REUSE flag (which is ok, since your
> clients are using different source addresses).
SO_REUSE might let my app's connections collide with those
of other apps, wouldn't it? Doesn't seem very clean. A web cache
or web spider probably wouldn't use SO_REUSE, would it?
I guess I'm resigned to managing the ephemeral port number in my app.
A bit of a pain, but that's life. If this ever starts bugging
lots of people, I'm sure a consensus about how to make life easier
will pop up.
- Dan
next prev parent reply other threads:[~2001-09-30 20:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-30 18:04 [PATCH] tcp_v4_get_port() and ephemeral ports Dan Kegel
2001-09-30 18:16 ` Davide Libenzi
2001-09-30 18:29 ` Dan Kegel
2001-09-30 18:41 ` Mika Liljeberg
2001-09-30 20:37 ` Dan Kegel [this message]
2001-09-30 21:45 ` Mika Liljeberg
2001-09-30 20:53 ` Chris Wedgwood
-- strict thread matches above, loose matches on Subject: below --
2001-09-30 21:15 Andi Kleen
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=3BB78291.F8732D4@kegel.com \
--to=dank@kegel.com \
--cc=Mika.Liljeberg@welho.com \
--cc=linux-kernel@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