[core] ApplyMeshLocalPrefix() to applicable ALOCs (#4894)

This commit is contained in:
Rongli Sun
2020-04-28 16:31:25 -07:00
committed by Jonathan Hui
parent 972acd734f
commit 79f1d4c5c8
7 changed files with 76 additions and 6 deletions
+14
View File
@@ -746,6 +746,20 @@ void BorderAgent::SetState(otBorderAgentState aState)
}
}
void BorderAgent::ApplyMeshLocalPrefix(void)
{
VerifyOrExit(mState == OT_BORDER_AGENT_STATE_ACTIVE, OT_NOOP);
if (Get<ThreadNetif>().RemoveUnicastAddress(mCommissionerAloc) == OT_ERROR_NONE)
{
mCommissionerAloc.GetAddress().SetPrefix(Get<Mle::MleRouter>().GetMeshLocalPrefix());
Get<ThreadNetif>().AddUnicastAddress(mCommissionerAloc);
}
exit:
return;
}
} // namespace MeshCoP
} // namespace ot
+6
View File
@@ -86,6 +86,12 @@ public:
*/
otBorderAgentState GetState(void) const { return mState; }
/**
* This method applies the Mesh Local Prefix.
*
*/
void ApplyMeshLocalPrefix(void);
private:
static void HandleStateChanged(Notifier::Callback &aCallback, otChangedFlags aFlags);
void HandleStateChanged(otChangedFlags aFlags);
+12
View File
@@ -1094,6 +1094,18 @@ exit:
return error;
}
void Commissioner::ApplyMeshLocalPrefix(void)
{
VerifyOrExit(mState == OT_COMMISSIONER_STATE_ACTIVE, OT_NOOP);
Get<ThreadNetif>().RemoveUnicastAddress(mCommissionerAloc);
mCommissionerAloc.GetAddress().SetPrefix(Get<Mle::MleRouter>().GetMeshLocalPrefix());
Get<ThreadNetif>().AddUnicastAddress(mCommissionerAloc);
exit:
return;
}
// LCOV_EXCL_START
#if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MLE == 1)
+6
View File
@@ -246,6 +246,12 @@ public:
*/
PanIdQueryClient &GetPanIdQueryClient(void) { return mPanIdQuery; }
/**
* This method applies the Mesh Local Prefix.
*
*/
void ApplyMeshLocalPrefix(void);
private:
enum
{
+20 -6
View File
@@ -64,7 +64,7 @@ otError Dhcp6Server::UpdateService(void)
Lowpan::Context lowpanContext;
// remove dhcp agent aloc and prefix delegation
for (int i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++)
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
{
bool found = false;
@@ -149,7 +149,7 @@ otError Dhcp6Server::AddPrefixAgent(const otIp6Prefix &aIp6Prefix, const Lowpan:
otError error = OT_ERROR_NONE;
PrefixAgent *newEntry = NULL;
for (int i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++)
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
{
if (!mPrefixAgents[i].IsValid())
{
@@ -312,7 +312,7 @@ otError Dhcp6Server::ProcessIaAddress(Message &aMessage, uint16_t aOffset)
error = OT_ERROR_PARSE);
// mask matching prefix
for (uint8_t i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++)
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
{
if (mPrefixAgents[i].IsValid() && mPrefixAgents[i].IsPrefixMatch(option.GetAddress()))
{
@@ -394,7 +394,7 @@ otError Dhcp6Server::AppendIaNa(Message &aMessage, IaNa &aIaNa)
if (mPrefixAgentsMask)
{
for (uint8_t i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++)
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
{
if ((mPrefixAgentsMask & (1 << i)))
{
@@ -434,7 +434,7 @@ otError Dhcp6Server::AppendIaAddress(Message &aMessage, ClientIdentifier &aClien
if (mPrefixAgentsMask)
{
// if specified, only apply specified prefixes
for (uint8_t i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++)
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
{
if (mPrefixAgentsMask & (1 << i))
{
@@ -445,7 +445,7 @@ otError Dhcp6Server::AppendIaAddress(Message &aMessage, ClientIdentifier &aClien
else
{
// if not specified, apply all configured prefixes
for (uint8_t i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++)
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
{
if (mPrefixAgents[i].IsValid())
{
@@ -482,6 +482,20 @@ otError Dhcp6Server::AppendRapidCommit(Message &aMessage)
return aMessage.Append(&option, sizeof(option));
}
void Dhcp6Server::ApplyMeshLocalPrefix(void)
{
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++)
{
if (mPrefixAgents[i].IsValid())
{
PrefixAgent *entry = &mPrefixAgents[i];
Get<ThreadNetif>().RemoveUnicastAddress(entry->GetAloc());
entry->GetAloc().GetAddress().SetPrefix(Get<Mle::MleRouter>().GetMeshLocalPrefix());
Get<ThreadNetif>().AddUnicastAddress(entry->GetAloc());
}
}
}
} // namespace Dhcp6
} // namespace ot
+6
View File
@@ -83,6 +83,12 @@ public:
*/
otError UpdateService();
/**
* This method applies the Mesh Local Prefix.
*
*/
void ApplyMeshLocalPrefix(void);
private:
class PrefixAgent
{
+12
View File
@@ -953,6 +953,18 @@ void Mle::ApplyMeshLocalPrefix(void)
Get<ThreadNetif>().AddUnicastAddress(mLeaderAloc);
}
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE
Get<MeshCoP::Commissioner>().ApplyMeshLocalPrefix();
#endif
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
Get<MeshCoP::BorderAgent>().ApplyMeshLocalPrefix();
#endif
#if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE
Get<Dhcp6::Dhcp6Server>().ApplyMeshLocalPrefix();
#endif
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mServiceAlocs); i++)