summaryrefslogtreecommitdiff
path: root/include/sessions.hpp
diff options
context:
space:
mode:
authorJiaqing Zhao <jiaqing.zhao@intel.com>2021-12-07 08:21:47 +0300
committerEd Tanous <ed@tanous.net>2021-12-10 04:16:55 +0300
commit41d61c8281ed9af50630c78f0a646e726139fb25 (patch)
tree2b904f845bd1d086fccd54014cb2b5e058acc175 /include/sessions.hpp
parent2558979c8b57a25ed8a4e676d3bf2a762d749056 (diff)
downloadbmcweb-41d61c8281ed9af50630c78f0a646e726139fb25.tar.xz
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>
Diffstat (limited to 'include/sessions.hpp')
-rw-r--r--include/sessions.hpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/include/sessions.hpp b/include/sessions.hpp
index 13a335a613..a05e47b6be 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 @@ class SessionStore
{
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 @@ class SessionStore
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;