mirror of
https://github.com/espressif/openthread.git
synced 2026-09-08 02:00:12 +00:00
[srp-server] use Array for Host IPv6 address list (#7137)
This commit is contained in:
@@ -1703,7 +1703,6 @@ void Server::Host::Free(void)
|
||||
|
||||
Server::Host::Host(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, mAddressesNum(0)
|
||||
, mNext(nullptr)
|
||||
, mLease(0)
|
||||
, mKeyLease(0)
|
||||
@@ -1874,7 +1873,7 @@ void Server::Host::FreeUnusedServiceDescriptions(void)
|
||||
|
||||
void Server::Host::ClearResources(void)
|
||||
{
|
||||
mAddressesNum = 0;
|
||||
mAddresses.Clear();
|
||||
}
|
||||
|
||||
Error Server::Host::MergeServicesAndResourcesFrom(Host &aHost)
|
||||
@@ -1887,8 +1886,7 @@ Error Server::Host::MergeServicesAndResourcesFrom(Host &aHost)
|
||||
|
||||
otLogInfoSrp("[server] update host %s", GetFullName());
|
||||
|
||||
memcpy(mAddresses, aHost.mAddresses, aHost.mAddressesNum * sizeof(mAddresses[0]));
|
||||
mAddressesNum = aHost.mAddressesNum;
|
||||
mAddresses = aHost.mAddresses;
|
||||
mKey = aHost.mKey;
|
||||
mLease = aHost.mLease;
|
||||
mKeyLease = aHost.mKeyLease;
|
||||
@@ -1964,23 +1962,16 @@ Error Server::Host::AddIp6Address(const Ip6::Address &aIp6Address)
|
||||
ExitNow(error = kErrorDrop);
|
||||
}
|
||||
|
||||
for (const Ip6::Address &addr : mAddresses)
|
||||
{
|
||||
if (aIp6Address == addr)
|
||||
{
|
||||
// Drop duplicate addresses.
|
||||
ExitNow(error = kErrorDrop);
|
||||
}
|
||||
}
|
||||
// Drop duplicate addresses.
|
||||
VerifyOrExit(!mAddresses.Contains(aIp6Address), error = kErrorDrop);
|
||||
|
||||
if (mAddressesNum >= kMaxAddressesNum)
|
||||
error = mAddresses.PushBack(aIp6Address);
|
||||
|
||||
if (error == kErrorNoBufs)
|
||||
{
|
||||
otLogWarnSrp("[server] too many addresses for host %s", GetFullName());
|
||||
ExitNow(error = kErrorNoBufs);
|
||||
}
|
||||
|
||||
mAddresses[mAddressesNum++] = aIp6Address;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
+14
-15
@@ -53,6 +53,7 @@
|
||||
#include <openthread/ip6.h>
|
||||
#include <openthread/srp_server.h>
|
||||
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/clearable.hpp"
|
||||
#include "common/heap_string.hpp"
|
||||
@@ -420,13 +421,13 @@ public:
|
||||
*
|
||||
* @param[out] aAddressesNum The number of the addresses.
|
||||
*
|
||||
* @returns A pointer to the addresses array.
|
||||
* @returns A pointer to the addresses array or `nullptr` if no addresses.
|
||||
*
|
||||
*/
|
||||
const Ip6::Address *GetAddresses(uint8_t &aAddressesNum) const
|
||||
{
|
||||
aAddressesNum = mAddressesNum;
|
||||
return mAddresses;
|
||||
aAddressesNum = mAddresses.GetLength();
|
||||
return mAddresses.Front();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -505,7 +506,7 @@ public:
|
||||
bool Matches(const char *aFullName) const { return (mFullName == aFullName); }
|
||||
|
||||
private:
|
||||
static constexpr uint16_t kMaxAddressesNum = OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM;
|
||||
static constexpr uint16_t kMaxAddresses = OPENTHREAD_CONFIG_SRP_SERVER_MAX_ADDRESSES_NUM;
|
||||
|
||||
static Host *New(Instance &aInstance);
|
||||
|
||||
@@ -528,17 +529,15 @@ public:
|
||||
Service * FindService(const char *aServiceName, const char *aInstanceName);
|
||||
const Service * FindService(const char *aServiceName, const char *aInstanceName) const;
|
||||
|
||||
HeapString mFullName;
|
||||
Ip6::Address mAddresses[kMaxAddressesNum];
|
||||
uint8_t mAddressesNum;
|
||||
Host * mNext;
|
||||
|
||||
Dns::Ecdsa256KeyRecord mKey;
|
||||
uint32_t mLease; // The LEASE time in seconds.
|
||||
uint32_t mKeyLease; // The KEY-LEASE time in seconds.
|
||||
TimeMilli mTimeLastUpdate;
|
||||
LinkedList<Service> mServices;
|
||||
LinkedList<Service::Description> mServiceDescriptions;
|
||||
Host * mNext;
|
||||
HeapString mFullName;
|
||||
Array<Ip6::Address, kMaxAddresses> mAddresses;
|
||||
Dns::Ecdsa256KeyRecord mKey;
|
||||
uint32_t mLease; // The LEASE time in seconds.
|
||||
uint32_t mKeyLease; // The KEY-LEASE time in seconds.
|
||||
TimeMilli mTimeLastUpdate;
|
||||
LinkedList<Service> mServices;
|
||||
LinkedList<Service::Description> mServiceDescriptions;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user