BIO_get_accept_socket weirdness

2014-07-05 Thread Kurt Roeckx
Hi, I've been working on IPv6 support, and one of the strangest things I find is BIO_get_accept_socket(). If bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED, and bind() fails with EADDRINUSE it creates a new socket and tries to connect to the port it tried to bind() to, and if that fails tries to bind

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Eric Covener
On Sat, Jul 5, 2014 at 7:37 AM, Kurt Roeckx k...@roeckx.be wrote: Does anybody have an idea why it's trying to do that, and why we shouldn't just do SO_REUSEADDR the first time? Was there some OS that maybe did strange things when trying to use SO_REUSEADDR and it was already in use? FWLIW:

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Kurt Roeckx
On Sat, Jul 05, 2014 at 08:13:04AM -0400, Eric Covener wrote: On Sat, Jul 5, 2014 at 7:37 AM, Kurt Roeckx k...@roeckx.be wrote: Does anybody have an idea why it's trying to do that, and why we shouldn't just do SO_REUSEADDR the first time? Was there some OS that maybe did strange things

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Tim Hudson
On 5/07/2014 9:12 AM, Kurt Roeckx wrote: On Sat, Jul 05, 2014 at 08:13:04AM -0400, Eric Covener wrote: On Sat, Jul 5, 2014 at 7:37 AM, Kurt Roeckx k...@roeckx.be wrote: Does anybody have an idea why it's trying to do that, and why we shouldn't just do SO_REUSEADDR the first time? Was there

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Kurt Roeckx
On Sat, Jul 05, 2014 at 12:45:37PM -0400, Tim Hudson wrote: On 5/07/2014 9:12 AM, Kurt Roeckx wrote: On Sat, Jul 05, 2014 at 08:13:04AM -0400, Eric Covener wrote: On Sat, Jul 5, 2014 at 7:37 AM, Kurt Roeckx k...@roeckx.be wrote: Does anybody have an idea why it's trying to do that, and why

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Tim Hudson
On 5/07/2014 2:14 PM, Kurt Roeckx wrote: On Sat, Jul 05, 2014 at 12:45:37PM -0400, Tim Hudson wrote: If you have SO_REUSEADDR set and a listener already in place you will start a new listener No you won't. You will get a bind() error: socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3

RE: BIO_get_accept_socket weirdness

2014-07-05 Thread Salz, Rich
Those who forget history are doomed to re-implement it, wrongly. SO_REUSEADDR was implemented in 4.2BSD so that a server could restart without waiting for the various FIN_WAIT timeouts to happen. :) /r$ -- Principal Security Engineer Akamai Technologies, Cambridge, MA IM:

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Kurt Roeckx
On Sat, Jul 05, 2014 at 02:37:49PM -0400, Tim Hudson wrote: On 5/07/2014 2:14 PM, Kurt Roeckx wrote: On Sat, Jul 05, 2014 at 12:45:37PM -0400, Tim Hudson wrote: If you have SO_REUSEADDR set and a listener already in place you will start a new listener No you won't. You will get a bind()

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Tim Hudson
Some google engineering (search) will show the the variety of confusion that this causes in cross-platform code. Start here for some interesting reading - http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t You will find

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Jeff Trawick
On Sat, Jul 5, 2014 at 2:37 PM, Tim Hudson t...@cryptsoft.com wrote: On 5/07/2014 2:14 PM, Kurt Roeckx wrote: On Sat, Jul 05, 2014 at 12:45:37PM -0400, Tim Hudson wrote: If you have SO_REUSEADDR set and a listener already in place you will start a new listener No you won't. You will get

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Kurt Roeckx
On Sat, Jul 05, 2014 at 02:55:36PM -0400, Tim Hudson wrote: Some google engineering (search) will show the the variety of confusion that this causes in cross-platform code. Start here for some interesting reading -

Re: BIO_get_accept_socket weirdness

2014-07-05 Thread Ben Laurie
On 5 July 2014 12:37, Kurt Roeckx k...@roeckx.be wrote: But then I found some MSDN documentation that says that Windows allows others to hijack your socket when you've set SO_REUSEADDR and the results are non-deterministic. They also created an SO_EXCLUSIVEADDRUSE and I'm getting confused