[border-agent] check that BA is enabled in RegisterService() (#11993)

This change adds a check at the beginning of `RegisterService()`
to ensure that the border agent is enabled before attempting to
register a service.

Previously, methods like `SetServiceBaseName()` would call
`RegisterService()` regardless of whether the agent was enabled,
leading to unintended service registration attempts on a disabled
agent.

This commit also adds a new test case to verify that changing the
service base name on a disabled border agent does not result in a
service being registered.
This commit is contained in:
Abtin Keshavarzian
2025-10-07 14:49:16 -07:00
committed by GitHub
parent d732acc6c6
commit c5971f7080
2 changed files with 21 additions and 0 deletions
+1
View File
@@ -466,6 +466,7 @@ void BorderAgent::RegisterService(void)
uint16_t txtDataBufferSize;
uint16_t txtDataLength;
VerifyOrExit(IsEnabled());
VerifyOrExit(Get<Dnssd>().IsReady());
// Allocate a large enough buffer to fit both the TXT data
+20
View File
@@ -1786,6 +1786,26 @@ void TestBorderAgentServiceRegistration(void)
sBrowseOutcomes.Clear();
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Change the base service name while agent is disabled and validate no service is registered");
SuccessOrQuit(node0.Get<MeshCoP::BorderAgent>().SetServiceBaseName("NewName"));
VerifyOrQuit(!node0.Get<MeshCoP::BorderAgent>().IsEnabled());
nexus.AdvanceTime(30 * Time::kOneSecondInMsec);
iterator = node0.Get<Dns::Multicast::Core>().AllocateIterator();
VerifyOrQuit(iterator != nullptr);
VerifyOrQuit(node0.Get<Dns::Multicast::Core>().GetNextService(*iterator, service, entryState) == kErrorNotFound);
node0.Get<Dns::Multicast::Core>().FreeIterator(*iterator);
VerifyOrQuit(sBrowseOutcomes.IsEmpty());
SuccessOrQuit(node0.Get<MeshCoP::BorderAgent>().SetServiceBaseName("OpenThreadAgent"));
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Log("Re-enable Border Agent and validate that service is registered again");