mirror of
https://github.com/espressif/openthread.git
synced 2026-10-18 21:48:12 +00:00
[dhcp6-pd-client] use OwnedPtr in receive path (#13546)
This commit updates `InfraIf::HandleDhcp6Received()` and `Dhcp6PdClient::HandleReceived()` to use `OwnedPtr<Message>` for managing the received message lifetime, ensuring automatic freeing across all early-exit and normal code paths.
This commit is contained in:
@@ -374,7 +374,7 @@ Error Dhcp6PdClient::AppendIaPrefixOption(Message &aMessage, const Ip6::Prefix &
|
|||||||
return aMessage.Append(iaPrefixOption);
|
return aMessage.Append(iaPrefixOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dhcp6PdClient::HandleReceived(Message &aMessage)
|
void Dhcp6PdClient::HandleReceived(OwnedPtr<Message> aMessagePtr)
|
||||||
{
|
{
|
||||||
Header header;
|
Header header;
|
||||||
OffsetRange serverDuidOffsetRange;
|
OffsetRange serverDuidOffsetRange;
|
||||||
@@ -394,7 +394,7 @@ void Dhcp6PdClient::HandleReceived(Message &aMessage)
|
|||||||
ExitNow();
|
ExitNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
SuccessOrExit(ParseHeaderAndValidateMessage(aMessage, header));
|
SuccessOrExit(ParseHeaderAndValidateMessage(*aMessagePtr, header));
|
||||||
|
|
||||||
switch (header.GetMsgType())
|
switch (header.GetMsgType())
|
||||||
{
|
{
|
||||||
@@ -420,8 +420,8 @@ void Dhcp6PdClient::HandleReceived(Message &aMessage)
|
|||||||
// - The message does not include a Server ID option.
|
// - The message does not include a Server ID option.
|
||||||
|
|
||||||
VerifyOrExit(header.GetTransactionId() == mRetxTracker.GetTransactionId());
|
VerifyOrExit(header.GetTransactionId() == mRetxTracker.GetTransactionId());
|
||||||
SuccessOrExit(ClientIdOption::MatchesEui64Duid(aMessage, Get<Mac::Mac>().GetExtAddress()));
|
SuccessOrExit(ClientIdOption::MatchesEui64Duid(*aMessagePtr, Get<Mac::Mac>().GetExtAddress()));
|
||||||
SuccessOrExit(ServerIdOption::ReadDuid(aMessage, serverDuidOffsetRange));
|
SuccessOrExit(ServerIdOption::ReadDuid(*aMessagePtr, serverDuidOffsetRange));
|
||||||
|
|
||||||
// If we have selected a server, ensure the received server DUID
|
// If we have selected a server, ensure the received server DUID
|
||||||
// matches the one saved in `mServerDuid`. However, during the
|
// matches the one saved in `mServerDuid`. However, during the
|
||||||
@@ -433,28 +433,28 @@ void Dhcp6PdClient::HandleReceived(Message &aMessage)
|
|||||||
if (!mServerDuid.IsEmpty() && (mState != kStateSoliciting))
|
if (!mServerDuid.IsEmpty() && (mState != kStateSoliciting))
|
||||||
{
|
{
|
||||||
VerifyOrExit(serverDuidOffsetRange.GetLength() == mServerDuid.GetLength());
|
VerifyOrExit(serverDuidOffsetRange.GetLength() == mServerDuid.GetLength());
|
||||||
VerifyOrExit(aMessage.CompareBytes(serverDuidOffsetRange, mServerDuid.GetArrayBuffer()));
|
VerifyOrExit(aMessagePtr->CompareBytes(serverDuidOffsetRange, mServerDuid.GetArrayBuffer()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The client MUST process any SOL_MAX_RT option in an Advertise
|
// The client MUST process any SOL_MAX_RT option in an Advertise
|
||||||
// or Reply message, even if the message contains a Status Code
|
// or Reply message, even if the message contains a Status Code
|
||||||
// option indicating a failure and will be discarded by the client
|
// option indicating a failure and will be discarded by the client
|
||||||
|
|
||||||
ProcessSolMaxRtOption(aMessage);
|
ProcessSolMaxRtOption(*aMessagePtr);
|
||||||
|
|
||||||
switch (header.GetMsgType())
|
switch (header.GetMsgType())
|
||||||
{
|
{
|
||||||
case kMsgTypeAdvertise:
|
case kMsgTypeAdvertise:
|
||||||
HandleAdvertise(aMessage);
|
HandleAdvertise(*aMessagePtr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kMsgTypeReply:
|
case kMsgTypeReply:
|
||||||
HandleReply(aMessage);
|
HandleReply(*aMessagePtr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
aMessage.Free();
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Error Dhcp6PdClient::ParseHeaderAndValidateMessage(Message &aMessage, Header &aHeader)
|
Error Dhcp6PdClient::ParseHeaderAndValidateMessage(Message &aMessage, Header &aHeader)
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ private:
|
|||||||
void UpdateStateAfterRetxExhausted(void);
|
void UpdateStateAfterRetxExhausted(void);
|
||||||
Error AppendIaPdOption(Message &aMessage);
|
Error AppendIaPdOption(Message &aMessage);
|
||||||
Error AppendIaPrefixOption(Message &aMessage, const Ip6::Prefix &aPrefix);
|
Error AppendIaPrefixOption(Message &aMessage, const Ip6::Prefix &aPrefix);
|
||||||
void HandleReceived(Message &aMessage);
|
void HandleReceived(OwnedPtr<Message> aMessagePtr);
|
||||||
Error ParseHeaderAndValidateMessage(Message &aMessage, Dhcp6::Header &aHeader);
|
Error ParseHeaderAndValidateMessage(Message &aMessage, Dhcp6::Header &aHeader);
|
||||||
void HandleAdvertise(const Message &aMessage);
|
void HandleAdvertise(const Message &aMessage);
|
||||||
void HandleReply(const Message &aMessage);
|
void HandleReply(const Message &aMessage);
|
||||||
|
|||||||
@@ -213,21 +213,16 @@ void InfraIf::SendDhcp6(Message &aMessage, Ip6::Address &aDestAddress)
|
|||||||
otPlatInfraIfDhcp6PdClientSend(&GetInstance(), &aMessage, &aDestAddress, mIfIndex);
|
otPlatInfraIfDhcp6PdClientSend(&GetInstance(), &aMessage, &aDestAddress, mIfIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InfraIf::HandleDhcp6Received(Message &aMessage, uint32_t aInfraIfIndex)
|
void InfraIf::HandleDhcp6Received(OwnedPtr<Message> aMessagePtr, uint32_t aInfraIfIndex)
|
||||||
{
|
{
|
||||||
Error error = kErrorNone;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
VerifyOrExit(mInitialized && mIsRunning, error = kErrorInvalidState);
|
VerifyOrExit(mInitialized && mIsRunning, error = kErrorInvalidState);
|
||||||
VerifyOrExit(aInfraIfIndex == mIfIndex, error = kErrorDrop);
|
VerifyOrExit(aInfraIfIndex == mIfIndex, error = kErrorDrop);
|
||||||
|
|
||||||
Get<Dhcp6PdClient>().HandleReceived(aMessage);
|
Get<Dhcp6PdClient>().HandleReceived(aMessagePtr.PassOwnership());
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != kErrorNone)
|
|
||||||
{
|
|
||||||
aMessage.Free();
|
|
||||||
}
|
|
||||||
|
|
||||||
LogDebgOnError(error, "process DHCPv6 msg");
|
LogDebgOnError(error, "process DHCPv6 msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +338,7 @@ extern "C" void otPlatInfraIfDhcp6PdClientHandleReceived(otInstance *aInstance,
|
|||||||
otMessage *aMessage,
|
otMessage *aMessage,
|
||||||
uint32_t aInfraIfIndex)
|
uint32_t aInfraIfIndex)
|
||||||
{
|
{
|
||||||
AsCoreType(aInstance).Get<InfraIf>().HandleDhcp6Received(AsCoreType(aMessage), aInfraIfIndex);
|
AsCoreType(aInstance).Get<InfraIf>().HandleDhcp6Received(OwnedPtr<Message>(AsCoreTypePtr(aMessage)), aInfraIfIndex);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
#include "common/error.hpp"
|
#include "common/error.hpp"
|
||||||
#include "common/locator.hpp"
|
#include "common/locator.hpp"
|
||||||
#include "common/message.hpp"
|
#include "common/message.hpp"
|
||||||
|
#include "common/owned_ptr.hpp"
|
||||||
#include "common/string.hpp"
|
#include "common/string.hpp"
|
||||||
#include "net/ip6.hpp"
|
#include "net/ip6.hpp"
|
||||||
|
|
||||||
@@ -277,7 +278,7 @@ private:
|
|||||||
void DiscoverNat64PrefixDone(uint32_t aIfIndex, const Ip6::Prefix &aPrefix);
|
void DiscoverNat64PrefixDone(uint32_t aIfIndex, const Ip6::Prefix &aPrefix);
|
||||||
#endif
|
#endif
|
||||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_CLIENT_ENABLE
|
#if OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE && OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_CLIENT_ENABLE
|
||||||
void HandleDhcp6Received(Message &aMessage, uint32_t aInfraIfIndex);
|
void HandleDhcp6Received(OwnedPtr<Message> aMessagePtr, uint32_t aInfraIfIndex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool mInitialized : 1;
|
bool mInitialized : 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user