[ip6] add multicast forwarding restrictions to host (#9863)

On Android, the platform doesn't restrict link-local/mesh-local source
addresses when forwarding multicast packets. For multicast packets sent
from link-local/mesh-local address to scope larger than realm-local,
set the hoplimit to 1 so the packet can be delivered to host, and will
not be forwarded to infrastructure link.

The feature is guarded by OPENTHREAD_CONFIG_IP6_RESTRICT_FORWARDING_LARGER_SCOPE_MCAST_WITH_LOCAL_SRC,
set as 1 to enable.
This commit is contained in:
Yang Sun
2024-02-21 10:44:33 -08:00
committed by GitHub
parent 00f22b52c9
commit 3aa3cbc341
2 changed files with 23 additions and 0 deletions
+10
View File
@@ -227,6 +227,16 @@
#define OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
#endif
/**
* @def OPENTHREAD_CONFIG_IP6_RESTRICT_FORWARDING_LARGER_SCOPE_MCAST_WITH_LOCAL_SRC
*
* Define as 1 to restrict multicast forwarding to larger scope from local sources.
*
*/
#ifndef OPENTHREAD_CONFIG_IP6_RESTRICT_FORWARDING_LARGER_SCOPE_MCAST_WITH_LOCAL_SRC
#define OPENTHREAD_CONFIG_IP6_RESTRICT_FORWARDING_LARGER_SCOPE_MCAST_WITH_LOCAL_SRC 0
#endif
/**
* @}
*
+13
View File
@@ -1037,6 +1037,19 @@ Error Ip6::PassToHost(OwnedPtr<Message> &aMessagePtr,
}
#endif
#if OPENTHREAD_CONFIG_IP6_RESTRICT_FORWARDING_LARGER_SCOPE_MCAST_WITH_LOCAL_SRC
// Some platforms (e.g. Android) currently doesn't restrict link-local/mesh-local source
// addresses when forwarding multicast packets.
// For a multicast packet sent from link-local/mesh-local address to scope larger
// than realm-local, set the hop limit to 1 before sending to host, so this packet
// will not be forwarded by host.
if (aMessageInfo.GetSockAddr().IsMulticastLargerThanRealmLocal() &&
(aMessageInfo.GetPeerAddr().IsLinkLocal() || (Get<Mle::Mle>().IsMeshLocalAddress(aMessageInfo.GetPeerAddr()))))
{
messagePtr->Write<uint8_t>(Header::kHopLimitFieldOffset, 1);
}
#endif
// Pass message to callback transferring its ownership.
mReceiveIp6DatagramCallback.Invoke(messagePtr.Release());