From 3fabc4660cad1bda4814726abdaedb8736442331 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Wed, 23 Jan 2019 15:34:26 +0800 Subject: [PATCH] [slaac] handle slaac internally (#3484) --- examples/drivers/windows/otLwf/filter.h | 1 - examples/drivers/windows/otLwf/thread.c | 1 - src/cli/cli.cpp | 31 +++---------------------- src/cli/cli.hpp | 8 ------- src/cli/cli_instance.cpp | 1 - src/core/api/ip6_api.cpp | 9 ------- src/core/thread/mle.cpp | 2 ++ src/core/thread/thread_netif.cpp | 8 +++++++ src/core/thread/thread_netif.hpp | 8 +++++++ 9 files changed, 21 insertions(+), 48 deletions(-) diff --git a/examples/drivers/windows/otLwf/filter.h b/examples/drivers/windows/otLwf/filter.h index 6883bf598..49d9b27d5 100644 --- a/examples/drivers/windows/otLwf/filter.h +++ b/examples/drivers/windows/otLwf/filter.h @@ -199,7 +199,6 @@ typedef struct _MS_FILTER IN6_ADDR otCachedAddr[OT_MAX_ADDRESSES]; ULONG otCachedAddrCount; IN6_ADDR otLinkLocalAddr; - otNetifAddress otAutoAddresses[OPENTHREAD_CONFIG_NUM_SLAAC_ADDRESSES]; union { diff --git a/examples/drivers/windows/otLwf/thread.c b/examples/drivers/windows/otLwf/thread.c index adc95cb6c..f9c796b9f 100644 --- a/examples/drivers/windows/otLwf/thread.c +++ b/examples/drivers/windows/otLwf/thread.c @@ -542,7 +542,6 @@ void otLwfStateChangedCallback(uint32_t aFlags, _In_ void *aContext) if ((aFlags & OT_CHANGED_THREAD_NETDATA) != 0) { LogVerbose(DRIVER_DEFAULT, "Filter %p received OT_CHANGED_THREAD_NETDATA", pFilter); - otIp6SlaacUpdate(pFilter->otCtx, pFilter->otAutoAddresses, ARRAYSIZE(pFilter->otAutoAddresses), otIp6CreateRandomIid, NULL); } if ((aFlags & OT_CHANGED_THREAD_ML_ADDR) != 0) diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index d9064a7f0..b10a1853b 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -310,11 +310,12 @@ Interpreter::Interpreter(Instance *aInstance) , mInstance(aInstance) { #ifdef OTDLL + // On Windows, mInstance represents the current selected otInstance + // which should be NULL now. + assert(aInstance = NULL); assert(mApiInstance); CacheInstances(); #else - memset(mSlaacAddresses, 0, sizeof(mSlaacAddresses)); - otSetStateChangedCallback(mInstance, &Interpreter::s_HandleNetifStateChanged, this); #if OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC otThreadSetReceiveDiagnosticGetCallback(mInstance, &Interpreter::s_HandleDiagnosticGetResponse, this); #endif @@ -3800,32 +3801,6 @@ exit: return; } -void OTCALL Interpreter::s_HandleNetifStateChanged(otChangedFlags aFlags, void *aContext) -{ -#ifdef OTDLL - otCliContext *cliContext = static_cast(aContext); - cliContext->mInterpreter->HandleNetifStateChanged(cliContext->mInstance, aFlags); -#else - static_cast(aContext)->HandleNetifStateChanged(aFlags); -#endif -} - -#ifdef OTDLL -void Interpreter::HandleNetifStateChanged(otInstance *mInstance, otChangedFlags aFlags) -#else -void Interpreter::HandleNetifStateChanged(otChangedFlags aFlags) -#endif -{ - VerifyOrExit((aFlags & OT_CHANGED_THREAD_NETDATA) != 0); - -#ifndef OTDLL - otIp6SlaacUpdate(mInstance, mSlaacAddresses, OT_ARRAY_LENGTH(mSlaacAddresses), otIp6CreateRandomIid, NULL); -#endif - -exit: - return; -} - #if OPENTHREAD_FTD || OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC void Interpreter::ProcessNetworkDiagnostic(int argc, char *argv[]) { diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index c4348b291..ab501382e 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -347,7 +347,6 @@ private: #endif static void OTCALL s_HandleActiveScanResult(otActiveScanResult *aResult, void *aContext); static void OTCALL s_HandleEnergyScanResult(otEnergyScanResult *aResult, void *aContext); - static void OTCALL s_HandleNetifStateChanged(otChangedFlags aFlags, void *aContext); #ifndef OTDLL static void s_HandleLinkPcapReceive(const otRadioFrame *aFrame, void *aContext); #endif @@ -381,11 +380,6 @@ private: #endif void HandleActiveScanResult(otActiveScanResult *aResult); void HandleEnergyScanResult(otEnergyScanResult *aResult); -#ifdef OTDLL - void HandleNetifStateChanged(otInstance *aInstance, otChangedFlags aFlags); -#else - void HandleNetifStateChanged(otChangedFlags aFlags); -#endif #ifndef OTDLL void HandleLinkPcapReceive(const otRadioFrame *aFrame); #endif @@ -433,8 +427,6 @@ private: uint32_t mInterval; TimerMilli mPingTimer; - otNetifAddress mSlaacAddresses[OPENTHREAD_CONFIG_NUM_SLAAC_ADDRESSES]; - otIcmp6Handler mIcmpHandler; #if OPENTHREAD_ENABLE_DNS_CLIENT bool mResolvingInProgress; diff --git a/src/cli/cli_instance.cpp b/src/cli/cli_instance.cpp index d20a5863d..d1bf6db63 100644 --- a/src/cli/cli_instance.cpp +++ b/src/cli/cli_instance.cpp @@ -62,7 +62,6 @@ void Interpreter::CacheInstances() mInstances[i].mInterpreter = this; mInstances[i].mInstance = static_cast(otInstanceInit(mApiInstance, &aDeviceList->aDevices[i])); assert(mInstances[i].mInstance); - otSetStateChangedCallback(mInstances[i].mInstance, &Interpreter::s_HandleNetifStateChanged, &mInstances[i]); } otFreeMemory(aDeviceList); diff --git a/src/core/api/ip6_api.cpp b/src/core/api/ip6_api.cpp index 524a32a2f..20720a622 100644 --- a/src/core/api/ip6_api.cpp +++ b/src/core/api/ip6_api.cpp @@ -133,15 +133,6 @@ void otIp6SetMulticastPromiscuousEnabled(otInstance *aInstance, bool aEnabled) instance.GetThreadNetif().SetMulticastPromiscuous(aEnabled); } -void otIp6SlaacUpdate(otInstance * aInstance, - otNetifAddress * aAddresses, - uint32_t aNumAddresses, - otIp6SlaacIidCreate aIidCreate, - void * aContext) -{ - Utils::Slaac::UpdateAddresses(aInstance, aAddresses, aNumAddresses, aIidCreate, aContext); -} - otError otIp6CreateRandomIid(otInstance *aInstance, otNetifAddress *aAddress, void *aContext) { return Utils::Slaac::CreateRandomIid(aInstance, aAddress, aContext); diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 078706ad9..fbdaf6feb 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -1510,6 +1510,8 @@ void Mle::HandleStateChanged(otChangedFlags aFlags) #endif #endif + GetNetif().UpdateSlaac(); + #if OPENTHREAD_ENABLE_DHCP6_SERVER GetNetif().GetDhcp6Server().UpdateService(); #endif // OPENTHREAD_ENABLE_DHCP6_SERVER diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index dab533be1..3f9164412 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -43,6 +43,7 @@ #include "thread/mle.hpp" #include "thread/thread_tlvs.hpp" #include "thread/thread_uri_paths.hpp" +#include "utils/slaac_address.hpp" using ot::Encoding::BigEndian::HostSwap16; @@ -109,6 +110,7 @@ ThreadNetif::ThreadNetif(Instance &aInstance) #endif { mCoap.SetInterceptor(&ThreadNetif::TmfFilter, this); + memset(mSlaacAddresses, 0, sizeof(mSlaacAddresses)); } otError ThreadNetif::Up(void) @@ -222,4 +224,10 @@ exit: return rval; } +void ThreadNetif::UpdateSlaac(void) +{ + Utils::Slaac::UpdateAddresses(&GetInstance(), mSlaacAddresses, OT_ARRAY_LENGTH(mSlaacAddresses), + otIp6CreateRandomIid, NULL); +} + } // namespace ot diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index 2530ff48f..90fa3176d 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -439,6 +439,12 @@ public: */ bool IsTmfMessage(const Ip6::MessageInfo &aMessageInfo); + /** + * This method updates addresses that shall be automatically created using SLAAC. + * + */ + void UpdateSlaac(void); + private: static otError TmfFilter(const Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext); @@ -449,6 +455,7 @@ private: #if OPENTHREAD_ENABLE_DHCP6_SERVER Dhcp6::Dhcp6Server mDhcp6Server; #endif // OPENTHREAD_ENABLE_DHCP6_SERVER + Ip6::NetifUnicastAddress mSlaacAddresses[OPENTHREAD_CONFIG_NUM_SLAAC_ADDRESSES]; #if OPENTHREAD_ENABLE_DNS_CLIENT Dns::Client mDnsClient; #endif // OPENTHREAD_ENABLE_DNS_CLIENT @@ -503,6 +510,7 @@ private: AnnounceBeginServer mAnnounceBegin; PanIdQueryServer mPanIdQuery; EnergyScanServer mEnergyScan; + #if OPENTHREAD_CONFIG_ENABLE_TIME_SYNC TimeSync mTimeSync; #endif