mirror of
https://github.com/espressif/openthread.git
synced 2026-08-04 18:07:47 +00:00
[message] add IsOrigin{}() helper methods (#9506)
This commit adds helper methods to the `Message` class to check if the message origin matches a specific origin. These methods are used in the code as syntactic sugar to simplify the code.
This commit is contained in:
@@ -211,7 +211,7 @@ otError otCoapSendRequestBlockWiseWithParameters(otInstance *aIn
|
||||
Error error;
|
||||
const Coap::TxParameters &txParameters = Coap::TxParameters::From(aTxParameters);
|
||||
|
||||
VerifyOrExit(AsCoreType(aMessage).GetOrigin() != Message::kOriginThreadNetif, error = kErrorInvalidArgs);
|
||||
VerifyOrExit(!AsCoreType(aMessage).IsOriginThreadNetif(), error = kErrorInvalidArgs);
|
||||
|
||||
if (aTxParameters != nullptr)
|
||||
{
|
||||
@@ -238,7 +238,7 @@ otError otCoapSendRequestWithParameters(otInstance *aInstance,
|
||||
|
||||
const Coap::TxParameters &txParameters = Coap::TxParameters::From(aTxParameters);
|
||||
|
||||
VerifyOrExit(AsCoreType(aMessage).GetOrigin() != Message::kOriginThreadNetif, error = kErrorInvalidArgs);
|
||||
VerifyOrExit(!AsCoreType(aMessage).IsOriginThreadNetif(), error = kErrorInvalidArgs);
|
||||
|
||||
if (aTxParameters != nullptr)
|
||||
{
|
||||
@@ -296,7 +296,7 @@ otError otCoapSendResponseBlockWiseWithParameters(otInstance *aI
|
||||
{
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(AsCoreType(aMessage).GetOrigin() != Message::kOriginThreadNetif, error = kErrorInvalidArgs);
|
||||
VerifyOrExit(!AsCoreType(aMessage).IsOriginThreadNetif(), error = kErrorInvalidArgs);
|
||||
|
||||
error = AsCoreType(aInstance).GetApplicationCoap().SendMessage(AsCoapMessage(aMessage), AsCoreType(aMessageInfo),
|
||||
Coap::TxParameters::From(aTxParameters), nullptr,
|
||||
@@ -313,7 +313,7 @@ otError otCoapSendResponseWithParameters(otInstance *aInstance,
|
||||
{
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(AsCoreType(aMessage).GetOrigin() != Message::kOriginThreadNetif, error = kErrorInvalidArgs);
|
||||
VerifyOrExit(!AsCoreType(aMessage).IsOriginThreadNetif(), error = kErrorInvalidArgs);
|
||||
|
||||
error = AsCoreType(aInstance).GetApplicationCoap().SendMessage(
|
||||
AsCoapMessage(aMessage), AsCoreType(aMessageInfo), Coap::TxParameters::From(aTxParameters), nullptr, nullptr);
|
||||
|
||||
@@ -134,7 +134,7 @@ otError otIp6Send(otInstance *aInstance, otMessage *aMessage)
|
||||
{
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(AsCoreType(aMessage).GetOrigin() != Message::kOriginThreadNetif, error = kErrorInvalidArgs);
|
||||
VerifyOrExit(!AsCoreType(aMessage).IsOriginThreadNetif(), error = kErrorInvalidArgs);
|
||||
|
||||
error = AsCoreType(aInstance).Get<Ip6::Ip6>().SendRaw(AsCoreType(aMessage));
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ otError otUdpSend(otInstance *aInstance, otUdpSocket *aSocket, otMessage *aMessa
|
||||
{
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(AsCoreType(aMessage).GetOrigin() != Message::kOriginThreadNetif, error = kErrorInvalidArgs);
|
||||
VerifyOrExit(!AsCoreType(aMessage).IsOriginThreadNetif(), error = kErrorInvalidArgs);
|
||||
|
||||
error = AsCoreType(aInstance).Get<Ip6::Udp>().SendTo(AsCoreType(aSocket), AsCoreType(aMessage),
|
||||
AsCoreType(aMessageInfo));
|
||||
@@ -124,7 +124,7 @@ otError otUdpSendDatagram(otInstance *aInstance, otMessage *aMessage, otMessageI
|
||||
{
|
||||
otError error;
|
||||
|
||||
VerifyOrExit(AsCoreType(aMessage).GetOrigin() != Message::kOriginThreadNetif, error = kErrorInvalidArgs);
|
||||
VerifyOrExit(!AsCoreType(aMessage).IsOriginThreadNetif(), error = kErrorInvalidArgs);
|
||||
|
||||
return AsCoreType(aInstance).Get<Ip6::Udp>().SendDatagram(AsCoreType(aMessage), AsCoreType(aMessageInfo),
|
||||
Ip6::kProtoUdp);
|
||||
|
||||
@@ -1184,6 +1184,33 @@ public:
|
||||
*/
|
||||
void SetOrigin(Origin aOrigin) { GetMetadata().mOrigin = aOrigin; }
|
||||
|
||||
/**
|
||||
* Indicates whether or not the message origin is Thread Netif.
|
||||
*
|
||||
* @retval TRUE If the message origin is Thread Netif.
|
||||
* @retval FALSE If the message origin is not Thread Netif.
|
||||
*
|
||||
*/
|
||||
bool IsOriginThreadNetif(void) const { return GetOrigin() == kOriginThreadNetif; }
|
||||
|
||||
/**
|
||||
* Indicates whether or not the message origin is a trusted source on host.
|
||||
*
|
||||
* @retval TRUE If the message origin is a trusted source on host.
|
||||
* @retval FALSE If the message origin is not a trusted source on host.
|
||||
*
|
||||
*/
|
||||
bool IsOriginHostTrusted(void) const { return GetOrigin() == kOriginHostTrusted; }
|
||||
|
||||
/**
|
||||
* Indicates whether or not the message origin is an untrusted source on host.
|
||||
*
|
||||
* @retval TRUE If the message origin is an untrusted source on host.
|
||||
* @retval FALSE If the message origin is not an untrusted source on host.
|
||||
*
|
||||
*/
|
||||
bool IsOriginHostUntrusted(void) const { return GetOrigin() == kOriginHostUntrusted; }
|
||||
|
||||
/**
|
||||
* Indicates whether or not link security is enabled for the message.
|
||||
*
|
||||
|
||||
+16
-17
@@ -830,7 +830,7 @@ Error Ip6::HandleExtensionHeaders(Message &aMessage,
|
||||
bool &aReceive)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
bool isOutbound = (aMessage.GetOrigin() != Message::kOriginThreadNetif);
|
||||
bool isOutbound = !aMessage.IsOriginThreadNetif();
|
||||
ExtensionHeader extHeader;
|
||||
|
||||
while (aReceive || aNextHeader == kProtoHopOpts)
|
||||
@@ -1136,15 +1136,14 @@ exit:
|
||||
|
||||
Error Ip6::HandleDatagram(Message &aMessage, const void *aLinkMessageInfo, bool aIsReassembled)
|
||||
{
|
||||
Error error;
|
||||
MessageInfo messageInfo;
|
||||
Header header;
|
||||
bool receive;
|
||||
bool forwardThread;
|
||||
bool forwardHost;
|
||||
bool shouldFreeMessage;
|
||||
uint8_t nextHeader;
|
||||
Message::Origin origin = aMessage.GetOrigin();
|
||||
Error error;
|
||||
MessageInfo messageInfo;
|
||||
Header header;
|
||||
bool receive;
|
||||
bool forwardThread;
|
||||
bool forwardHost;
|
||||
bool shouldFreeMessage;
|
||||
uint8_t nextHeader;
|
||||
|
||||
start:
|
||||
receive = false;
|
||||
@@ -1168,10 +1167,10 @@ start:
|
||||
{
|
||||
// Destination is multicast
|
||||
|
||||
forwardThread = (origin != Message::kOriginThreadNetif);
|
||||
forwardThread = !aMessage.IsOriginThreadNetif();
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
if ((origin == Message::kOriginThreadNetif) && header.GetDestination().IsMulticastLargerThanRealmLocal() &&
|
||||
if (aMessage.IsOriginThreadNetif() && header.GetDestination().IsMulticastLargerThanRealmLocal() &&
|
||||
Get<ChildTable>().HasSleepyChildWithAddress(header.GetDestination()))
|
||||
{
|
||||
forwardThread = true;
|
||||
@@ -1180,7 +1179,7 @@ start:
|
||||
|
||||
forwardHost = header.GetDestination().IsMulticastLargerThanRealmLocal();
|
||||
|
||||
if (((origin == Message::kOriginThreadNetif) || aMessage.GetMulticastLoop()) &&
|
||||
if ((aMessage.IsOriginThreadNetif() || aMessage.GetMulticastLoop()) &&
|
||||
Get<ThreadNetif>().IsMulticastSubscribed(header.GetDestination()))
|
||||
{
|
||||
receive = true;
|
||||
@@ -1198,7 +1197,7 @@ start:
|
||||
{
|
||||
receive = true;
|
||||
}
|
||||
else if ((origin != Message::kOriginThreadNetif) || !header.GetDestination().IsLinkLocal())
|
||||
else if (!aMessage.IsOriginThreadNetif() || !header.GetDestination().IsLinkLocal())
|
||||
{
|
||||
if (header.GetDestination().IsLinkLocal())
|
||||
{
|
||||
@@ -1261,7 +1260,7 @@ start:
|
||||
{
|
||||
uint8_t hopLimit;
|
||||
|
||||
if (origin == Message::kOriginThreadNetif)
|
||||
if (aMessage.IsOriginThreadNetif())
|
||||
{
|
||||
VerifyOrExit(Get<Mle::Mle>().IsRouterOrLeader());
|
||||
header.SetHopLimit(header.GetHopLimit() - 1);
|
||||
@@ -1289,7 +1288,7 @@ start:
|
||||
VerifyOrExit(isAllowedType, error = kErrorDrop);
|
||||
}
|
||||
|
||||
if (aMessage.GetOrigin() == Message::kOriginHostUntrusted && nextHeader == kProtoUdp)
|
||||
if (aMessage.IsOriginHostUntrusted() && (nextHeader == kProtoUdp))
|
||||
{
|
||||
uint16_t destPort;
|
||||
|
||||
@@ -1304,7 +1303,7 @@ start:
|
||||
}
|
||||
|
||||
#if !OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
if ((origin == Message::kOriginHostTrusted && !aMessage.IsLoopbackToHostAllowed()) && (nextHeader == kProtoUdp))
|
||||
if (aMessage.IsOriginHostTrusted() && !aMessage.IsLoopbackToHostAllowed() && (nextHeader == kProtoUdp))
|
||||
{
|
||||
uint16_t destPort;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user