From 0adedb2da5372de54a9ff2fa7053aff7ba8e13cd Mon Sep 17 00:00:00 2001 From: Przemyslaw Bida Date: Wed, 20 Oct 2021 09:01:52 +0200 Subject: [PATCH] [posix] add support for ipv6 group join in multicastrouter (#7116) This commit adds support for joining and leaving multicast group in order to send proper Multicast Listener Reports from thread network to backbone link. --- src/posix/platform/multicast_routing.cpp | 23 +++++++++++++++++++++++ src/posix/platform/multicast_routing.hpp | 1 + 2 files changed, 24 insertions(+) diff --git a/src/posix/platform/multicast_routing.cpp b/src/posix/platform/multicast_routing.cpp index a5ef307c7..8759e3c2e 100644 --- a/src/posix/platform/multicast_routing.cpp +++ b/src/posix/platform/multicast_routing.cpp @@ -114,6 +114,8 @@ void MulticastRoutingManager::Add(const Ip6::Address &aAddress) VerifyOrExit(IsEnabled()); UnblockInboundMulticastForwardingCache(aAddress); + UpdateMldReport(aAddress, true); + otLogResultPlat(OT_ERROR_NONE, "MulticastRoutingManager: %s: %s", __FUNCTION__, aAddress.ToString().AsCString()); exit: @@ -127,12 +129,30 @@ void MulticastRoutingManager::Remove(const Ip6::Address &aAddress) VerifyOrExit(IsEnabled()); RemoveInboundMulticastForwardingCache(aAddress); + UpdateMldReport(aAddress, false); + otLogResultPlat(error, "MulticastRoutingManager: %s: %s", __FUNCTION__, aAddress.ToString().AsCString()); exit: return; } +void MulticastRoutingManager::UpdateMldReport(const Ip6::Address &aAddress, bool isAdd) +{ + struct ipv6_mreq ipv6mr; + otError error = OT_ERROR_NONE; + + ipv6mr.ipv6mr_interface = if_nametoindex(gBackboneNetifName); + memcpy(&ipv6mr.ipv6mr_multiaddr, aAddress.GetBytes(), sizeof(ipv6mr.ipv6mr_multiaddr)); + error = (setsockopt(mMulticastRouterSock, IPPROTO_IPV6, (isAdd ? IPV6_JOIN_GROUP : IPV6_LEAVE_GROUP), + (void *)&ipv6mr, sizeof(ipv6mr)) + ? OT_ERROR_FAILED + : OT_ERROR_NONE); + + otLogResultPlat(error, "MulticastRoutingManager: %s: address %s %s", __FUNCTION__, aAddress.ToString().AsCString(), + (isAdd ? "Added" : "Removed")); +} + bool MulticastRoutingManager::HasMulticastListener(const Ip6::Address &aAddress) const { bool found = false; @@ -350,6 +370,7 @@ void MulticastRoutingManager::RemoveInboundMulticastForwardingCache(const Ip6::A { if (mfc.IsValid() && mfc.mIif == kMifIndexBackbone && mfc.mGroupAddr == aGroupAddr) { + UpdateMldReport(mfc.mGroupAddr, false); RemoveMulticastForwardingCache(mfc); } } @@ -374,6 +395,7 @@ void MulticastRoutingManager::ExpireMulticastForwardingCache(void) { if (!UpdateMulticastRouteInfo(mfc)) { + UpdateMldReport(mfc.mGroupAddr, false); // The multicast route is expired RemoveMulticastForwardingCache(mfc); } @@ -539,6 +561,7 @@ void MulticastRoutingManager::SaveMulticastForwardingCache(const Ip6::Address & } else { + UpdateMldReport(oldest->mGroupAddr, false); RemoveMulticastForwardingCache(*oldest); oldest->Set(aSrcAddr, aGroupAddr, aIif, aOif); } diff --git a/src/posix/platform/multicast_routing.hpp b/src/posix/platform/multicast_routing.hpp index ec48d4c2b..72177d805 100644 --- a/src/posix/platform/multicast_routing.hpp +++ b/src/posix/platform/multicast_routing.hpp @@ -108,6 +108,7 @@ private: void Disable(void); void Add(const Ip6::Address &aAddress); void Remove(const Ip6::Address &aAddress); + void UpdateMldReport(const Ip6::Address &aAddress, bool isAdd); bool HasMulticastListener(const Ip6::Address &aAddress) const; bool IsEnabled(void) const { return mMulticastRouterSock >= 0; } void InitMulticastRouterSock(void);