Skip to content

Commit 378d658

Browse files
committed
[mle] derive address registration limit from runtime pool sizes
When `OPENTHREAD_CONFIG_IP6_INIT_EXT_ADDR_POOL_ENABLE` is set, the external unicast and multicast address pool sizes are determined at runtime by the caller of `otIp6Init()`, not at compile time. The existing compile-time constant `kMaxIpAddressesToRegister` (from `OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER`) is therefore not meaningful in this mode: a library compiled without knowledge of the pool sizes will silently cap MLE Address Registration TLVs at the default of 4, discarding any addresses beyond that limit even when the runtime pools are larger.
1 parent e336e7a commit 378d658

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/core/config/ip6.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@
5858
* new OpenThread stack configuration to be built.
5959
*
6060
* When this feature is enabled, the configs `OPENTHREAD_CONFIG_IP6_MAX_EXT_UCAST_ADDRS` and
61-
* `OPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS` are no longer applicable or used.
61+
* `OPENTHREAD_CONFIG_IP6_MAX_EXT_MCAST_ADDRS` are no longer applicable or used. Similarly,
62+
* `OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER` is not used; the MLE address registration limit
63+
* is instead derived at runtime from the pool sizes passed to `otIp6Init()`.
6264
*/
6365
#ifndef OPENTHREAD_CONFIG_IP6_INIT_EXT_ADDR_POOL_ENABLE
6466
#define OPENTHREAD_CONFIG_IP6_INIT_EXT_ADDR_POOL_ENABLE 0

src/core/config/mle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
* @def OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER
8787
*
8888
* The maximum number of IPv6 address registrations for MTD.
89+
*
90+
* If `OPENTHREAD_CONFIG_IP6_INIT_EXT_ADDR_POOL_ENABLE` is enabled, this config is not used;
91+
* the registration limit is derived at runtime from the pool sizes passed to `otIp6Init()`.
8992
*/
9093
#ifndef OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER
9194
#define OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER (OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD)

src/core/net/netif.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,20 @@ class Netif : public InstanceLocator, private NonCopyable
355355
*/
356356
bool IsInitialized(void) const { return mInitialized; }
357357

358+
/**
359+
* Returns the capacity of the external unicast address pool.
360+
*
361+
* @returns The number of external unicast address entries in the pool passed to `Init()`.
362+
*/
363+
uint16_t GetExtUnicastAddressPoolCapacity(void) const { return mExtUnicastAddressPool.GetSize(); }
364+
365+
/**
366+
* Returns the capacity of the external multicast address pool.
367+
*
368+
* @returns The number of external multicast address entries in the pool passed to `Init()`.
369+
*/
370+
uint16_t GetExtMulticastAddressPoolCapacity(void) const { return mExtMulticastAddressPool.GetSize(); }
371+
358372
#endif // OPENTHREAD_CONFIG_IP6_INIT_EXT_ADDR_POOL_ENABLE
359373

360374
/**

src/core/thread/mle.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,6 +3640,17 @@ Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode
36403640
Tlv::Bookmark tlvBookmark;
36413641
uint8_t counter = 0;
36423642

3643+
#if OPENTHREAD_CONFIG_IP6_INIT_EXT_ADDR_POOL_ENABLE
3644+
// When using runtime-configured external address pools, derive the registration
3645+
// limit from the actual pool sizes rather than the compile-time config constant,
3646+
// since `OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER` is not meaningful when pool
3647+
// sizes are not known at compile time.
3648+
const uint8_t maxAddrs = ClampToUint8(Get<ThreadNetif>().GetExtUnicastAddressPoolCapacity() +
3649+
Get<ThreadNetif>().GetExtMulticastAddressPoolCapacity());
3650+
#else
3651+
const uint8_t maxAddrs = kMaxIpAddressesToRegister;
3652+
#endif
3653+
36433654
SuccessOrExit(error = Tlv::StartTlv(*this, Tlv::kAddressRegistration, tlvBookmark));
36443655

36453656
// Prioritize ML-EID
@@ -3680,7 +3691,7 @@ Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode
36803691
SuccessOrExit(error = AppendAddressRegistrationEntry(addr.GetAddress()));
36813692
counter++;
36823693
// only continue to append if there is available entry.
3683-
VerifyOrExit(counter < kMaxIpAddressesToRegister);
3694+
VerifyOrExit(counter < maxAddrs);
36843695
}
36853696

36863697
// Append external multicast addresses. For sleepy end device,
@@ -3710,7 +3721,7 @@ Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode
37103721
SuccessOrExit(error = AppendAddressRegistrationEntry(addr.GetAddress()));
37113722
counter++;
37123723
// only continue to append if there is available entry.
3713-
VerifyOrExit(counter < kMaxIpAddressesToRegister);
3724+
VerifyOrExit(counter < maxAddrs);
37143725
}
37153726
}
37163727

0 commit comments

Comments
 (0)