From e7535f7183db4a80ced0f4eb39e0c09bc89c6b7d Mon Sep 17 00:00:00 2001 From: gytxxsy Date: Thu, 23 May 2024 22:41:35 +0800 Subject: [PATCH] [mle] update router table after adding a new neighbor (#10288) Use the `Route64 TLV` to update the router table after adding a new neighbor in `HandleLinkAccept`. With this change, when a router re-joins the network, it will restore its nexthop table while processing the `link accept`, rather than having to wait for an `mle advertisement`. --- src/core/thread/mle_router.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 8578d1de1..c1036fc9e 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -886,6 +886,7 @@ Error MleRouter::HandleLinkAccept(RxInfo &aRxInfo, bool aRequest) RouteTlv routeTlv; LeaderData leaderData; uint8_t linkMargin; + bool shouldUpdateRoutes = false; SuccessOrExit(error = Tlv::Find(aRxInfo.mMessage, sourceAddress)); @@ -972,6 +973,7 @@ Error MleRouter::HandleLinkAccept(RxInfo &aRxInfo, bool aRequest) mLinkRequestAttempts = 0; mRetrieveNewNetworkData = true; IgnoreError(SendDataRequest(aRxInfo.mMessageInfo.GetPeerAddr())); + shouldUpdateRoutes = true; #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE Get().HandleTimeSyncMessage(aRxInfo.mMessage); @@ -1007,8 +1009,7 @@ Error MleRouter::HandleLinkAccept(RxInfo &aRxInfo, bool aRequest) router = mRouterTable.FindRouterById(routerId); OT_ASSERT(router != nullptr); } - - mRouterTable.UpdateRoutes(routeTlv, routerId); + shouldUpdateRoutes = true; break; case kErrorNotFound: @@ -1043,6 +1044,11 @@ Error MleRouter::HandleLinkAccept(RxInfo &aRxInfo, bool aRequest) mNeighborTable.Signal(NeighborTable::kRouterAdded, *router); + if (shouldUpdateRoutes) + { + mRouterTable.UpdateRoutes(routeTlv, routerId); + } + aRxInfo.mClass = RxInfo::kAuthoritativeMessage; ProcessKeySequence(aRxInfo);