From: Remi Gacogne Date: Fri, 12 Nov 2021 14:59:13 +0000 (+0100) Subject: dnsdist: Disable deprecated DynBlock methods when DISABLE_DEPRECATED_DYNBLOCK is... X-Git-Tag: auth-4.7.0-alpha1~103^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc3eafdc6385fbd8fe2ec91bb3ef7edfd64a48fc;p=thirdparty%2Fpdns.git dnsdist: Disable deprecated DynBlock methods when DISABLE_DEPRECATED_DYNBLOCK is defined --- diff --git a/pdns/dnsdist-lua-inspection.cc b/pdns/dnsdist-lua-inspection.cc index 451682a97e..a365698c5a 100644 --- a/pdns/dnsdist-lua-inspection.cc +++ b/pdns/dnsdist-lua-inspection.cc @@ -28,7 +28,7 @@ #include "statnode.hh" -static std::unordered_map>> getGenResponses(unsigned int top, boost::optional labels, std::function pred) +static std::vector>>> getGenResponses(uint64_t top, boost::optional labels, std::function pred) { setLuaNoSideEffect(); map counts; @@ -69,25 +69,29 @@ static std::unordered_map>> g return b.first < a.first; }); - std::unordered_map>> ret; - unsigned int count=1, rest=0; + std::vector>>> ret; + ret.reserve(std::min(rcounts.size(), top + 1U)); + uint64_t count = 1; + unsigned int rest = 0; for(const auto& rc : rcounts) { if(count==top+1) rest+=rc.first; else - ret.insert({count++, {rc.second.toString(), rc.first, 100.0*rc.first/total}}); + ret.push_back({count++, {rc.second.toString(), rc.first, 100.0*rc.first/total}}); } if (total > 0) { - ret.insert({count, {"Rest", rest, 100.0*rest/total}}); + ret.push_back({count, {"Rest", rest, 100.0*rest/total}}); } else { - ret.insert({count, {"Rest", rest, 100.0 }}); + ret.push_back({count, {"Rest", rest, 100.0 }}); } return ret; } +#ifndef DISABLE_DEPRECATED_DYNBLOCK + typedef std::unordered_map counts_t; static counts_t filterScore(const counts_t& counts, @@ -105,10 +109,9 @@ static counts_t filterScore(const counts_t& counts, return ret; } - typedef std::function statvisitor_t; -static void statNodeRespRing(statvisitor_t visitor, unsigned int seconds) +static void statNodeRespRing(statvisitor_t visitor, uint64_t seconds) { struct timespec cutoff, now; gettime(&now); @@ -135,22 +138,23 @@ static void statNodeRespRing(statvisitor_t visitor, unsigned int seconds) visitor(*node_, self, children);}, node); } -static vector > > getRespRing(boost::optional rcode) +static vector > > > getRespRing(boost::optional rcode) { - typedef std::unordered_map entry_t; - vector > ret; + typedef std::vector> entry_t; + vector > ret; for (const auto& shard : g_rings.d_shards) { auto rl = shard->respRing.lock(); - entry_t e; - unsigned int count=1; - for(const auto& c : *rl) { - if(rcode && (rcode.get() != c.dh.rcode)) + int count = 1; + for (const auto& c : *rl) { + if (rcode && (rcode.get() != c.dh.rcode)) { continue; - e["qname"]=c.name.toString(); - e["rcode"]=std::to_string(c.dh.rcode); - ret.emplace_back(count, e); + } + entry_t e; + e.push_back({ "qname", c.name.toString() }); + e.push_back({ "rcode", std::to_string(c.dh.rcode) }); + ret.emplace_back(count, std::move(e)); count++; } } @@ -232,9 +236,11 @@ static counts_t exceedRespByterate(unsigned int rate, int seconds) }); } +#endif /* DISABLE_DEPRECATED_DYNBLOCK */ + void setupLuaInspection(LuaContext& luaCtx) { - luaCtx.writeFunction("topClients", [](boost::optional top_) { + luaCtx.writeFunction("topClients", [](boost::optional top_) { setLuaNoSideEffect(); auto top = top_.get_value_or(10); map counts; @@ -268,7 +274,7 @@ void setupLuaInspection(LuaContext& luaCtx) g_outputBuffer += (fmt % (count) % "Rest" % rest % (total > 0 ? 100.0*rest/total : 100.0)).str(); }); - luaCtx.writeFunction("getTopQueries", [](unsigned int top, boost::optional labels) { + luaCtx.writeFunction("getTopQueries", [](uint64_t top, boost::optional labels) { setLuaNoSideEffect(); map counts; unsigned int total=0; @@ -352,21 +358,21 @@ void setupLuaInspection(LuaContext& luaCtx) return ret; }); - luaCtx.writeFunction("getTopResponses", [](unsigned int top, unsigned int kind, boost::optional labels) { + luaCtx.writeFunction("getTopResponses", [](uint64_t top, uint64_t kind, boost::optional labels) { return getGenResponses(top, labels, [kind](const Rings::Response& r) { return r.dh.rcode == kind; }); }); luaCtx.executeCode(R"(function topResponses(top, kind, labels) top = top or 10; kind = kind or 0; for k,v in ipairs(getTopResponses(top, kind, labels)) do show(string.format("%4d %-40s %4d %4.1f%%",k,v[1],v[2],v[3])) end end)"); - luaCtx.writeFunction("getSlowResponses", [](unsigned int top, unsigned int msec, boost::optional labels) { + luaCtx.writeFunction("getSlowResponses", [](uint64_t top, uint64_t msec, boost::optional labels) { return getGenResponses(top, labels, [msec](const Rings::Response& r) { return r.usec > msec*1000; }); }); luaCtx.executeCode(R"(function topSlow(top, msec, labels) top = top or 10; msec = msec or 500; for k,v in ipairs(getSlowResponses(top, msec, labels)) do show(string.format("%4d %-40s %4d %4.1f%%",k,v[1],v[2],v[3])) end end)"); - luaCtx.writeFunction("getTopBandwidth", [](unsigned int top) { + luaCtx.writeFunction("getTopBandwidth", [](uint64_t top) { setLuaNoSideEffect(); return g_rings.getTopBandwidth(top); }); @@ -710,6 +716,7 @@ void setupLuaInspection(LuaContext& luaCtx) } }); +#ifndef DISABLE_DEPRECATED_DYNBLOCK luaCtx.writeFunction("exceedServFails", [](unsigned int rate, int seconds) { setLuaNoSideEffect(); return exceedRCode(rate, seconds, RCode::ServFail); @@ -755,9 +762,10 @@ void setupLuaInspection(LuaContext& luaCtx) luaCtx.registerMember("drops", &StatNode::Stat::drops); luaCtx.registerMember("bytes", &StatNode::Stat::bytes); - luaCtx.writeFunction("statNodeRespRing", [](statvisitor_t visitor, boost::optional seconds) { - statNodeRespRing(visitor, seconds ? *seconds : 0); + luaCtx.writeFunction("statNodeRespRing", [](statvisitor_t visitor, boost::optional seconds) { + statNodeRespRing(visitor, seconds ? *seconds : 0U); }); +#endif /* DISABLE_DEPRECATED_DYNBLOCK */ /* DynBlockRulesGroup */ luaCtx.writeFunction("dynBlockRulesGroup", []() { return std::make_shared(); });