From 2087df406742a3d58f219d8fdae840417632c58f Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Mon, 3 Feb 2020 12:15:25 +0100 Subject: [PATCH] WIP for researching #8697 --- pdns/rec_channel_rec.cc | 41 +++++++++++-------- .../docs/manpages/rec_control.1.rst | 3 ++ pdns/reczones.cc | 6 +-- pdns/syncres.cc | 6 ++- pdns/syncres.hh | 4 +- pdns/ws-recursor.cc | 4 +- 6 files changed, 39 insertions(+), 25 deletions(-) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 5acc418519..a37d4cbc89 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -394,14 +394,14 @@ static string doDumpFailedServers(T begin, T end) return "dumped "+std::to_string(total)+" records\n"; } -uint64_t* pleaseWipeCache(const DNSName& canon, bool subtree) +uint64_t* pleaseWipeCache(const DNSName& canon, bool subtree, uint16_t qtype) { - return new uint64_t(t_RC->doWipeCache(canon, subtree)); + return new uint64_t(t_RC->doWipeCache(canon, subtree, qtype)); } -uint64_t* pleaseWipePacketCache(const DNSName& canon, bool subtree) +uint64_t* pleaseWipePacketCache(const DNSName& canon, bool subtree, uint16_t qtype) { - return new uint64_t(t_packetCache->doWipePacketCache(canon,0xffff, subtree)); + return new uint64_t(t_packetCache->doWipePacketCache(canon, qtype, subtree)); } @@ -413,7 +413,7 @@ uint64_t* pleaseWipeAndCountNegCache(const DNSName& canon, bool subtree) template -static string doWipeCache(T begin, T end) +static string doWipeCache(T begin, T end, uint16_t qtype) { vector > toWipe; for(T i=begin; i != end; ++i) { @@ -435,8 +435,8 @@ static string doWipeCache(T begin, T end) int count=0, pcount=0, countNeg=0; for (auto wipe : toWipe) { - count+= broadcastAccFunction(boost::bind(pleaseWipeCache, wipe.first, wipe.second)); - pcount+= broadcastAccFunction(boost::bind(pleaseWipePacketCache, wipe.first, wipe.second)); + count+= broadcastAccFunction(boost::bind(pleaseWipeCache, wipe.first, wipe.second, qtype)); + pcount+= broadcastAccFunction(boost::bind(pleaseWipePacketCache, wipe.first, wipe.second, qtype)); countNeg+=broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, wipe.first, wipe.second)); } @@ -538,8 +538,8 @@ static string doAddNTA(T begin, T end) g_luaconfs.modify([who, why](LuaConfigItems& lci) { lci.negAnchors[who] = why; }); - broadcastAccFunction(boost::bind(pleaseWipeCache, who, true)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, who, true)); + broadcastAccFunction(boost::bind(pleaseWipeCache, who, true, 0xffff)); + broadcastAccFunction(boost::bind(pleaseWipePacketCache, who, true, 0xffff)); broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, who, true)); return "Added Negative Trust Anchor for " + who.toLogString() + " with reason '" + why + "'\n"; } @@ -586,8 +586,8 @@ static string doClearNTA(T begin, T end) g_luaconfs.modify([entry](LuaConfigItems& lci) { lci.negAnchors.erase(entry); }); - broadcastAccFunction(boost::bind(pleaseWipeCache, entry, true)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, entry, true)); + broadcastAccFunction(boost::bind(pleaseWipeCache, entry, true, 0xffff)); + broadcastAccFunction(boost::bind(pleaseWipePacketCache, entry, true, 0xffff)); broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, entry, true)); if (!first) { first = false; @@ -643,8 +643,8 @@ static string doAddTA(T begin, T end) auto ds=std::dynamic_pointer_cast(DSRecordContent::make(what)); lci.dsAnchors[who].insert(*ds); }); - broadcastAccFunction(boost::bind(pleaseWipeCache, who, true)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, who, true)); + broadcastAccFunction(boost::bind(pleaseWipeCache, who, true, 0xffff)); + broadcastAccFunction(boost::bind(pleaseWipePacketCache, who, true, 0xffff)); broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, who, true)); g_log<(boost::bind(pleaseWipeCache, entry, true)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, entry, true)); + broadcastAccFunction(boost::bind(pleaseWipeCache, entry, true, 0xffff)); + broadcastAccFunction(boost::bind(pleaseWipePacketCache, entry, true, 0xffff)); broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, entry, true)); if (!first) { first = false; @@ -1690,7 +1690,8 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP "top-bogus-remotes show top remotes receiving bogus answers\n" "unload-lua-script unload Lua script\n" "version return Recursor version number\n" -"wipe-cache domain0 [domain1] .. wipe domain data from cache\n"; +"wipe-cache domain0 [domain1] .. wipe domain data from cache\n" +"wipe-cache-typed type domain0 [domain1] .. wipe domain data with qtype from cache\n"; if(cmd=="get-all") return getAllStats(); @@ -1735,7 +1736,13 @@ string RecursorControlParser::getAnswer(const string& question, RecursorControlP return doDumpThrottleMap(begin, end); if(cmd=="wipe-cache" || cmd=="flushname") - return doWipeCache(begin, end); + return doWipeCache(begin, end, 0xffff); + + if(cmd=="wipe-cache-typed") { + uint16_t qtype = QType::chartocode(begin->c_str()); + ++begin; + return doWipeCache(begin, end, qtype); + } if(cmd=="reload-lua-script") return doQueueReloadLuaScript(begin, end); diff --git a/pdns/recursordist/docs/manpages/rec_control.1.rst b/pdns/recursordist/docs/manpages/rec_control.1.rst index 2217adc163..c9f95b4183 100644 --- a/pdns/recursordist/docs/manpages/rec_control.1.rst +++ b/pdns/recursordist/docs/manpages/rec_control.1.rst @@ -332,6 +332,9 @@ wipe-cache *DOMAIN* [*DOMAIN*] [...] **Warning**: Don't just wipe "www.somedomain.com", its NS records or CNAME target may still be undesired, so wipe "somedomain.com" as well. +wipe-cache-typed qtype *DOMAIN* [*DOMAIN*] [...] + Same as wip-cache, but only wipe records of type *qtype*. + See also -------- :manpage:`pdns_recursor(1)` diff --git a/pdns/reczones.cc b/pdns/reczones.cc index cade82750a..6cba83b5e0 100644 --- a/pdns/reczones.cc +++ b/pdns/reczones.cc @@ -341,9 +341,9 @@ string reloadAuthAndForwards() } for(const auto i : oldAndNewDomains) { - broadcastAccFunction(boost::bind(pleaseWipeCache, i, true)); - broadcastAccFunction(boost::bind(pleaseWipePacketCache, i, true)); - broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, i, true)); + broadcastAccFunction(boost::bind(pleaseWipeCache, i, true, 0xffff)); + broadcastAccFunction(boost::bind(pleaseWipePacketCache, i, true, 0xffff)); + broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, i, true)); } broadcastFunction(boost::bind(pleaseUseNewSDomainsMap, newDomainMap)); diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 06a9b2f028..83cd882205 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -685,12 +685,16 @@ int SyncRes::doResolve(const DNSName &qname, const QType &qtype, vector bestns; + DNSName nsdomain(qname); + if (qtype == QType::DS) { + nsdomain.chopOff(); + } // the two retries allow getBestNSFromCache&co to reprime the root // hints, in case they ever go missing for (int tries = 0; tries < 2 && bestns.empty(); ++tries) { bool flawedNSSet = false; set beenthereIgnored; - getBestNSFromCache(qname, qtype, bestns, &flawedNSSet, depth + 1, beenthereIgnored); + getBestNSFromCache(nsdomain, qtype, bestns, &flawedNSSet, depth + 1, beenthereIgnored); } if (bestns.size() == 0) { diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 411ad3dd9e..3b8cc14e73 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -1099,8 +1099,8 @@ uint64_t* pleaseGetConcurrentQueries(); uint64_t* pleaseGetThrottleSize(); uint64_t* pleaseGetPacketCacheHits(); uint64_t* pleaseGetPacketCacheSize(); -uint64_t* pleaseWipeCache(const DNSName& canon, bool subtree=false); -uint64_t* pleaseWipePacketCache(const DNSName& canon, bool subtree); +uint64_t* pleaseWipeCache(const DNSName& canon, bool subtree=false, uint16_t qtype=0xffff); +uint64_t* pleaseWipePacketCache(const DNSName& canon, bool subtree, uint16_t qtype=0xffff); uint64_t* pleaseWipeAndCountNegCache(const DNSName& canon, bool subtree=false); void doCarbonDump(void*); void primeHints(void); diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index 81651ab880..8a0977495b 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -382,8 +382,8 @@ static void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) { DNSName canon = apiNameToDNSName(req->getvars["domain"]); bool subtree = (req->getvars.count("subtree") > 0 && req->getvars["subtree"].compare("true") == 0); - int count = broadcastAccFunction(boost::bind(pleaseWipeCache, canon, subtree)); - count += broadcastAccFunction(boost::bind(pleaseWipePacketCache, canon, subtree)); + int count = broadcastAccFunction(boost::bind(pleaseWipeCache, canon, subtree, 0xffff)); + count += broadcastAccFunction(boost::bind(pleaseWipePacketCache, canon, subtree, 0xffff)); count += broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, canon, subtree)); resp->setBody(Json::object { { "count", count }, -- 2.47.2