From: Pieter Lexis Date: Fri, 8 Apr 2016 07:27:01 +0000 (+0200) Subject: Catch an error in wipe-cache X-Git-Tag: dnsdist-1.0.0-beta1~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74e5a8d412ef37b733b5cdb03728c93f004d18c8;p=thirdparty%2Fpdns.git Catch an error in wipe-cache When an invalid DNSName is encountered, we do not wipe anything from the cache. Also update the manpage. Closes #3645 --- diff --git a/docs/manpages/rec_control.1.md b/docs/manpages/rec_control.1.md index 2d2ce201a6..b86ebaba0f 100644 --- a/docs/manpages/rec_control.1.md +++ b/docs/manpages/rec_control.1.md @@ -113,20 +113,17 @@ version : Report running version. wipe-cache *DOMAIN* [*DOMAIN*] [...] -: Wipe entries for *DOMAIN* from the cache. This is useful if, for example, - an important server has a new IP address, but the TTL has not yet - expired. Multiple domain names can be passed. Note that you must - terminate a domain with a .! So to wipe powerdns.org, issue - 'rec_control wipe-cache powerdns.org.'. - Versions beyond 3.1 don't need the trailing dot. Consider not only - wiping 'www.domain.com.' but also 'domain.com.', as the cached nameservers - or target of CNAME may continue to be undesired. +: Wipe entries for *DOMAIN* (exact name match) from the cache. This is useful + if, for example, an important server has a new IP address, but the TTL has + not yet expired. Multiple domain names can be passed. *DOMAIN* can be + suffixed with a '$' to delete the whole tree from the cache. i.e. 'powerdns.com$' + will remove all cached entries under and including the powerdns.com name. # BUGS None known. File new ones at https://github.com/PowerDNS/pdns/issues. # RESOURCES -Website: http://wiki.powerdns.com, http://www.powerdns.com +Website: https://docs.powerdns.com, https://www.powerdns.com # SEE ALSO pdns_recursor(1) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 6e94c88d10..56b5ed8fff 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -294,20 +294,29 @@ uint64_t* pleaseWipeAndCountNegCache(const DNSName& canon, bool subtree) template string doWipeCache(T begin, T end) { - int count=0, pcount=0, countNeg=0; + vector > toWipe; for(T i=begin; i != end; ++i) { DNSName canon; bool subtree=false; - if(boost::ends_with(*i, "$")) { - canon=DNSName(i->substr(0, i->size()-1)); - subtree=true; + + try { + if(boost::ends_with(*i, "$")) { + canon=DNSName(i->substr(0, i->size()-1)); + subtree=true; + } else { + canon=DNSName(*i); + } + } catch (std::exception &e) { + return "Error: " + std::string(e.what()) + ", nothing wiped\n"; } - else - canon=DNSName(*i); - - count+= broadcastAccFunction(boost::bind(pleaseWipeCache, canon, subtree)); - pcount+= broadcastAccFunction(boost::bind(pleaseWipePacketCache, canon, subtree)); - countNeg+=broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, canon, subtree)); + toWipe.push_back({canon, subtree}); + } + + 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)); + countNeg+=broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, wipe.first, wipe.second)); } return "wiped "+std::to_string(count)+" records, "+std::to_string(countNeg)+" negative records, "+std::to_string(pcount)+" packets\n";