mirror of
https://github.com/espressif/openthread.git
synced 2026-08-23 02:39:52 +00:00
[mle] use newly added Netif::IterateExternalMulticastAddresses (#5286)
This commit updates `Mle` class to use the newly added `Netif` iterator for external multicast addresses. It also adds a helper method in `Netif` to indicate if it is subscribed to any external multicast address.
This commit is contained in:
+23
-5
@@ -219,12 +219,21 @@ public:
|
||||
* @param[in] aNetif A reference to the Netif instance.
|
||||
*
|
||||
*/
|
||||
explicit ExternalMulticastAddressIterator(Netif &aNetif)
|
||||
explicit ExternalMulticastAddressIterator(const Netif &aNetif)
|
||||
: mNetif(aNetif)
|
||||
{
|
||||
AdvanceFrom(mNetif.GetMulticastAddresses());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method indicates whether the iterator has reached end of the list.
|
||||
*
|
||||
* @retval TRUE There are no more entries in the list (reached end of the list).
|
||||
* @retval FALSE The current address entry is valid.
|
||||
*
|
||||
*/
|
||||
bool IsDone(void) const { return mCurrent != nullptr; }
|
||||
|
||||
/**
|
||||
* This method overloads `++` operator (pre-increment) to advance the iterator.
|
||||
*
|
||||
@@ -298,7 +307,7 @@ public:
|
||||
kEndIterator,
|
||||
};
|
||||
|
||||
ExternalMulticastAddressIterator(Netif &aNetif, IteratorType)
|
||||
ExternalMulticastAddressIterator(const Netif &aNetif, IteratorType)
|
||||
: mNetif(aNetif)
|
||||
, mCurrent(nullptr)
|
||||
{
|
||||
@@ -315,7 +324,7 @@ public:
|
||||
const_cast<ExternalNetifMulticastAddress *>(static_cast<const ExternalNetifMulticastAddress *>(aAddr));
|
||||
}
|
||||
|
||||
Netif & mNetif;
|
||||
const Netif & mNetif;
|
||||
ExternalNetifMulticastAddress *mCurrent;
|
||||
};
|
||||
|
||||
@@ -569,6 +578,15 @@ public:
|
||||
return ExternalMulticastAddressIteratorBuilder(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the network interfaces is subscribed to any external multicast address.
|
||||
*
|
||||
* @retval TRUE The network interface is subscribed to at least one external multicast address.
|
||||
* @retval FALSE The network interface is not subscribed to any external multicast address.
|
||||
*
|
||||
*/
|
||||
bool HasAnyExternalMulticastAddress(void) const { return !ExternalMulticastAddressIterator(*this).IsDone(); }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* This method subscribes the network interface to the realm-local all MPL forwarders, link-local, and realm-local
|
||||
@@ -595,7 +613,7 @@ private:
|
||||
class ExternalMulticastAddressIteratorBuilder
|
||||
{
|
||||
public:
|
||||
ExternalMulticastAddressIteratorBuilder(Netif &aNetif)
|
||||
ExternalMulticastAddressIteratorBuilder(const Netif &aNetif)
|
||||
: mNetif(aNetif)
|
||||
{
|
||||
}
|
||||
@@ -607,7 +625,7 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
Netif &mNetif;
|
||||
const Netif &mNetif;
|
||||
};
|
||||
|
||||
LinkedList<NetifUnicastAddress> mUnicastAddresses;
|
||||
|
||||
+4
-17
@@ -1235,14 +1235,7 @@ bool Mle::HasUnregisteredAddress(void)
|
||||
// For sleepy end-device, we register any external multicast
|
||||
// addresses.
|
||||
|
||||
for (const Ip6::NetifMulticastAddress *address = Get<ThreadNetif>().GetMulticastAddresses(); address != nullptr;
|
||||
address = address->GetNext())
|
||||
{
|
||||
if (Get<ThreadNetif>().IsMulticastAddressExternal(*address))
|
||||
{
|
||||
ExitNow(retval = true);
|
||||
}
|
||||
}
|
||||
retval = Get<ThreadNetif>().HasAnyExternalMulticastAddress();
|
||||
}
|
||||
|
||||
exit:
|
||||
@@ -1341,25 +1334,19 @@ otError Mle::AppendAddressRegistration(Message &aMessage, AddressRegistrationMod
|
||||
#endif
|
||||
)
|
||||
{
|
||||
for (const Ip6::NetifMulticastAddress *addr = Get<ThreadNetif>().GetMulticastAddresses(); addr != nullptr;
|
||||
addr = addr->GetNext())
|
||||
for (const Ip6::NetifMulticastAddress &addr : Get<ThreadNetif>().IterateExternalMulticastAddresses())
|
||||
{
|
||||
if (!Get<ThreadNetif>().IsMulticastAddressExternal(*addr))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
#if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
|
||||
// For Thread 1.2 MED, skip multicast address with scope not
|
||||
// larger than realm local when registering.
|
||||
if (IsRxOnWhenIdle() && !addr->GetAddress().IsMulticastLargerThanRealmLocal())
|
||||
if (IsRxOnWhenIdle() && !addr.GetAddress().IsMulticastLargerThanRealmLocal())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
entry.SetUncompressed();
|
||||
entry.SetIp6Address(addr->GetAddress());
|
||||
entry.SetIp6Address(addr.GetAddress());
|
||||
SuccessOrExit(error = aMessage.Append(&entry, entry.GetLength()));
|
||||
length += entry.GetLength();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user