From b7c40afb6674fc777185f44f26824df89dfc8edc Mon Sep 17 00:00:00 2001 From: Simon Lin Date: Fri, 24 Dec 2021 04:26:04 +0800 Subject: [PATCH] [border-routing] add configuration for Vicarious Router Solicitation (#7248) This commit adds `OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE` configuration to allow disabling Vicarious Router Solicitation feature. --- src/core/border_router/routing_manager.cpp | 10 ++++++++++ src/core/border_router/routing_manager.hpp | 4 ++++ src/core/config/border_router.h | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 443e81854..533ec4965 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -69,7 +69,9 @@ RoutingManager::RoutingManager(Instance &aInstance) , mDiscoveredPrefixStaleTimer(aInstance, HandleDiscoveredPrefixStaleTimer) , mRouterAdvertisementTimer(aInstance, HandleRouterAdvertisementTimer) , mRouterAdvertisementCount(0) +#if OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE , mVicariousRouterSolicitTimer(aInstance, HandleVicariousRouterSolicitTimer) +#endif , mRouterSolicitTimer(aInstance, HandleRouterSolicitTimer) , mRouterSolicitCount(0) , mRoutingPolicyTimer(aInstance, HandleRoutingPolicyTimer) @@ -246,7 +248,9 @@ void RoutingManager::Stop(void) mRouterAdvertisementTimer.Stop(); mRouterAdvertisementCount = 0; +#if OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE mVicariousRouterSolicitTimer.Stop(); +#endif mRouterSolicitTimer.Stop(); mRouterSolicitCount = 0; @@ -640,7 +644,9 @@ void RoutingManager::StartRouterSolicitationDelay(void) OT_ASSERT(mRouterSolicitCount == 0); +#if OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE mVicariousRouterSolicitTimer.Stop(); +#endif static_assert(kMaxRtrSolicitationDelay > 0, "invalid maximum Router Solicitation delay"); randomDelay = Random::NonCrypto::GetUint32InRange(0, Time::SecToMsec(kMaxRtrSolicitationDelay)); @@ -824,6 +830,7 @@ void RoutingManager::HandleRouterAdvertisementTimer(void) EvaluateRoutingPolicy(); } +#if OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE void RoutingManager::HandleVicariousRouterSolicitTimer(Timer &aTimer) { aTimer.Get().HandleVicariousRouterSolicitTimer(); @@ -842,6 +849,7 @@ void RoutingManager::HandleVicariousRouterSolicitTimer(void) } } } +#endif void RoutingManager::HandleRouterSolicitTimer(Timer &aTimer) { @@ -952,11 +960,13 @@ void RoutingManager::HandleRouterSolicit(const Ip6::Address &aSrcAddress, otLogInfoBr("Received Router Solicitation from %s on interface %u", aSrcAddress.ToString().AsCString(), mInfraIfIndex); +#if OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE if (!mVicariousRouterSolicitTimer.IsRunning()) { mTimeVicariousRouterSolicitStart = TimerMilli::GetNow(); mVicariousRouterSolicitTimer.Start(Time::SecToMsec(kVicariousSolicitationTime)); } +#endif // Schedule Router Advertisements with random delay. randomDelay = Random::NonCrypto::GetUint32InRange(0, kMaxRaDelayTime); diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index ab383b6da..4e4354e50 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -292,8 +292,10 @@ private: static void HandleRouterAdvertisementTimer(Timer &aTimer); void HandleRouterAdvertisementTimer(void); +#if OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE static void HandleVicariousRouterSolicitTimer(Timer &aTimer); void HandleVicariousRouterSolicitTimer(void); +#endif static void HandleRouterSolicitTimer(Timer &aTimer); void HandleRouterSolicitTimer(void); static void HandleDiscoveredPrefixInvalidTimer(Timer &aTimer); @@ -375,8 +377,10 @@ private: TimerMilli mRouterAdvertisementTimer; uint32_t mRouterAdvertisementCount; +#if OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE TimerMilli mVicariousRouterSolicitTimer; TimeMilli mTimeVicariousRouterSolicitStart; +#endif TimerMilli mRouterSolicitTimer; TimeMilli mTimeRouterSolicitStart; uint8_t mRouterSolicitCount; diff --git a/src/core/config/border_router.h b/src/core/config/border_router.h index da5742557..9e01b0425 100644 --- a/src/core/config/border_router.h +++ b/src/core/config/border_router.h @@ -65,6 +65,16 @@ #define OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE 0 #endif +/** + * @def OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE + * + * Define to 1 to enable Border Routing Vicarious Router Solicitation. + * + */ +#ifndef OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE +#define OPENTHREAD_CONFIG_BORDER_ROUTING_VICARIOUS_RS_ENABLE 1 +#endif + /** * @def OPENTHREAD_CONFIG_BORDER_AGENT_UDP_PORT *