From: Alex Rousskov Date: Sun, 20 Oct 2019 07:35:40 +0000 (+0000) Subject: Preserve caller context across DNS lookups (#496) X-Git-Tag: SQUID_5_0_1~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cd2a20f7187c727447c008891c18f9f5f780618d;p=thirdparty%2Fsquid.git Preserve caller context across DNS lookups (#496) For now, the context is restored when communicating with _individual_ callers waiting for their DNS lookup results. Eventually, we might also support establishing a multi-caller context during DNS answer parsing, before individual callers are notified. That feature would most likely require making idns_query refcount-based (a serious change). Or we could realize that maintaining a very basic query ID-based context is enough. --- diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 10fcb486a3..30502dc210 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -9,6 +9,7 @@ /* DEBUG: section 78 DNS lookups; interacts with dns/rfc1035.cc */ #include "squid.h" +#include "base/CodeContext.h" #include "base/InstanceId.h" #include "base/RunnersRegistry.h" #include "comm.h" @@ -103,7 +104,9 @@ class idns_query CBDATA_CLASS(idns_query); public: - idns_query() { + idns_query(): + codeContext(CodeContext::Current()) + { callback = nullptr; memset(&query, 0, sizeof(query)); *buf = 0; @@ -141,8 +144,11 @@ public: struct timeval sent_t; struct timeval queue_t; dlink_node lru; + IDNSCB *callback; void *callback_data = nullptr; + CodeContext::Pointer codeContext; ///< requestor's context + int attempt = 0; int rcode = 0; idns_query *queue = nullptr; @@ -1104,6 +1110,7 @@ idnsCallbackNewCallerWithOldAnswers(IDNSCB *callback, void *cbdata, const idns_q for (auto query = master; query; query = query->slave) { if (query->pending) continue; // no answer yet + // no CallBack(CodeContext...) -- we always run in requestor's context if (!idnsCallbackOneWithAnswer(callback, cbdata, *query, lastAnswer)) break; // the caller disappeared } @@ -1116,8 +1123,10 @@ idnsCallbackAllCallersWithNewAnswer(const idns_query * const answered, const boo const auto master = answered->master ? answered->master : answered; // iterate all queued lookup callers for (auto looker = master; looker; looker = looker->queue) { - (void)idnsCallbackOneWithAnswer(looker->callback, looker->callback_data, - *answered, lastAnswer); + CallBack(looker->codeContext, [&] { + (void)idnsCallbackOneWithAnswer(looker->callback, looker->callback_data, + *answered, lastAnswer); + }); } }