Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Mar 2012 09:10:12 GMT
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/166458: bind() incorrectly interprets SO_REUSEADDR option as also implying SO_REUSEPORT on FreeBSD
Message-ID:  <201203280910.q2S9ACIl046367@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/166458; it has been noted by GNATS.

From: Gleb Smirnoff <glebius@FreeBSD.org>
To: Sean Bruno <sbruno@FreeBSD.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: kern/166458: bind() incorrectly interprets SO_REUSEADDR option
 as also implying SO_REUSEPORT on FreeBSD
Date: Wed, 28 Mar 2012 13:01:40 +0400

   Sean,
 
 On Wed, Mar 28, 2012 at 12:53:03AM +0000, Sean Bruno wrote:
 S> <There> ... seems to be a bug in FreeBSD when specifying port number 0 in the 
 S> socket address passed to the bind system call in order to let the kernel
 S> select a free port number.
 S> 
 S> The semantics of SO_REUSEADDR is inconsistently implemented on FreeBSD.
 S> 
 S> FreeBSD 4 jail environment (on a FreeBSD 4 host):
 S> 
 S> dev-tegge:~$ ./bindbug 
 S> serversock addr is 10.76.250.174:40328
 S> dup bind: Address already in use
 S> This error was expected, tried to bind to used addr/port
 S> dup2 bind: Address already in use
 S> This error was expected, tried to bind to used port without SO_REUSEPORT
 S> autosock addr is 10.76.250.174:40328
 S> bug triggered, port number conflict on sockets without SO_REUSEPORT
 S> listen succeded after implicitly overlapping port bind
 S> 
 S> FreeBSD 6 host enironment:
 S> 
 S> tegge-store1:~:$ ./bindbug 
 S> serversock addr is 127.0.0.1:59073
 S> dup bind: Address already in use
 S> This error was expected, tried to bind to used addr/port
 S> BUG: binding duplicate socket to server port succeeded
 S> dup2sock addr is 0.0.0.0:59073
 S> overlapping explicit bind to same port number succeeded without SO_REUSEPORT
 S> listen succeeded after explicitly overlapping port bind
 S> autosock addr is 0.0.0.0:59073
 S> bug triggered, port number conflict on sockets without SO_REUSEPORT
 S> listen succeded after implicitly overlapping port bind
 S> 
 S> RHEL4 host environment:
 S> 
 S> [tegge@dell-bl1s3 ~]$ time ./bindbug 
 S> serversock addr is 127.0.0.1:43270
 S> dup bind: Address already in use
 S> This error was expected, tried to bind to used addr/port
 S> dup2 bind: Address already in use
 S> This error was expected, tried to bind to used port without SO_REUSEPORT
 S> bug not triggered after 16777216 iterations
 
 I don't see a bug in FreeBSD 6 behavior.
 
 To speak about bug we need to have a clear description of correct behavior.
 Unfortunately the SO_REUSEADDR option is tersely documented in our manuals,
 as well as in POSIX. Thus I will advocate to the TCP/IP Book by Stevens
 as documentation, quoting it, page 720:
 
 SO_REUSEADDR	Allows the process to bind to a port number that is already in use, but
 		the IP address being bound (including the wildcard) must not already
 		be bound to that same port.
 		For example, if an attached interface has the IP address 140.252.1.29
 		then one socket can be bound to 140.252.1.29, port 5555; another
 		socket can be bound to 127.0.0.1, port 5555; and another socket can be
 		bound to the wildcard IP address, port 5555. The call to bind for the
 		second and third cases must be preceeded by a call to setsockopt,
 		setting the SO_REUSEADDR option.
 
 http://books.google.ru/books?id=ESM3CWY5xRYC&pg=PA720&hl=ru&source=gbs_toc_r&cad=4#v=onepage&q&f=false
 
 -- 
 Totus tuus, Glebius.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203280910.q2S9ACIl046367>