From b058ea4e17b793219d52e97434ae59ee94e90617 Mon Sep 17 00:00:00 2001 From: Eduardo Montoya Date: Wed, 29 Jun 2022 20:11:46 +0200 Subject: [PATCH] [dua] allow MTD to handle ADDR_ERR.ntf messages (#7844) An MTD interface should be able to handle Address Error Notifications as per Thread Specification section 5.6.4. --- src/core/common/instance.hpp | 10 ++++---- src/core/thread/address_resolver.cpp | 24 ++++++++++++++----- src/core/thread/address_resolver.hpp | 11 +++++---- src/core/thread/thread_netif.cpp | 2 +- src/core/thread/thread_netif.hpp | 2 +- .../v1_2_test_dua_handle_address_error.py | 1 + 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index ff0e37243..b59f5da5f 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -576,6 +576,11 @@ template <> inline Ip6::Filter &Instance::Get(void) return mThreadNetif.mIp6Filter; } +template <> inline AddressResolver &Instance::Get(void) +{ + return mThreadNetif.mAddressResolver; +} + #if OPENTHREAD_FTD template <> inline IndirectSender &Instance::Get(void) @@ -600,11 +605,6 @@ template <> inline CslTxScheduler &Instance::Get(void) } #endif -template <> inline AddressResolver &Instance::Get(void) -{ - return mThreadNetif.mAddressResolver; -} - template <> inline MeshCoP::Leader &Instance::Get(void) { return mThreadNetif.mLeader; diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index 4041c0121..9876e938a 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -33,8 +33,6 @@ #include "address_resolver.hpp" -#if OPENTHREAD_FTD - #include "coap/coap_message.hpp" #include "common/as_core_type.hpp" #include "common/code_utils.hpp" @@ -57,18 +55,24 @@ RegisterLogModule("AddrResolver"); AddressResolver::AddressResolver(Instance &aInstance) : InstanceLocator(aInstance) , mAddressError(UriPath::kAddressError, &AddressResolver::HandleAddressError, this) +#if OPENTHREAD_FTD , mAddressQuery(UriPath::kAddressQuery, &AddressResolver::HandleAddressQuery, this) , mAddressNotification(UriPath::kAddressNotify, &AddressResolver::HandleAddressNotification, this) , mCacheEntryPool(aInstance) , mIcmpHandler(&AddressResolver::HandleIcmpReceive, this) +#endif { Get().AddResource(mAddressError); +#if OPENTHREAD_FTD Get().AddResource(mAddressQuery); Get().AddResource(mAddressNotification); IgnoreError(Get().RegisterHandler(mIcmpHandler)); +#endif } +#if OPENTHREAD_FTD + void AddressResolver::Clear(void) { CacheEntryList *lists[] = {&mCachedList, &mSnoopedList, &mQueryList, &mQueryRetryList}; @@ -703,6 +707,8 @@ exit: } } +#endif // OPENTHREAD_FTD + void AddressResolver::HandleAddressError(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo) { static_cast(aContext)->HandleAddressError(AsCoapMessage(aMessage), AsCoreType(aMessageInfo)); @@ -713,8 +719,10 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes Error error = kErrorNone; Ip6::Address target; Ip6::InterfaceIdentifier meshLocalIid; - Mac::ExtAddress extAddr; - Ip6::Address destination; +#if OPENTHREAD_FTD + Mac::ExtAddress extAddr; + Ip6::Address destination; +#endif VerifyOrExit(aMessage.IsPostRequest(), error = kErrorDrop); @@ -751,6 +759,7 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes } } +#if OPENTHREAD_FTD meshLocalIid.ConvertToExtAddress(extAddr); for (Child &child : Get().Iterate(Child::kInStateValid)) @@ -774,6 +783,7 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes } } } +#endif // OPENTHREAD_FTD exit: @@ -783,6 +793,8 @@ exit: } } +#if OPENTHREAD_FTD + void AddressResolver::HandleAddressQuery(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo) { static_cast(aContext)->HandleAddressQuery(AsCoapMessage(aMessage), AsCoreType(aMessageInfo)); @@ -1073,6 +1085,6 @@ exit: return; } -} // namespace ot - #endif // OPENTHREAD_FTD + +} // namespace ot diff --git a/src/core/thread/address_resolver.hpp b/src/core/thread/address_resolver.hpp index 6a177b9a8..b65fc604d 100644 --- a/src/core/thread/address_resolver.hpp +++ b/src/core/thread/address_resolver.hpp @@ -36,8 +36,6 @@ #include "openthread-core-config.h" -#if OPENTHREAD_FTD - #include "coap/coap.hpp" #include "common/linked_list.hpp" #include "common/locator.hpp" @@ -87,6 +85,7 @@ public: */ explicit AddressResolver(Instance &aInstance); +#if OPENTHREAD_FTD /** * This method clears the EID-to-RLOC cache. * @@ -317,9 +316,12 @@ private: static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo); +#endif // OPENTHREAD_FTD + static void HandleAddressError(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo); void HandleAddressError(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); +#if OPENTHREAD_FTD static void HandleAddressQuery(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo); void HandleAddressQuery(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); @@ -345,7 +347,9 @@ private: static AddressResolver::CacheEntry *GetEntryAfter(CacheEntry *aPrev, CacheEntryList &aList); +#endif // OPENTHREAD_FTD Coap::Resource mAddressError; +#if OPENTHREAD_FTD Coap::Resource mAddressQuery; Coap::Resource mAddressNotification; @@ -356,6 +360,7 @@ private: CacheEntryList mQueryRetryList; Ip6::Icmp::Handler mIcmpHandler; +#endif // OPENTHREAD_FTD }; /** @@ -364,6 +369,4 @@ private: } // namespace ot -#endif // OPENTHREAD_FTD - #endif // ADDRESS_RESOLVER_HPP_ diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index 7cc880c73..445922ae8 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -91,6 +91,7 @@ ThreadNetif::ThreadNetif(Instance &aInstance) , mMeshForwarder(aInstance) , mMleRouter(aInstance) , mDiscoverScanner(aInstance) + , mAddressResolver(aInstance) #if OPENTHREAD_CONFIG_MULTI_RADIO , mRadioSelector(aInstance) #endif @@ -127,7 +128,6 @@ ThreadNetif::ThreadNetif(Instance &aInstance) #if OPENTHREAD_FTD , mJoinerRouter(aInstance) , mLeader(aInstance) - , mAddressResolver(aInstance) #endif #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) , mBackboneRouterLeader(aInstance) diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index 97efc3396..0561f4ae5 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -210,6 +210,7 @@ private: MeshForwarder mMeshForwarder; Mle::MleRouter mMleRouter; Mle::DiscoverScanner mDiscoverScanner; + AddressResolver mAddressResolver; #if OPENTHREAD_CONFIG_MULTI_RADIO RadioSelector mRadioSelector; #endif @@ -251,7 +252,6 @@ private: #if OPENTHREAD_FTD MeshCoP::JoinerRouter mJoinerRouter; MeshCoP::Leader mLeader; - AddressResolver mAddressResolver; #endif // OPENTHREAD_FTD #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) diff --git a/tests/scripts/thread-cert/v1_2_test_dua_handle_address_error.py b/tests/scripts/thread-cert/v1_2_test_dua_handle_address_error.py index 60bb2a9e8..c9017ea44 100755 --- a/tests/scripts/thread-cert/v1_2_test_dua_handle_address_error.py +++ b/tests/scripts/thread-cert/v1_2_test_dua_handle_address_error.py @@ -77,6 +77,7 @@ class TestDomainUnicastAddress(thread_cert.TestCase): }, MED: { 'version': '1.2', + 'is_mtd': True, 'allowlist': [ROUTER], 'mode': 'rn', },