[srp-server] allow disabling "Fast Start Mode" via auto-enable (#11319)

This commit updates the `Srp::Server` so that Fast Start Mode can be
disabled by a call to `otSrpServerSetAutoEnableMode()`, in addition
to the existing method of calling `otSrpServerSetEnabled()`.

The `test_srp_server` unit test is updated to validate this new
behavior.
This commit is contained in:
Abtin Keshavarzian
2025-03-04 15:18:37 -08:00
committed by GitHub
parent eb15a56a91
commit b1ca77aae9
5 changed files with 57 additions and 9 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ extern "C" {
*
* @note This number versions both OpenThread platform and user APIs.
*/
#define OPENTHREAD_API_VERSION (482)
#define OPENTHREAD_API_VERSION (483)
/**
* @addtogroup api-instance
+6 -2
View File
@@ -301,8 +301,12 @@ bool otSrpServerIsAutoEnableMode(otInstance *aInstance);
* The Fast Start Mode can be enabled when the device is in the detached or disabled state, the SRP server is currently
* disabled, and "auto-enable mode" is not in use (i.e., `otSrpServerIsAutoEnableMode()` returns `false`).
*
* After successfully enabling Fast Start Mode, it can be disabled by a direct call to `otSrpServerSetEnabled()`,
* explicitly enabling or disabling the SRP server function.
* After successfully enabling Fast Start Mode, it can be disabled either by a call to `otSrpServerSetEnabled()`,
* explicitly enabling or disabling the SRP server, or by a call to `otSrpServerSetAutoEnableMode()`, enabling or
* disabling the auto-enable mode. If the Fast Start Mode (while active) enables the SRP server, upon disabling
* Fast Start Mode (regardless of how it is done), the SRP server will also be stopped, and the use of the
* `OT_SRP_SERVER_ADDRESS_MODE_UNICAST_FORCE_ADD` address mode will be stopped, and the address mode will be
* automatically reverted back to its previous setting before Fast Start Mode was enabled.
*
* @param[in] aInstance A pointer to the OpenThread instance.
*
+33 -6
View File
@@ -128,7 +128,7 @@ void Server::SetEnabled(bool aEnabled)
mAutoEnable = false;
#endif
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
mFastStartMode = false;
DisableFastStartMode();
#endif
if (aEnabled)
@@ -144,6 +144,15 @@ void Server::SetEnabled(bool aEnabled)
void Server::Enable(void)
{
VerifyOrExit(mState == kStateDisabled);
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
if (mFastStartMode)
{
mPrevAddressMode = mAddressMode;
IgnoreError(SetAddressMode(kAddressModeUnicastForceAdd));
}
#endif
mState = kStateStopped;
// Request publishing of "DNS/SRP Address Service" entry in the
@@ -199,6 +208,13 @@ void Server::Disable(void)
Stop();
mState = kStateDisabled;
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
if (mFastStartMode)
{
IgnoreError(SetAddressMode(mPrevAddressMode));
}
#endif
exit:
return;
}
@@ -206,6 +222,10 @@ exit:
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
void Server::SetAutoEnableMode(bool aEnabled)
{
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
DisableFastStartMode();
#endif
VerifyOrExit(mAutoEnable != aEnabled);
mAutoEnable = aEnabled;
@@ -236,6 +256,18 @@ exit:
return error;
}
void Server::DisableFastStartMode(void)
{
VerifyOrExit(mFastStartMode);
Disable();
mFastStartMode = false;
LogInfo("FastStartMode disabled");
exit:
return;
}
void Server::HandleNotifierEvents(Events aEvents)
{
VerifyOrExit(mFastStartMode);
@@ -248,9 +280,6 @@ void Server::HandleNotifierEvents(Events aEvents)
if (!NetDataContainsOtherSrpServers())
{
LogInfo("FastStartMode - No SRP server in NetData");
mPrevAddressMode = mAddressMode;
IgnoreError(SetAddressMode(kAddressModeUnicastForceAdd));
Enable();
}
}
@@ -261,9 +290,7 @@ void Server::HandleNotifierEvents(Events aEvents)
if (NetDataContainsOtherSrpServers())
{
LogInfo("FastStartMode - New SRP server entry in NetData");
Disable();
IgnoreError(SetAddressMode(mPrevAddressMode));
}
}
+1
View File
@@ -949,6 +949,7 @@ private:
#endif
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
void DisableFastStartMode(void);
void HandleNotifierEvents(Events aEvents);
bool NetDataContainsOtherSrpServers(void) const;
#endif
+16
View File
@@ -1367,6 +1367,22 @@ void TestSrpServerFastStartMode(void)
VerifyOrQuit(srpServer->IsFastStartModeEnabled());
VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateRunning);
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Start auto-enable mode and ensure "fast start mode" is turned
// off and the original AddressMode is restored on the SRP server.
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
srpServer->SetAutoEnableMode(true);
VerifyOrQuit(!srpServer->IsFastStartModeEnabled());
VerifyOrQuit(srpServer->IsAutoEnableMode());
VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateDisabled);
VerifyOrQuit(srpServer->GetAddressMode() == Srp::Server::kAddressModeUnicast);
VerifyOrQuit(srpServer->EnableFastStartMode() == kErrorInvalidState);
#endif
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Finalize OT instance and validate all heap allocations are freed.