From owner-freebsd-bugs@FreeBSD.ORG Wed Mar 28 09:10:13 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 202BA106564A for ; Wed, 28 Mar 2012 09:10:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 005AB8FC16 for ; Wed, 28 Mar 2012 09:10:13 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q2S9ACeB046368 for ; Wed, 28 Mar 2012 09:10:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q2S9ACIl046367; Wed, 28 Mar 2012 09:10:12 GMT (envelope-from gnats) Date: Wed, 28 Mar 2012 09:10:12 GMT Message-Id: <201203280910.q2S9ACIl046367@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Gleb Smirnoff Cc: Subject: Re: kern/166458: bind() incorrectly interprets SO_REUSEADDR option as also implying SO_REUSEPORT on FreeBSD X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Gleb Smirnoff List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Mar 2012 09:10:13 -0000 The following reply was made to PR kern/166458; it has been noted by GNATS. From: Gleb Smirnoff To: Sean Bruno 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> ... 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.