diff --git a/src/core/config/ip6.h b/src/core/config/ip6.h index 2e8e982c2..f16f8a3dd 100644 --- a/src/core/config/ip6.h +++ b/src/core/config/ip6.h @@ -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 + /** * @} * diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 3a6472a3f..0c0bf5abd 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -1037,6 +1037,19 @@ Error Ip6::PassToHost(OwnedPtr &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().IsMeshLocalAddress(aMessageInfo.GetPeerAddr())))) + { + messagePtr->Write(Header::kHopLimitFieldOffset, 1); + } +#endif + // Pass message to callback transferring its ownership. mReceiveIp6DatagramCallback.Invoke(messagePtr.Release());