[slaac] handle slaac internally (#3484)

This commit is contained in:
Yakun Xu
2019-01-22 23:34:26 -08:00
committed by Jonathan Hui
parent 26c5d0ecb8
commit 3fabc4660c
9 changed files with 21 additions and 48 deletions
-1
View File
@@ -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
{
-1
View File
@@ -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)
+3 -28
View File
@@ -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<otCliContext *>(aContext);
cliContext->mInterpreter->HandleNetifStateChanged(cliContext->mInstance, aFlags);
#else
static_cast<Interpreter *>(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[])
{
-8
View File
@@ -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;
-1
View File
@@ -62,7 +62,6 @@ void Interpreter::CacheInstances()
mInstances[i].mInterpreter = this;
mInstances[i].mInstance = static_cast<Instance *>(otInstanceInit(mApiInstance, &aDeviceList->aDevices[i]));
assert(mInstances[i].mInstance);
otSetStateChangedCallback(mInstances[i].mInstance, &Interpreter::s_HandleNetifStateChanged, &mInstances[i]);
}
otFreeMemory(aDeviceList);
-9
View File
@@ -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);
+2
View File
@@ -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
+8
View File
@@ -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
+8
View File
@@ -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