From 9475bce07a0ed8af8f48fcd76558b66ea85a8706 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 14 Feb 2022 21:10:26 -0800 Subject: [PATCH] [srp-server] allow any number of host addresses (use `Heap::Array`) (#7420) This commit changes the `Srp::Server` definition to use `Heap::Array` to store the list of IPv6 addresses associated with a given `Host`. This makes the array length dynamic and removes the need for specifying a hard limit on the number of addresses and allow us to remove `OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM` config. --- src/core/config/openthread-core-config-check.h | 5 +++++ src/core/config/srp_server.h | 10 ---------- src/core/net/srp_server.cpp | 4 ++-- src/core/net/srp_server.hpp | 14 +++++++------- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/core/config/openthread-core-config-check.h b/src/core/config/openthread-core-config-check.h index dc4032ab3..d7975d8cb 100644 --- a/src/core/config/openthread-core-config-check.h +++ b/src/core/config/openthread-core-config-check.h @@ -614,4 +614,9 @@ #error "OPENTHREAD_CONFIG_LOG_PREPEND_REGION was removed and not longer supported" #endif +#ifdef OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM +#error "OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM was removed. "\ + "SRP host uses dynamic heap array to store addresses so no need for config on max number of addresses". +#endif + #endif // OPENTHREAD_CORE_CONFIG_CHECK_H_ diff --git a/src/core/config/srp_server.h b/src/core/config/srp_server.h index 7bc5aefbd..aeffbdf31 100644 --- a/src/core/config/srp_server.h +++ b/src/core/config/srp_server.h @@ -109,14 +109,4 @@ #define OPENTHREAD_CONFIG_SRP_SERVER_SERVICE_UPDATE_TIMEOUT ((4 * 250u) + 250u) #endif -/** - * @def OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM - * - * Specifies the maximum number of addresses the SRP server can handle for a host. - * - */ -#ifndef OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM -#define OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM 2 -#endif - #endif // CONFIG_SRP_SERVER_H_ diff --git a/src/core/net/srp_server.cpp b/src/core/net/srp_server.cpp index 44c13db98..9927cc9ea 100644 --- a/src/core/net/srp_server.cpp +++ b/src/core/net/srp_server.cpp @@ -1797,7 +1797,7 @@ void Server::Host::FreeAllServices(void) void Server::Host::ClearResources(void) { - mAddresses.Clear(); + mAddresses.Free(); } Error Server::Host::MergeServicesAndResourcesFrom(Host &aHost) @@ -1810,7 +1810,7 @@ Error Server::Host::MergeServicesAndResourcesFrom(Host &aHost) LogInfo("update host %s", GetFullName()); - mAddresses = aHost.mAddresses; + mAddresses.TakeFrom(static_cast &&>(aHost.mAddresses)); mKeyRecord = aHost.mKeyRecord; mLease = aHost.mLease; mKeyLease = aHost.mKeyLease; diff --git a/src/core/net/srp_server.hpp b/src/core/net/srp_server.hpp index e3cd50339..e86284cd6 100644 --- a/src/core/net/srp_server.hpp +++ b/src/core/net/srp_server.hpp @@ -58,12 +58,14 @@ #include "common/clearable.hpp" #include "common/heap.hpp" #include "common/heap_allocatable.hpp" +#include "common/heap_array.hpp" #include "common/heap_data.hpp" #include "common/heap_string.hpp" #include "common/linked_list.hpp" #include "common/locator.hpp" #include "common/non_copyable.hpp" #include "common/notifier.hpp" +#include "common/numeric_limits.hpp" #include "common/retain_ptr.hpp" #include "common/timer.hpp" #include "crypto/ecdsa.hpp" @@ -432,8 +434,8 @@ public: */ const Ip6::Address *GetAddresses(uint8_t &aAddressesNum) const { - aAddressesNum = mAddresses.GetLength(); - return mAddresses.Front(); + aAddressesNum = static_cast(OT_MIN(mAddresses.GetLength(), NumericLimits::kMax)); + return mAddresses.AsCArray(); } /** @@ -512,8 +514,6 @@ public: bool Matches(const char *aFullName) const; private: - static constexpr uint16_t kMaxAddresses = OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM; - Host(Instance &aInstance, TimeMilli aUpdateTime); ~Host(void); @@ -537,9 +537,9 @@ public: Service * FindService(const char *aServiceName, const char *aInstanceName); const Service * FindService(const char *aServiceName, const char *aInstanceName) const; - Host * mNext; - Heap::String mFullName; - Array mAddresses; + Host * mNext; + Heap::String mFullName; + Heap::Array mAddresses; // TODO(wgtdkp): there is no necessary to save the entire resource // record, saving only the ECDSA-256 public key should be enough.