[srp] add support for short (4-bytes) lease option variant (#8879)

This commit updates SRP client and server to support short variant
format for Update Lease Option. The short variant includes the lease
interval only (4 bytes) vs the long variant which includes both lease
and key lease intervals (8 bytes). Client and server can parse and
process both formats in received messages. Client by default uses the
long variant. Server will also use the long variant in its response
unless the request message uses the short variant format, i.e., if
the client uses the short variant, the server will also respond using
the short variant. This behavior is required by the latest Update
Lease draft.

This commit also updates `test_srp_server` unit test, adding a new
test-case to validate the behavior of client and server when short
Update Lease Option is used. A new method (intended for testing and
and only available under `REFERENCE_DEVCIE` config) is added which
configures the client to use the short variant format changing the
default behavior.
This commit is contained in:
Abtin Keshavarzian
2023-03-23 17:43:33 -07:00
committed by GitHub
parent a43484ed44
commit 84be135243
7 changed files with 405 additions and 67 deletions
+63 -1
View File
@@ -1100,7 +1100,69 @@ bool SigRecord::IsValid(void) const
return GetType() == Dns::ResourceRecord::kTypeSig && GetLength() >= sizeof(*this) - sizeof(ResourceRecord);
}
bool LeaseOption::IsValid(void) const { return GetLeaseInterval() <= GetKeyLeaseInterval(); }
void LeaseOption::InitAsShortVariant(uint32_t aLeaseInterval)
{
SetOptionCode(kUpdateLease);
SetOptionLength(kShortLength);
SetLeaseInterval(aLeaseInterval);
}
void LeaseOption::InitAsLongVariant(uint32_t aLeaseInterval, uint32_t aKeyLeaseInterval)
{
SetOptionCode(kUpdateLease);
SetOptionLength(kLongLength);
SetLeaseInterval(aLeaseInterval);
SetKeyLeaseInterval(aKeyLeaseInterval);
}
bool LeaseOption::IsValid(void) const
{
bool isValid = false;
VerifyOrExit((GetOptionLength() == kShortLength) || (GetOptionLength() >= kLongLength));
isValid = (GetLeaseInterval() <= GetKeyLeaseInterval());
exit:
return isValid;
}
Error LeaseOption::ReadFrom(const Message &aMessage, uint16_t aOffset, uint16_t aLength)
{
Error error = kErrorNone;
uint16_t endOffset;
VerifyOrExit(static_cast<uint32_t>(aOffset) + aLength <= aMessage.GetLength(), error = kErrorParse);
endOffset = aOffset + aLength;
while (aOffset < endOffset)
{
uint16_t size;
SuccessOrExit(error = aMessage.Read(aOffset, this, sizeof(Option)));
VerifyOrExit(aOffset + GetSize() <= endOffset, error = kErrorParse);
size = static_cast<uint16_t>(GetSize());
if (GetOptionCode() == kUpdateLease)
{
VerifyOrExit(GetOptionLength() >= kShortLength, error = kErrorParse);
IgnoreError(aMessage.Read(aOffset, this, Min(size, static_cast<uint16_t>(sizeof(LeaseOption)))));
VerifyOrExit(IsValid(), error = kErrorParse);
ExitNow();
}
aOffset += size;
}
error = kErrorNotFound;
exit:
return error;
}
Error PtrRecord::ReadPtrName(const Message &aMessage,
uint16_t &aOffset,
+50 -21
View File
@@ -2492,23 +2492,40 @@ OT_TOOL_PACKED_BEGIN
class LeaseOption : public Option
{
public:
static constexpr uint16_t kOptionLength = sizeof(uint32_t) + sizeof(uint32_t); ///< lease and key lease values
/**
* This method initialize the Update Lease Option by setting the Option Code and Option Length.
* This method initializes the Update Lease Option using the short variant format which contains lease interval
* only.
*
* The lease and key lease intervals remain unchanged/uninitialized.
* @param[in] aLeaseInterval The lease interval in seconds.
*
*/
void Init(void)
{
SetOptionCode(kUpdateLease);
SetOptionLength(kOptionLength);
}
void InitAsShortVariant(uint32_t aLeaseInterval);
/**
* This method initializes the Update Lease Option using the long variant format which contains both lease and
* key lease intervals.
*
* @param[in] aLeaseInterval The lease interval in seconds.
* @param[in] aKeyLeaseInterval The key lease interval in seconds.
*
*/
void InitAsLongVariant(uint32_t aLeaseInterval, uint32_t aKeyLeaseInterval);
/**
* This method indicates whether or not the Update Lease Option follows the short variant format which contains
* only the lease interval.
*
* @retval TRUE The Update Lease Option follows the short variant format.
* @retval FALSE The Update Lease Option follows the long variant format.
*
*/
bool IsShortVariant(void) const { return (GetOptionLength() == kShortLength); }
/**
* This method tells whether this is a valid Lease Option.
*
* This method validates that option follows either short or long variant format.
*
* @returns TRUE if this is a valid Lease Option, FALSE if not a valid Lease Option.
*
*/
@@ -2522,31 +2539,43 @@ public:
*/
uint32_t GetLeaseInterval(void) const { return HostSwap32(mLeaseInterval); }
/**
* This method sets the Update Lease OPT record's lease interval value.
*
* @param[in] aLeaseInterval The lease interval value.
*
*/
void SetLeaseInterval(uint32_t aLeaseInterval) { mLeaseInterval = HostSwap32(aLeaseInterval); }
/**
* This method returns the Update Lease OPT record's key lease interval value.
*
* If the Update Lease Option follows the short variant format the lease interval is returned as key lease interval.
*
* @returns The key lease interval value (in seconds).
*
*/
uint32_t GetKeyLeaseInterval(void) const { return HostSwap32(mKeyLeaseInterval); }
uint32_t GetKeyLeaseInterval(void) const
{
return IsShortVariant() ? GetLeaseInterval() : HostSwap32(mKeyLeaseInterval);
}
/**
* This method sets the Update Lease OPT record's key lease interval value.
* This method searches among the Options is a given message and reads and validates the Update Lease Option if
* found.
*
* @param[in] aKeyLeaseInterval The key lease interval value (in seconds).
* This method reads the Update Lease Option whether it follows the short or long variant formats.
*
* @param[in] aMessage The message to read the Option from.
* @param[in] aOffset Offset in @p aMessage to the start of Options (start of OPT Record data).
* @param[in] aLength Length of Option data in OPT record.
*
* @retval kErrorNone Successfully read and validated the Update Lease Option from @p aMessage.
* @retval kErrorNotFound Did not find any Update Lease Option.
* @retval kErrorParse Failed to parse the Options.
*
*/
void SetKeyLeaseInterval(uint32_t aKeyLeaseInterval) { mKeyLeaseInterval = HostSwap32(aKeyLeaseInterval); }
Error ReadFrom(const Message &aMessage, uint16_t aOffset, uint16_t aLength);
private:
static constexpr uint16_t kShortLength = sizeof(uint32_t); // lease only.
static constexpr uint16_t kLongLength = sizeof(uint32_t) + sizeof(uint32_t); // lease and key lease values
void SetLeaseInterval(uint32_t aLeaseInterval) { mLeaseInterval = HostSwap32(aLeaseInterval); }
void SetKeyLeaseInterval(uint32_t aKeyLeaseInterval) { mKeyLeaseInterval = HostSwap32(aKeyLeaseInterval); }
uint32_t mLeaseInterval;
uint32_t mKeyLeaseInterval;
} OT_TOOL_PACKED_END;
+35 -31
View File
@@ -248,6 +248,7 @@ Client::Client(Instance &aInstance)
, mSingleServiceMode(false)
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
, mServiceKeyRecordEnabled(false)
, mUseShortLeaseOption(false)
#endif
, mUpdateMessageId(0)
, mRetryWaitInterval(kMinRetryWaitInterval)
@@ -1332,11 +1333,12 @@ exit:
return error;
}
Error Client::AppendUpdateLeaseOptRecord(Message &aMessage) const
Error Client::AppendUpdateLeaseOptRecord(Message &aMessage)
{
Error error;
Dns::OptRecord optRecord;
Dns::LeaseOption leaseOption;
uint16_t optionSize;
// Append empty (root domain) as OPT RR name.
SuccessOrExit(error = Dns::Name::AppendTerminator(aMessage));
@@ -1346,15 +1348,26 @@ Error Client::AppendUpdateLeaseOptRecord(Message &aMessage) const
optRecord.Init();
optRecord.SetUdpPayloadSize(kUdpPayloadSize);
optRecord.SetDnsSecurityFlag();
optRecord.SetLength(sizeof(Dns::LeaseOption));
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
if (mUseShortLeaseOption)
{
LogInfo("Test mode - appending short variant of Lease Option");
mKeyLease = mLease;
leaseOption.InitAsShortVariant(mLease);
}
else
#endif
{
leaseOption.InitAsLongVariant(mLease, mKeyLease);
}
optionSize = static_cast<uint16_t>(leaseOption.GetSize());
optRecord.SetLength(optionSize);
SuccessOrExit(error = aMessage.Append(optRecord));
leaseOption.Init();
leaseOption.SetLeaseInterval(mLease);
leaseOption.SetKeyLeaseInterval(mKeyLease);
error = aMessage.Append(leaseOption);
error = aMessage.AppendBytes(&leaseOption, optionSize);
exit:
return error;
@@ -1651,36 +1664,27 @@ Error Client::ProcessOptRecord(const Message &aMessage, uint16_t aOffset, const
// Read and process all options (in an OPT RR) from a message.
// The `aOffset` points to beginning of record in `aMessage`.
Error error = kErrorNone;
uint16_t len;
Error error = kErrorNone;
Dns::LeaseOption leaseOption;
IgnoreError(Dns::Name::ParseName(aMessage, aOffset));
aOffset += sizeof(Dns::OptRecord);
len = aOptRecord.GetLength();
while (len > 0)
switch (error = leaseOption.ReadFrom(aMessage, aOffset, aOptRecord.GetLength()))
{
Dns::LeaseOption leaseOption;
Dns::Option &option = leaseOption;
uint16_t size;
case kErrorNone:
mLease = Min(leaseOption.GetLeaseInterval(), kMaxLease);
mKeyLease = Min(leaseOption.GetKeyLeaseInterval(), kMaxLease);
break;
SuccessOrExit(error = aMessage.Read(aOffset, option));
case kErrorNotFound:
// If server does not include a lease option in its response, it
// indicates that it accepted what we requested.
error = kErrorNone;
break;
VerifyOrExit(aOffset + option.GetSize() <= aMessage.GetLength(), error = kErrorParse);
if ((option.GetOptionCode() == Dns::Option::kUpdateLease) &&
(option.GetOptionLength() >= Dns::LeaseOption::kOptionLength))
{
SuccessOrExit(error = aMessage.Read(aOffset, leaseOption));
mLease = Min(leaseOption.GetLeaseInterval(), kMaxLease);
mKeyLease = Min(leaseOption.GetKeyLeaseInterval(), kMaxLease);
}
size = static_cast<uint16_t>(option.GetSize());
aOffset += size;
len -= size;
default:
ExitNow();
}
exit:
+24 -1
View File
@@ -766,6 +766,28 @@ public:
*
*/
bool IsServiceKeyRecordEnabled(void) const { return mServiceKeyRecordEnabled; }
/**
* This method enables/disables "use short Update Lease Option" behavior.
*
* When enabled, the SRP client will use the short variant format of Update Lease Option in its message. The short
* format only includes the lease interval.
*
* This method is added under `REFERENCE_DEVICE` config and is intended to override the default behavior for
* testing only.
*
* @param[in] aUseShort TRUE to enable, FALSE to disable the "use short Update Lease Option" mode.
*
*/
void SetUseShortLeaseOption(bool aUseShort) { mUseShortLeaseOption = aUseShort; }
/**
* This method gets the current "use short Update Lease Option" mode.
*
* @returns TRUE if "use short Update Lease Option" mode is enabled, FALSE otherwise.
*
*/
bool GetUseShortLeaseOption(void) const { return mUseShortLeaseOption; }
#endif // OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
private:
@@ -990,7 +1012,7 @@ private:
Error AppendDeleteAllRrsets(Message &aMessage) const;
Error AppendHostName(Message &aMessage, Info &aInfo, bool aDoNotCompress = false) const;
Error AppendAaaaRecord(const Ip6::Address &aAddress, Message &aMessage, Info &aInfo) const;
Error AppendUpdateLeaseOptRecord(Message &aMessage) const;
Error AppendUpdateLeaseOptRecord(Message &aMessage);
Error AppendSignature(Message &aMessage, Info &aInfo);
void UpdateRecordLengthInMessage(Dns::ResourceRecord &aRecord, uint16_t aOffset, Message &aMessage) const;
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
@@ -1035,6 +1057,7 @@ private:
bool mSingleServiceMode : 1;
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
bool mServiceKeyRecordEnabled : 1;
bool mUseShortLeaseOption : 1;
#endif
uint16_t mUpdateMessageId;
+24 -11
View File
@@ -454,7 +454,7 @@ void Server::CommitSrpUpdate(Error aError,
hostLease = aHost.GetLease();
hostKeyLease = aHost.GetKeyLease();
grantedLease = aLeaseConfig.GrantLease(hostLease);
grantedKeyLease = aLeaseConfig.GrantKeyLease(hostKeyLease);
grantedKeyLease = aHost.ShouldUseShortLeaseOption() ? grantedLease : aLeaseConfig.GrantKeyLease(hostKeyLease);
grantedTtl = aTtlConfig.GrantTtl(grantedLease, aHost.GetTtl());
aHost.SetLease(grantedLease);
@@ -523,7 +523,7 @@ exit:
{
if (aError == kErrorNone && !(grantedLease == hostLease && grantedKeyLease == hostKeyLease))
{
SendResponse(aDnsHeader, grantedLease, grantedKeyLease, *aMessageInfo);
SendResponse(aDnsHeader, grantedLease, grantedKeyLease, aHost.ShouldUseShortLeaseOption(), *aMessageInfo);
}
else
{
@@ -1116,15 +1116,18 @@ Error Server::ProcessAdditionalSection(Host *aHost, const Message &aMessage, Mes
SuccessOrExit(error = Dns::Name::ReadName(aMessage, offset, name, sizeof(name)));
SuccessOrExit(error = aMessage.Read(offset, optRecord));
SuccessOrExit(error = aMessage.Read(offset + sizeof(optRecord), leaseOption));
VerifyOrExit(leaseOption.IsValid(), error = kErrorFailed);
VerifyOrExit(optRecord.GetSize() == sizeof(optRecord) + sizeof(leaseOption), error = kErrorParse);
SuccessOrExit(error = leaseOption.ReadFrom(aMessage, offset + sizeof(optRecord), optRecord.GetLength()));
offset += optRecord.GetSize();
aHost->SetLease(leaseOption.GetLeaseInterval());
aHost->SetKeyLease(leaseOption.GetKeyLeaseInterval());
// If the client included the short variant of Lease Option,
// server must also use the short variant in its response.
aHost->SetUseShortLeaseOption(leaseOption.IsShortVariant());
if (aHost->GetLease() > 0)
{
uint8_t hostAddressesNum;
@@ -1429,6 +1432,7 @@ exit:
void Server::SendResponse(const Dns::UpdateHeader &aHeader,
uint32_t aLease,
uint32_t aKeyLease,
bool mUseShortLeaseOption,
const Ip6::MessageInfo &aMessageInfo)
{
Error error;
@@ -1436,6 +1440,7 @@ void Server::SendResponse(const Dns::UpdateHeader &aHeader,
Dns::UpdateHeader header;
Dns::OptRecord optRecord;
Dns::LeaseOption leaseOption;
uint16_t optionSize;
response = GetSocket().NewMessage(0);
VerifyOrExit(response != nullptr, error = kErrorNoBufs);
@@ -1453,13 +1458,21 @@ void Server::SendResponse(const Dns::UpdateHeader &aHeader,
optRecord.Init();
optRecord.SetUdpPayloadSize(kUdpPayloadSize);
optRecord.SetDnsSecurityFlag();
optRecord.SetLength(sizeof(Dns::LeaseOption));
SuccessOrExit(error = response->Append(optRecord));
leaseOption.Init();
leaseOption.SetLeaseInterval(aLease);
leaseOption.SetKeyLeaseInterval(aKeyLease);
SuccessOrExit(error = response->Append(leaseOption));
if (mUseShortLeaseOption)
{
leaseOption.InitAsShortVariant(aLease);
}
else
{
leaseOption.InitAsLongVariant(aLease, aKeyLease);
}
optionSize = static_cast<uint16_t>(leaseOption.GetSize());
optRecord.SetLength(optionSize);
SuccessOrExit(error = response->Append(optRecord));
SuccessOrExit(error = response->AppendBytes(&leaseOption, optionSize));
SuccessOrExit(error = GetSocket().SendTo(*response, aMessageInfo));
+4
View File
@@ -593,6 +593,8 @@ public:
void SetTtl(uint32_t aTtl) { mTtl = aTtl; }
void SetLease(uint32_t aLease) { mLease = aLease; }
void SetKeyLease(uint32_t aKeyLease) { mKeyLease = aKeyLease; }
void SetUseShortLeaseOption(bool aUse) { mUseShortLeaseOption = aUse; }
bool ShouldUseShortLeaseOption(void) const { return mUseShortLeaseOption; }
Error ProcessTtl(uint32_t aTtl);
LinkedList<Service> &GetServices(void) { return mServices; }
@@ -626,6 +628,7 @@ public:
uint32_t mKeyLease; // The KEY-LEASE time in seconds.
TimeMilli mUpdateTime;
LinkedList<Service> mServices;
bool mUseShortLeaseOption; // Use short lease option (lease only - 4 byte) when responding.
};
/**
@@ -1044,6 +1047,7 @@ private:
void SendResponse(const Dns::UpdateHeader &aHeader,
uint32_t aLease,
uint32_t aKeyLease,
bool mUseShortLeaseOption,
const Ip6::MessageInfo &aMessageInfo);
static void HandleUdpReceive(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo);
void HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo);
+205 -2
View File
@@ -225,8 +225,10 @@ enum UpdateHandlerMode
kIgnore // Ignore all updates (do not call `otSrpServerHandleServiceUpdateResult()`).
};
static UpdateHandlerMode sUpdateHandlerMode = kAccept;
static bool sProcessedUpdateCallback = false;
static UpdateHandlerMode sUpdateHandlerMode = kAccept;
static bool sProcessedUpdateCallback = false;
static otSrpServerLeaseInfo sUpdateHostLeaseInfo;
static uint32_t sUpdateHostKeyLease;
void HandleSrpServerUpdate(otSrpServerServiceUpdateId aId,
const otSrpServerHost *aHost,
@@ -240,6 +242,8 @@ void HandleSrpServerUpdate(otSrpServerServiceUpdateId aId,
sProcessedUpdateCallback = true;
otSrpServerHostGetLeaseInfo(aHost, &sUpdateHostLeaseInfo);
switch (sUpdateHandlerMode)
{
case kAccept:
@@ -699,6 +703,202 @@ void TestSrpServerIgnore(void)
Log("End of TestSrpServerIgnore");
}
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
void TestUpdateLeaseShortVariant(void)
{
// Test behavior of SRP client and server when short variant of
// Update Lease Option is used (which only include lease interval).
// This test uses `SetUseShortLeaseOption()` method of `Srp::Client`
// which changes the default behavior and is available under the
// `REFERENCE_DEVICE` config.
Srp::Server *srpServer;
Srp::Server::LeaseConfig leaseConfig;
const Srp::Server::Service *service;
Srp::Client *srpClient;
Srp::Client::Service service1;
uint16_t heapAllocations;
Log("--------------------------------------------------------------------------------------------");
Log("TestUpdateLeaseShortVariant");
InitTest();
srpServer = &sInstance->Get<Srp::Server>();
srpClient = &sInstance->Get<Srp::Client>();
heapAllocations = sHeapAllocatedPtrs.GetLength();
PrepareService1(service1);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Start SRP server.
SuccessOrQuit(srpServer->SetAddressMode(Srp::Server::kAddressModeUnicast));
VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateDisabled);
srpServer->SetServiceHandler(HandleSrpServerUpdate, sInstance);
srpServer->SetEnabled(true);
VerifyOrQuit(srpServer->GetState() != Srp::Server::kStateDisabled);
AdvanceTime(10000);
VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateRunning);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Check the default Lease Config on SRP server.
// Server to accept lease in [30 sec, 27 hours] and
// key-lease in [30 sec, 189 hours].
srpServer->GetLeaseConfig(leaseConfig);
VerifyOrQuit(leaseConfig.mMinLease == 30); // 30 seconds
VerifyOrQuit(leaseConfig.mMaxLease == 27u * 3600); // 27 hours
VerifyOrQuit(leaseConfig.mMinKeyLease == 30); // 30 seconds
VerifyOrQuit(leaseConfig.mMaxKeyLease == 189u * 3600); // 189 hours
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Start SRP client.
srpClient->SetCallback(HandleSrpClientCallback, sInstance);
srpClient->EnableAutoStartMode(nullptr, nullptr);
VerifyOrQuit(srpClient->IsAutoStartModeEnabled());
AdvanceTime(2000);
VerifyOrQuit(srpClient->IsRunning());
SuccessOrQuit(srpClient->SetHostName(kHostName));
SuccessOrQuit(srpClient->EnableAutoHostAddress());
sUpdateHandlerMode = kAccept;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Change default lease intervals on SRP client and enable
// "use short Update Lease Option" mode.
srpClient->SetLeaseInterval(15u * 3600);
srpClient->SetKeyLeaseInterval(40u * 3600);
srpClient->SetUseShortLeaseOption(true);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Register a service, validate that update handler is called
// and service is successfully registered.
SuccessOrQuit(srpClient->AddService(service1));
sProcessedUpdateCallback = false;
sProcessedClientCallback = false;
AdvanceTime(2 * 1000);
VerifyOrQuit(sProcessedUpdateCallback);
VerifyOrQuit(sProcessedClientCallback);
VerifyOrQuit(sLastClientCallbackError == kErrorNone);
VerifyOrQuit(service1.GetState() == Srp::Client::kRegistered);
ValidateHost(*srpServer, kHostName);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Validate the lease info for service on SRP server. The client
// is set up to use "short Update Lease Option format, so it only
// include the lease interval as 15 hours in its request
// message. Server should then see 15 hours for both lease and
// key lease
VerifyOrQuit(sUpdateHostLeaseInfo.mLease == 15u * 3600 * 1000);
VerifyOrQuit(sUpdateHostLeaseInfo.mKeyLease == 15u * 3600 * 1000);
// Check that SRP server granted 15 hours for both lease and
// key lease.
service = srpServer->GetNextHost(nullptr)->GetServices().GetHead();
VerifyOrQuit(service != nullptr);
VerifyOrQuit(service->GetLease() == 15u * 3600);
VerifyOrQuit(service->GetKeyLease() == 15u * 3600);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Remove the service.
SuccessOrQuit(srpClient->RemoveService(service1));
sProcessedUpdateCallback = false;
sProcessedClientCallback = false;
AdvanceTime(2 * 1000);
VerifyOrQuit(sProcessedUpdateCallback);
VerifyOrQuit(sProcessedClientCallback);
VerifyOrQuit(sLastClientCallbackError == kErrorNone);
VerifyOrQuit(service1.GetState() == Srp::Client::kRemoved);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Register the service again, but this time change it to request
// a lease time that is larger than the `LeaseConfig.mMinLease` of
// 27 hours. This ensures that server needs to include the Lease
// Option in its response (since it need to grant a different
// lease interval).
service1.mLease = 100u * 3600; // 100 hours >= 27 hours.
service1.mKeyLease = 110u * 3600;
SuccessOrQuit(srpClient->AddService(service1));
sProcessedUpdateCallback = false;
sProcessedClientCallback = false;
AdvanceTime(2 * 1000);
VerifyOrQuit(sProcessedUpdateCallback);
VerifyOrQuit(sProcessedClientCallback);
VerifyOrQuit(sLastClientCallbackError == kErrorNone);
VerifyOrQuit(service1.GetState() == Srp::Client::kRegistered);
ValidateHost(*srpServer, kHostName);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Validate the lease info for service on SRP server.
// We should see the 100 hours in request from client
VerifyOrQuit(sUpdateHostLeaseInfo.mLease == 100u * 3600 * 1000);
VerifyOrQuit(sUpdateHostLeaseInfo.mKeyLease == 100u * 3600 * 1000);
// Check that SRP server granted 27 hours for both lease and
// key lease.
service = srpServer->GetNextHost(nullptr)->GetServices().GetHead();
VerifyOrQuit(service != nullptr);
VerifyOrQuit(service->GetLease() == 27u * 3600);
VerifyOrQuit(service->GetKeyLease() == 27u * 3600);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Disable SRP server, verify that all heap allocations by SRP server
// are freed.
Log("Disabling SRP server");
srpServer->SetEnabled(false);
AdvanceTime(100);
VerifyOrQuit(heapAllocations == sHeapAllocatedPtrs.GetLength());
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Finalize OT instance and validate all heap allocations are freed.
Log("Finalizing OT instance");
FinalizeTest();
VerifyOrQuit(sHeapAllocatedPtrs.IsEmpty());
Log("End of TestUpdateLeaseShortVariant");
}
#endif // OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
#endif // ENABLE_SRP_TEST
int main(void)
@@ -707,6 +907,9 @@ int main(void)
TestSrpServerBase();
TestSrpServerReject();
TestSrpServerIgnore();
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
TestUpdateLeaseShortVariant();
#endif
printf("All tests passed\n");
#else
printf("SRP_SERVER or SRP_CLIENT feature is not enabled\n");