From 893f2d4cef5b0ee619a04ef6208ef0c1b974c8a3 Mon Sep 17 00:00:00 2001 From: Shauren Date: Tue, 12 Nov 2024 13:54:43 +0100 Subject: Core/Networking: Support IPv6 (cherry picked from commit af4dcc93ed04c4f2219c14821b25cb9efeb7e781) # Conflicts: # sql/base/auth_database.sql # sql/updates/auth/cata_classic/2024_11_12_00_auth.sql --- src/server/bnetserver/REST/LoginRESTService.cpp | 37 ++++++++++++------------- src/server/bnetserver/REST/LoginRESTService.h | 3 +- src/server/bnetserver/bnetserver.conf.dist | 1 + 3 files changed, 20 insertions(+), 21 deletions(-) (limited to 'src/server/bnetserver') 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 configKeys = { { "LoginREST.ExternalAddress"s, "LoginREST.LocalAddress"s } }; + Trinity::Asio::Resolver resolver(ioContext); - _hostnames[0] = sConfigMgr->GetStringDefault("LoginREST.ExternalAddress", "127.0.0.1"); - Optional 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 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 _hostnames; - std::array _addresses; + std::array>, 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" -- cgit v1.2.3