Disable IPv6 socket in server for IPv4 only network
This commit is contained in:
parent
58a2010d0f
commit
6d2e060bf2
@ -189,6 +189,7 @@ bool NetworkConfig::roundValuesNow() const
|
||||
*/
|
||||
void NetworkConfig::detectIPType()
|
||||
{
|
||||
#ifdef ENABLE_IPV6
|
||||
ENetAddress addr;
|
||||
addr.host = STKHost::HOST_ANY;
|
||||
addr.port = STKHost::PORT_ANY;
|
||||
@ -346,4 +347,7 @@ void NetworkConfig::detectIPType()
|
||||
"NAT64 prefix is %s.", m_nat64_prefix.c_str());
|
||||
}
|
||||
}
|
||||
#else
|
||||
m_ip_type = IP_V4;
|
||||
#endif
|
||||
} // detectIPType
|
||||
|
@ -105,6 +105,7 @@ void ConnectToServer::getClientServerInfo()
|
||||
{
|
||||
assert(m_server);
|
||||
// Allow up to 10 seconds for the separate process to fully start-up
|
||||
bool server_ipv6_socket = false;
|
||||
bool started = false;
|
||||
uint64_t timeout = StkTime::getMonoTimeMs() + 10000;
|
||||
const std::string& sid = NetworkConfig::get()->getServerIdFile();
|
||||
@ -123,12 +124,13 @@ void ConnectToServer::getClientServerInfo()
|
||||
if (f.find(server_id_file) != std::string::npos)
|
||||
{
|
||||
auto split = StringUtils::split(f, '_');
|
||||
if (split.size() != 3)
|
||||
if (split.size() != 4)
|
||||
continue;
|
||||
if (!StringUtils::fromString(split[1], server_id))
|
||||
continue;
|
||||
if (!StringUtils::fromString(split[2], port))
|
||||
continue;
|
||||
server_ipv6_socket = split[3] == "v6";
|
||||
file_manager->removeFile(dir + "/" + f);
|
||||
started = true;
|
||||
break;
|
||||
@ -151,6 +153,11 @@ void ConnectToServer::getClientServerInfo()
|
||||
assert(port != 0);
|
||||
m_server_address.setPort(port);
|
||||
m_server->setPrivatePort(port);
|
||||
if (server_ipv6_socket)
|
||||
{
|
||||
m_server->setIPV6Address("::1");
|
||||
m_server->setIPV6Connection(true);
|
||||
}
|
||||
if (server_id != 0)
|
||||
{
|
||||
m_server->setSupportsEncryption(true);
|
||||
@ -404,13 +411,13 @@ bool ConnectToServer::tryConnect(int timeout, int retry, bool another_port,
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
std::string addr_string = m_server->getIPV6Address();
|
||||
std::string port =
|
||||
StringUtils::toString(m_server->getAddress().getPort());
|
||||
StringUtils::toString(m_server_address.getPort());
|
||||
// Convert to a NAT64 address from IPv4
|
||||
if (!m_server->useIPV6Connection() &&
|
||||
NetworkConfig::get()->getIPType() == NetworkConfig::IP_V6_NAT64)
|
||||
{
|
||||
// From IPv4
|
||||
addr_string = m_server->getAddress().toString(false/*show_port*/);
|
||||
addr_string = m_server_address.toString(false/*show_port*/);
|
||||
addr_string = NetworkConfig::get()->getNAT64Prefix() + addr_string;
|
||||
}
|
||||
if (getaddrinfo_compat(addr_string.c_str(), port.c_str(),
|
||||
|
@ -866,6 +866,10 @@ void ServerLobby::createServerIdFile()
|
||||
std::fstream fs;
|
||||
sid += StringUtils::toString(m_server_id_online.load()) + "_" +
|
||||
StringUtils::toString(STKHost::get()->getPrivatePort());
|
||||
if (isIPv6Socket())
|
||||
sid += "_v6";
|
||||
else
|
||||
sid += "_v4";
|
||||
io::IWriteFile* file = irr::io::createWriteFile(sid.c_str(), false);
|
||||
if (file)
|
||||
file->drop();
|
||||
|
@ -260,6 +260,14 @@ STKHost::STKHost(bool server)
|
||||
if (server)
|
||||
{
|
||||
setIPv6Socket(ServerConfig::m_ipv6_server ? 1 : 0);
|
||||
#ifdef ENABLE_IPV6
|
||||
if (NetworkConfig::get()->getIPType() == NetworkConfig::IP_V4 &&
|
||||
ServerConfig::m_ipv6_server)
|
||||
{
|
||||
Log::warn("STKHost", "Disable IPv6 socket due to missing IPv6.");
|
||||
setIPv6Socket(0);
|
||||
}
|
||||
#endif
|
||||
addr.port = ServerConfig::m_server_port;
|
||||
if (addr.port == 0 && !UserConfigParams::m_random_server_port)
|
||||
addr.port = stk_config->m_server_port;
|
||||
@ -728,7 +736,7 @@ void STKHost::setPublicAddress(bool ipv4)
|
||||
if (NetworkConfig::get()->isServer() && ipv4 &&
|
||||
port != m_public_address.getPort())
|
||||
{
|
||||
if (ServerConfig::m_ipv6_server)
|
||||
if (isIPv6Socket())
|
||||
{
|
||||
Log::error("STKHost",
|
||||
"IPv6 has different port than IPv4.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user