mirror of
https://github.com/espressif/openthread.git
synced 2026-08-15 07:07:46 +00:00
Update TMF rules to reflect updates in SPEC-719 (#1807)
* Update TMF rules to reflect updates in SPEC-719 * update for comments * rebase and resolve conflicts * fix typo * Limit allowable TMF multicast address to be link local or realm local. * update involved files to fit in 120 columns * update for comments
This commit is contained in:
@@ -58,6 +58,7 @@ Coap::Coap(ThreadNetif &aNetif):
|
||||
mSocket(aNetif.GetIp6().mUdp),
|
||||
mRetransmissionTimer(aNetif.GetIp6().mTimerScheduler, &Coap::HandleRetransmissionTimer, this),
|
||||
mResources(NULL),
|
||||
mContext(NULL),
|
||||
mInterceptor(NULL),
|
||||
mResponsesQueue(aNetif),
|
||||
mDefaultHandler(NULL),
|
||||
@@ -640,7 +641,7 @@ void Coap::ProcessReceivedRequest(Header &aHeader, Message &aMessage, const Ip6:
|
||||
|
||||
if (mInterceptor != NULL)
|
||||
{
|
||||
SuccessOrExit(error = mInterceptor(aMessage, aMessageInfo));
|
||||
SuccessOrExit(error = mInterceptor(aMessage, aMessageInfo, mContext));
|
||||
}
|
||||
|
||||
aMessage.MoveOffset(aHeader.GetLength());
|
||||
|
||||
@@ -427,6 +427,7 @@ public:
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
@ @param[in] aMessageInfo A reference to the message info associated with @p aMessage.
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Server should continue processing this message, other
|
||||
* return values indicates the server should stop processing
|
||||
@@ -434,7 +435,7 @@ public:
|
||||
* @retval OT_ERROR_NOT_TMF The message is not a TMF message.
|
||||
*
|
||||
*/
|
||||
typedef otError(* Interceptor)(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
typedef otError(* Interceptor)(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
|
||||
|
||||
/**
|
||||
* This constructor initializes the object.
|
||||
@@ -617,10 +618,12 @@ public:
|
||||
* This method sets interceptor to be called before processing a CoAP packet.
|
||||
*
|
||||
* @param[in] aInterceptor A pointer to the interceptor.
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
*
|
||||
*/
|
||||
void SetInterceptor(Interceptor aInterpreter) {
|
||||
mInterceptor = aInterpreter;
|
||||
void SetInterceptor(Interceptor aInterceptor, void *aContext) {
|
||||
mInterceptor = aInterceptor;
|
||||
mContext = aContext;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -692,6 +695,7 @@ private:
|
||||
|
||||
Resource *mResources;
|
||||
|
||||
void *mContext;
|
||||
Interceptor mInterceptor;
|
||||
ResponsesQueue mResponsesQueue;
|
||||
|
||||
|
||||
@@ -3233,7 +3233,13 @@ bool Mle::IsRoutingLocator(const Ip6::Address &aAddress) const
|
||||
|
||||
bool Mle::IsAnycastLocator(const Ip6::Address &aAddress) const
|
||||
{
|
||||
return memcmp(&mMeshLocal16, &aAddress, kRlocPrefixLength) == 0 && aAddress.mFields.m8[14] == Ip6::Address::kAloc16Mask;
|
||||
return memcmp(&mMeshLocal16, &aAddress, kRlocPrefixLength) == 0 &&
|
||||
aAddress.mFields.m8[14] == Ip6::Address::kAloc16Mask;
|
||||
}
|
||||
|
||||
bool Mle::IsMeshLocalAddress(const Ip6::Address &aAddress) const
|
||||
{
|
||||
return aAddress.PrefixMatch(GetMeshLocal16()) >= Ip6::Address::kMeshLocalPrefixLength;
|
||||
}
|
||||
|
||||
Router *Mle::GetParent(void)
|
||||
|
||||
+13
-2
@@ -539,7 +539,8 @@ public:
|
||||
* @param[in] aScanChannels A bit vector indicating which channels to scan.
|
||||
* @param[in] aPanId The PAN ID filter (set to Broadcast PAN to disable filter).
|
||||
* @param[in] aJoiner Value of the Joiner Flag in the Discovery Request TLV.
|
||||
* @param[in] aEnableEui64Filtering Enable filtering out MLE discovery responses that don't match our factory assigned EUI64.
|
||||
* @param[in] aEnableEui64Filtering Enable filtering out MLE discovery responses that don't match our factory
|
||||
* assigned EUI64.
|
||||
* @param[in] aHandler A pointer to a function that is called on receiving an MLE Discovery Response.
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
*
|
||||
@@ -702,6 +703,15 @@ public:
|
||||
*/
|
||||
bool IsAnycastLocator(const Ip6::Address &aAddress) const;
|
||||
|
||||
/**
|
||||
* This method indicates whether or not an IPv6 address is a Mesh Local Address.
|
||||
*
|
||||
* @retval TRUE If @p aAddress is a Mesh Local Address.
|
||||
* @retval FALSE If @p aAddress is not a Mesh Local Address.
|
||||
*
|
||||
*/
|
||||
bool IsMeshLocalAddress(const Ip6::Address &aAddress) const;
|
||||
|
||||
/**
|
||||
* This method returns the MLE Timeout value.
|
||||
*
|
||||
@@ -1097,7 +1107,8 @@ protected:
|
||||
* This method appends a Active Timestamp TLV to a message.
|
||||
*
|
||||
* @param[in] aMessage A reference to the message.
|
||||
* @param[in] aCouldUseLocal True to use local Active Timestamp when network Active Timestamp is not available, False not.
|
||||
* @param[in] aCouldUseLocal True to use local Active Timestamp when network Active Timestamp is not available,
|
||||
* False not.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully appended the Active Timestamp TLV.
|
||||
* @retval OT_ERROR_NO_BUFS Insufficient buffers available to append the Active Timestamp TLV.
|
||||
|
||||
@@ -116,7 +116,7 @@ ThreadNetif::ThreadNetif(Ip6::Ip6 &aIp6):
|
||||
|
||||
{
|
||||
mKeyManager.SetMasterKey(kThreadMasterKey);
|
||||
mCoap.SetInterceptor(&ThreadNetif::TmfFilter);
|
||||
mCoap.SetInterceptor(&ThreadNetif::TmfFilter, this);
|
||||
}
|
||||
|
||||
otError ThreadNetif::Up(void)
|
||||
@@ -182,19 +182,19 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
otError ThreadNetif::TmfFilter(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
otError ThreadNetif::TmfFilter(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
// A TMF message must comply at least one of the following rules:
|
||||
// 1. The IPv6 source address is RLOC or ALOC.
|
||||
// 2. The IPv6 destination address is RLOC or ALOC.
|
||||
// 3. The IPv6 destination address is Link-Local address.
|
||||
VerifyOrExit(aMessageInfo.GetPeerAddr().IsRoutingLocator() ||
|
||||
aMessageInfo.GetPeerAddr().IsAnycastRoutingLocator() ||
|
||||
aMessageInfo.GetSockAddr().IsRoutingLocator() ||
|
||||
aMessageInfo.GetSockAddr().IsAnycastRoutingLocator() ||
|
||||
aMessageInfo.GetSockAddr().IsLinkLocal(),
|
||||
// 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.
|
||||
// 2. Both the destination and the source are Link-Local Addresses.
|
||||
VerifyOrExit(((static_cast<ThreadNetif *>(aContext)->mMleRouter.IsMeshLocalAddress(aMessageInfo.GetSockAddr()) ||
|
||||
aMessageInfo.GetSockAddr().IsLinkLocalMulticast() ||
|
||||
aMessageInfo.GetSockAddr().IsRealmLocalMulticast()) &&
|
||||
static_cast<ThreadNetif *>(aContext)->mMleRouter.IsMeshLocalAddress(aMessageInfo.GetPeerAddr())) ||
|
||||
(aMessageInfo.GetSockAddr().IsLinkLocal() && aMessageInfo.GetPeerAddr().IsLinkLocal()),
|
||||
error = OT_ERROR_NOT_TMF);
|
||||
exit:
|
||||
(void)aMessage;
|
||||
|
||||
@@ -407,7 +407,7 @@ public:
|
||||
otInstance *GetInstance(void);
|
||||
|
||||
private:
|
||||
static otError TmfFilter(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
|
||||
static otError TmfFilter(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
|
||||
|
||||
Coap::Coap mCoap;
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
|
||||
Reference in New Issue
Block a user