mirror of
https://github.com/espressif/openthread.git
synced 2026-09-05 00:30:07 +00:00
[dhcp6-client] remove dhcp6 client api (#3287)
This commit is contained in:
@@ -200,9 +200,6 @@ typedef struct _MS_FILTER
|
||||
ULONG otCachedAddrCount;
|
||||
IN6_ADDR otLinkLocalAddr;
|
||||
otNetifAddress otAutoAddresses[OPENTHREAD_CONFIG_NUM_SLAAC_ADDRESSES];
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
otDhcpAddress otDhcpAddresses[OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES];
|
||||
#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
|
||||
union
|
||||
{
|
||||
|
||||
@@ -70,7 +70,6 @@ RtlCopyBufferToMdl(
|
||||
#include <openthread/commissioner.h>
|
||||
#include <openthread/joiner.h>
|
||||
#include <openthread/dhcp6_server.h>
|
||||
#include <openthread/dhcp6_client.h>
|
||||
#include <common/code_utils.hpp>
|
||||
#include <openthread/platform/logging.h>
|
||||
#include <openthread/platform/logging-windows.h>
|
||||
|
||||
@@ -547,10 +547,6 @@ void otLwfStateChangedCallback(uint32_t aFlags, _In_ void *aContext)
|
||||
#if OPENTHREAD_ENABLE_DHCP6_SERVER
|
||||
otDhcp6ServerUpdate(pFilter->otCtx);
|
||||
#endif // OPENTHREAD_ENABLE_DHCP6_SERVER
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
otDhcp6ClientUpdate(pFilter->otCtx, pFilter->otDhcpAddresses, ARRAYSIZE(pFilter->otDhcpAddresses), NULL);
|
||||
#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
}
|
||||
|
||||
if ((aFlags & OT_CHANGED_THREAD_ML_ADDR) != 0)
|
||||
|
||||
@@ -61,7 +61,6 @@ openthread_headers = \
|
||||
dataset.h \
|
||||
dataset_ftd.h \
|
||||
diag.h \
|
||||
dhcp6_client.h \
|
||||
dhcp6_server.h \
|
||||
dns.h \
|
||||
error.h \
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* This file includes the platform abstraction for the Thread DHCPv6 client.
|
||||
*/
|
||||
|
||||
#ifndef OPENTHREAD_DHCP6_CLIENT_H_
|
||||
#define OPENTHREAD_DHCP6_CLIENT_H_
|
||||
|
||||
#include <openthread/ip6.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup api-dhcp6
|
||||
*
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This structure represents a DHCPv6 address.
|
||||
*
|
||||
*/
|
||||
typedef struct otDhcpAddress
|
||||
{
|
||||
otNetifAddress mAddress; ///< The network interface address.
|
||||
uint32_t mPreferredLifetime; ///< The preferred lifetime.
|
||||
uint32_t mValidLifetime; ///< The valid lifetime.
|
||||
} otDhcpAddress;
|
||||
|
||||
/**
|
||||
* Update all automatically created IPv6 addresses for prefixes from current Network Data with DHCP procedure.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[inout] aAddresses A pointer to an array of automatically created IPv6 addresses.
|
||||
* @param[in] aNumAddresses The number of slots in aAddresses array.
|
||||
* @param[in] aContext A pointer to data passed to aIidCreate function.
|
||||
*
|
||||
*/
|
||||
void otDhcp6ClientUpdate(otInstance *aInstance, otDhcpAddress *aAddresses, uint32_t aNumAddresses, void *aContext);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // end of extern "C"
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_DHCP6_CLIENT_H_
|
||||
@@ -64,7 +64,6 @@
|
||||
#endif
|
||||
|
||||
#ifndef OTDLL
|
||||
#include <openthread/dhcp6_client.h>
|
||||
#include <openthread/dhcp6_server.h>
|
||||
#include <openthread/diag.h>
|
||||
#include <openthread/icmp6.h>
|
||||
@@ -324,10 +323,6 @@ Interpreter::Interpreter(Instance *aInstance)
|
||||
mIcmpHandler.mContext = this;
|
||||
otIcmp6RegisterHandler(mInstance, &mIcmpHandler);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
memset(mDhcpAddresses, 0, sizeof(mDhcpAddresses));
|
||||
#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
|
||||
#if OPENTHREAD_ENABLE_DNS_CLIENT
|
||||
memset(mResolvingHostname, 0, sizeof(mResolvingHostname));
|
||||
#endif // OPENTHREAD_ENABLE_DNS_CLIENT
|
||||
@@ -3829,9 +3824,6 @@ void Interpreter::HandleNetifStateChanged(otChangedFlags aFlags)
|
||||
otDhcp6ServerUpdate(mInstance);
|
||||
#endif // OPENTHREAD_ENABLE_DHCP6_SERVER
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
otDhcp6ClientUpdate(mInstance, mDhcpAddresses, OT_ARRAY_LENGTH(mDhcpAddresses), NULL);
|
||||
#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
#endif
|
||||
|
||||
exit:
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
#include "common/instance.hpp"
|
||||
|
||||
#ifndef OTDLL
|
||||
#include <openthread/dhcp6_client.h>
|
||||
#include <openthread/dns.h>
|
||||
#include <openthread/sntp.h>
|
||||
#include "common/timer.hpp"
|
||||
@@ -433,9 +432,6 @@ private:
|
||||
TimerMilli mPingTimer;
|
||||
|
||||
otNetifAddress mSlaacAddresses[OPENTHREAD_CONFIG_NUM_SLAAC_ADDRESSES];
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
otDhcpAddress mDhcpAddresses[OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES];
|
||||
#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
|
||||
otIcmp6Handler mIcmpHandler;
|
||||
#if OPENTHREAD_ENABLE_DNS_CLIENT
|
||||
|
||||
@@ -33,22 +33,12 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#include <openthread/dhcp6_client.h>
|
||||
#include <openthread/dhcp6_server.h>
|
||||
|
||||
#include "common/instance.hpp"
|
||||
|
||||
using namespace ot;
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
void otDhcp6ClientUpdate(otInstance *aInstance, otDhcpAddress *aAddresses, uint32_t aNumAddresses, void *aContext)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
instance.GetThreadNetif().GetDhcp6Client().UpdateAddresses(aInstance, aAddresses, aNumAddresses, aContext);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_SERVER
|
||||
void otDhcp6ServerUpdate(otInstance *aInstance)
|
||||
{
|
||||
|
||||
@@ -472,7 +472,7 @@ public:
|
||||
* @returns A pointer to the IPv6 address.
|
||||
*
|
||||
*/
|
||||
otIp6Address *GetAddress(void) { return &mAddress; }
|
||||
Ip6::Address &GetAddress(void) { return mAddress; }
|
||||
|
||||
/**
|
||||
* This method sets the IPv6 address.
|
||||
@@ -515,7 +515,7 @@ public:
|
||||
void SetValidLifetime(uint32_t aValidLifetime) { mValidLifetime = HostSwap32(aValidLifetime); }
|
||||
|
||||
private:
|
||||
otIp6Address mAddress; ///< IPv6 address
|
||||
Ip6::Address mAddress; ///< IPv6 address
|
||||
uint32_t mPreferredLifetime; ///< Preferred Lifetime
|
||||
uint32_t mValidLifetime; ///< Valid Lifetime
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
+79
-203
@@ -59,42 +59,30 @@ Dhcp6Client::Dhcp6Client(Instance &aInstance)
|
||||
, mSocket(aInstance.GetThreadNetif().GetIp6().GetUdp())
|
||||
, mTrickleTimer(aInstance, &Dhcp6Client::HandleTrickleTimer, NULL, this)
|
||||
, mStartTime(0)
|
||||
, mAddresses(NULL)
|
||||
, mNumAddresses(0)
|
||||
, mIdentityAssociationCurrent(NULL)
|
||||
{
|
||||
memset(mIdentityAssociations, 0, sizeof(IdentityAssociation));
|
||||
|
||||
for (uint8_t i = 0; i < (OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES - 1); i++)
|
||||
{
|
||||
mIdentityAssociations[i].SetNext(&(mIdentityAssociations[i + 1]));
|
||||
}
|
||||
|
||||
mIdentityAssociationHead = NULL;
|
||||
mIdentityAssociationAvail = &mIdentityAssociations[0];
|
||||
memset(mIdentityAssociations, 0, sizeof(mIdentityAssociations));
|
||||
}
|
||||
|
||||
void Dhcp6Client::UpdateAddresses(otInstance * aInstance,
|
||||
otDhcpAddress *aAddresses,
|
||||
uint32_t aNumAddresses,
|
||||
void * aContext)
|
||||
bool Dhcp6Client::MatchNetifAddressWithPrefix(const otNetifAddress &aNetifAddress, const otIp6Prefix &aIp6Prefix)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aContext);
|
||||
return aIp6Prefix.mLength == aNetifAddress.mPrefixLength &&
|
||||
otIp6PrefixMatch(&aNetifAddress.mAddress, &aIp6Prefix.mPrefix) >= aIp6Prefix.mLength;
|
||||
}
|
||||
|
||||
void Dhcp6Client::UpdateAddresses(void)
|
||||
{
|
||||
bool found = false;
|
||||
bool newAgent = false;
|
||||
otDhcpAddress * address = NULL;
|
||||
otNetworkDataIterator iterator;
|
||||
otBorderRouterConfig config;
|
||||
|
||||
mAddresses = aAddresses;
|
||||
mNumAddresses = aNumAddresses;
|
||||
|
||||
// remove addresses directly if prefix not valid in network data
|
||||
for (uint8_t i = 0; i < mNumAddresses; i++)
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); i++)
|
||||
{
|
||||
address = &mAddresses[i];
|
||||
IdentityAssociation &ia = mIdentityAssociations[i];
|
||||
|
||||
if (address->mValidLifetime == 0)
|
||||
if (ia.mStatus == kIaStatusInvalid || ia.mValidLifetime == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -102,16 +90,14 @@ void Dhcp6Client::UpdateAddresses(otInstance * aInstance,
|
||||
found = false;
|
||||
iterator = OT_NETWORK_DATA_ITERATOR_INIT;
|
||||
|
||||
while ((otNetDataGetNextOnMeshPrefix(aInstance, &iterator, &config)) == OT_ERROR_NONE)
|
||||
while ((otNetDataGetNextOnMeshPrefix(&GetInstance(), &iterator, &config)) == OT_ERROR_NONE)
|
||||
{
|
||||
if (!config.mDhcp)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((otIp6PrefixMatch(&(address->mAddress.mAddress), &(config.mPrefix.mPrefix)) >=
|
||||
address->mAddress.mPrefixLength) &&
|
||||
(config.mPrefix.mLength == address->mAddress.mPrefixLength))
|
||||
if (MatchNetifAddressWithPrefix(ia.mNetifAddress, config.mPrefix))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
@@ -120,17 +106,18 @@ void Dhcp6Client::UpdateAddresses(otInstance * aInstance,
|
||||
|
||||
if (!found)
|
||||
{
|
||||
GetNetif().RemoveUnicastAddress(*static_cast<Ip6::NetifUnicastAddress *>(&address->mAddress));
|
||||
RemoveIdentityAssociation(config.mRloc16, config.mPrefix);
|
||||
memset(address, 0, sizeof(*address));
|
||||
GetNetif().RemoveUnicastAddress(*static_cast<Ip6::NetifUnicastAddress *>(&ia.mNetifAddress));
|
||||
mIdentityAssociations[i].mStatus = kIaStatusInvalid;
|
||||
}
|
||||
}
|
||||
|
||||
// add IdentityAssociation for new configured prefix
|
||||
iterator = OT_NETWORK_DATA_ITERATOR_INIT;
|
||||
|
||||
while (otNetDataGetNextOnMeshPrefix(aInstance, &iterator, &config) == OT_ERROR_NONE)
|
||||
while (otNetDataGetNextOnMeshPrefix(&GetInstance(), &iterator, &config) == OT_ERROR_NONE)
|
||||
{
|
||||
IdentityAssociation *ia = NULL;
|
||||
|
||||
if (!config.mDhcp)
|
||||
{
|
||||
continue;
|
||||
@@ -138,18 +125,17 @@ void Dhcp6Client::UpdateAddresses(otInstance * aInstance,
|
||||
|
||||
found = false;
|
||||
|
||||
for (uint8_t i = 0; i < mNumAddresses; i++)
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); i++)
|
||||
{
|
||||
address = &mAddresses[i];
|
||||
|
||||
if (address->mAddress.mPrefixLength == 0)
|
||||
if (mIdentityAssociations[i].mStatus == kIaStatusInvalid)
|
||||
{
|
||||
continue;
|
||||
// record an available ia
|
||||
if (ia == NULL)
|
||||
{
|
||||
ia = &mIdentityAssociations[i];
|
||||
}
|
||||
}
|
||||
|
||||
if ((otIp6PrefixMatch(&(config.mPrefix.mPrefix), &(address->mAddress.mAddress)) >=
|
||||
config.mPrefix.mLength) &&
|
||||
(config.mPrefix.mLength == address->mAddress.mPrefixLength))
|
||||
else if (MatchNetifAddressWithPrefix(mIdentityAssociations[i].mNetifAddress, config.mPrefix))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
@@ -158,24 +144,18 @@ void Dhcp6Client::UpdateAddresses(otInstance * aInstance,
|
||||
|
||||
if (!found)
|
||||
{
|
||||
for (size_t i = 0; i < mNumAddresses; i++)
|
||||
if (ia != NULL)
|
||||
{
|
||||
address = &mAddresses[i];
|
||||
|
||||
if (address->mAddress.mPrefixLength != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
memset(address, 0, sizeof(*address));
|
||||
|
||||
// suppose all configured prefix are ::/64
|
||||
memcpy(address->mAddress.mAddress.mFields.m8, config.mPrefix.mPrefix.mFields.m8, 8);
|
||||
address->mAddress.mPrefixLength = config.mPrefix.mLength;
|
||||
|
||||
AddIdentityAssociation(config.mRloc16, config.mPrefix);
|
||||
newAgent = true;
|
||||
break;
|
||||
ia->mPrefixAgentRloc = config.mRloc16;
|
||||
ia->mNetifAddress.mAddress = config.mPrefix.mPrefix;
|
||||
ia->mNetifAddress.mPrefixLength = config.mPrefix.mLength;
|
||||
ia->mStatus = kIaStatusSolicit;
|
||||
ia->mValidLifetime = 0;
|
||||
newAgent = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
otLogWarnIp6("Insufficient memory for new DHCP prefix");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,82 +170,6 @@ void Dhcp6Client::UpdateAddresses(otInstance * aInstance,
|
||||
}
|
||||
}
|
||||
|
||||
void Dhcp6Client::AddIdentityAssociation(uint16_t aRloc16, otIp6Prefix &aIp6Prefix)
|
||||
{
|
||||
IdentityAssociation *identityAssociation = NULL;
|
||||
IdentityAssociation *identityAssociationCursor = NULL;
|
||||
|
||||
VerifyOrExit(mIdentityAssociationAvail);
|
||||
|
||||
identityAssociation = mIdentityAssociationAvail;
|
||||
mIdentityAssociationAvail = mIdentityAssociationAvail->GetNext();
|
||||
|
||||
identityAssociation->SetPrefixAgentRloc(aRloc16);
|
||||
identityAssociation->SetPrefix(aIp6Prefix);
|
||||
identityAssociation->SetStatus(IdentityAssociation::kStatusSolicit);
|
||||
|
||||
identityAssociation->SetNext(NULL);
|
||||
|
||||
if (mIdentityAssociationHead)
|
||||
{
|
||||
// append the new identityassociation to the tail of used list
|
||||
for (identityAssociationCursor = mIdentityAssociationHead; identityAssociationCursor->GetNext();
|
||||
identityAssociationCursor = identityAssociationCursor->GetNext())
|
||||
{
|
||||
}
|
||||
|
||||
identityAssociationCursor->SetNext(identityAssociation);
|
||||
}
|
||||
else
|
||||
{
|
||||
mIdentityAssociationHead = identityAssociation;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Dhcp6Client::RemoveIdentityAssociation(uint16_t aRloc16, otIp6Prefix &aIp6Prefix)
|
||||
{
|
||||
IdentityAssociation *prevIdentityAssociation = NULL;
|
||||
IdentityAssociation *identityAssociation = NULL;
|
||||
|
||||
VerifyOrExit(mIdentityAssociationHead);
|
||||
|
||||
for (identityAssociation = mIdentityAssociationHead; identityAssociation;
|
||||
prevIdentityAssociation = identityAssociation, identityAssociation = identityAssociation->GetNext())
|
||||
{
|
||||
if (identityAssociation->GetPrefixAgentRloc() != aRloc16)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (otIp6PrefixMatch(&(aIp6Prefix.mPrefix), &(identityAssociation->GetPrefix()->mPrefix)) < aIp6Prefix.mLength)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// remove from used list
|
||||
if (prevIdentityAssociation)
|
||||
{
|
||||
prevIdentityAssociation->SetNext(identityAssociation->GetNext());
|
||||
}
|
||||
else
|
||||
{
|
||||
mIdentityAssociationHead = identityAssociation->GetNext();
|
||||
}
|
||||
|
||||
// return to available list
|
||||
memset(identityAssociation, 0, sizeof(*identityAssociation));
|
||||
identityAssociation->SetNext(mIdentityAssociationAvail);
|
||||
mIdentityAssociationAvail = identityAssociation;
|
||||
break;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
otError Dhcp6Client::Start(void)
|
||||
{
|
||||
Ip6::SockAddr sockaddr;
|
||||
@@ -287,20 +191,16 @@ otError Dhcp6Client::Stop(void)
|
||||
|
||||
bool Dhcp6Client::ProcessNextIdentityAssociation()
|
||||
{
|
||||
bool rval = false;
|
||||
IdentityAssociation *prevIdentityAssociation = NULL;
|
||||
IdentityAssociation *identityAssociation = NULL;
|
||||
bool rval = false;
|
||||
|
||||
VerifyOrExit(mIdentityAssociationHead);
|
||||
// not interrupt in-progress solicit
|
||||
VerifyOrExit((mIdentityAssociationHead->GetStatus() != IdentityAssociation::kStatusSoliciting));
|
||||
VerifyOrExit(mIdentityAssociationCurrent == NULL || mIdentityAssociationCurrent->mStatus != kIaStatusSoliciting);
|
||||
|
||||
mTrickleTimer.Stop();
|
||||
|
||||
for (identityAssociation = mIdentityAssociationHead; identityAssociation;
|
||||
prevIdentityAssociation = identityAssociation, identityAssociation = identityAssociation->GetNext())
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); ++i)
|
||||
{
|
||||
if (identityAssociation->GetStatus() != IdentityAssociation::kStatusSolicit)
|
||||
if (mIdentityAssociations[i].mStatus != kIaStatusSolicit)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -308,13 +208,7 @@ bool Dhcp6Client::ProcessNextIdentityAssociation()
|
||||
// new transaction id
|
||||
Random::FillBuffer(mTransactionId, kTransactionIdSize);
|
||||
|
||||
// ensure mIdentityAssociationHead is the prefix agent to solicit.
|
||||
if (prevIdentityAssociation)
|
||||
{
|
||||
prevIdentityAssociation->SetNext(identityAssociation->GetNext());
|
||||
identityAssociation->SetNext(mIdentityAssociationHead);
|
||||
mIdentityAssociationHead = identityAssociation;
|
||||
}
|
||||
mIdentityAssociationCurrent = &mIdentityAssociations[i];
|
||||
|
||||
mTrickleTimer.Start(TimerMilli::SecToMsec(kTrickleTimerImin), TimerMilli::SecToMsec(kTrickleTimerImax),
|
||||
TrickleTimer::kModeNormal);
|
||||
@@ -337,21 +231,23 @@ bool Dhcp6Client::HandleTrickleTimer(void)
|
||||
{
|
||||
bool rval = true;
|
||||
|
||||
VerifyOrExit(mIdentityAssociationHead, rval = false);
|
||||
VerifyOrExit(mIdentityAssociationCurrent != NULL, rval = false);
|
||||
|
||||
switch (mIdentityAssociationHead->GetStatus())
|
||||
switch (mIdentityAssociationCurrent->mStatus)
|
||||
{
|
||||
case IdentityAssociation::kStatusSolicit:
|
||||
mStartTime = TimerMilli::GetNow();
|
||||
mIdentityAssociationHead->SetStatus(IdentityAssociation::kStatusSoliciting);
|
||||
case kIaStatusSolicit:
|
||||
mStartTime = TimerMilli::GetNow();
|
||||
mIdentityAssociationCurrent->mStatus = kIaStatusSoliciting;
|
||||
|
||||
// fall through
|
||||
|
||||
case IdentityAssociation::kStatusSoliciting:
|
||||
Solicit(mIdentityAssociationHead->GetPrefixAgentRloc());
|
||||
case kIaStatusSoliciting:
|
||||
Solicit(mIdentityAssociationCurrent->mPrefixAgentRloc);
|
||||
break;
|
||||
|
||||
case IdentityAssociation::kStatusSolicitReplied:
|
||||
case kIaStatusSolicitReplied:
|
||||
mIdentityAssociationCurrent = NULL;
|
||||
|
||||
if (!ProcessNextIdentityAssociation())
|
||||
{
|
||||
mTrickleTimer.Stop();
|
||||
@@ -440,23 +336,21 @@ otError Dhcp6Client::AppendClientIdentifier(Message &aMessage)
|
||||
|
||||
otError Dhcp6Client::AppendIaNa(Message &aMessage, uint16_t aRloc16)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t count = 0;
|
||||
uint16_t length = 0;
|
||||
IdentityAssociation *identityAssociation = NULL;
|
||||
IaNa option;
|
||||
otError error = OT_ERROR_NONE;
|
||||
uint8_t count = 0;
|
||||
uint16_t length = 0;
|
||||
IaNa option;
|
||||
|
||||
VerifyOrExit(mIdentityAssociationHead, error = OT_ERROR_DROP);
|
||||
VerifyOrExit(mIdentityAssociationCurrent != NULL, error = OT_ERROR_DROP);
|
||||
|
||||
for (identityAssociation = mIdentityAssociationHead; identityAssociation;
|
||||
identityAssociation = identityAssociation->GetNext())
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); ++i)
|
||||
{
|
||||
if (identityAssociation->GetStatus() == IdentityAssociation::kStatusSolicitReplied)
|
||||
if (mIdentityAssociations[i].mStatus == kIaStatusSolicitReplied)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identityAssociation->GetPrefixAgentRloc() == aRloc16)
|
||||
if (mIdentityAssociations[i].mPrefixAgentRloc == aRloc16)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
@@ -478,21 +372,19 @@ exit:
|
||||
|
||||
otError Dhcp6Client::AppendIaAddress(Message &aMessage, uint16_t aRloc16)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
IdentityAssociation *identityAssociation = NULL;
|
||||
IaAddress option;
|
||||
otError error = OT_ERROR_NONE;
|
||||
IaAddress option;
|
||||
|
||||
VerifyOrExit(mIdentityAssociationHead, error = OT_ERROR_DROP);
|
||||
VerifyOrExit(mIdentityAssociationCurrent, error = OT_ERROR_DROP);
|
||||
|
||||
option.Init();
|
||||
|
||||
for (identityAssociation = mIdentityAssociationHead; identityAssociation;
|
||||
identityAssociation = identityAssociation->GetNext())
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); ++i)
|
||||
{
|
||||
if ((identityAssociation->GetStatus() != IdentityAssociation::kStatusSolicitReplied) &&
|
||||
(identityAssociation->GetPrefixAgentRloc() == aRloc16))
|
||||
if ((mIdentityAssociations[i].mStatus != kIaStatusSolicitReplied) &&
|
||||
(mIdentityAssociations[i].mPrefixAgentRloc == aRloc16))
|
||||
{
|
||||
option.SetAddress(identityAssociation->GetPrefix()->mPrefix);
|
||||
option.SetAddress(mIdentityAssociations[i].mNetifAddress.mAddress);
|
||||
option.SetPreferredLifetime(0);
|
||||
option.SetValidLifetime(0);
|
||||
SuccessOrExit(error = aMessage.Append(&option, sizeof(option)));
|
||||
@@ -664,47 +556,31 @@ exit:
|
||||
|
||||
otError Dhcp6Client::ProcessIaAddress(Message &aMessage, uint16_t aOffset)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
IdentityAssociation *identityAssociation = NULL;
|
||||
otDhcpAddress * address = NULL;
|
||||
otIp6Prefix * prefix = NULL;
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
IaAddress option;
|
||||
|
||||
VerifyOrExit(((aMessage.Read(aOffset, sizeof(option), &option) == sizeof(option)) &&
|
||||
(option.GetLength() == (sizeof(option) - sizeof(Dhcp6Option)))),
|
||||
error = OT_ERROR_PARSE);
|
||||
|
||||
for (uint8_t i = 0; i < mNumAddresses; i++)
|
||||
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mIdentityAssociations); ++i)
|
||||
{
|
||||
address = &mAddresses[i];
|
||||
IdentityAssociation &ia = mIdentityAssociations[i];
|
||||
|
||||
if (address->mValidLifetime != 0)
|
||||
if (ia.mStatus == kIaStatusInvalid || ia.mValidLifetime != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (otIp6PrefixMatch(&(address->mAddress.mAddress), option.GetAddress()) >= address->mAddress.mPrefixLength)
|
||||
if (otIp6PrefixMatch(&ia.mNetifAddress.mAddress, &option.GetAddress()) >= ia.mNetifAddress.mPrefixLength)
|
||||
{
|
||||
memcpy(address->mAddress.mAddress.mFields.m8, option.GetAddress()->mFields.m8, sizeof(otIp6Address));
|
||||
address->mPreferredLifetime = option.GetPreferredLifetime();
|
||||
address->mValidLifetime = option.GetValidLifetime();
|
||||
address->mAddress.mPreferred = address->mPreferredLifetime != 0;
|
||||
address->mAddress.mValid = address->mValidLifetime != 0;
|
||||
GetNetif().AddUnicastAddress(*static_cast<Ip6::NetifUnicastAddress *>(&address->mAddress));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// mark IdentityAssociation as replied
|
||||
for (identityAssociation = mIdentityAssociationHead; identityAssociation;
|
||||
identityAssociation = identityAssociation->GetNext())
|
||||
{
|
||||
prefix = identityAssociation->GetPrefix();
|
||||
|
||||
if (otIp6PrefixMatch(option.GetAddress(), &(prefix->mPrefix)) >= prefix->mLength)
|
||||
{
|
||||
identityAssociation->SetStatus(IdentityAssociation::kStatusSolicitReplied);
|
||||
mIdentityAssociations[i].mNetifAddress.mAddress = option.GetAddress();
|
||||
mIdentityAssociations[i].mPreferredLifetime = option.GetPreferredLifetime();
|
||||
mIdentityAssociations[i].mValidLifetime = option.GetValidLifetime();
|
||||
mIdentityAssociations[i].mNetifAddress.mPreferred = option.GetPreferredLifetime() != 0;
|
||||
mIdentityAssociations[i].mNetifAddress.mValid = option.GetValidLifetime() != 0;
|
||||
mIdentityAssociations[i].mStatus = kIaStatusSolicitReplied;
|
||||
GetNetif().AddUnicastAddress(*static_cast<Ip6::NetifUnicastAddress *>(&ia.mNetifAddress));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
|
||||
#include <openthread/dhcp6_client.h>
|
||||
|
||||
#include "common/locator.hpp"
|
||||
#include "common/message.hpp"
|
||||
#include "common/timer.hpp"
|
||||
@@ -71,94 +69,30 @@ enum
|
||||
kTrickleTimerImax = 120,
|
||||
};
|
||||
|
||||
/**
|
||||
* Status of IdentityAssociation
|
||||
*
|
||||
*/
|
||||
enum IaStatus
|
||||
{
|
||||
kIaStatusInvalid,
|
||||
kIaStatusSolicit,
|
||||
kIaStatusSoliciting,
|
||||
kIaStatusSolicitReplied,
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements IdentityAssociation.
|
||||
*
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class IdentityAssociation
|
||||
struct IdentityAssociation
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Status of IdentityAssociation
|
||||
*
|
||||
*/
|
||||
typedef enum Status
|
||||
{
|
||||
kStatusInvalid,
|
||||
kStatusSolicit,
|
||||
kStatusSoliciting,
|
||||
kStatusSolicitReplied,
|
||||
} Status;
|
||||
|
||||
/**
|
||||
* This method returns the status of the object.
|
||||
*
|
||||
* @returns Status.
|
||||
*
|
||||
*/
|
||||
Status GetStatus(void) const { return static_cast<Status>(mStatus); }
|
||||
|
||||
/**
|
||||
* This method sets the status of the object.
|
||||
*
|
||||
* @param[in] aStatus The Status to set.
|
||||
*
|
||||
*/
|
||||
void SetStatus(Status aStatus) { mStatus = static_cast<uint8_t>(aStatus); }
|
||||
|
||||
/**
|
||||
* This method returns the rloc of the DHCP Agent.
|
||||
*
|
||||
* @returns Status.
|
||||
*
|
||||
*/
|
||||
uint16_t GetPrefixAgentRloc(void) const { return mPrefixAgentRloc; }
|
||||
|
||||
/**
|
||||
* This method sets the rloc of the DHCP Agent.
|
||||
*
|
||||
* @param[in] aRloc The rloc of the DHCP Agent.
|
||||
*
|
||||
*/
|
||||
void SetPrefixAgentRloc(uint16_t aRloc16) { mPrefixAgentRloc = aRloc16; }
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the IPv6 prefix.
|
||||
*
|
||||
* @returns A pointer to the IPv6 prefix.
|
||||
*
|
||||
*/
|
||||
otIp6Prefix *GetPrefix(void) { return &mIp6Prefix; }
|
||||
|
||||
/**
|
||||
* This method sets the IPv6 prefix to specified location.
|
||||
*
|
||||
* @param[in] aIp6Prefix The reference to the IPv6 prefix to set.
|
||||
*
|
||||
*/
|
||||
void SetPrefix(otIp6Prefix &aIp6Prefix) { memcpy(&mIp6Prefix, &aIp6Prefix, sizeof(otIp6Prefix)); }
|
||||
|
||||
/**
|
||||
* This method returns the pointer to the next IdentityAssociation.
|
||||
*
|
||||
* @returns A pointer to the next IdentityAssociation.
|
||||
*
|
||||
*/
|
||||
IdentityAssociation *GetNext(void) { return mNext; }
|
||||
|
||||
/**
|
||||
* This method sets the pointer to the next IdentityAssociation.
|
||||
*
|
||||
*/
|
||||
void SetNext(IdentityAssociation *aNext) { mNext = aNext; }
|
||||
|
||||
private:
|
||||
uint8_t mStatus; ///< Status of IdentityAssocation
|
||||
uint16_t mPrefixAgentRloc; ///< Rloc of Prefix Agent
|
||||
otIp6Prefix mIp6Prefix; ///< Prefix
|
||||
IdentityAssociation *mNext; ///< Pointer to next IdentityAssocation
|
||||
} OT_TOOL_PACKED_END;
|
||||
otNetifAddress mNetifAddress; ///< the NetifAddress
|
||||
uint32_t mPreferredLifetime; ///< The preferred lifetime.
|
||||
uint32_t mValidLifetime; ///< The valid lifetime.
|
||||
uint16_t mPrefixAgentRloc; ///< Rloc of Prefix Agent
|
||||
uint8_t mStatus; ///< Status of IdentityAssocation
|
||||
};
|
||||
|
||||
/**
|
||||
* This class implements DHCPv6 Client.
|
||||
@@ -178,18 +112,16 @@ public:
|
||||
/**
|
||||
* This method update addresses that shall be automatically created using DHCP.
|
||||
*
|
||||
* @param[in] aInstance A pointer to OpenThread instance.
|
||||
* @param[inout] aAddresses A pointer to an array containing addresses created by this module.
|
||||
* @param[in] aNumAddresses The number of elements in aAddresses array.
|
||||
* @param[in] aContext A pointer to IID creator-specific context data.
|
||||
*
|
||||
*/
|
||||
void UpdateAddresses(otInstance *aInstance, otDhcpAddress *aAddresses, uint32_t aNumAddresses, void *aContext);
|
||||
void UpdateAddresses(void);
|
||||
|
||||
private:
|
||||
otError Start(void);
|
||||
otError Stop(void);
|
||||
|
||||
static bool MatchNetifAddressWithPrefix(const otNetifAddress &aNetifAddress, const otIp6Prefix &aIp6Prefix);
|
||||
|
||||
otError Solicit(uint16_t aRloc16);
|
||||
|
||||
void AddIdentityAssociation(uint16_t aRloc16, otIp6Prefix &aIp6Prefix);
|
||||
@@ -222,14 +154,11 @@ private:
|
||||
|
||||
TrickleTimer mTrickleTimer;
|
||||
|
||||
uint8_t mTransactionId[kTransactionIdSize];
|
||||
uint32_t mStartTime;
|
||||
otDhcpAddress *mAddresses;
|
||||
uint32_t mNumAddresses;
|
||||
uint8_t mTransactionId[kTransactionIdSize];
|
||||
uint32_t mStartTime;
|
||||
|
||||
IdentityAssociation mIdentityAssociations[OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES];
|
||||
IdentityAssociation *mIdentityAssociationHead;
|
||||
IdentityAssociation *mIdentityAssociationAvail;
|
||||
IdentityAssociation *mIdentityAssociationCurrent;
|
||||
};
|
||||
|
||||
} // namespace Dhcp6
|
||||
|
||||
@@ -401,7 +401,7 @@ otError Dhcp6Server::ProcessIaAddress(Message &aMessage, uint16_t aOffset)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (otIp6PrefixMatch(option.GetAddress(), &(prefix->mPrefix)) >= prefix->mLength)
|
||||
if (otIp6PrefixMatch(&option.GetAddress(), &prefix->mPrefix) >= prefix->mLength)
|
||||
{
|
||||
mPrefixAgentsMask |= (1 << i);
|
||||
break;
|
||||
@@ -553,9 +553,8 @@ otError Dhcp6Server::AddIaAddress(Message &aMessage, otIp6Prefix &aIp6Prefix, Cl
|
||||
IaAddress option;
|
||||
|
||||
option.Init();
|
||||
memcpy((option.GetAddress()->mFields.m8), &(aIp6Prefix.mPrefix), 8);
|
||||
static_cast<Ip6::Address *>(option.GetAddress())
|
||||
->SetIid(*reinterpret_cast<Mac::ExtAddress *>(aClient.GetDuidLinkLayerAddress()));
|
||||
memcpy(option.GetAddress().mFields.m8, &aIp6Prefix.mPrefix, 8);
|
||||
option.GetAddress().SetIid(*reinterpret_cast<Mac::ExtAddress *>(aClient.GetDuidLinkLayerAddress()));
|
||||
option.SetPreferredLifetime(OT_DHCP6_DEFAULT_PREFERRED_LIFETIME);
|
||||
option.SetValidLifetime(OT_DHCP6_DEFAULT_VALID_LIFETIME);
|
||||
SuccessOrExit(error = aMessage.Append(&option, sizeof(option)));
|
||||
|
||||
@@ -1509,6 +1509,10 @@ void Mle::HandleStateChanged(otChangedFlags aFlags)
|
||||
this->UpdateServiceAlocs();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
GetNetif().GetDhcp6Client().UpdateAddresses();
|
||||
#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
}
|
||||
|
||||
if (aFlags & (OT_CHANGED_THREAD_ROLE | OT_CHANGED_THREAD_KEY_SEQUENCE_COUNTER))
|
||||
|
||||
@@ -257,10 +257,6 @@ NcpBase::NcpBase(Instance *aInstance)
|
||||
|
||||
memset(&mResponseQueue, 0, sizeof(mResponseQueue));
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
memset(mDhcpAddresses, 0, sizeof(mDhcpAddresses));
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_MTD || OPENTHREAD_FTD
|
||||
otMessageQueueInit(&mMessageQueue);
|
||||
otSetStateChangedCallback(mInstance, &NcpBase::HandleStateChanged, this);
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
#if OPENTHREAD_FTD
|
||||
#include <openthread/thread_ftd.h>
|
||||
#endif
|
||||
#include <openthread/dhcp6_client.h>
|
||||
#include <openthread/message.h>
|
||||
#include <openthread/ncp.h>
|
||||
|
||||
@@ -535,10 +534,6 @@ protected:
|
||||
bool mDisableStreamWrite;
|
||||
bool mShouldEmitChildTableUpdate;
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
otDhcpAddress mDhcpAddresses[OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES];
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
#if OPENTHREAD_CONFIG_ENABLE_STEERING_DATA_SET_OOB
|
||||
otExtAddress mSteeringDataAddress;
|
||||
|
||||
@@ -3437,10 +3437,6 @@ void NcpBase::ProcessThreadChangedFlags(void)
|
||||
mChangedPropsSet.AddProperty(SPINEL_PROP_THREAD_ON_MESH_NETS);
|
||||
mChangedPropsSet.AddProperty(SPINEL_PROP_THREAD_OFF_MESH_ROUTES);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_CLIENT
|
||||
otDhcp6ClientUpdate(mInstance, mDhcpAddresses, OT_ARRAY_LENGTH(mDhcpAddresses), NULL);
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_ENABLE_DHCP6_SERVER
|
||||
otDhcp6ServerUpdate(mInstance);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user