Skip to content

Commit 5178d25

Browse files
committed
[mle] derive address registration limit for children from runtime pool
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 compile-time limit, discarding any addresses beyond that limit even when the runtime pools are larger.
1 parent 5c90231 commit 5178d25

4 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/core/config/ip6.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
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()` plus internal
64+
+ * addresses (ML-EID, and optionally DUA and SLAAC).
6265
*/
6366
#ifndef OPENTHREAD_CONFIG_IP6_INIT_EXT_ADDR_POOL_ENABLE
6467
#define OPENTHREAD_CONFIG_IP6_INIT_EXT_ADDR_POOL_ENABLE 0

src/core/config/mle.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
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()`
92+
* plus internal address slots (ML-EID, and optionally DUA and SLAAC).
8993
*/
9094
#ifndef OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER
9195
#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: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,6 +3640,23 @@ 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 total registration
3645+
// budget from the pool sizes plus compile-time internal address slots (ML-EID, DUA,
3646+
// SLAAC), since `OPENTHREAD_CONFIG_MLE_IP_ADDRS_TO_REGISTER` is not meaningful here.
3647+
const uint8_t maxAddrs = ClampToUint8(Get<ThreadNetif>().GetExtUnicastAddressPoolCapacity() +
3648+
Get<ThreadNetif>().GetExtMulticastAddressPoolCapacity() +
3649+
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
3650+
OPENTHREAD_CONFIG_IP6_SLAAC_NUM_ADDRESSES +
3651+
#endif
3652+
#if OPENTHREAD_CONFIG_DUA_ENABLE
3653+
1 + // Domain Unicast Address
3654+
#endif
3655+
1); // ML-EID
3656+
#else
3657+
const uint8_t maxAddrs = kMaxIpAddressesToRegister;
3658+
#endif
3659+
36433660
SuccessOrExit(error = Tlv::StartTlv(*this, Tlv::kAddressRegistration, tlvBookmark));
36443661

36453662
// Prioritize ML-EID
@@ -3680,7 +3697,7 @@ Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode
36803697
SuccessOrExit(error = AppendAddressRegistrationEntry(addr.GetAddress()));
36813698
counter++;
36823699
// only continue to append if there is available entry.
3683-
VerifyOrExit(counter < kMaxIpAddressesToRegister);
3700+
VerifyOrExit(counter < maxAddrs);
36843701
}
36853702

36863703
// Append external multicast addresses. For sleepy end device,
@@ -3710,7 +3727,7 @@ Error Mle::TxMessage::AppendAddressRegistrationTlv(AddressRegistrationMode aMode
37103727
SuccessOrExit(error = AppendAddressRegistrationEntry(addr.GetAddress()));
37113728
counter++;
37123729
// only continue to append if there is available entry.
3713-
VerifyOrExit(counter < kMaxIpAddressesToRegister);
3730+
VerifyOrExit(counter < maxAddrs);
37143731
}
37153732
}
37163733

0 commit comments

Comments
 (0)