diff options
author | Ryan Keane <rwkeane@google.com> | 2020-06-10 09:56:11 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-10 18:11:55 +0000 |
commit | 3e5d23e8ac3deb4e74be56249d181ae7b0f407d6 (patch) | |
tree | aee337e19db286c0e9d3200a9cacd968363dc44b /discovery | |
parent | 8299d3e32489592fc07764bb593629ba401e2331 (diff) | |
download | openscreen-3e5d23e8ac3deb4e74be56249d181ae7b0f407d6.tar.gz |
mDNS: Add more detailed logging
This CL adds more detailed logging to help debug ongoing issues.
bug: b/157683753
Change-Id: Ibee54a379c95773571cd3e7ec0095aa5f4ac9152
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2223828
Commit-Queue: Ryan Keane <rwkeane@google.com>
Reviewed-by: Jordan Bayles <jophba@chromium.org>
Diffstat (limited to 'discovery')
-rw-r--r-- | discovery/mdns/mdns_querier.cc | 9 | ||||
-rw-r--r-- | discovery/mdns/mdns_receiver.cc | 8 | ||||
-rw-r--r-- | discovery/mdns/mdns_records.cc | 31 | ||||
-rw-r--r-- | discovery/mdns/mdns_records.h | 2 | ||||
-rw-r--r-- | discovery/mdns/mdns_responder.cc | 17 |
5 files changed, 54 insertions, 13 deletions
diff --git a/discovery/mdns/mdns_querier.cc b/discovery/mdns/mdns_querier.cc index 800aef4a..7152be24 100644 --- a/discovery/mdns/mdns_querier.cc +++ b/discovery/mdns/mdns_querier.cc @@ -372,9 +372,7 @@ void MdnsQuerier::OnMessageReceived(const MdnsMessage& message) { for (const MdnsRecord& record : message.answers()) { if (ShouldAnswerRecordBeProcessed(record)) { ProcessRecord(record); - OSP_DVLOG << "\tProcessing answer record for domain '" - << record.name().ToString() << "' of type '" - << record.dns_type() << "'..."; + OSP_DVLOG << "\tProcessing answer record (" << record.ToString() << ")"; found_relevant_records = true; processed_count++; } @@ -385,9 +383,8 @@ void MdnsQuerier::OnMessageReceived(const MdnsMessage& message) { // individual records relevant to this querier to update the cache. for (const MdnsRecord& record : message.additional_records()) { if (found_relevant_records || ShouldAnswerRecordBeProcessed(record)) { - OSP_DVLOG << "\tProcessing additional record for domain '" - << record.name().ToString() << "' of type '" - << record.dns_type() << "'..."; + OSP_DVLOG << "\tProcessing additional record (" << record.ToString() + << ")"; ProcessRecord(record); processed_count++; } diff --git a/discovery/mdns/mdns_receiver.cc b/discovery/mdns/mdns_receiver.cc index b21d748f..bb8634d2 100644 --- a/discovery/mdns/mdns_receiver.cc +++ b/discovery/mdns/mdns_receiver.cc @@ -4,6 +4,8 @@ #include "discovery/mdns/mdns_receiver.h" +#include <utility> + #include "discovery/mdns/mdns_reader.h" #include "util/trace_logging.h" @@ -66,6 +68,7 @@ void MdnsReceiver::OnRead(UdpSocket* socket, MdnsReader reader(config_, packet.data(), packet.size()); MdnsMessage message; if (!reader.Read(&message)) { + OSP_DVLOG << "mDNS message failed to parse..."; return; } @@ -74,13 +77,14 @@ void MdnsReceiver::OnRead(UdpSocket* socket, client->OnMessageReceived(message); } if (response_clients_.empty()) { - OSP_DVLOG << "Response message dropped. No response client registered..."; + OSP_DVLOG + << "mDNS response message dropped. No response client registered..."; } } else { if (query_callback_) { query_callback_(message, packet.source()); } else { - OSP_DVLOG << "Query message dropped. No query client registered..."; + OSP_DVLOG << "mDNS query message dropped. No query client registered..."; } } } diff --git a/discovery/mdns/mdns_records.cc b/discovery/mdns/mdns_records.cc index a04c2694..8be7fe00 100644 --- a/discovery/mdns/mdns_records.cc +++ b/discovery/mdns/mdns_records.cc @@ -5,6 +5,9 @@ #include "discovery/mdns/mdns_records.h" #include <cctype> +#include <limits> +#include <sstream> +#include <vector> #include "absl/strings/ascii.h" #include "absl/strings/match.h" @@ -562,6 +565,34 @@ size_t MdnsRecord::MaxWireSize() const { return name_.MaxWireSize() + absl::visit(wire_size_visitor, rdata_) + 8; } +std::string MdnsRecord::ToString() const { + std::stringstream ss; + ss << "name: '" << name_.ToString() << "'"; + ss << ", type: " << dns_type_; + + if (dns_type_ == DnsType::kPTR) { + const DomainName& target = absl::get<PtrRecordRdata>(rdata_).ptr_domain(); + ss << ", target: '" << target.ToString() << "'"; + } else if (dns_type_ == DnsType::kSRV) { + const DomainName& target = absl::get<SrvRecordRdata>(rdata_).target(); + ss << ", target: '" << target.ToString() << "'"; + } else if (dns_type_ == DnsType::kNSEC) { + const auto& nsec_rdata = absl::get<NsecRecordRdata>(rdata_); + std::vector<DnsType> types = nsec_rdata.types(); + ss << ", representing ["; + if (!types.empty()) { + auto it = types.begin(); + ss << *it++; + while (it != types.end()) { + ss << ", " << *it++; + } + ss << "]"; + } + } + + return ss.str(); +} + MdnsRecord CreateAddressRecord(DomainName name, const IPAddress& address) { Rdata rdata; DnsType type; diff --git a/discovery/mdns/mdns_records.h b/discovery/mdns/mdns_records.h index 8e9ac244..696eaf8c 100644 --- a/discovery/mdns/mdns_records.h +++ b/discovery/mdns/mdns_records.h @@ -419,6 +419,8 @@ class MdnsRecord { record.ttl_.count(), record.rdata_); } + std::string ToString() const; + private: static bool IsValidConfig(const DomainName& name, DnsType dns_type, diff --git a/discovery/mdns/mdns_responder.cc b/discovery/mdns/mdns_responder.cc index 3627f2fd..faef9a18 100644 --- a/discovery/mdns/mdns_responder.cc +++ b/discovery/mdns/mdns_responder.cc @@ -513,7 +513,7 @@ void MdnsResponder::ProcessQueries( for (const auto& question : questions) { OSP_DVLOG << "\tProcessing mDNS Query for domain: '" << question.name().ToString() << "', type: '" - << question.dns_type() << "'"; + << question.dns_type() << "' from '" << src << "'"; // NSEC records should not be queried for. if (question.dns_type() == DnsType::kNSEC) { @@ -586,18 +586,25 @@ void MdnsResponder::SendResponse( // method is called. Exclusive ownership cannot be gained for a record which // has previously been published, and if this host is the exclusive owner // then this method will have been called without any delay on the task - // runner + // runner. ApplyQueryResults(&message, record_handler_, question.name(), known_answers, question.dns_type(), question.dns_class(), is_exclusive_owner); } // Send the response only if it contains answers to the query. + OSP_DVLOG << "\tCompleted Processing mDNS Query for domain: '" + << question.name().ToString() << "', type: '" << question.dns_type() + << "', with " << message.answers().size() << " results:"; + for (const auto& record : message.answers()) { + OSP_DVLOG << "\t\tanswer (" << record.ToString() << ")"; + } + for (const auto& record : message.additional_records()) { + OSP_DVLOG << "\t\tadditional record ('" << record.ToString() << ")"; + } + if (!message.answers().empty()) { - OSP_DVLOG << "\tmDNS Query processed and response sent!"; send_response(message); - } else { - OSP_DVLOG << "\tmDNS Query processed and no response sent!"; } } |