mirror of
https://github.com/espressif/openthread.git
synced 2026-09-14 05:00:11 +00:00
[srp-server] add more error tracing logs (#7582)
This commit add more error tracing logs to help identify where a SRP service registration fails. The log format is also updated to capitalize the first char to align with rest of the codebase.
This commit is contained in:
+68
-30
@@ -261,6 +261,8 @@ const Server::Host *Server::GetNextHost(const Server::Host *aHost)
|
|||||||
// The caller MUST make sure that there is no existing host with the same hostname.
|
// The caller MUST make sure that there is no existing host with the same hostname.
|
||||||
void Server::AddHost(Host &aHost)
|
void Server::AddHost(Host &aHost)
|
||||||
{
|
{
|
||||||
|
LogInfo("Add new host %s", aHost.GetFullName());
|
||||||
|
|
||||||
OT_ASSERT(mHosts.FindMatching(aHost.GetFullName()) == nullptr);
|
OT_ASSERT(mHosts.FindMatching(aHost.GetFullName()) == nullptr);
|
||||||
IgnoreError(mHosts.Add(aHost));
|
IgnoreError(mHosts.Add(aHost));
|
||||||
}
|
}
|
||||||
@@ -274,13 +276,13 @@ void Server::RemoveHost(Host *aHost, RetainName aRetainName, NotifyMode aNotifyS
|
|||||||
|
|
||||||
if (aRetainName)
|
if (aRetainName)
|
||||||
{
|
{
|
||||||
LogInfo("remove host '%s' (but retain its name)", aHost->GetFullName());
|
LogInfo("Remove host %s (but retain its name)", aHost->GetFullName());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
aHost->mKeyLease = 0;
|
aHost->mKeyLease = 0;
|
||||||
IgnoreError(mHosts.Remove(*aHost));
|
IgnoreError(mHosts.Remove(*aHost));
|
||||||
LogInfo("fully remove host '%s'", aHost->GetFullName());
|
LogInfo("Fully remove host %s", aHost->GetFullName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aNotifyServiceHandler && mServiceUpdateHandler != nullptr)
|
if (aNotifyServiceHandler && mServiceUpdateHandler != nullptr)
|
||||||
@@ -312,6 +314,7 @@ bool Server::HasNameConflictsWith(Host &aHost) const
|
|||||||
|
|
||||||
if (existingHost != nullptr && aHost.GetKeyRecord()->GetKey() != existingHost->GetKeyRecord()->GetKey())
|
if (existingHost != nullptr && aHost.GetKeyRecord()->GetKey() != existingHost->GetKeyRecord()->GetKey())
|
||||||
{
|
{
|
||||||
|
LogWarn("Name conflict: host name %s has already been allocated", aHost.GetFullName());
|
||||||
ExitNow(hasConflicts = true);
|
ExitNow(hasConflicts = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,9 +326,11 @@ bool Server::HasNameConflictsWith(Host &aHost) const
|
|||||||
|
|
||||||
for (const Host &host : mHosts)
|
for (const Host &host : mHosts)
|
||||||
{
|
{
|
||||||
if (host.HasServiceInstance(service.GetInstanceName()))
|
if (host.HasServiceInstance(service.GetInstanceName()) &&
|
||||||
|
aHost.GetKeyRecord()->GetKey() != host.GetKeyRecord()->GetKey())
|
||||||
{
|
{
|
||||||
VerifyOrExit(aHost.GetKeyRecord()->GetKey() == host.GetKeyRecord()->GetKey(), hasConflicts = true);
|
LogWarn("Name conflict: service name %s has already been allocated", service.GetInstanceName());
|
||||||
|
ExitNow(hasConflicts = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,13 +349,13 @@ void Server::HandleServiceUpdateResult(ServiceUpdateId aId, Error aError)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogInfo("delayed SRP host update result, the SRP update has been committed (updateId = %u)", aId);
|
LogInfo("Delayed SRP host update result, the SRP update has been committed (updateId = %u)", aId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::HandleServiceUpdateResult(UpdateMetadata *aUpdate, Error aError)
|
void Server::HandleServiceUpdateResult(UpdateMetadata *aUpdate, Error aError)
|
||||||
{
|
{
|
||||||
LogInfo("handler result of SRP update (id = %u) is received: %s", aUpdate->GetId(), otThreadErrorToString(aError));
|
LogInfo("Handler result of SRP update (id = %u) is received: %s", aUpdate->GetId(), ErrorToString(aError));
|
||||||
|
|
||||||
IgnoreError(mOutstandingUpdates.Remove(*aUpdate));
|
IgnoreError(mOutstandingUpdates.Remove(*aUpdate));
|
||||||
CommitSrpUpdate(aError, *aUpdate);
|
CommitSrpUpdate(aError, *aUpdate);
|
||||||
@@ -414,7 +419,7 @@ void Server::CommitSrpUpdate(Error aError,
|
|||||||
{
|
{
|
||||||
if (aHost.GetKeyLease() == 0)
|
if (aHost.GetKeyLease() == 0)
|
||||||
{
|
{
|
||||||
LogInfo("remove key of host %s", aHost.GetFullName());
|
LogInfo("Remove key of host %s", aHost.GetFullName());
|
||||||
RemoveHost(existingHost, kDeleteName, kDoNotNotifyServiceHandler);
|
RemoveHost(existingHost, kDeleteName, kDoNotNotifyServiceHandler);
|
||||||
}
|
}
|
||||||
else if (existingHost != nullptr)
|
else if (existingHost != nullptr)
|
||||||
@@ -434,7 +439,8 @@ void Server::CommitSrpUpdate(Error aError,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogInfo("add new host %s", aHost.GetFullName());
|
AddHost(aHost);
|
||||||
|
shouldFreeHost = false;
|
||||||
|
|
||||||
for (Service &service : aHost.GetServices())
|
for (Service &service : aHost.GetServices())
|
||||||
{
|
{
|
||||||
@@ -442,9 +448,6 @@ void Server::CommitSrpUpdate(Error aError,
|
|||||||
service.Log(Service::kAddNew);
|
service.Log(Service::kAddNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddHost(aHost);
|
|
||||||
shouldFreeHost = false;
|
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_SRP_SERVER_PORT_SWITCH_ENABLE
|
#if OPENTHREAD_CONFIG_SRP_SERVER_PORT_SWITCH_ENABLE
|
||||||
if (!mHasRegisteredAnyService && (mAddressMode == kAddressModeUnicast))
|
if (!mHasRegisteredAnyService && (mAddressMode == kAddressModeUnicast))
|
||||||
{
|
{
|
||||||
@@ -498,7 +501,7 @@ void Server::SelectPort(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LogInfo("selected port %u", mPort);
|
LogInfo("Selected port %u", mPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::Start(void)
|
void Server::Start(void)
|
||||||
@@ -507,7 +510,7 @@ void Server::Start(void)
|
|||||||
|
|
||||||
mState = kStateRunning;
|
mState = kStateRunning;
|
||||||
PrepareSocket();
|
PrepareSocket();
|
||||||
LogInfo("start listening on port %u", mPort);
|
LogInfo("Start listening on port %u", mPort);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return;
|
return;
|
||||||
@@ -538,7 +541,7 @@ void Server::PrepareSocket(void)
|
|||||||
exit:
|
exit:
|
||||||
if (error != kErrorNone)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
LogCrit("failed to prepare socket: %s", ErrorToString(error));
|
LogCrit("Failed to prepare socket: %s", ErrorToString(error));
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -614,7 +617,7 @@ void Server::Stop(void)
|
|||||||
mLeaseTimer.Stop();
|
mLeaseTimer.Stop();
|
||||||
mOutstandingUpdatesTimer.Stop();
|
mOutstandingUpdatesTimer.Stop();
|
||||||
|
|
||||||
LogInfo("stop listening on %u", mPort);
|
LogInfo("Stop listening on %u", mPort);
|
||||||
IgnoreError(mSocket.Close());
|
IgnoreError(mSocket.Close());
|
||||||
mHasRegisteredAnyService = false;
|
mHasRegisteredAnyService = false;
|
||||||
|
|
||||||
@@ -722,6 +725,11 @@ Error Server::ProcessZoneSection(const Message &aMessage, MessageMetadata &aMeta
|
|||||||
aMetadata.mOffset = offset;
|
aMetadata.mOffset = offset;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (error != kErrorNone)
|
||||||
|
{
|
||||||
|
LogWarn("Failed to process DNS Zone section: %s", ErrorToString(error));
|
||||||
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -747,6 +755,11 @@ Error Server::ProcessUpdateSection(Host &aHost, const Message &aMessage, Message
|
|||||||
VerifyOrExit(!HasNameConflictsWith(aHost), error = kErrorDuplicated);
|
VerifyOrExit(!HasNameConflictsWith(aHost), error = kErrorDuplicated);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (error != kErrorNone)
|
||||||
|
{
|
||||||
|
LogWarn("Failed to process DNS Update section: %s", ErrorToString(error));
|
||||||
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -823,6 +836,11 @@ Error Server::ProcessHostDescriptionInstruction(Host & aHost,
|
|||||||
// the host is being removed or registered.
|
// the host is being removed or registered.
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (error != kErrorNone)
|
||||||
|
{
|
||||||
|
LogWarn("Failed to process Host Description instructions: %s", ErrorToString(error));
|
||||||
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,6 +911,11 @@ Error Server::ProcessServiceDiscoveryInstructions(Host & aHost,
|
|||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (error != kErrorNone)
|
||||||
|
{
|
||||||
|
LogWarn("Failed to process Service Discovery instructions: %s", ErrorToString(error));
|
||||||
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -989,6 +1012,11 @@ Error Server::ProcessServiceDescriptionInstructions(Host & aHost,
|
|||||||
aMetadata.mOffset = offset;
|
aMetadata.mOffset = offset;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (error != kErrorNone)
|
||||||
|
{
|
||||||
|
LogWarn("Failed to process Service Description instructions: %s", ErrorToString(error));
|
||||||
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1067,6 +1095,11 @@ Error Server::ProcessAdditionalSection(Host *aHost, const Message &aMessage, Mes
|
|||||||
aMetadata.mOffset = offset;
|
aMetadata.mOffset = offset;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (error != kErrorNone)
|
||||||
|
{
|
||||||
|
LogWarn("Failed to process DNS Additional section: %s", ErrorToString(error));
|
||||||
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1113,6 +1146,11 @@ Error Server::VerifySignature(const Dns::Ecdsa256KeyRecord &aKeyRecord,
|
|||||||
error = aKeyRecord.GetKey().Verify(hash, signature);
|
error = aKeyRecord.GetKey().Verify(hash, signature);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (error != kErrorNone)
|
||||||
|
{
|
||||||
|
LogWarn("Failed to verify message signature: %s", ErrorToString(error));
|
||||||
|
}
|
||||||
|
|
||||||
FreeMessage(signerNameMessage);
|
FreeMessage(signerNameMessage);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -1191,17 +1229,17 @@ void Server::SendResponse(const Dns::UpdateHeader & aHeader,
|
|||||||
|
|
||||||
if (aResponseCode != Dns::UpdateHeader::kResponseSuccess)
|
if (aResponseCode != Dns::UpdateHeader::kResponseSuccess)
|
||||||
{
|
{
|
||||||
LogInfo("send fail response: %d", aResponseCode);
|
LogWarn("Send fail response: %d", aResponseCode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogInfo("send success response");
|
LogInfo("Send success response");
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != kErrorNone)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
LogWarn("failed to send response: %s", ErrorToString(error));
|
LogWarn("Failed to send response: %s", ErrorToString(error));
|
||||||
FreeMessage(response);
|
FreeMessage(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1243,12 +1281,12 @@ void Server::SendResponse(const Dns::UpdateHeader &aHeader,
|
|||||||
|
|
||||||
SuccessOrExit(error = GetSocket().SendTo(*response, aMessageInfo));
|
SuccessOrExit(error = GetSocket().SendTo(*response, aMessageInfo));
|
||||||
|
|
||||||
LogInfo("send response with granted lease: %u and key lease: %u", aLease, aKeyLease);
|
LogInfo("Send success response with granted lease: %u and key lease: %u", aLease, aKeyLease);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if (error != kErrorNone)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
LogWarn("failed to send response: %s", ErrorToString(error));
|
LogWarn("Failed to send response: %s", ErrorToString(error));
|
||||||
FreeMessage(response);
|
FreeMessage(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1264,7 +1302,7 @@ void Server::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessag
|
|||||||
|
|
||||||
if (error != kErrorNone)
|
if (error != kErrorNone)
|
||||||
{
|
{
|
||||||
LogInfo("failed to handle DNS message: %s", ErrorToString(error));
|
LogInfo("Failed to handle DNS message: %s", ErrorToString(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1406,13 +1444,13 @@ void Server::HandleLeaseTimer(void)
|
|||||||
OT_ASSERT(earliestExpireTime >= now);
|
OT_ASSERT(earliestExpireTime >= now);
|
||||||
if (!mLeaseTimer.IsRunning() || earliestExpireTime <= mLeaseTimer.GetFireTime())
|
if (!mLeaseTimer.IsRunning() || earliestExpireTime <= mLeaseTimer.GetFireTime())
|
||||||
{
|
{
|
||||||
LogInfo("lease timer is scheduled for %u seconds", Time::MsecToSec(earliestExpireTime - now));
|
LogInfo("Lease timer is scheduled for %u seconds", Time::MsecToSec(earliestExpireTime - now));
|
||||||
mLeaseTimer.StartAt(earliestExpireTime, 0);
|
mLeaseTimer.StartAt(earliestExpireTime, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogInfo("lease timer is stopped");
|
LogInfo("Lease timer is stopped");
|
||||||
mLeaseTimer.Stop();
|
mLeaseTimer.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1426,7 +1464,7 @@ void Server::HandleOutstandingUpdatesTimer(void)
|
|||||||
{
|
{
|
||||||
while (!mOutstandingUpdates.IsEmpty() && mOutstandingUpdates.GetTail()->GetExpireTime() <= TimerMilli::GetNow())
|
while (!mOutstandingUpdates.IsEmpty() && mOutstandingUpdates.GetTail()->GetExpireTime() <= TimerMilli::GetNow())
|
||||||
{
|
{
|
||||||
LogInfo("outstanding service update timeout (updateId = %u)", mOutstandingUpdates.GetTail()->GetId());
|
LogInfo("Outstanding service update timeout (updateId = %u)", mOutstandingUpdates.GetTail()->GetId());
|
||||||
HandleServiceUpdateResult(mOutstandingUpdates.GetTail(), kErrorResponseTimeout);
|
HandleServiceUpdateResult(mOutstandingUpdates.GetTail(), kErrorResponseTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1544,10 +1582,10 @@ exit:
|
|||||||
void Server::Service::Log(Action aAction) const
|
void Server::Service::Log(Action aAction) const
|
||||||
{
|
{
|
||||||
static const char *const kActionStrings[] = {
|
static const char *const kActionStrings[] = {
|
||||||
"add new", // (0) kAddNew
|
"Add new", // (0) kAddNew
|
||||||
"update existing", // (1) kUpdateExisting
|
"Update existing", // (1) kUpdateExisting
|
||||||
"remove but retain name of", // (2) kRemoveButRetainName
|
"Remove but retain name of", // (2) kRemoveButRetainName
|
||||||
"full remove", // (3) kFullyRemove
|
"Fully remove", // (3) kFullyRemove
|
||||||
"LEASE expired for ", // (4) kLeaseExpired
|
"LEASE expired for ", // (4) kLeaseExpired
|
||||||
"KEY LEASE expired for", // (5) kKeyLeaseExpired
|
"KEY LEASE expired for", // (5) kKeyLeaseExpired
|
||||||
};
|
};
|
||||||
@@ -1808,7 +1846,7 @@ Error Server::Host::MergeServicesAndResourcesFrom(Host &aHost)
|
|||||||
|
|
||||||
Error error = kErrorNone;
|
Error error = kErrorNone;
|
||||||
|
|
||||||
LogInfo("update host %s", GetFullName());
|
LogInfo("Update host %s", GetFullName());
|
||||||
|
|
||||||
mAddresses.TakeFrom(static_cast<Heap::Array<Ip6::Address> &&>(aHost.mAddresses));
|
mAddresses.TakeFrom(static_cast<Heap::Array<Ip6::Address> &&>(aHost.mAddresses));
|
||||||
mKeyRecord = aHost.mKeyRecord;
|
mKeyRecord = aHost.mKeyRecord;
|
||||||
@@ -1909,7 +1947,7 @@ Error Server::Host::AddIp6Address(const Ip6::Address &aIp6Address)
|
|||||||
|
|
||||||
if (error == kErrorNoBufs)
|
if (error == kErrorNoBufs)
|
||||||
{
|
{
|
||||||
LogWarn("too many addresses for host %s", GetFullName());
|
LogWarn("Too many addresses for host %s", GetFullName());
|
||||||
}
|
}
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|||||||
Reference in New Issue
Block a user