From: Otto Date: Thu, 19 Aug 2021 09:46:49 +0000 (+0200) Subject: Basic runtime global enabling/disabling of event traces via setting and rec_control X-Git-Tag: dnsdist-1.7.0-alpha2~9^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0416940be1a23f03369b3f096451527bfeea456a;p=thirdparty%2Fpdns.git Basic runtime global enabling/disabling of event traces via setting and rec_control --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index b78753ad16..adc9953993 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1109,7 +1109,7 @@ static void protobufLogResponse(const struct dnsheader* dh, LocalStateHolderd_logResponse) { @@ -2344,7 +2344,7 @@ static void startDoResolve(void *p) } } - if (sr.d_eventTrace.enabled()) { + if (sr.d_eventTrace.enabled() && SyncRes::s_event_trace_enabled & SyncRes::event_trace_to_log) { g_log << Logger::Info << sr.d_eventTrace.toString() << endl; } @@ -2749,7 +2749,7 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var) bool logQuery = false; bool qnameParsed = false; - dc->d_eventTrace.setEnabled(true); + dc->d_eventTrace.setEnabled(SyncRes::s_event_trace_enabled); dc->d_eventTrace.add(RecEventTrace::RecRecv); auto luaconfsLocal = g_luaconfs.getLocal(); if (checkProtobufExport(luaconfsLocal)) { @@ -2902,7 +2902,7 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var) protobufLogResponse(dh, luaconfsLocal, pbData, tv, true, dc->d_source, dc->d_destination, dc->d_ednssubnet, dc->d_uuid, dc->d_requestorId, dc->d_deviceId, dc->d_deviceName, dc->d_meta, dc->d_eventTrace); } - if (dc->d_eventTrace.enabled()) { + if (dc->d_eventTrace.enabled() && SyncRes::s_event_trace_enabled & SyncRes::event_trace_to_log) { g_log << Logger::Info << dc->d_eventTrace.toString() << endl; } } else { @@ -3153,7 +3153,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr protobufLogResponse(dh, luaconfsLocal, pbData, tv, false, source, destination, ednssubnet, uniqueId, requestorId, deviceId, deviceName, meta, eventTrace); } - if (eventTrace.enabled()) { + if (eventTrace.enabled() && SyncRes::s_event_trace_enabled & SyncRes::event_trace_to_log) { g_log << Logger::Info << eventTrace.toString() << endl; } if (sendErr && g_logCommonErrors) { @@ -3258,7 +3258,7 @@ static void handleNewUDPQuestion(int fd, FDMultiplexer::funcparam_t& var) if((len=recvmsg(fd, &msgh, 0)) >= 0) { eventTrace.clear(); - eventTrace.setEnabled(true); + eventTrace.setEnabled(SyncRes::s_event_trace_enabled); eventTrace.add(RecEventTrace::RecRecv); firstQuery = false; @@ -4981,6 +4981,7 @@ static int serviceMain(int argc, char*argv[]) SyncRes::s_tcp_fast_open_connect = ::arg().mustDo("tcp-fast-open-connect"); SyncRes::s_dot_to_port_853 = ::arg().mustDo("dot-to-port-853"); + SyncRes::s_event_trace_enabled = ::arg().asNum("event-trace-enabled"); if (SyncRes::s_tcp_fast_open_connect) { checkFastOpenSysctl(true); @@ -5999,6 +6000,7 @@ int main(int argc, char **argv) ::arg().setSwitch("dot-to-port-853", "Force DoT connection to target port 853 if DoT compiled in")="yes"; ::arg().set("dot-to-auth-names", "Use DoT to authoritative servers with these names or suffixes")=""; + ::arg().set("event-trace-enabled", "If set, event traces are collected and send out via protobuf logging (1), logfile (2) or both(3)")="0"; ::arg().set("tcp-out-max-idle-ms", "Time TCP/DoT connections are left idle in milliseconds or 0 if no limit") = "10000"; ::arg().set("tcp-out-max-idle-per-auth", "Maximum number of idle TCP/DoT connections to a specific IP per thread, 0 means do not keep idle connections open") = "10"; diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index d19d719b0c..dbc3a15355 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -1882,6 +1882,20 @@ static string clearDontThrottleNetmasks(T begin, T end) { return ret + "\n"; } +template +static string setEventTracing(T begin, T end) +{ + if (begin == end) { + return "No event trace enabled value specified\n"; + } + try { + SyncRes::s_event_trace_enabled = pdns_stou(*begin); + return "New event trace enabled value: " + std::to_string(SyncRes::s_event_trace_enabled) + "\n"; + } + catch (const std::exception& e) { + return "Error parsing the new event trace enabled value: " + std::string(e.what()) + "\n"; + } +} RecursorControlChannel::Answer RecursorControlParser::getAnswer(int s, const string& question, RecursorControlParser::func_t** command) { @@ -1940,6 +1954,7 @@ RecursorControlChannel::Answer RecursorControlParser::getAnswer(int s, const str "set-minimum-ttl value set minimum-ttl-override\n" "set-carbon-server set a carbon server for telemetry\n" "set-dnssec-log-bogus SETTING enable (SETTING=yes) or disable (SETTING=no) logging of DNSSEC validation failures\n" +"set-event-trace-enabled SETTING set logging of event trace messages, 0 = disabled, 1 = prottobuf, 2 = log file, 3 = both\n" "trace-regex [regex] emit resolution trace for matching queries (empty regex to clear trace)\n" "top-largeanswer-remotes show top remotes receiving large answers\n" "top-queries show top queries\n" @@ -2157,6 +2172,9 @@ RecursorControlChannel::Answer RecursorControlParser::getAnswer(int s, const str if (cmd == "clear-dont-throttle-netmasks") { return {0, clearDontThrottleNetmasks(begin, end)}; } + if (cmd == "set-event-trace-enabled") { + return {0, setEventTracing(begin, end)}; + } return {1, "Unknown command '"+cmd+"', try 'help'\n"}; } diff --git a/pdns/syncres.cc b/pdns/syncres.cc index b73f21ac30..55c13620ff 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -100,6 +100,7 @@ unsigned int SyncRes::s_refresh_ttlperc; int SyncRes::s_tcp_fast_open; bool SyncRes::s_tcp_fast_open_connect; bool SyncRes::s_dot_to_port_853; +int SyncRes::s_event_trace_enabled; #define LOG(x) if(d_lm == Log) { g_log < d_discardedPolicies; DNSFilterEngine::Policy d_appliedPolicy; std::unordered_set d_policyTags;