mirror of
https://github.com/espressif/openthread.git
synced 2026-08-14 14:47:46 +00:00
[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.
This commit is contained in:
@@ -1369,8 +1369,7 @@ bool Ip6::ShouldForwardToThread(const MessageInfo &aMessageInfo, MessageOrigin a
|
||||
shouldForward = true;
|
||||
#endif
|
||||
}
|
||||
else if (Get<ThreadNetif>().RouteLookup(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr(), nullptr) ==
|
||||
kErrorNone)
|
||||
else if (Get<ThreadNetif>().RouteLookup(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr()) == kErrorNone)
|
||||
{
|
||||
shouldForward = true;
|
||||
}
|
||||
|
||||
@@ -617,8 +617,8 @@ Error MeshForwarder::UpdateIp6RouteFtd(Ip6::Header &ip6Header, Message &aMessage
|
||||
}
|
||||
else
|
||||
{
|
||||
IgnoreError(Get<NetworkData::Leader>().RouteLookup(ip6Header.GetSource(), ip6Header.GetDestination(), nullptr,
|
||||
&mMeshDest));
|
||||
IgnoreError(
|
||||
Get<NetworkData::Leader>().RouteLookup(ip6Header.GetSource(), ip6Header.GetDestination(), mMeshDest));
|
||||
}
|
||||
|
||||
VerifyOrExit(mMeshDest != Mac::kShortAddrInvalid, error = kErrorDrop);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -123,12 +123,12 @@ Error ThreadNetif::SendMessage(Message &aMessage)
|
||||
return Get<MeshForwarder>().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<NetworkData::Leader>().RouteLookup(aSource, aDestination, aPrefixMatch, &rloc));
|
||||
SuccessOrExit(error = Get<NetworkData::Leader>().RouteLookup(aSource, aDestination, rloc));
|
||||
|
||||
if (rloc == Get<Mle::MleRouter>().GetRloc16())
|
||||
{
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user