All of lore.kernel.org
 help / color / mirror / Atom feed
From: Flavio Leitner <fbl@redhat.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev <netdev@vger.kernel.org>, Marcelo Leitner <mleitner@redhat.com>
Subject: Re: bind()/inet_csk_get_port() fails when no port is requested
Date: Wed, 18 Jan 2012 15:57:42 -0200	[thread overview]
Message-ID: <20120118155742.5ed38f98@asterix.rh> (raw)
In-Reply-To: <1326908219.4910.14.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>

On Wed, 18 Jan 2012 18:36:59 +0100
Eric Dumazet <eric.dumazet@gmail.com> wrote:

> Le mercredi 18 janvier 2012 à 15:11 -0200, Flavio Leitner a écrit :
> > Hi folks,
> > 
> > It has been reported to me that bind() fails when you leave
> > the port up to the kernel to choose and succeed when you
> > request a certain port in the same conditions.
> > 
> > For example, let's restrict the ephemeral port range to 3 ports only:
> > # echo "32768 32770" > /proc/sys/net/ipv4/ip_local_port_range
> > 
> > Assuming the system has two IP addresses: 172.31.1.6/24 and
> > 192.168.100.6/24 then run the following python script which
> > allocates all ephemeral ports using one IP address and then
> > try to bind another one using another IP address.
> > 
> ...
> > Conclusion: When using ephemeral ports, inet_csk_get_port()
> > fails without checking if a conflict had happened. When using
> > fixed ports on the other hand, inet_csk_get_port() works
> > as expected.
> > 
> > I will attach a quick hack to illustrate what I am thinking.
> > The idea is to check all ports first and if it fails, then
> > try again looking for a port that doesn't conflict. So, for
> > most cases, the algorithm is the same, but when the system
> > ran out of ports, there is a hope :-)
> > 
> > Is there a reason to behave like that? or is this a real bug?
> > Sounds like a FAQ, but I am not finding an explanation for this
> > on the net yet.
> > 
> 
> Hi Flavio
> 
> This seems a very good idea.
> 
> Only drawback is when table is really full, we'll scan it twice.
> 

That's right. Maybe checking for conflicts in the first round
helps, but it would add a cost for the average case scenario.

But first, I'd like to know if this is a bug before spending
more time working on it. Maybe there is a reason for behaving
like that.

thanks!
fbl

      parent reply	other threads:[~2012-01-18 17:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-18 17:11 bind()/inet_csk_get_port() fails when no port is requested Flavio Leitner
2012-01-18 17:36 ` Eric Dumazet
2012-01-18 17:50   ` Eric Dumazet
2012-01-18 17:57   ` Flavio Leitner [this message]

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=20120118155742.5ed38f98@asterix.rh \
    --to=fbl@redhat.com \
    --cc=eric.dumazet@gmail.com \
    --cc=mleitner@redhat.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 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.