From ae1fda44032a361874417c4006ddcbd951974399 Mon Sep 17 00:00:00 2001 From: Vernon Mauery Date: Mon, 15 Oct 2018 12:55:34 -0700 Subject: netipmid: use std::shared_ptr instead of weak_ptr/lock All of the instances of getSession and startSession were assigning the result to a local shared_ptr via lock on the weak_ptr. It doesn't make sense to demote the shared_ptr (from the sessionsMap) to a weak_ptr via the return, only to promote to a shared_ptr again via lock. Tested-by: running ipmitool -H a.b.c.d -P 0penBmc -I lanplus mc info Sessions start and stop, same as before. Change-Id: Ic10779285891d73ee51115f16ed0000b38d1c52a Signed-off-by: Vernon Mauery --- command/open_session.cpp | 19 +++++++++---------- command/payload_cmds.cpp | 5 ++--- command/rakp12.cpp | 7 +++---- command/rakp34.cpp | 13 +++++-------- command/session_cmds.cpp | 5 ++--- command/sol_cmds.cpp | 3 +-- message_handler.cpp | 17 ++++++----------- message_parsers.cpp | 20 ++++++++------------ sessions_manager.cpp | 6 +++--- sessions_manager.hpp | 12 ++++++------ sol/sol_context.cpp | 3 +-- 11 files changed, 46 insertions(+), 64 deletions(-) diff --git a/command/open_session.cpp b/command/open_session.cpp index b41eefa..b48b7e9 100644 --- a/command/open_session.cpp +++ b/command/open_session.cpp @@ -50,16 +50,15 @@ std::vector openSession(const std::vector& inPayload, { // Start an IPMI session session = - (std::get(singletonPool) - .startSession( - endian::from_ipmi<>(request->remoteConsoleSessionID), - static_cast(request->maxPrivLevel), - static_cast( - request->authAlgo), - static_cast( - request->intAlgo), - static_cast(request->confAlgo))) - .lock(); + std::get(singletonPool) + .startSession( + endian::from_ipmi<>(request->remoteConsoleSessionID), + static_cast(request->maxPrivLevel), + static_cast( + request->authAlgo), + static_cast( + request->intAlgo), + static_cast(request->confAlgo)); } catch (std::exception& e) { diff --git a/command/payload_cmds.cpp b/command/payload_cmds.cpp index 8030b92..2e8ac6f 100644 --- a/command/payload_cmds.cpp +++ b/command/payload_cmds.cpp @@ -47,9 +47,8 @@ std::vector activatePayload(const std::vector& inPayload, return outPayload; } - auto session = (std::get(singletonPool) - .getSession(handler.sessionID)) - .lock(); + auto session = std::get(singletonPool) + .getSession(handler.sessionID); if (!request->encryption && session->isCryptAlgoEnabled()) { diff --git a/command/rakp12.cpp b/command/rakp12.cpp index b0aad87..b4842b2 100644 --- a/command/rakp12.cpp +++ b/command/rakp12.cpp @@ -35,10 +35,9 @@ std::vector RAKP12(const std::vector& inPayload, std::shared_ptr session; try { - session = (std::get(singletonPool) - .getSession( - endian::from_ipmi(request->managedSystemSessionID))) - .lock(); + session = + std::get(singletonPool) + .getSession(endian::from_ipmi(request->managedSystemSessionID)); } catch (std::exception& e) { diff --git a/command/rakp34.cpp b/command/rakp34.cpp index 76236d5..84c90fc 100644 --- a/command/rakp34.cpp +++ b/command/rakp34.cpp @@ -16,8 +16,7 @@ namespace command void applyIntegrityAlgo(const uint32_t bmcSessionID) { auto session = - (std::get(singletonPool).getSession(bmcSessionID)) - .lock(); + std::get(singletonPool).getSession(bmcSessionID); auto authAlgo = session->getAuthAlgo(); @@ -45,8 +44,7 @@ void applyIntegrityAlgo(const uint32_t bmcSessionID) void applyCryptAlgo(const uint32_t bmcSessionID) { auto session = - (std::get(singletonPool).getSession(bmcSessionID)) - .lock(); + std::get(singletonPool).getSession(bmcSessionID); auto authAlgo = session->getAuthAlgo(); @@ -96,10 +94,9 @@ std::vector RAKP34(const std::vector& inPayload, std::shared_ptr session; try { - session = (std::get(singletonPool) - .getSession( - endian::from_ipmi(request->managedSystemSessionID))) - .lock(); + session = + std::get(singletonPool) + .getSession(endian::from_ipmi(request->managedSystemSessionID)); } catch (std::exception& e) { diff --git a/command/session_cmds.cpp b/command/session_cmds.cpp index fb2d074..d363c1e 100644 --- a/command/session_cmds.cpp +++ b/command/session_cmds.cpp @@ -23,9 +23,8 @@ std::vector response->completionCode = IPMI_CC_OK; uint8_t reqPrivilegeLevel = request->reqPrivLevel; - auto session = (std::get(singletonPool) - .getSession(handler.sessionID)) - .lock(); + auto session = std::get(singletonPool) + .getSession(handler.sessionID); if (reqPrivilegeLevel == 0) // Just return present privilege level { diff --git a/command/sol_cmds.cpp b/command/sol_cmds.cpp index fb6f19e..a8fa410 100644 --- a/command/sol_cmds.cpp +++ b/command/sol_cmds.cpp @@ -57,8 +57,7 @@ void activating(uint8_t payloadInstance, uint32_t sessionID) request->minorVersion = MINOR_VERSION; auto session = - (std::get(singletonPool).getSession(sessionID)) - .lock(); + std::get(singletonPool).getSession(sessionID); message::Handler msgHandler(session->channelPtr, sessionID); diff --git a/message_handler.cpp b/message_handler.cpp index 62855a9..c5d5d4e 100644 --- a/message_handler.cpp +++ b/message_handler.cpp @@ -35,9 +35,8 @@ std::unique_ptr Handler::receive() std::unique_ptr message; std::tie(message, sessionHeader) = parser::unflatten(packet); - auto session = (std::get(singletonPool) - .getSession(message->bmcSessionID)) - .lock(); + auto session = std::get(singletonPool) + .getSession(message->bmcSessionID); sessionID = message->bmcSessionID; message->rcSessionID = session->getRCSessionID(); @@ -166,8 +165,7 @@ uint32_t Handler::getCommand(Message& message) void Handler::send(Message& outMessage) { auto session = - (std::get(singletonPool).getSession(sessionID)) - .lock(); + std::get(singletonPool).getSession(sessionID); // Flatten the packet auto packet = parser::flatten(outMessage, sessionHeader, *session); @@ -183,8 +181,7 @@ void Handler::send(Message& outMessage) void Handler::setChannelInSession() const { auto session = - (std::get(singletonPool).getSession(sessionID)) - .lock(); + std::get(singletonPool).getSession(sessionID); session->channelPtr = channel; } @@ -194,8 +191,7 @@ void Handler::sendSOLPayload(const std::vector& input) Message outMessage; auto session = - (std::get(singletonPool).getSession(sessionID)) - .lock(); + std::get(singletonPool).getSession(sessionID); outMessage.payloadType = PayloadType::SOL; outMessage.payload = input; @@ -213,8 +209,7 @@ void Handler::sendUnsolicitedIPMIPayload(uint8_t netfn, uint8_t cmd, Message outMessage; auto session = - (std::get(singletonPool).getSession(sessionID)) - .lock(); + std::get(singletonPool).getSession(sessionID); outMessage.payloadType = PayloadType::IPMI; outMessage.isPacketEncrypted = session->isCryptAlgoEnabled(); diff --git a/message_parsers.cpp b/message_parsers.cpp index 695b5b7..7497747 100644 --- a/message_parsers.cpp +++ b/message_parsers.cpp @@ -280,9 +280,8 @@ bool verifyPacketIntegrity(const std::vector& packet, return false; } - auto session = (std::get(singletonPool) - .getSession(message.bmcSessionID)) - .lock(); + auto session = std::get(singletonPool) + .getSession(message.bmcSessionID); auto integrityAlgo = session->getIntegrityAlgo(); @@ -322,9 +321,8 @@ void addIntegrityData(std::vector& packet, const Message& message, trailer->padLength = paddingLen; trailer->nextHeader = parser::RMCP_MESSAGE_CLASS_IPMI; - auto session = (std::get(singletonPool) - .getSession(message.bmcSessionID)) - .lock(); + auto session = std::get(singletonPool) + .getSession(message.bmcSessionID); auto integrityData = session->getIntegrityAlgo()->generateIntegrityData(packet); @@ -335,9 +333,8 @@ void addIntegrityData(std::vector& packet, const Message& message, std::vector decryptPayload(const std::vector& packet, const Message& message, size_t payloadLen) { - auto session = (std::get(singletonPool) - .getSession(message.bmcSessionID)) - .lock(); + auto session = std::get(singletonPool) + .getSession(message.bmcSessionID); return session->getCryptAlgo()->decryptPayload( packet, sizeof(SessionHeader_t), payloadLen); @@ -345,9 +342,8 @@ std::vector decryptPayload(const std::vector& packet, std::vector encryptPayload(Message& message) { - auto session = (std::get(singletonPool) - .getSession(message.bmcSessionID)) - .lock(); + auto session = std::get(singletonPool) + .getSession(message.bmcSessionID); return session->getCryptAlgo()->encryptPayload(message.payload); } diff --git a/sessions_manager.cpp b/sessions_manager.cpp index 10c2764..bf7ff34 100644 --- a/sessions_manager.cpp +++ b/sessions_manager.cpp @@ -24,7 +24,7 @@ Manager::Manager() std::srand(std::time(0)); } -std::weak_ptr +std::shared_ptr Manager::startSession(SessionID remoteConsoleSessID, Privilege priv, cipher::rakp_auth::Algorithms authAlgo, cipher::integrity::Algorithms intAlgo, @@ -120,8 +120,8 @@ bool Manager::stopSession(SessionID bmcSessionID) } } -std::weak_ptr Manager::getSession(SessionID sessionID, - RetrieveOption option) +std::shared_ptr Manager::getSession(SessionID sessionID, + RetrieveOption option) { switch (option) { diff --git a/sessions_manager.hpp b/sessions_manager.hpp index cf28238..251ca96 100644 --- a/sessions_manager.hpp +++ b/sessions_manager.hpp @@ -53,11 +53,11 @@ class Manager * @return session handle on success and nullptr on failure * */ - std::weak_ptr startSession(SessionID remoteConsoleSessID, - Privilege priv, - cipher::rakp_auth::Algorithms authAlgo, - cipher::integrity::Algorithms intAlgo, - cipher::crypt::Algorithms cryptAlgo); + std::shared_ptr + startSession(SessionID remoteConsoleSessID, Privilege priv, + cipher::rakp_auth::Algorithms authAlgo, + cipher::integrity::Algorithms intAlgo, + cipher::crypt::Algorithms cryptAlgo); /** * @brief Stop IPMI Session @@ -79,7 +79,7 @@ class Manager * @return session handle on success and nullptr on failure * */ - std::weak_ptr + std::shared_ptr getSession(SessionID sessionID, RetrieveOption option = RetrieveOption::BMC_SESSION_ID); diff --git a/sol/sol_context.cpp b/sol/sol_context.cpp index 7329ed2..fffb66f 100644 --- a/sol/sol_context.cpp +++ b/sol/sol_context.cpp @@ -205,8 +205,7 @@ void Context::resendPayload(bool clear) void Context::sendPayload(const std::vector& out) const { auto session = - (std::get(singletonPool).getSession(sessionID)) - .lock(); + std::get(singletonPool).getSession(sessionID); message::Handler msgHandler(session->channelPtr, sessionID); -- cgit v1.2.1