From fd23fb1add4e909b1d32f0df3ffe0e8c124a197a Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 8 Nov 2022 02:49:31 -0800 Subject: [PATCH] [netdata] simplify `RouteLookup()` methods (#8374) This commit updates the `RouteLookup()` methods in `NetworkData` and `ThreadNetif`: - Removes the unused `aPrefixMatchLength` parameter. - Requires `aRloc` to be a reference instead of a pointer. --- src/core/net/ip6.cpp | 3 +- src/core/thread/mesh_forwarder_ftd.cpp | 4 +-- src/core/thread/network_data_leader.cpp | 40 +++++-------------------- src/core/thread/network_data_leader.hpp | 17 ++++------- src/core/thread/thread_netif.cpp | 4 +-- src/core/thread/thread_netif.hpp | 3 +- 6 files changed, 19 insertions(+), 52 deletions(-) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 74da1e8d6..3071236a9 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1369,8 +1369,7 @@ bool Ip6::ShouldForwardToThread(const MessageInfo &aMessageInfo, MessageOrigin a shouldForward = true; #endif } - else if (Get().RouteLookup(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr(), nullptr) == - kErrorNone) + else if (Get().RouteLookup(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr()) == kErrorNone) { shouldForward = true; } diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 1c86ada73..1b501e0fc 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -617,8 +617,8 @@ Error MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header, Message &aMessage } else { - IgnoreError(Get().RouteLookup(ip6Header.GetSource(), ip6Header.GetDestination(), nullptr, - &mMeshDest)); + IgnoreError( + Get().RouteLookup(ip6Header.GetSource(), ip6Header.GetDestination(), mMeshDest)); } VerifyOrExit(mMeshDest != Mac::kShortAddrInvalid, error = kErrorDrop); diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index 4c1dee72b..5e659b5b8 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -236,28 +236,20 @@ exit: return rval; } -Error LeaderBase::RouteLookup(const Ip6::Address &aSource, - const Ip6::Address &aDestination, - uint8_t * aPrefixMatchLength, - uint16_t * aRloc16) const +Error LeaderBase::RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination, uint16_t &aRloc16) const { Error error = kErrorNoRoute; const PrefixTlv *prefix = nullptr; while ((prefix = FindNextMatchingPrefix(aSource, prefix)) != nullptr) { - if (ExternalRouteLookup(prefix->GetDomainId(), aDestination, aPrefixMatchLength, aRloc16) == kErrorNone) + if (ExternalRouteLookup(prefix->GetDomainId(), aDestination, aRloc16) == kErrorNone) { ExitNow(error = kErrorNone); } if (DefaultRouteLookup(*prefix, aRloc16) == kErrorNone) { - if (aPrefixMatchLength) - { - *aPrefixMatchLength = 0; - } - ExitNow(error = kErrorNone); } } @@ -266,10 +258,7 @@ exit: return error; } -Error LeaderBase::ExternalRouteLookup(uint8_t aDomainId, - const Ip6::Address &aDestination, - uint8_t * aPrefixMatchLength, - uint16_t * aRloc16) const +Error LeaderBase::ExternalRouteLookup(uint8_t aDomainId, const Ip6::Address &aDestination, uint16_t &aRloc16) const { Error error = kErrorNoRoute; TlvIterator tlvIterator(GetTlvsStart(), GetTlvsEnd()); @@ -319,23 +308,14 @@ Error LeaderBase::ExternalRouteLookup(uint8_t aDomainId, if (bestRouteEntry != nullptr) { - if (aRloc16 != nullptr) - { - *aRloc16 = bestRouteEntry->GetRloc(); - } - - if (aPrefixMatchLength != nullptr) - { - *aPrefixMatchLength = bestMatchLength; - } - - error = kErrorNone; + aRloc16 = bestRouteEntry->GetRloc(); + error = kErrorNone; } return error; } -Error LeaderBase::DefaultRouteLookup(const PrefixTlv &aPrefix, uint16_t *aRloc16) const +Error LeaderBase::DefaultRouteLookup(const PrefixTlv &aPrefix, uint16_t &aRloc16) const { Error error = kErrorNoRoute; TlvIterator subTlvIterator(aPrefix); @@ -365,12 +345,8 @@ Error LeaderBase::DefaultRouteLookup(const PrefixTlv &aPrefix, uint16_t *aRloc16 if (route != nullptr) { - if (aRloc16 != nullptr) - { - *aRloc16 = route->GetRloc(); - } - - error = kErrorNone; + aRloc16 = route->GetRloc(); + error = kErrorNone; } return error; diff --git a/src/core/thread/network_data_leader.hpp b/src/core/thread/network_data_leader.hpp index 556112f36..ac58803b1 100644 --- a/src/core/thread/network_data_leader.hpp +++ b/src/core/thread/network_data_leader.hpp @@ -134,17 +134,13 @@ public: * * @param[in] aSource A reference to the IPv6 source address. * @param[in] aDestination A reference to the IPv6 destination address. - * @param[out] aPrefixMatchLength A pointer to output the longest prefix match length in bits. - * @param[out] aRloc16 A pointer to the RLOC16 for the selected route. + * @param[out] aRloc16 A reference to return the RLOC16 for the selected route. * - * @retval kErrorNone Successfully found a route. + * @retval kErrorNone Successfully found a route. @p aRloc16 is updated. * @retval kErrorNoRoute No valid route was found. * */ - Error RouteLookup(const Ip6::Address &aSource, - const Ip6::Address &aDestination, - uint8_t * aPrefixMatchLength, - uint16_t * aRloc16) const; + Error RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination, uint16_t &aRloc16) const; /** * This method is used by non-Leader devices to set newly received Network Data from the Leader. @@ -292,11 +288,8 @@ private: void RemoveCommissioningData(void); - Error ExternalRouteLookup(uint8_t aDomainId, - const Ip6::Address &aDestination, - uint8_t * aPrefixMatchLength, - uint16_t * aRloc16) const; - Error DefaultRouteLookup(const PrefixTlv &aPrefix, uint16_t *aRloc16) const; + Error ExternalRouteLookup(uint8_t aDomainId, const Ip6::Address &aDestination, uint16_t &aRloc16) const; + Error DefaultRouteLookup(const PrefixTlv &aPrefix, uint16_t &aRloc16) const; Error SteeringDataCheck(const FilterIndexes &aFilterIndexes) const; void GetContextForMeshLocalPrefix(Lowpan::Context &aContext) const; diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index 1ed533990..0f92b4d5f 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -123,12 +123,12 @@ Error ThreadNetif::SendMessage(Message &aMessage) return Get().SendMessage(aMessage); } -Error ThreadNetif::RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination, uint8_t *aPrefixMatch) +Error ThreadNetif::RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination) { Error error; uint16_t rloc; - SuccessOrExit(error = Get().RouteLookup(aSource, aDestination, aPrefixMatch, &rloc)); + SuccessOrExit(error = Get().RouteLookup(aSource, aDestination, rloc)); if (rloc == Get().GetRloc16()) { diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index e06e6b678..58391e3a9 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -97,13 +97,12 @@ public: * * @param[in] aSource A reference to the IPv6 source address. * @param[in] aDestination A reference to the IPv6 destination address. - * @param[out] aPrefixMatch A pointer where the number of prefix match bits for the chosen route is stored. * * @retval kErrorNone Successfully found a route. * @retval kErrorNoRoute Could not find a valid route. * */ - Error RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination, uint8_t *aPrefixMatch); + Error RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination); /** * This method indicates whether @p aAddress matches an on-mesh prefix.