mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 22:27:47 +00:00
[border-routing] fix on-link prefix validation (#6917)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user