[border-routing] fix on-link prefix validation (#6917)

This commit is contained in:
Simon Lin
2021-08-12 09:57:17 -07:00
committed by GitHub
parent 1fcc67d4cb
commit b6fb0f4f93
2 changed files with 32 additions and 4 deletions
+2 -4
View File
@@ -169,7 +169,7 @@ Error RoutingManager::LoadOrGenerateRandomOnLinkPrefix(void)
Error error = kErrorNone;
if (Get<Settings>().Read<Settings::OnLinkPrefix>(mLocalOnLinkPrefix) != kErrorNone ||
!IsValidOnLinkPrefix(mLocalOnLinkPrefix))
!mLocalOnLinkPrefix.IsUniqueLocal())
{
Ip6::NetworkPrefix randomOnLinkPrefix;
@@ -803,9 +803,7 @@ bool RoutingManager::IsValidOnLinkPrefix(const RouterAdv::PrefixInfoOption &aPio
bool RoutingManager::IsValidOnLinkPrefix(const Ip6::Prefix &aOnLinkPrefix)
{
// Accept ULA prefix with length of 64 bits and GUA prefix.
return (aOnLinkPrefix.mLength == kOnLinkPrefixLength && aOnLinkPrefix.mPrefix.mFields.m8[0] == 0xfd) ||
(aOnLinkPrefix.mLength >= 3 && (aOnLinkPrefix.GetBytes()[0] & 0xE0) == 0x20);
return !aOnLinkPrefix.IsLinkLocal() && !aOnLinkPrefix.IsMulticast();
}
void RoutingManager::HandleRouterAdvertisementTimer(Timer &aTimer)
+30
View File
@@ -159,6 +159,36 @@ public:
*/
bool IsValid(void) const { return (mLength <= kMaxLength); }
/**
* This method indicates whether the prefix is a Link-Local prefix.
*
* @retval TRUE The prefix is a Link-Local prefix.
* @retval FALSE The prefix is not a Link-Local prefix.
*
*/
bool IsLinkLocal(void) const
{
return mLength >= 10 && mPrefix.mFields.m8[0] == 0xfe && (mPrefix.mFields.m8[1] & 0xc0) == 0x80;
}
/**
* This method indicates whether the prefix is a Multicast prefix.
*
* @retval TRUE The prefix is a Multicast prefix.
* @retval FALSE The prefix is not a Multicast prefix.
*
*/
bool IsMulticast(void) const { return mLength >= 8 && mPrefix.mFields.m8[0] == 0xff; }
/**
* This method indicates whether the prefix is a Unique-Local prefix.
*
* @retval TRUE The prefix is a Unique-Local prefix.
* @retval FALSE The prefix is not a Unique-Local prefix.
*
*/
bool IsUniqueLocal(void) const { return mLength >= 7 && (mPrefix.mFields.m8[0] & 0xfe) == 0xfc; }
/**
* This method indicates whether the prefix is equal to a given prefix.
*