aboutsummaryrefslogtreecommitdiff
path: root/src/server/bnetserver
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-11-12 13:54:43 +0100
committerShauren <shauren.trinity@gmail.com>2024-11-12 13:54:43 +0100
commitaf4dcc93ed04c4f2219c14821b25cb9efeb7e781 (patch)
tree4fc5ac7ef91398ebf7d0684ab5a97ef392e2a2bc /src/server/bnetserver
parent280af853374b3cabcc2514d9604deeb39d03908b (diff)
Core/Networking: Support IPv6
Diffstat (limited to 'src/server/bnetserver')
-rw-r--r--src/server/bnetserver/REST/LoginRESTService.cpp37
-rw-r--r--src/server/bnetserver/REST/LoginRESTService.h3
-rw-r--r--src/server/bnetserver/bnetserver.conf.dist1
3 files changed, 20 insertions, 21 deletions
diff --git a/src/server/bnetserver/REST/LoginRESTService.cpp b/src/server/bnetserver/REST/LoginRESTService.cpp
index c9aabb248a3..b2ce7ddab56 100644
--- a/src/server/bnetserver/REST/LoginRESTService.cpp
+++ b/src/server/bnetserver/REST/LoginRESTService.cpp
@@ -77,28 +77,26 @@ bool LoginRESTService::StartNetwork(Trinity::Asio::IoContext& ioContext, std::st
_bindIP = bindIp;
_port = port;
+ using namespace std::string_literals;
+ std::array<std::string, 2> configKeys = { { "LoginREST.ExternalAddress"s, "LoginREST.LocalAddress"s } };
+
Trinity::Asio::Resolver resolver(ioContext);
- _hostnames[0] = sConfigMgr->GetStringDefault("LoginREST.ExternalAddress", "127.0.0.1");
- Optional<boost::asio::ip::tcp::endpoint> externalAddress = resolver.Resolve(boost::asio::ip::tcp::v4(), _hostnames[0], std::to_string(_port));
- if (!externalAddress)
+ for (std::size_t i = 0; i < _hostnames.size(); ++i)
{
- TC_LOG_ERROR("server.http.login", "Could not resolve LoginREST.ExternalAddress {}", _hostnames[0]);
- return false;
- }
+ _hostnames[i].first = sConfigMgr->GetStringDefault(configKeys[i], "127.0.0.1");
- _addresses[0] = externalAddress->address();
+ std::ranges::transform(resolver.ResolveAll(_hostnames[i].first, ""),
+ std::back_inserter(_hostnames[i].second),
+ [](boost::asio::ip::tcp::endpoint const& endpoint) { return endpoint.address(); });
- _hostnames[1] = sConfigMgr->GetStringDefault("LoginREST.LocalAddress", "127.0.0.1");
- Optional<boost::asio::ip::tcp::endpoint> localAddress = resolver.Resolve(boost::asio::ip::tcp::v4(), _hostnames[1], std::to_string(_port));
- if (!localAddress)
- {
- TC_LOG_ERROR("server.http.login", "Could not resolve LoginREST.LocalAddress {}", _hostnames[1]);
- return false;
+ if (_hostnames[i].second.empty())
+ {
+ TC_LOG_ERROR("server.http.login", "Could not resolve {} {}", configKeys[i], _hostnames[i].first);
+ return false;
+ }
}
- _addresses[1] = localAddress->address();
-
// set up form inputs
JSON::Login::FormInput* input;
_formInputs.set_type(JSON::Login::LOGIN_FORM);
@@ -129,13 +127,14 @@ bool LoginRESTService::StartNetwork(Trinity::Asio::IoContext& ioContext, std::st
std::string const& LoginRESTService::GetHostnameForClient(boost::asio::ip::address const& address) const
{
- if (auto addressIndex = Trinity::Net::SelectAddressForClient(address, _addresses))
- return _hostnames[*addressIndex];
+ for (std::size_t i = 0; i < _hostnames.size(); ++i)
+ if (Trinity::Net::SelectAddressForClient(address, _hostnames[i].second))
+ return _hostnames[i].first;
if (address.is_loopback())
- return _hostnames[1];
+ return _hostnames[1].first;
- return _hostnames[0];
+ return _hostnames[0].first;
}
std::string LoginRESTService::ExtractAuthorization(HttpRequest const& request)
diff --git a/src/server/bnetserver/REST/LoginRESTService.h b/src/server/bnetserver/REST/LoginRESTService.h
index bcc99808505..079bb6fca9c 100644
--- a/src/server/bnetserver/REST/LoginRESTService.h
+++ b/src/server/bnetserver/REST/LoginRESTService.h
@@ -83,8 +83,7 @@ private:
JSON::Login::FormInputs _formInputs;
std::string _bindIP;
uint16 _port;
- std::array<std::string, 2> _hostnames;
- std::array<boost::asio::ip::address, 2> _addresses;
+ std::array<std::pair<std::string, std::vector<boost::asio::ip::address>>, 2> _hostnames;
uint32 _loginTicketDuration;
};
}
diff --git a/src/server/bnetserver/bnetserver.conf.dist b/src/server/bnetserver/bnetserver.conf.dist
index 94fd3964590..1936d57d3fa 100644
--- a/src/server/bnetserver/bnetserver.conf.dist
+++ b/src/server/bnetserver/bnetserver.conf.dist
@@ -83,6 +83,7 @@ LoginREST.TicketDuration=3600
#
# BindIP
# Description: Bind auth server to IP/hostname
+# Using IPv6 address (such as "::") will enable both IPv4 and IPv6 connections
# Default: "0.0.0.0" - (Bind to all IPs on the system)
BindIP = "0.0.0.0"