[mle-router] simplify 'GetNeighbor(const Ip6::Address &)' (#5326)

This commit simplifies `MleRouter:GetNeighbor(const Ip6::Address &)`
handling of mesh-local router locator IPv6 addresses.
This commit is contained in:
Abtin Keshavarzian
2020-08-03 09:06:18 -07:00
committed by GitHub
parent 471129460e
commit be288331ac
+9 -17
View File
@@ -3512,8 +3512,7 @@ Neighbor *MleRouter::GetNeighbor(const Mac::Address &aAddress)
Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress)
{
Lowpan::Context context;
Neighbor * rval = nullptr;
Neighbor *rval = nullptr;
if (aAddress.IsLinkLocal())
{
@@ -3523,32 +3522,25 @@ Neighbor *MleRouter::GetNeighbor(const Ip6::Address &aAddress)
ExitNow(rval = GetNeighbor(macAddr));
}
if (Get<NetworkData::Leader>().GetContext(aAddress, context) != OT_ERROR_NONE)
if (IsRoutingLocator(aAddress))
{
context.mContextId = 0xff;
uint16_t rloc16 = aAddress.GetIid().GetLocator();
rval = mChildTable.FindChild(rloc16, Child::kInStateValidOrRestoring);
VerifyOrExit(rval == nullptr, OT_NOOP);
rval = mRouterTable.GetNeighbor(rloc16);
ExitNow();
}
for (Child &child : Get<ChildTable>().Iterate(Child::kInStateValidOrRestoring))
{
if ((context.mContextId == kMeshLocalPrefixContextId) && aAddress.GetIid().IsLocator() &&
(aAddress.GetIid().GetLocator() == child.GetRloc16()))
{
ExitNow(rval = &child);
}
if (child.HasIp6Address(aAddress))
{
ExitNow(rval = &child);
}
}
VerifyOrExit(context.mContextId == kMeshLocalPrefixContextId, rval = nullptr);
if (aAddress.GetIid().IsLocator())
{
rval = mRouterTable.GetNeighbor(aAddress.GetIid().GetLocator());
}
exit:
return rval;
}