[ip6] simplify Ip6::HandleDatagram() (#8787)

This commit updates `HandleDatagram()` simplifying the code related to
determining `forwardThread` and `forwardHost` based on the
destination address.
This commit is contained in:
Abtin Keshavarzian
2023-02-22 14:15:45 -08:00
committed by GitHub
parent 852d076f00
commit 9e1e8f546d
2 changed files with 27 additions and 48 deletions
+27 -47
View File
@@ -1140,24 +1140,22 @@ start:
messageInfo.SetEcn(header.GetEcn());
messageInfo.SetLinkInfo(aLinkMessageInfo);
// Determine `forwardThread`, `forwardHost` and `receive`
// based on the destination address.
if (header.GetDestination().IsMulticast())
{
// Destination is multicast
if (aOrigin == kFromThreadNetif)
{
forwardThread = (aOrigin != kFromThreadNetif);
#if OPENTHREAD_FTD
if (header.GetDestination().IsMulticastLargerThanRealmLocal() &&
Get<ChildTable>().HasSleepyChildWithAddress(header.GetDestination()))
{
forwardThread = true;
}
#endif
}
else
if ((aOrigin == kFromThreadNetif) && header.GetDestination().IsMulticastLargerThanRealmLocal() &&
Get<ChildTable>().HasSleepyChildWithAddress(header.GetDestination()))
{
forwardThread = true;
}
#endif
forwardHost = header.GetDestination().IsMulticastLargerThanRealmLocal();
@@ -1179,19 +1177,27 @@ start:
{
receive = true;
}
else if (!header.GetDestination().IsLinkLocal())
else if ((aOrigin != kFromThreadNetif) || !header.GetDestination().IsLinkLocal())
{
forwardThread = true;
}
else if (aOrigin != kFromThreadNetif)
{
forwardThread = true;
}
if (header.GetDestination().IsLinkLocal())
{
forwardThread = true;
}
else if (IsOnLink(header.GetDestination()))
{
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
forwardThread = ((aOrigin == kFromHostDisallowLoopBack) ||
!Get<BackboneRouter::Manager>().ShouldForwardDuaToBackbone(header.GetDestination()));
#else
forwardThread = true;
#endif
}
else if (Get<ThreadNetif>().RouteLookup(header.GetSource(), header.GetDestination()) == kErrorNone)
{
forwardThread = true;
}
if (forwardThread && !ShouldForwardToThread(messageInfo, aOrigin))
{
forwardThread = false;
forwardHost = true;
forwardHost = !forwardThread;
}
}
@@ -1318,32 +1324,6 @@ exit:
return error;
}
bool Ip6::ShouldForwardToThread(const MessageInfo &aMessageInfo, MessageOrigin aOrigin) const
{
bool shouldForward = false;
if (aMessageInfo.GetSockAddr().IsMulticast() || aMessageInfo.GetSockAddr().IsLinkLocal())
{
shouldForward = true;
}
else if (IsOnLink(aMessageInfo.GetSockAddr()))
{
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE
shouldForward = ((aOrigin == kFromHostDisallowLoopBack) ||
!Get<BackboneRouter::Manager>().ShouldForwardDuaToBackbone(aMessageInfo.GetSockAddr()));
#else
OT_UNUSED_VARIABLE(aOrigin);
shouldForward = true;
#endif
}
else if (Get<ThreadNetif>().RouteLookup(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr()) == kErrorNone)
{
shouldForward = true;
}
return shouldForward;
}
Error Ip6::SelectSourceAddress(MessageInfo &aMessageInfo) const
{
Error error = kErrorNone;
-1
View File
@@ -408,7 +408,6 @@ private:
MessageInfo &aMessageInfo,
uint8_t aIpProto,
Message::Ownership aMessageOwnership);
bool ShouldForwardToThread(const MessageInfo &aMessageInfo, MessageOrigin aOrigin) const;
bool IsOnLink(const Address &aAddress) const;
#if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE
void UpdateBorderRoutingCounters(const Header &aHeader, uint16_t aMessageLength, bool aIsInbound);