From 484134d818a88ebd486827d6106c5c9240f7ec30 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 6 Dec 2020 01:07:57 +0100 Subject: [PATCH] LookupServer: Put debug spam behind a macro --- CMakeLists.txt | 2 +- Services/LookupServer/DNSResponse.cpp | 8 +++++++- Services/LookupServer/LookupServer.cpp | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 300e14e6079..13b56feef0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,7 +62,7 @@ if (ALL_THE_DEBUG_MACROS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DICMP_DEBUG -DICO_DEBUG -DImage_DEBUG -DIMAGE_DECODER_CLIENT_DEBUG -DIMAGE_DECODER_DEBUG -DIMAGE_LOADER_DEBUG -DINTERPRETER_DEBUG -DINTERRUPT_DEBUG -DIOAPIC_DEBUG -DIPC_DEBUG -DIPV4_DEBUG -DIPV4_SOCKET_DEBUG -DIRC_DEBUG -DIRQ_DEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DJOB_DEBUG -DJPG_DEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DKEYBOARD_DEBUG -DKEYBOARD_SHORTCUTS_DEBUG -DKMALLOC_DEBUG_LARGE_ALLOCATIONS") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLEXER_DEBUG -DLoader_DEBUG -DLOCK_DEBUG") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLEXER_DEBUG -DLoader_DEBUG -DLOCK_DEBUG -DLOOKUPSERVER_DEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMALLOC_DEBUG -DMASTERPTY_DEBUG -DMBR_DEBUG -DMEMORY_DEBUG -DMENU_DEBUG -DMINIMIZE_ANIMATION_DEBUG -DMM_DEBUG -DMOVE_DEBUG -DMULTIPROCESSOR_DEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNETWORK_TASK_DEBUG -DNT_DEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOBJECT_DEBUG -DOCCLUSIONS_DEBUG -DOFFD_DEBUG") diff --git a/Services/LookupServer/DNSResponse.cpp b/Services/LookupServer/DNSResponse.cpp index cf8599ab2d4..1cb617d2227 100644 --- a/Services/LookupServer/DNSResponse.cpp +++ b/Services/LookupServer/DNSResponse.cpp @@ -62,11 +62,13 @@ Optional DNSResponse::from_raw_response(const u8* raw_data, size_t } auto& response_header = *(const DNSPacket*)(raw_data); +#ifdef LOOKUPSERVER_DEBUG dbgln("Got response (ID: {})", response_header.id()); dbgln(" Question count: {}", response_header.question_count()); dbgln(" Answer count: {}", response_header.answer_count()); dbgln(" Authority count: {}", response_header.authority_count()); dbgln("Additional count: {}", response_header.additional_count()); +#endif DNSResponse response; response.m_id = response_header.id(); @@ -85,9 +87,11 @@ Optional DNSResponse::from_raw_response(const u8* raw_data, size_t }; auto& record_and_class = *(const RawDNSAnswerQuestion*)&raw_data[offset]; response.m_questions.empend(name, record_and_class.record_type, record_and_class.class_code); - auto& question = response.m_questions.last(); offset += 4; +#ifdef LOOKUPSERVER_DEBUG + auto& question = response.m_questions.last(); dbgln("Question #{}: name=_{}_, type={}, class={}", i, question.name(), question.record_type(), question.class_code()); +#endif } for (u16 i = 0; i < response_header.answer_count(); ++i) { @@ -108,7 +112,9 @@ Optional DNSResponse::from_raw_response(const u8* raw_data, size_t // FIXME: Parse some other record types perhaps? dbgln("data=(unimplemented record type {})", record.type()); } +#ifdef LOOKUPSERVER_DEBUG dbgln("Answer #{}: name=_{}_, type={}, ttl={}, length={}, data=_{}_", i, name, record.type(), record.ttl(), record.data_length(), data); +#endif response.m_answers.empend(name, record.type(), record.record_class(), record.ttl(), data); offset += record.data_length(); } diff --git a/Services/LookupServer/LookupServer.cpp b/Services/LookupServer/LookupServer.cpp index 47608ec11a7..98edf066b5b 100644 --- a/Services/LookupServer/LookupServer.cpp +++ b/Services/LookupServer/LookupServer.cpp @@ -40,6 +40,8 @@ #include #include +//#define LOOKUPSERVER_DEBUG + LookupServer::LookupServer() { auto config = Core::ConfigFile::get_for_system("LookupServer"); @@ -114,7 +116,9 @@ void LookupServer::service_client(RefPtr socket) return; } auto hostname = String((const char*)client_buffer + 1, nrecv - 1, Chomp); +#ifdef LOOKUPSERVER_DEBUG dbgln("Got request for '{}'", hostname); +#endif Vector responses; @@ -122,7 +126,9 @@ void LookupServer::service_client(RefPtr socket) responses.append(known_host.value()); } else if (!hostname.is_empty()) { for (auto& nameserver : m_nameservers) { +#ifdef LOOKUPSERVER_DEBUG dbgln("Doing lookup using nameserver '{}'", nameserver); +#endif bool did_get_response = false; int retries = 3; do { @@ -171,7 +177,9 @@ Vector LookupServer::lookup(const String& hostname, const String& namese if (cached_lookup.question.record_type() == record_type) { Vector responses; for (auto& cached_answer : cached_lookup.answers) { +#ifdef LOOKUPSERVER_DEBUG dbgln("Cache hit: {} -> {}, expired: {}", hostname, cached_answer.record_data(), cached_answer.has_expired()); +#endif if (!cached_answer.has_expired()) responses.append(cached_answer.record_data()); }