diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index edb808332..496f14da0 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -169,7 +169,7 @@ Error RoutingManager::LoadOrGenerateRandomOnLinkPrefix(void) Error error = kErrorNone; if (Get().Read(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) diff --git a/src/core/net/ip6_address.hpp b/src/core/net/ip6_address.hpp index ca8055bed..9139af7bd 100644 --- a/src/core/net/ip6_address.hpp +++ b/src/core/net/ip6_address.hpp @@ -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. *