From owner-freebsd-net@FreeBSD.ORG Thu Jul 18 14:32:10 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C8C30940; Thu, 18 Jul 2013 14:32:10 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) by mx1.freebsd.org (Postfix) with ESMTP id A52AC198; Thu, 18 Jul 2013 14:32:10 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id DE497B982; Thu, 18 Jul 2013 10:32:09 -0400 (EDT) From: John Baldwin To: Mikolaj Golub Subject: Re: bind error when using SO_REUSEPORT(implies SO_REUSEADDR) Date: Thu, 18 Jul 2013 10:04:21 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p25; KDE/4.5.5; amd64; ; ) References: <1331855948.3317.17.camel@powernoodle-l7.corp.yahoo.com> <201307161112.46116.jhb@freebsd.org> <20130717212336.GA35489@gmail.com> In-Reply-To: <20130717212336.GA35489@gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201307181004.21844.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Thu, 18 Jul 2013 10:32:10 -0400 (EDT) Cc: freebsd-net@freebsd.org X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jul 2013 14:32:10 -0000 On Wednesday, July 17, 2013 5:23:37 pm Mikolaj Golub wrote: > On Tue, Jul 16, 2013 at 11:12:46AM -0400, John Baldwin wrote: > > On Thursday, March 15, 2012 8:07:46 pm Sean Bruno wrote: > > > On Thu, 2012-03-15 at 16:59 -0700, Sean Bruno wrote: > > > > Hey, I just found a bind bug ticket in my queue about bind. I noted > > > > that on stable/6 stable/7 stable/9 & head the referenced code "fails". > > > > > > > > It seems that this is a problem, but I have no idea if its a real > > > > problem or not. Our devs think it is. Anyway, here is a code snippet > > > > to show the failure in bind. On linux/solaris this does not fail. > > > > > > > > http://people.freebsd.org/~sbruno/bind_test.c > > > > > > > > simple compile with gcc -o test test.c and run as normal user. > > > > > > > > Sean > > > > > > > > > > this is bind() not bind ... :-) > > > > Did the recent commit to HEAD fix this btw? > > As for me, bind_test.c does not expose any bug in freebsd, it only > shows different behavior for freebsd and linux. > > On freebsd the test output is: > > serversock addr is 127.0.0.1:27539 > dup bind: Address already in use > This error was expected, tried to bind to used addr/port > BUG: binding duplicate socket to server port succeeded > dup2sock addr is 0.0.0.0:27539 > overlapping explicit bind to same port number succeeded without SO_REUSEPORT > listen succeeded after explicitly overlapping port bind > autosock addr is 0.0.0.0:27539 > bug triggered, port number conflict on sockets without SO_REUSEPORT > listen succeded after implicitly overlapping port bind > > So, the first socket (serversock) is bound to the loopback address, > then it tries some combinations of binding the second socket to the > same port but to the wildcard address. When SO_REUSEADDR socket option > is set, binding to the wildcard address succeeds for freebsd (and > fails for linux). > > They call this a bug in freebsd, but this is well known and expected > behavior (see e.g. Stevens' TCP/IP Illustrated Vol1). > > Or I missed the test's point? No, that is probably true. I wasn't sure if it was a bug or not when Sean originally posted it. -- John Baldwin