From 0f55e7926313bce4cd5791a411010f705df683d2 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 9 Nov 2023 15:31:41 -0800 Subject: [PATCH] [routing-manager] use `Heap::Array` for `OnMeshPrefixArray` (#9592) This commit updates `RoutingManager` to use heap allocated array for `OnMeshPrefixArray` under `BORDER_ROUTING_USE_HEAP_ENABLE` config. This commit also updates the `toranj-config-posix` header to explicitly disable `BORDER_ROUTING_USE_HEAP_ENABLE` under the POSIX config to validate builds with this config disabled. This aligns with the main purpose of the `toranj` posix build config, which is to validate builds under different configs (run from the `toranj-unittest` job in the `toranj.yml` GitHub action workflow). --- src/core/border_router/routing_manager.cpp | 4 ++++ src/core/border_router/routing_manager.hpp | 8 +++++++- tests/toranj/openthread-core-toranj-config-posix.h | 3 +++ tests/toranj/openthread-core-toranj-config-simulation.h | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 2b073b4b987..2af95e2bc36 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -362,7 +362,11 @@ void RoutingManager::Stop(void) SendRouterAdvertisement(kInvalidateAllPrevPrefixes); +#if OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE + mAdvertisedPrefixes.Free(); +#else mAdvertisedPrefixes.Clear(); +#endif mDiscoveredPrefixTable.RemoveAllEntries(); mDiscoveredPrefixStaleTimer.Stop(); diff --git a/src/core/border_router/routing_manager.hpp b/src/core/border_router/routing_manager.hpp index c78862931ba..55da201915b 100644 --- a/src/core/border_router/routing_manager.hpp +++ b/src/core/border_router/routing_manager.hpp @@ -54,6 +54,7 @@ #include "common/array.hpp" #include "common/error.hpp" #include "common/heap_allocatable.hpp" +#include "common/heap_array.hpp" #include "common/linked_list.hpp" #include "common/locator.hpp" #include "common/message.hpp" @@ -954,7 +955,12 @@ class RoutingManager : public InstanceLocator typedef Ip6::Prefix OnMeshPrefix; - class OnMeshPrefixArray : public Array + class OnMeshPrefixArray : +#if OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE + public Heap::Array +#else + public Array +#endif { public: void Add(const OnMeshPrefix &aPrefix); diff --git a/tests/toranj/openthread-core-toranj-config-posix.h b/tests/toranj/openthread-core-toranj-config-posix.h index 95cf37ac372..60e86777fcc 100644 --- a/tests/toranj/openthread-core-toranj-config-posix.h +++ b/tests/toranj/openthread-core-toranj-config-posix.h @@ -47,4 +47,7 @@ #define OPENTHREAD_POSIX_CONFIG_SPINEL_HDLC_INTERFACE_ENABLE 1 +// Disabled explicitly on posix `toranj` to validate the build with this config +#define OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE 0 + #endif /* OPENTHREAD_CORE_TORANJ_CONFIG_POSIX_H_ */ diff --git a/tests/toranj/openthread-core-toranj-config-simulation.h b/tests/toranj/openthread-core-toranj-config-simulation.h index 234465a6f09..8a1063c5cbd 100644 --- a/tests/toranj/openthread-core-toranj-config-simulation.h +++ b/tests/toranj/openthread-core-toranj-config-simulation.h @@ -59,6 +59,8 @@ #define OPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE 1 +#define OPENTHREAD_CONFIG_BORDER_ROUTING_USE_HEAP_ENABLE 1 + #define OPENTHREAD_CONFIG_RADIO_STATS_ENABLE 0 #endif /* OPENTHREAD_CORE_TORANJ_CONFIG_SIMULATION_H_ */