[tmf] update IsTmfMessage() method (#7875)

This commit updates `Tmf::IsTmfMessage()` method to check source and
destination addresses. This change helps make this method more
generic(allow it to be used for both rx/tx messages). This commit
also simplifies the implementation (avoid using complex expression
containing multiple `&&` and `||`).
This commit is contained in:
Abtin Keshavarzian
2022-07-12 10:15:34 -07:00
committed by GitHub
parent eca7a63adc
commit 158e59f267
2 changed files with 35 additions and 19 deletions
+21 -15
View File
@@ -89,26 +89,32 @@ Error Agent::Filter(const Message &aMessage, const Ip6::MessageInfo &aMessageInf
{
OT_UNUSED_VARIABLE(aMessage);
return static_cast<Agent *>(aContext)->IsTmfMessage(aMessageInfo) ? kErrorNone : kErrorNotTmf;
return static_cast<Agent *>(aContext)->IsTmfMessage(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr(),
aMessageInfo.GetSockPort())
? kErrorNone
: kErrorNotTmf;
}
bool Agent::IsTmfMessage(const Ip6::MessageInfo &aMessageInfo) const
bool Agent::IsTmfMessage(const Ip6::Address &aSourceAddress, const Ip6::Address &aDestAddress, uint16_t aDestPort) const
{
bool rval = true;
bool isTmf = false;
VerifyOrExit(aDestPort == kUdpPort);
if (aSourceAddress.IsLinkLocal())
{
isTmf = aDestAddress.IsLinkLocal() || aDestAddress.IsLinkLocalMulticast();
ExitNow();
}
VerifyOrExit(Get<Mle::Mle>().IsMeshLocalAddress(aSourceAddress));
VerifyOrExit(Get<Mle::Mle>().IsMeshLocalAddress(aDestAddress) || aDestAddress.IsLinkLocalMulticast() ||
aDestAddress.IsRealmLocalMulticast());
isTmf = true;
// A TMF message must comply with following rules:
// 1. The destination is a Mesh Local Address or a Link-Local Multicast Address or a Realm-Local Multicast Address,
// and the source is a Mesh Local Address. Or
// 2. Both the destination and the source are Link-Local Addresses.
VerifyOrExit(
((Get<Mle::MleRouter>().IsMeshLocalAddress(aMessageInfo.GetSockAddr()) ||
aMessageInfo.GetSockAddr().IsLinkLocalMulticast() || aMessageInfo.GetSockAddr().IsRealmLocalMulticast()) &&
Get<Mle::MleRouter>().IsMeshLocalAddress(aMessageInfo.GetPeerAddr())) ||
((aMessageInfo.GetSockAddr().IsLinkLocal() || aMessageInfo.GetSockAddr().IsLinkLocalMulticast()) &&
aMessageInfo.GetPeerAddr().IsLinkLocal()),
rval = false);
exit:
return rval;
return isTmf;
}
} // namespace Tmf
+14 -4
View File
@@ -153,13 +153,23 @@ public:
Error Start(void);
/**
* This method returns whether Thread Management Framework Addressing Rules are met.
* This method indicates whether or not a message meets TMF addressing rules.
*
* @retval TRUE if Thread Management Framework Addressing Rules are met.
* @retval FALSE if Thread Management Framework Addressing Rules are not met.
* A TMF message MUST comply with following rules:
*
* - The destination port is `Tmf::kUdpPort`.
* - Both source and destination addresses are Link-Local, or
* - Source is Mesh Local and then destination is Mesh Local or Link-Local Multicast or Realm-Local Multicast.
*
* @param[in] aSourceAddress Source IPv6 address.
* @param[in] aDestAddress Destination IPv6 address.
* @param[in] aDestPort Destination port number.
*
* @retval TRUE if TMF addressing rules are met.
* @retval FALSE if TMF addressing rules are not met.
*
*/
bool IsTmfMessage(const Ip6::MessageInfo &aMessageInfo) const;
bool IsTmfMessage(const Ip6::Address &aSourceAddress, const Ip6::Address &aDestAddress, uint16_t aDestPort) const;
private:
static Error Filter(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);