From: Otto Moerbeek Date: Mon, 21 Feb 2022 15:11:37 +0000 (+0100) Subject: Drop queries with packet types we do not like. X-Git-Tag: rec-4.7.0-alpha1~5^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cfbcc0f3891e5a62cef7a0258056fad8dbfcdf47;p=thirdparty%2Fpdns.git Drop queries with packet types we do not like. While working on this, I noticed inconsistencies between UDP and TDP logging: 1 uses g_quiet, the other g_logCommonErrors. This needs to be revisited. Also: the use of MT->getTid() seems strange, as it is used in places where no mthread has been started yet in doProcessUDPQuestion() and handleRunningTCPQuestion(). That is, unless I'm missing something. --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 8d07675df7..2e7093995c 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -1999,6 +1999,16 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr } auto dc = std::make_unique(question, g_now, std::move(policyTags), t_pdl, std::move(data), std::move(records)); + + if (SyncRes::isUnsupported(dc->d_mdp.d_qtype)) { + g_stats.ignoredCount++; + if (!g_quiet) { + g_log << Logger::Notice << RecThreadInfo::id() << " Unsupported qtype " << dc->d_mdp.d_qtype << " from " << source.toStringWithPort() << (source != fromaddr ? " (via " + fromaddr.toStringWithPort() + ")" : "") << endl; + } + + return 0; + } + dc->setSocket(fd); dc->d_tag = ctag; dc->d_qhash = qhash; diff --git a/pdns/recursordist/rec-taskqueue.cc b/pdns/recursordist/rec-taskqueue.cc index 1e6593006a..883b26087d 100644 --- a/pdns/recursordist/rec-taskqueue.cc +++ b/pdns/recursordist/rec-taskqueue.cc @@ -181,13 +181,8 @@ void runTaskOnce(bool logErrors) void pushAlmostExpiredTask(const DNSName& qname, uint16_t qtype, time_t deadline) { - switch (qtype) { - // Internal types - case QType::ENT: - case QType::ADDR: - case QType::ALIAS: - case QType::LUA: - g_log << Logger::Debug << "Cannot push task for " << QType(qtype).toString() << endl; + if (SyncRes::isUnsupported(qtype)) { + g_log << Logger::Error << "Cannot push task for " << QType(qtype).toString() << endl; return; } pdns::ResolveTask task{qname, qtype, deadline, true, resolve}; diff --git a/pdns/recursordist/rec-tcp.cc b/pdns/recursordist/rec-tcp.cc index 807b3dce1c..9e46bf7c1e 100644 --- a/pdns/recursordist/rec-tcp.cc +++ b/pdns/recursordist/rec-tcp.cc @@ -338,6 +338,14 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var) } return; } + if (SyncRes::isUnsupported(dc->d_mdp.d_qtype)) { + g_stats.ignoredCount++; + if (g_logCommonErrors) { + g_log << Logger::Error << "Unsupported qtype " << dc->d_mdp.d_qtype << " from TCP client " << conn->d_remote.toStringWithPort() << endl; + } + return; + } + dc->d_tcpConnection = conn; // carry the torch dc->setSocket(conn->getFD()); // this is the only time a copy is made of the actual fd dc->d_tcp = true; diff --git a/pdns/syncres.hh b/pdns/syncres.hh index dddf299e95..815724e355 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -736,6 +736,19 @@ public: d_queryReceivedOverTCP = tcp; } + static bool isUnsupported(QType qtype) + { + switch (qtype.getCode()) { + // Internal types + case QType::ENT: + case QType::ADDR: + case QType::ALIAS: + case QType::LUA: + return true; + } + return false; + } + static thread_local ThreadLocalStorage t_sstorage; static pdns::stat_t s_queries;