[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bind_socket uses SO_REUSEADDR


Hi,

The reason we use SO_REUSEADDR is not to start two servers on the same
port. Actually that wouldn't work, the port would be marked as busy
until the application is closed. This flag is important because without
it, it can take a few minutes after the server exited or was killed
before we can bind again to the same port. It's a stupid legacy from BSD
sockets and I not aware of a single server that does not use it.
This links describes what happens without it:
https://stackoverflow.com/questions/24194961/how-do-i-use-setsockoptso-reuseaddr

Are you mistaking it with SO_REUSEPORT ?

       *SO_REUSEPORT *(since Linux 3.9)
              Permits multiple *AF_INET *or *AF_INET6 *sockets to be bound to an
              identical socket address.  This option must be set on each
              socket (including the first socket) prior to calling bind(2) <http://man7.org/linux/man-pages/man2/bind.2.html>
              on the socket.  To prevent port hijacking, all of the
              processes binding to the same address must have the same
              effective UID.  This option can be employed with both TCP and
              UDP sockets.

If you have very specific needs about the port binding,
ssh_bind_set_fd() is the way to go
Aris


On 23/06/17 10:53, Игорь Коваленко wrote:
> Hello!
> I'm developing an ssh server and I came to the following problem.
> In bind_socket functional hard coded using SO_REUSEADDR socket
> option. Why is that so?
> Because of that it is possible to start two servers on the same port
> which I don't need. 
> What alternatives do I have? I see the following:
> - to add new SSH_BIND_OPTIONS_REUSEADDR or something like that (but I
> need to change libssh for that)
> - to use ssh_bind_set_fd with a socket created by myself
> - something else?
>



Follow-Ups:
Re: bind_socket uses SO_REUSEADDRИгорь Коваленко <igor.a.kovalenko@xxxxxxxxx>
References:
bind_socket uses SO_REUSEADDRИгорь Коваленко <igor.a.kovalenko@xxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org