mirror of
https://github.com/espressif/openthread.git
synced 2026-08-10 12:47:47 +00:00
[net] move slaac module from utils to net (#11955)
This commit moves the `SlaacAddress` module from `src/core/utils` to `src/core/net`. This change also updates the namespace from `ot::Utils` to `ot::Ip6` and updates all includes and usages throughout the codebase. The `SlaacAddress` module was originally placed in `core/utils` as SLAAC management was historically handled by the platform. Now that the OpenThread stack manages SLAAC directly, this logic is better placed under `core/net`.
This commit is contained in:
+2
-2
@@ -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",
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -241,7 +241,7 @@ otError otIp6RegisterMulticastListeners(otInstance *
|
||||
|
||||
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
|
||||
|
||||
bool otIp6IsSlaacEnabled(otInstance *aInstance) { return AsCoreType(aInstance).Get<Utils::Slaac>().IsEnabled(); }
|
||||
bool otIp6IsSlaacEnabled(otInstance *aInstance) { return AsCoreType(aInstance).Get<Ip6::Slaac>().IsEnabled(); }
|
||||
|
||||
void otIp6SetSlaacEnabled(otInstance *aInstance, bool aEnabled)
|
||||
{
|
||||
@@ -249,17 +249,17 @@ void otIp6SetSlaacEnabled(otInstance *aInstance, bool aEnabled)
|
||||
|
||||
if (aEnabled)
|
||||
{
|
||||
instance.Get<Utils::Slaac>().Enable();
|
||||
instance.Get<Ip6::Slaac>().Enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
instance.Get<Utils::Slaac>().Disable();
|
||||
instance.Get<Ip6::Slaac>().Disable();
|
||||
}
|
||||
}
|
||||
|
||||
void otIp6SetSlaacPrefixFilter(otInstance *aInstance, otIp6SlaacPrefixFilter aFilter)
|
||||
{
|
||||
AsCoreType(aInstance).Get<Utils::Slaac>().SetFilter(aFilter);
|
||||
AsCoreType(aInstance).Get<Ip6::Slaac>().SetFilter(aFilter);
|
||||
}
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
|
||||
|
||||
@@ -146,7 +146,7 @@ void Notifier::EmitEvents(void)
|
||||
Get<TimeSync>().HandleNotifierEvents(events);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
|
||||
Get<Utils::Slaac>().HandleNotifierEvents(events);
|
||||
Get<Ip6::Slaac>().HandleNotifierEvents(events);
|
||||
#endif
|
||||
#if OPENTHREAD_CONFIG_JAM_DETECTION_ENABLE
|
||||
Get<Utils::JamDetector>().HandleNotifierEvents(events);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
@@ -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<ThreadNetif>().GetUnicastAddresses())
|
||||
for (const Netif::UnicastAddress &netifAddr : Get<ThreadNetif>().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
|
||||
@@ -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<Slaac, &Slaac::HandleTimer>;
|
||||
|
||||
@@ -225,7 +225,7 @@ private:
|
||||
* @}
|
||||
*/
|
||||
|
||||
} // namespace Utils
|
||||
} // namespace Ip6
|
||||
} // namespace ot
|
||||
|
||||
#endif // OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
|
||||
@@ -135,7 +135,7 @@ Error DuaManager::GenerateDomainUnicastAddressIid(void)
|
||||
Error error;
|
||||
uint8_t dadCounter = mDadCounter;
|
||||
|
||||
if ((error = Get<Utils::Slaac>().GenerateIid(mDomainUnicastAddress, dadCounter)) == kErrorNone)
|
||||
if ((error = Get<Ip6::Slaac>().GenerateIid(mDomainUnicastAddress, dadCounter)) == kErrorNone)
|
||||
{
|
||||
if (dadCounter != mDadCounter)
|
||||
{
|
||||
|
||||
@@ -288,7 +288,7 @@ Error Leader::RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDest
|
||||
|
||||
uint8_t domainId;
|
||||
|
||||
if (Get<Utils::Slaac>().FindDomainIdFor(aSource, domainId) == kErrorNone)
|
||||
if (Get<Ip6::Slaac>().FindDomainIdFor(aSource, domainId) == kErrorNone)
|
||||
{
|
||||
error = ExternalRouteLookup(domainId, aDestination, aRloc16);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user