From 95a434d737b7309d31a601ca0cc9dd062b40bfd6 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 17 Jun 2020 14:47:41 -0700 Subject: [PATCH] [slaac] set plen to 128 if prefix is not on-mesh (#5116) --- src/core/utils/slaac_address.cpp | 18 +++++++++++------- src/core/utils/slaac_address.hpp | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/core/utils/slaac_address.cpp b/src/core/utils/slaac_address.cpp index 101b48084..f4d646863 100644 --- a/src/core/utils/slaac_address.cpp +++ b/src/core/utils/slaac_address.cpp @@ -138,6 +138,14 @@ exit: return; } +bool Slaac::DoesConfigMatchNetifAddr(const NetworkData::OnMeshPrefixConfig &aConfig, + const Ip6::NetifUnicastAddress & aAddr) +{ + return (((aConfig.mOnMesh && (aAddr.mPrefixLength == aConfig.mPrefix.mLength)) || + (!aConfig.mOnMesh && (aAddr.mPrefixLength == 128))) && + (aAddr.GetAddress().PrefixMatch(aConfig.mPrefix.mPrefix) >= aConfig.mPrefix.mLength)); +} + void Slaac::Update(UpdateMode aMode) { NetworkData::Iterator iterator; @@ -165,16 +173,13 @@ void Slaac::Update(UpdateMode aMode) while (Get().GetNextOnMeshPrefix(iterator, config) == OT_ERROR_NONE) { - otIp6Prefix &prefix = config.mPrefix; - if (config.mDp) { // Skip domain prefix which is processed in MLE. continue; } - if (config.mSlaac && !ShouldFilter(prefix) && (prefix.mLength == slaacAddr->mPrefixLength) && - (slaacAddr->GetAddress().PrefixMatch(prefix.mPrefix) >= prefix.mLength)) + if (config.mSlaac && !ShouldFilter(config.mPrefix) && DoesConfigMatchNetifAddr(config, *slaacAddr)) { found = true; break; @@ -212,8 +217,7 @@ void Slaac::Update(UpdateMode aMode) for (const Ip6::NetifUnicastAddress *netifAddr = Get().GetUnicastAddresses(); netifAddr != nullptr; netifAddr = netifAddr->GetNext()) { - if ((netifAddr->mPrefixLength == prefix.mLength) && - (netifAddr->GetAddress().PrefixMatch(prefix.mPrefix) >= prefix.mLength)) + if (DoesConfigMatchNetifAddr(config, *netifAddr)) { found = true; break; @@ -234,7 +238,7 @@ void Slaac::Update(UpdateMode aMode) slaacAddr->Clear(); memcpy(&slaacAddr->mAddress, &prefix.mPrefix, BitVectorBytes(prefix.mLength)); - slaacAddr->mPrefixLength = prefix.mLength; + slaacAddr->mPrefixLength = config.mOnMesh ? prefix.mLength : 128; slaacAddr->mAddressOrigin = OT_ADDRESS_ORIGIN_SLAAC; slaacAddr->mPreferred = config.mPreferred; slaacAddr->mValid = true; diff --git a/src/core/utils/slaac_address.hpp b/src/core/utils/slaac_address.hpp index b391d47a6..3c035cec3 100644 --- a/src/core/utils/slaac_address.hpp +++ b/src/core/utils/slaac_address.hpp @@ -39,6 +39,7 @@ #include "common/locator.hpp" #include "common/notifier.hpp" #include "net/netif.hpp" +#include "thread/network_data.hpp" namespace ot { namespace Utils { @@ -163,6 +164,8 @@ private: void GetIidSecretKey(IidSecretKey &aKey) const; static void HandleNotifierEvents(Notifier::Receiver &aReceiver, Events aEvents); void HandleNotifierEvents(Events aEvents); + static bool DoesConfigMatchNetifAddr(const NetworkData::OnMeshPrefixConfig &aConfig, + const Ip6::NetifUnicastAddress & aAddr); bool mEnabled; otIp6SlaacPrefixFilter mFilter;