All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
To: <david.laight@aculab.com>
Cc: <davem@davemloft.net>, <edumazet@google.com>,
	<kuni1840@gmail.com>, <kuniyu@amazon.co.jp>,
	<kuznet@ms2.inr.ac.ru>, <netdev@vger.kernel.org>,
	<osa-contribution-log@amazon.com>, <yoshfuji@linux-ipv6.org>
Subject: Re: [PATCH net-next 0/3] Improve bind(addr, 0) behaviour.
Date: Fri, 21 Feb 2020 19:01:55 +0900	[thread overview]
Message-ID: <20200221100155.76241-1-kuniyu@amazon.co.jp> (raw)
In-Reply-To: <2aead5c10d7c4bc6b80bbc5f079bef8e@AcuMS.aculab.com>

From: David Laight <David.Laight@ACULAB.COM>
Date: Thu, 20 Feb 2020 17:11:46 +0000
> From: Kuniyuki Iwashima
> > Sent: 20 February 2020 15:20
> >
> > Currently we fail to bind sockets to ephemeral ports when all of the ports
> > are exhausted even if all sockets have SO_REUSEADDR enabled. In this case,
> > we still have a chance to connect to the different remote hosts.
> >
> > The second and third patches fix the behaviour to fully utilize all space
> > of the local (addr, port) tuples.
> 
> Would it make sense to only do this for the implicit bind() done
> when connect() is called on an unbound socket?
> In that case only the quadruplet of the local and remote addresses
> needs to be unique.

The function to reserve a epehemral port is different between bind() and
connect(). 

  bind    : inet_csk_find_open_port
  connect : __inet_hash_connect

The connect() cannot use ports which are consumed by bind()
because __inet_hash_connect() fails to get a port if tb->fastreuse or
or tb->fastreuseport is not -1, which only __inet_hash_connect() sets.
On the other hand, bind() can use ports which are used by connect().

Moreover, we can call bind() before connect() to decide which IP to use.
By setting IP_BIND_ADDRESS_NO_PORT to socket, we can defer getting a port
until connect() is called. However, this means that getting port
is done by __inet_hash_connect, so that connect() may fail to get a local 
port if it is reserved by bind(). So if we want to reuse ports consumed by
bind(), we have to call bind() to get ports.

Without this patch, we may fail to get a ephemeral port and to fail to 
bind() in such case we should be able to reuse a local port when connecting
to remote hosts.

  reply	other threads:[~2020-02-21 10:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-20 15:20 [PATCH net-next 0/3] Improve bind(addr, 0) behaviour Kuniyuki Iwashima
2020-02-20 15:20 ` [PATCH net-next 1/3] tcp: Remove unnecessary conditions in inet_csk_bind_conflict() Kuniyuki Iwashima
2020-02-20 15:20 ` [PATCH net-next 2/3] tcp: bind(addr, 0) remove the SO_REUSEADDR restriction when ephemeral ports are exhausted Kuniyuki Iwashima
2020-02-20 15:20 ` [PATCH net-next 3/3] tcp: Prevent port hijacking when " Kuniyuki Iwashima
2020-02-20 17:11 ` [PATCH net-next 0/3] Improve bind(addr, 0) behaviour David Laight
2020-02-21 10:01   ` Kuniyuki Iwashima [this message]
2020-02-21 10:46     ` David Laight
2020-02-20 19:58 ` Eric Dumazet
2020-02-21 20:35   ` [PATCH net-next 0/3] ImpArove " Kuniyuki Iwashima
2020-02-22  1:07     ` [PATCH net-next 0/3] Improve " Kuniyuki Iwashima
2020-02-23 21:06       ` Kuniyuki Iwashima

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=20200221100155.76241-1-kuniyu@amazon.co.jp \
    --to=kuniyu@amazon.co.jp \
    --cc=davem@davemloft.net \
    --cc=david.laight@aculab.com \
    --cc=edumazet@google.com \
    --cc=kuni1840@gmail.com \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=netdev@vger.kernel.org \
    --cc=osa-contribution-log@amazon.com \
    --cc=yoshfuji@linux-ipv6.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.