diff --git a/src/core/BUILD.gn b/src/core/BUILD.gn index a539fda0f..40e5fddb7 100644 --- a/src/core/BUILD.gn +++ b/src/core/BUILD.gn @@ -594,6 +594,8 @@ openthread_core_files = [ "net/nd_agent.hpp", "net/netif.cpp", "net/netif.hpp", + "net/slaac_address.cpp", + "net/slaac_address.hpp", "net/sntp_client.cpp", "net/sntp_client.hpp", "net/socket.cpp", @@ -757,8 +759,6 @@ openthread_core_files = [ "utils/ping_sender.hpp", "utils/power_calibration.cpp", "utils/power_calibration.hpp", - "utils/slaac_address.cpp", - "utils/slaac_address.hpp", "utils/srp_client_buffers.cpp", "utils/srp_client_buffers.hpp", "utils/static_counter.hpp", diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 95487475f..839214106 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -192,6 +192,7 @@ set(COMMON_SOURCES net/nd6.cpp net/nd_agent.cpp net/netif.cpp + net/slaac_address.cpp net/sntp_client.cpp net/socket.cpp net/srp_advertising_proxy.cpp @@ -274,7 +275,6 @@ set(COMMON_SOURCES utils/parse_cmdline.cpp utils/ping_sender.cpp utils/power_calibration.cpp - utils/slaac_address.cpp utils/srp_client_buffers.cpp utils/verhoeff_checksum.cpp ) diff --git a/src/core/api/ip6_api.cpp b/src/core/api/ip6_api.cpp index 5ed41d107..4ad0fda39 100644 --- a/src/core/api/ip6_api.cpp +++ b/src/core/api/ip6_api.cpp @@ -241,7 +241,7 @@ otError otIp6RegisterMulticastListeners(otInstance * #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE -bool otIp6IsSlaacEnabled(otInstance *aInstance) { return AsCoreType(aInstance).Get().IsEnabled(); } +bool otIp6IsSlaacEnabled(otInstance *aInstance) { return AsCoreType(aInstance).Get().IsEnabled(); } void otIp6SetSlaacEnabled(otInstance *aInstance, bool aEnabled) { @@ -249,17 +249,17 @@ void otIp6SetSlaacEnabled(otInstance *aInstance, bool aEnabled) if (aEnabled) { - instance.Get().Enable(); + instance.Get().Enable(); } else { - instance.Get().Disable(); + instance.Get().Disable(); } } void otIp6SetSlaacPrefixFilter(otInstance *aInstance, otIp6SlaacPrefixFilter aFilter) { - AsCoreType(aInstance).Get().SetFilter(aFilter); + AsCoreType(aInstance).Get().SetFilter(aFilter); } #endif // OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE diff --git a/src/core/common/notifier.cpp b/src/core/common/notifier.cpp index 949628fe5..eda668878 100644 --- a/src/core/common/notifier.cpp +++ b/src/core/common/notifier.cpp @@ -146,7 +146,7 @@ void Notifier::EmitEvents(void) Get().HandleNotifierEvents(events); #endif #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE - Get().HandleNotifierEvents(events); + Get().HandleNotifierEvents(events); #endif #if OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE Get().HandleNotifierEvents(events); diff --git a/src/core/common/settings.hpp b/src/core/common/settings.hpp index 32226092b..27836ae0b 100644 --- a/src/core/common/settings.hpp +++ b/src/core/common/settings.hpp @@ -50,9 +50,9 @@ #include "meshcop/border_agent.hpp" #include "meshcop/dataset.hpp" #include "net/ip6_address.hpp" +#include "net/slaac_address.hpp" #include "thread/version.hpp" #include "utils/flash.hpp" -#include "utils/slaac_address.hpp" namespace ot { @@ -479,7 +479,7 @@ public: public: static constexpr Key kKey = kKeySlaacIidSecretKey; ///< The associated key. - typedef Utils::Slaac::IidSecretKey ValueType; ///< The associated value type. + typedef Ip6::Slaac::IidSecretKey ValueType; ///< The associated value type. private: SlaacIidSecretKey(void) = default; diff --git a/src/core/instance/instance.hpp b/src/core/instance/instance.hpp index 858a45ead..6fe983e55 100644 --- a/src/core/instance/instance.hpp +++ b/src/core/instance/instance.hpp @@ -105,6 +105,7 @@ #include "net/nat64_translator.hpp" #include "net/nd_agent.hpp" #include "net/netif.hpp" +#include "net/slaac_address.hpp" #include "net/sntp_client.hpp" #include "net/srp_advertising_proxy.hpp" #include "net/srp_client.hpp" @@ -143,7 +144,6 @@ #include "utils/link_metrics_manager.hpp" #include "utils/mesh_diag.hpp" #include "utils/ping_sender.hpp" -#include "utils/slaac_address.hpp" #include "utils/srp_client_buffers.hpp" #endif // OPENTHREAD_FTD || OPENTHREAD_MTD @@ -511,7 +511,7 @@ private: #endif #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE - Utils::Slaac mSlaac; + Ip6::Slaac mSlaac; #endif #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE @@ -967,7 +967,7 @@ template <> inline NeighborDiscovery::Agent &Instance::Get(void) { return mNeigh #endif #if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE -template <> inline Utils::Slaac &Instance::Get(void) { return mSlaac; } +template <> inline Ip6::Slaac &Instance::Get(void) { return mSlaac; } #endif #if OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index 80130b36a..e7a76d10c 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -85,6 +85,7 @@ namespace Ip6 { * @defgroup core-ip6-ip6 IPv6 * @defgroup core-ip6-mpl MPL * @defgroup core-ip6-netif Network Interfaces + * @defgroup core-ip6-slaac SLAAC * * @} */ diff --git a/src/core/utils/slaac_address.cpp b/src/core/net/slaac_address.cpp similarity index 95% rename from src/core/utils/slaac_address.cpp rename to src/core/net/slaac_address.cpp index 83ccfa49f..f5c11a024 100644 --- a/src/core/utils/slaac_address.cpp +++ b/src/core/net/slaac_address.cpp @@ -39,7 +39,7 @@ #include "instance/instance.hpp" namespace ot { -namespace Utils { +namespace Ip6 { RegisterLogModule("Slaac"); @@ -94,7 +94,7 @@ exit: return; } -Error Slaac::FindDomainIdFor(const Ip6::Address &aAddress, uint8_t &aDomainId) const +Error Slaac::FindDomainIdFor(const Address &aAddress, uint8_t &aDomainId) const { Error error = kErrorNotFound; @@ -105,7 +105,7 @@ Error Slaac::FindDomainIdFor(const Ip6::Address &aAddress, uint8_t &aDomainId) c continue; } - if (aAddress.PrefixMatch(slaacAddr.GetAddress()) >= Ip6::NetworkPrefix::kLength) + if (aAddress.PrefixMatch(slaacAddr.GetAddress()) >= NetworkPrefix::kLength) { aDomainId = slaacAddr.GetDomainId(); error = kErrorNone; @@ -118,7 +118,7 @@ Error Slaac::FindDomainIdFor(const Ip6::Address &aAddress, uint8_t &aDomainId) c bool Slaac::IsSlaac(const NetworkData::OnMeshPrefixConfig &aConfig) const { - return aConfig.mSlaac && !aConfig.mDp && (aConfig.GetPrefix().GetLength() == Ip6::NetworkPrefix::kLength); + return aConfig.mSlaac && !aConfig.mDp && (aConfig.GetPrefix().GetLength() == NetworkPrefix::kLength); } bool Slaac::IsFiltered(const NetworkData::OnMeshPrefixConfig &aConfig) const @@ -155,8 +155,7 @@ exit: return; } -bool Slaac::DoesConfigMatchNetifAddr(const NetworkData::OnMeshPrefixConfig &aConfig, - const Ip6::Netif::UnicastAddress &aAddr) +bool Slaac::DoesConfigMatchNetifAddr(const NetworkData::OnMeshPrefixConfig &aConfig, const Netif::UnicastAddress &aAddr) { return (((aConfig.mOnMesh && (aAddr.mPrefixLength == aConfig.mPrefix.mLength)) || (!aConfig.mOnMesh && (aAddr.mPrefixLength == 128))) && @@ -287,7 +286,7 @@ void Slaac::AddAddresses(void) continue; } - for (const Ip6::Netif::UnicastAddress &netifAddr : Get().GetUnicastAddresses()) + for (const Netif::UnicastAddress &netifAddr : Get().GetUnicastAddresses()) { if (DoesConfigMatchNetifAddr(prefixConfig, netifAddr)) { @@ -403,7 +402,7 @@ void Slaac::HandleTimer(void) mTimer.FireAtIfEarlier(nextTime); } -Error Slaac::GenerateIid(Ip6::Netif::UnicastAddress &aAddress, uint8_t &aDadCounter) const +Error Slaac::GenerateIid(Netif::UnicastAddress &aAddress, uint8_t &aDadCounter) const { /* * This method generates a semantically opaque IID per RFC 7217. @@ -425,7 +424,7 @@ Error Slaac::GenerateIid(Ip6::Netif::UnicastAddress &aAddress, uint8_t &aDadCoun Crypto::Sha256 sha256; Crypto::Sha256::Hash hash; - static_assert(sizeof(hash) >= Ip6::InterfaceIdentifier::kSize, + static_assert(sizeof(hash) >= InterfaceIdentifier::kSize, "SHA-256 hash size is too small to use as IPv6 address IID"); GetIidSecretKey(secretKey); @@ -506,7 +505,7 @@ exit: return; } -} // namespace Utils +} // namespace Ip6 } // namespace ot #endif // OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE diff --git a/src/core/utils/slaac_address.hpp b/src/core/net/slaac_address.hpp similarity index 95% rename from src/core/utils/slaac_address.hpp rename to src/core/net/slaac_address.hpp index 87a99b75a..e825c00ff 100644 --- a/src/core/utils/slaac_address.hpp +++ b/src/core/net/slaac_address.hpp @@ -45,10 +45,10 @@ #include "thread/network_data.hpp" namespace ot { -namespace Utils { +namespace Ip6 { /** - * @addtogroup core-slaac-address + * @addtogroup core-ip6-slaac * * @brief * This module includes definitions for Thread global IPv6 address configuration with SLAAC. @@ -132,7 +132,7 @@ public: * @retval kErrorNone If successfully generated the IID. * @retval kErrorFailed If no valid IID was generated. */ - Error GenerateIid(Ip6::Netif::UnicastAddress &aAddress, uint8_t &aDadCounter) const; + Error GenerateIid(Netif::UnicastAddress &aAddress, uint8_t &aDadCounter) const; /** * Searches in the list of deprecating SLAAC prefixes for a match to a given address and if found, returns the @@ -148,7 +148,7 @@ public: * @retval kErrorNone Found a match for @p aAddress and updated @p aDomainId. * @retval kErrorNotFound Could not find a match for @p aAddress in deprecating SLAAC prefixes. */ - Error FindDomainIdFor(const Ip6::Address &aAddress, uint8_t &aDomainId) const; + Error FindDomainIdFor(const Address &aAddress, uint8_t &aDomainId) const; private: static constexpr uint16_t kNumSlaacAddresses = OPENTHREAD_CONFIG_IP6_SLAAC_NUM_ADDRESSES; @@ -165,7 +165,7 @@ private: kDeprecating, }; - class SlaacAddress : public Ip6::Netif::UnicastAddress + class SlaacAddress : public Netif::UnicastAddress { public: static constexpr uint8_t kInvalidContextId = 0; @@ -211,7 +211,7 @@ private: void HandleNotifierEvents(Events aEvents); void LogAddress(Action aAction, const SlaacAddress &aAddress); static bool DoesConfigMatchNetifAddr(const NetworkData::OnMeshPrefixConfig &aConfig, - const Ip6::Netif::UnicastAddress &aAddr); + const Netif::UnicastAddress &aAddr); using ExpireTimer = TimerMilliIn; @@ -225,7 +225,7 @@ private: * @} */ -} // namespace Utils +} // namespace Ip6 } // namespace ot #endif // OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE diff --git a/src/core/thread/dua_manager.cpp b/src/core/thread/dua_manager.cpp index 5904e5b53..16a9d5c27 100644 --- a/src/core/thread/dua_manager.cpp +++ b/src/core/thread/dua_manager.cpp @@ -135,7 +135,7 @@ Error DuaManager::GenerateDomainUnicastAddressIid(void) Error error; uint8_t dadCounter = mDadCounter; - if ((error = Get().GenerateIid(mDomainUnicastAddress, dadCounter)) == kErrorNone) + if ((error = Get().GenerateIid(mDomainUnicastAddress, dadCounter)) == kErrorNone) { if (dadCounter != mDadCounter) { diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index 51f666c4f..3f82d8f6e 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -288,7 +288,7 @@ Error Leader::RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDest uint8_t domainId; - if (Get().FindDomainIdFor(aSource, domainId) == kErrorNone) + if (Get().FindDomainIdFor(aSource, domainId) == kErrorNone) { error = ExternalRouteLookup(domainId, aDestination, aRloc16); }