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

[no sq] Enable ipv6_server by default #15739

Open
wants to merge 2 commits into
base: master
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
8 changes: 5 additions & 3 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -835,10 +835,12 @@ protocol_version_min (Protocol version minimum) int 1 1 65535
# Files that are not present will be fetched the usual way.
remote_media (Remote media) string

# Enable/disable running an IPv6 server.
# Enable IPv6 support for server.
# Note that clients will be able to connect with both IPv4 and IPv6.
# Ignored if bind_address is set.
# Needs enable_ipv6 to be enabled.
ipv6_server (IPv6 server) bool false
#
# Requires: enable_ipv6
ipv6_server (IPv6 server) bool true

[*Server Security]

Expand Down
2 changes: 1 addition & 1 deletion src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void set_default_settings()

// Network
settings->setDefault("enable_ipv6", "true");
settings->setDefault("ipv6_server", "false");
settings->setDefault("ipv6_server", "true");
settings->setDefault("max_packets_per_iteration", "1024");
settings->setDefault("port", "30000");
settings->setDefault("strict_protocol_version_checking", "false");
Expand Down
33 changes: 19 additions & 14 deletions src/network/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,16 @@ bool UDPSocket::init(bool ipv6, bool noExceptions)
m_handle = socket(m_addr_family, SOCK_DGRAM, IPPROTO_UDP);

if (m_handle < 0) {
if (noExceptions) {
auto msg = std::string("Failed to create socket: ") +
SOCKET_ERR_STR(LAST_SOCKET_ERR());
verbosestream << msg << std::endl;
if (noExceptions)
return false;
}

throw SocketException(std::string("Failed to create socket: error ") +
SOCKET_ERR_STR(LAST_SOCKET_ERR()));
throw SocketException(msg);
}

setTimeoutMs(0);

if (m_addr_family == AF_INET6) {
// Allow our socket to accept both IPv4 and IPv6 connections
// required on Windows:
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb513665(v=vs.85).aspx
int value = 0;
setsockopt(m_handle, IPPROTO_IPV6, IPV6_V6ONLY,
reinterpret_cast<char *>(&value), sizeof(value));
}

return true;
}

Expand All @@ -129,6 +120,20 @@ void UDPSocket::Bind(Address addr)
throw SocketException(errmsg);
}

if (m_addr_family == AF_INET6) {
// Allow our socket to accept both IPv4 and IPv6 connections
// required on Windows:
// <https://msdn.microsoft.com/en-us/library/windows/desktop/bb513665(v=vs.85).aspx>
int value = 0;
if (setsockopt(m_handle, IPPROTO_IPV6, IPV6_V6ONLY,
reinterpret_cast<char *>(&value), sizeof(value)) != 0) {
auto errmsg = SOCKET_ERR_STR(LAST_SOCKET_ERR());
errorstream << "Failed to disable V6ONLY: " << errmsg
<< "\nTry disabling ipv6_server to fix this." << std::endl;
throw SocketException(errmsg);
}
}

int ret = 0;

if (m_addr_family == AF_INET6) {
Expand Down
Loading