// If the NSEC3 hashes have a long common prefix, they deny only a small subset of all possible hashes
// So don't take the trouble to store those.
-static bool isSmallCoveringNSEC3(const DNSName& owner, const std::shared_ptr<NSEC3RecordContent>& nsec)
+bool AggressiveNSECCache::isSmallCoveringNSEC3(const DNSName& owner, const std::string& nextHash)
{
std::string ownerHash(fromBase32Hex(owner.getRawLabel(0)));
- const std::string& nextHash = nsec->d_nexthash;
auto commonPrefix = computeCommonPrefix(ownerHash, nextHash);
return commonPrefix > AggressiveNSECCache::s_maxNSEC3CommonPrefix;
}
return;
}
- if (isSmallCoveringNSEC3(owner, content)) {
+ if (isSmallCoveringNSEC3(owner, content->d_nexthash)) {
/* not accepting small covering answers since they only deny a small subset */
return;
}
BOOST_AUTO_TEST_SUITE(aggressive_nsec_cc)
+BOOST_AUTO_TEST_CASE(test_small_coverering_nsec3)
+{
+ AggressiveNSECCache::s_maxNSEC3CommonPrefix = 1;
+
+ const std::tuple<string, string, uint8_t, bool> table[] = {
+ { "gujhshp2lhmnpoo9qde4blg4gq3hgl99", "gujhshp2lhmnpoo9qde4blg4gq3hgl9a", 157, true},
+ { "gujhshp2lhmnpoo9qde4blg4gq3hgl99", "gujhshp2lhmnpoo9qde4blg4gq3hgl9a", 158, false},
+ { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "vujhshp2lhmnpoo9qde4blg4gq3hgl9a", 0, false},
+ { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "7ujhshp2lhmnpoo9qde4blg4gq3hgl9a", 1, true},
+ { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "7ujhshp2lhmnpoo9qde4blg4gq3hgl9a", 2, false},
+ { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "fujhshp2lhmnpoo9qde4blg4gq3hgl9a", 1, false},
+ { "0ujhshp2lhmnpoo9qde4blg4gq3hgl99", "8ujhshp2lhmnpoo9qde4blg4gq3hgl9a", 1, false},
+ };
+
+ for (const auto& [owner, next, boundary, result]: table) {
+ AggressiveNSECCache::s_maxNSEC3CommonPrefix = boundary;
+ BOOST_CHECK_EQUAL(AggressiveNSECCache::isSmallCoveringNSEC3(DNSName(owner), fromBase32Hex(next)), result);
+ }
+}
+
BOOST_AUTO_TEST_CASE(test_aggressive_nsec_nxdomain)
{
std::unique_ptr<SyncRes> sr;