Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Stop setting SO_REUSEADDR to fix Port Forwarding #654

Open
wants to merge 2 commits into
base: latestw_all
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -3683,8 +3683,18 @@ channel_setup_fwd_listener_tcpip(struct ssh *ssh, int type,
strerror(errno));
continue;
}

#ifndef WINDOWS
/*
Setting the SO_REUSEADDR flag on a socket behaves differently on Windows than on *NIX OS.
On *NIX OS, the flag is used for handling specific edge cases and allows the port to be reused
while busy only during TIME_WAIT state in the short period after termination.
On Windows, the option allows a socket to forcibly bind to a port in use by another socket in any
state.
This was allowing more than one socket to be created in the same port on Windows, which is
unnexpected behavior.
*/
set_reuseaddr(sock);
#endif
if (ai->ai_family == AF_INET6)
sock_set_v6only(sock);

Expand Down
2 changes: 2 additions & 0 deletions sshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,9 @@ listen_on_addrs(struct listenaddr *la)
continue;
}
/* Socket options */
#ifndef WINDOWS
set_reuseaddr(listen_sock);
#endif
if (la->rdomain != NULL &&
set_rdomain(listen_sock, la->rdomain) == -1) {
close(listen_sock);
Expand Down