From 32a538f773c94cc44ab03338bb6da14e6713af5c Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 21 Mar 2023 17:54:08 -0700 Subject: [PATCH] [netif] simplify `ThreadNetif` (#8882) This commit simplifies `ThreadNetif` class by removing methods like `IsOnMesh()` and `SendMessage()` which just call same method on other modules (`NetworkData::Leader` and `MeshForwarder`). It also moves the `RouteLookup()` method to `Ip6` class. --- src/core/net/ip6.cpp | 34 ++++++++++++++++++++------- src/core/net/ip6.hpp | 1 + src/core/thread/child_supervision.cpp | 2 +- src/core/thread/thread_netif.cpp | 20 ---------------- src/core/thread/thread_netif.hpp | 33 -------------------------- 5 files changed, 27 insertions(+), 63 deletions(-) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index b6d793cdc..e94f2b876 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1192,7 +1192,7 @@ start: forwardThread = true; #endif } - else if (Get().RouteLookup(header.GetSource(), header.GetDestination()) == kErrorNone) + else if (RouteLookup(header.GetSource(), header.GetDestination()) == kErrorNone) { forwardThread = true; } @@ -1310,7 +1310,7 @@ start: #endif // `SendMessage()` takes custody of message in the success case - SuccessOrExit(error = Get().SendMessage(aMessage)); + SuccessOrExit(error = Get().SendMessage(aMessage)); shouldFreeMessage = false; } @@ -1442,23 +1442,39 @@ exit: bool Ip6::IsOnLink(const Address &aAddress) const { - bool rval = false; + bool isOnLink = false; - if (Get().IsOnMesh(aAddress)) + if (Get().IsOnMesh(aAddress)) { - ExitNow(rval = true); + ExitNow(isOnLink = true); } - for (const Netif::UnicastAddress &cur : Get().GetUnicastAddresses()) + for (const Netif::UnicastAddress &unicastAddr : Get().GetUnicastAddresses()) { - if (cur.GetAddress().PrefixMatch(aAddress) >= cur.mPrefixLength) + if (unicastAddr.GetAddress().PrefixMatch(aAddress) >= unicastAddr.mPrefixLength) { - ExitNow(rval = true); + ExitNow(isOnLink = true); } } exit: - return rval; + return isOnLink; +} + +Error Ip6::RouteLookup(const Address &aSource, const Address &aDestination) const +{ + Error error; + uint16_t rloc; + + SuccessOrExit(error = Get().RouteLookup(aSource, aDestination, rloc)); + + if (rloc == Get().GetRloc16()) + { + error = kErrorNoRoute; + } + +exit: + return error; } #if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index bfb387ce7..3c3092495 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -409,6 +409,7 @@ private: uint8_t aIpProto, Message::Ownership aMessageOwnership); bool IsOnLink(const Address &aAddress) const; + Error RouteLookup(const Address &aSource, const Address &aDestination) const; #if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE void UpdateBorderRoutingCounters(const Header &aHeader, uint16_t aMessageLength, bool aIsInbound); #endif diff --git a/src/core/thread/child_supervision.cpp b/src/core/thread/child_supervision.cpp index 51237a6aa..02ba64ada 100644 --- a/src/core/thread/child_supervision.cpp +++ b/src/core/thread/child_supervision.cpp @@ -83,7 +83,7 @@ void ChildSupervisor::SendMessage(Child &aChild) childIndex = Get().GetChildIndex(aChild); SuccessOrExit(message->Append(childIndex)); - SuccessOrExit(Get().SendMessage(*message)); + SuccessOrExit(Get().SendMessage(*message)); message = nullptr; LogInfo("Sending supervision message to child 0x%04x", aChild.GetRloc16()); diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index 469dd0466..e01d19218 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -118,24 +118,4 @@ exit: return; } -Error ThreadNetif::SendMessage(Message &aMessage) { return Get().SendMessage(aMessage); } - -Error ThreadNetif::RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination) -{ - Error error; - uint16_t rloc; - - SuccessOrExit(error = Get().RouteLookup(aSource, aDestination, rloc)); - - if (rloc == Get().GetRloc16()) - { - error = kErrorNoRoute; - } - -exit: - return error; -} - -bool ThreadNetif::IsOnMesh(const Ip6::Address &aAddress) const { return Get().IsOnMesh(aAddress); } - } // namespace ot diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index 58391e3a9..af776bee2 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -82,39 +82,6 @@ public: */ bool IsUp(void) const { return mIsUp; } - /** - * This method submits a message to the network interface. - * - * @param[in] aMessage A reference to the message. - * - * @retval kErrorNone Successfully submitted the message to the interface. - * - */ - Error SendMessage(Message &aMessage); - - /** - * This method performs a route lookup. - * - * @param[in] aSource A reference to the IPv6 source address. - * @param[in] aDestination A reference to the IPv6 destination address. - * - * @retval kErrorNone Successfully found a route. - * @retval kErrorNoRoute Could not find a valid route. - * - */ - Error RouteLookup(const Ip6::Address &aSource, const Ip6::Address &aDestination); - - /** - * This method indicates whether @p aAddress matches an on-mesh prefix. - * - * @param[in] aAddress The IPv6 address. - * - * @retval TRUE If @p aAddress matches an on-mesh prefix. - * @retval FALSE If @p aAddress does not match an on-mesh prefix. - * - */ - bool IsOnMesh(const Ip6::Address &aAddress) const; - private: bool mIsUp; };