Convert IPv4-mapped IPv6 ClientIP back to IPv4
Current HTTP server creates an IPv6 acceptor to accept both IPv4 and
IPv6 connections. In this way, IPv4 address will be presented as IPv6
address in IPv4-mapped format. This patch converts it back to IPv4.
Tested:
Verified the ClientOriginIP in Session is shown in native IPv4 format
instead of IPv4-mapped IPv6 format.
Change-Id: Icd51260b2d4572d52f5c670128b7f07f6b5e6912
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/include/sessions.hpp b/include/sessions.hpp
index 13a335a..a05e47b 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -15,6 +15,7 @@
#include <pam_authenticate.hpp>
#include <random.hpp>
#include <sdbusplus/bus/match.hpp>
+#include <utils/ip_utils.hpp>
#include <csignal>
#include <random>
@@ -211,7 +212,8 @@
{
public:
std::shared_ptr<UserSession> generateUserSession(
- const std::string_view username, const std::string_view clientIp,
+ const std::string_view username,
+ const boost::asio::ip::address& clientIp,
const std::string_view clientId,
PersistenceType persistence = PersistenceType::TIMEOUT,
bool isConfigureSelfOnly = false)
@@ -261,11 +263,12 @@
return nullptr;
}
}
- auto session = std::make_shared<UserSession>(
- UserSession{uniqueId, sessionToken, std::string(username),
- csrfToken, std::string(clientId), std::string(clientIp),
- std::chrono::steady_clock::now(), persistence, false,
- isConfigureSelfOnly});
+
+ auto session = std::make_shared<UserSession>(UserSession{
+ uniqueId, sessionToken, std::string(username), csrfToken,
+ std::string(clientId), redfish::ip_util::toString(clientIp),
+ std::chrono::steady_clock::now(), persistence, false,
+ isConfigureSelfOnly});
auto it = authTokens.emplace(std::make_pair(sessionToken, session));
// Only need to write to disk if session isn't about to be destroyed.
needWrite = persistence == PersistenceType::TIMEOUT;