Skip to content
Snippets Groups Projects
Commit 67219137 authored by Avi Kivity's avatar Avi Kivity Committed by Pekka Enberg
Browse files

net: adjust SO_REUSEADDR to match Linux semantics

As detailed in [1], SO_REUSEADDR means slightly different things on BSD and
Linux.  One of the differences is in the treatment of sockets that are bound
to addresses already occupied by existing sockets in the TIME_WAIT state;
Linux allows the new socket if SO_REUSEADDR is set on it, while BSD refuses.

Adjust the code to match the Linux behaviour.  This allows multiple connection
tests to pass, and will likely be required by other network intensive
applications.

[1] http://stackoverflow.com/questions/14388706/socket-options-so-reuseaddr-and-so-reuseport-how-do-they-differ-do-they-mean-t



Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 8cf576ca
No related branches found
No related tags found
No related merge requests found
......@@ -566,9 +566,18 @@ in_pcbbind_setup(struct inpcb *inp, struct bsd_sockaddr *nam, in_addr_t *laddrp,
* being in use (for now). This is better
* than a panic, but not desirable.
*/
/*
* Linux allows a SO_REUSEADDR socket to be
* bound to an existing TIME_WAIT socket
* if SO_REUSEADDR is set on the new socket.
*
* Allow for that in addition to the BSD
* SO_REUSEPORT semantics.
*/
tw = intotw(t);
if (tw == NULL ||
(reuseport & tw->tw_so_options) == 0)
((reuseport & tw->tw_so_options) == 0)
&& (so->so_options & SO_REUSEADDR) == 0)
return (EADDRINUSE);
} else if (t && (reuseport == 0 ||
(t->inp_flags2 & INP_REUSEPORT) == 0)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment