bind error when using SO_REUSEPORT(implies SO_REUSEADDR)

John Baldwin jhb at freebsd.org
Thu Jul 18 14:32:10 UTC 2013


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


More information about the freebsd-net mailing list