-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make minmdns be move verbose in terms of packets sent and received. (#…
…18566) * Add some log points for minmdns parsing * Log when operational/commission records were found * Log IP addresses as well * Update logging for resource data a bit to be less repeating * Conditional compile on progress logging * code clarity: add endif * Restyle
- Loading branch information
Showing
6 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <lib/dnssd/minimal_mdns/Logging.h> | ||
#include <lib/support/StringBuilder.h> | ||
#include <lib/support/logging/CHIPLogging.h> | ||
|
||
namespace mdns { | ||
namespace Minimal { | ||
namespace Logging { | ||
|
||
namespace { | ||
|
||
#if CHIP_PROGRESS_LOGGING | ||
|
||
const char * QueryTypeToString(mdns::Minimal::QType type) | ||
{ | ||
// NOTE: not all values are handled, only things that matter | ||
// and minmdns really cares about | ||
switch (type) | ||
{ | ||
case QType::A: | ||
return "A"; | ||
case QType::PTR: | ||
return "PTR"; | ||
case QType::TXT: | ||
return "TXT"; | ||
case QType::AAAA: | ||
return "AAAA"; | ||
case QType::SRV: | ||
return "SRV"; | ||
case QType::ANY: | ||
return "ANY"; | ||
default: | ||
// Not reentrant, however our logging is in the chip thread so seems ok. | ||
static char buff[16]; | ||
snprintf(buff, sizeof(buff), "(%d)", static_cast<int>(type)); | ||
return buff; | ||
} | ||
} | ||
|
||
#endif // CHIP_PROGRESS_LOGGING | ||
|
||
class QNameString | ||
{ | ||
public: | ||
QNameString(const mdns::Minimal::FullQName & name) | ||
{ | ||
for (unsigned i = 0; i < name.nameCount; i++) | ||
{ | ||
if (i != 0) | ||
{ | ||
mBuffer.Add("."); | ||
} | ||
mBuffer.Add(name.names[i]); | ||
} | ||
} | ||
|
||
QNameString(mdns::Minimal::SerializedQNameIterator name) | ||
{ | ||
bool first = true; | ||
while (name.Next()) | ||
{ | ||
if (first) | ||
{ | ||
first = false; | ||
} | ||
else | ||
{ | ||
mBuffer.Add("."); | ||
} | ||
mBuffer.Add(name.Value()); | ||
} | ||
if (!name.IsValid()) | ||
{ | ||
mBuffer.Add("(!INVALID!)"); | ||
} | ||
} | ||
|
||
const char * c_str() const { return mBuffer.c_str(); } | ||
|
||
bool Fit() const { return mBuffer.Fit(); } | ||
|
||
private: | ||
static constexpr size_t kMaxQNameLength = 128; | ||
chip::StringBuilder<kMaxQNameLength> mBuffer; | ||
}; | ||
|
||
} // namespace | ||
|
||
void LogSendingQuery(const mdns::Minimal::Query & query) | ||
{ | ||
QNameString name(query.GetName()); | ||
|
||
ChipLogProgress(Discovery, "MINMDNS: Sending query %s/%s for %s%s", QueryTypeToString(query.GetType()), | ||
query.IsAnswerViaUnicast() ? "UNICAST" : "MULTICAST", name.c_str(), name.Fit() ? "" : "..."); | ||
} | ||
|
||
void LogReceivedResource(const mdns::Minimal::ResourceData & data) | ||
{ | ||
QNameString name(data.GetName()); | ||
|
||
ChipLogProgress(Discovery, "MINMDNS: received %s record for %s%s", QueryTypeToString(data.GetType()), name.c_str(), | ||
name.Fit() ? "" : "..."); | ||
} | ||
|
||
void LogFoundOperationalSrvRecord(const chip::PeerId & peerId, const mdns::Minimal::SerializedQNameIterator & targetHost) | ||
{ | ||
QNameString host(targetHost); | ||
|
||
ChipLogProgress(Discovery, "MINMDNS: Operational SRV for " ChipLogFormatX64 "-" ChipLogFormatX64 ": %s", | ||
ChipLogValueX64(peerId.GetCompressedFabricId()), ChipLogValueX64(peerId.GetNodeId()), host.c_str()); | ||
} | ||
|
||
void LogFoundCommissionSrvRecord(const char * instance, const mdns::Minimal::SerializedQNameIterator & targetHost) | ||
{ | ||
QNameString host(targetHost); | ||
|
||
ChipLogProgress(Discovery, "MINMDNS: Commission SRV for instance %s: %s", instance, host.c_str()); | ||
} | ||
|
||
void LogFoundIPAddress(const mdns::Minimal::SerializedQNameIterator & targetHost, const chip::Inet::IPAddress & addr) | ||
{ | ||
QNameString host(targetHost); | ||
char ipBuff[chip::Inet::IPAddress::kMaxStringLength]; | ||
|
||
addr.ToString(ipBuff); | ||
|
||
ChipLogProgress(Discovery, "MINMDNS: IP address %s found for %s%s", ipBuff, host.c_str(), host.Fit() ? "" : "..."); | ||
} | ||
|
||
} // namespace Logging | ||
} // namespace Minimal | ||
} // namespace mdns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
|
||
#include <inet/IPAddress.h> | ||
#include <lib/core/PeerId.h> | ||
#include <lib/dnssd/minimal_mdns/Parser.h> | ||
#include <lib/dnssd/minimal_mdns/Query.h> | ||
|
||
namespace mdns { | ||
namespace Minimal { | ||
|
||
/// Provides potentially verbose logging for DNSSD operations when using | ||
/// MinMdns. | ||
namespace Logging { | ||
|
||
#if CHIP_MINMDNS_HIGH_VERBOSITY | ||
|
||
void LogSendingQuery(const mdns::Minimal::Query & query); | ||
void LogReceivedResource(const mdns::Minimal::ResourceData & data); | ||
void LogFoundOperationalSrvRecord(const chip::PeerId & peerId, const mdns::Minimal::SerializedQNameIterator & targetHost); | ||
void LogFoundCommissionSrvRecord(const char * instance, const mdns::Minimal::SerializedQNameIterator & targetHost); | ||
void LogFoundIPAddress(const mdns::Minimal::SerializedQNameIterator & targetHost, const chip::Inet::IPAddress & addr); | ||
|
||
#else | ||
|
||
inline void LogSendingQuery(const mdns::Minimal::Query & query) {} | ||
inline void LogReceivedResource(const mdns::Minimal::ResourceData & data) {} | ||
inline void LogFoundOperationalSrvRecord(const chip::PeerId & peerId, const mdns::Minimal::SerializedQNameIterator & targetHost) {} | ||
inline void LogFoundCommissionSrvRecord(const char * instance, const mdns::Minimal::SerializedQNameIterator & targetHost) {} | ||
inline void LogFoundIPAddress(const mdns::Minimal::SerializedQNameIterator & targetHost, const chip::Inet::IPAddress & addr) {} | ||
|
||
#endif | ||
|
||
} // namespace Logging | ||
} // namespace Minimal | ||
} // namespace mdns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters