[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.
This commit is contained in:
Przemyslaw Bida
2021-10-28 23:35:47 -07:00
committed by Jonathan Hui
parent f5e995135e
commit 0adedb2da5
2 changed files with 24 additions and 0 deletions
+23
View File
@@ -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);
}
+1
View File
@@ -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);