Date: Thu, 18 Jul 2013 00:23:37 +0300 From: Mikolaj Golub <trociny@FreeBSD.org> To: John Baldwin <jhb@freebsd.org> Cc: freebsd-net@freebsd.org Subject: Re: bind error when using SO_REUSEPORT(implies SO_REUSEADDR) Message-ID: <20130717212336.GA35489@gmail.com> In-Reply-To: <201307161112.46116.jhb@freebsd.org> References: <1331855948.3317.17.camel@powernoodle-l7.corp.yahoo.com> <1331856466.3317.18.camel@powernoodle-l7.corp.yahoo.com> <201307161112.46116.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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? -- Mikolaj Golub
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130717212336.GA35489>