From: JINMEI Tatuya Date: Wed, 22 Feb 2012 22:43:05 +0000 (-0800) Subject: [master] [1701] small optimization: skip generating sync RRSIG for wildcard if !DNSSEC. X-Git-Tag: trac2351_base~226^2~116^2~175 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=82bb5bc1cd3385d1bd0362c10308afb04a0e6914;p=thirdparty%2Fkea.git [master] [1701] small optimization: skip generating sync RRSIG for wildcard if !DNSSEC. tests were slightly adjusted accordingly. --- diff --git a/src/lib/datasrc/memory_datasrc.cc b/src/lib/datasrc/memory_datasrc.cc index d785b64cd8..dfe1614d71 100644 --- a/src/lib/datasrc/memory_datasrc.cc +++ b/src/lib/datasrc/memory_datasrc.cc @@ -605,11 +605,15 @@ struct InMemoryZoneFinder::InMemoryZoneFinderImpl { * * If rename is false, it returns the one provided. If it is true, it * creates a new rrset with the same data but with provided name. + * In addition, if DNSSEC records are required by the original caller of + * find(), it also creates expanded RRSIG based on the RRSIG of the + * wildcard RRset. * It is designed for wildcard case, where we create the rrsets * dynamically. */ static ConstRRsetPtr prepareRRset(const Name& name, - const ConstRRsetPtr& rrset, bool rename) + const ConstRRsetPtr& rrset, + bool rename, FindOptions options) { if (rename) { LOG_DEBUG(logger, DBG_TRACE_DETAILED, DATASRC_MEM_RENAME). @@ -620,19 +624,20 @@ struct InMemoryZoneFinder::InMemoryZoneFinderImpl { i->next()) { result->addRdata(i->getCurrent()); } - // TBD: skip it if dnssec not required. - ConstRRsetPtr sig_rrset = rrset->getRRsig(); - if (sig_rrset) { - RRsetPtr result_sig(new RRset(name, sig_rrset->getClass(), - RRType::RRSIG(), - sig_rrset->getTTL())); - for (RdataIteratorPtr i(sig_rrset->getRdataIterator()); - !i->isLast(); - i->next()) - { - result_sig->addRdata(i->getCurrent()); + if ((options & FIND_DNSSEC) != 0) { + ConstRRsetPtr sig_rrset = rrset->getRRsig(); + if (sig_rrset) { + RRsetPtr result_sig(new RRset(name, sig_rrset->getClass(), + RRType::RRSIG(), + sig_rrset->getTTL())); + for (RdataIteratorPtr i(sig_rrset->getRdataIterator()); + !i->isLast(); + i->next()) + { + result_sig->addRdata(i->getCurrent()); + } + result->addRRsig(result_sig); } - result->addRRsig(result_sig); } return (result); } else { @@ -697,14 +702,14 @@ struct InMemoryZoneFinder::InMemoryZoneFinderImpl { // We were traversing a DNAME node (and wanted to go // lower below it), so return the DNAME return (FindResult(DNAME, prepareRRset(name, state.rrset_, - false))); + false, options))); } if (state.zonecut_node_ != NULL) { LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_DELEG_FOUND). arg(state.rrset_->getName()); return (FindResult(DELEGATION, prepareRRset(name, state.rrset_, - false))); + false, options))); } // If the RBTree search stopped at a node for a super domain @@ -808,7 +813,8 @@ struct InMemoryZoneFinder::InMemoryZoneFinderImpl { LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_EXACT_DELEGATION).arg(name); return (FindResult(DELEGATION, - prepareRRset(name, found->second, rename))); + prepareRRset(name, found->second, rename, + options))); } } @@ -818,7 +824,8 @@ struct InMemoryZoneFinder::InMemoryZoneFinderImpl { for (found = node->getData()->begin(); found != node->getData()->end(); ++found) { - target->push_back(prepareRRset(name, found->second, rename)); + target->push_back(prepareRRset(name, found->second, rename, + options)); } LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_ANY_SUCCESS). arg(name); @@ -832,7 +839,8 @@ struct InMemoryZoneFinder::InMemoryZoneFinderImpl { arg(type); return (createFindResult(SUCCESS, prepareRRset(name, found->second, - rename), rename)); + rename, options), + rename)); } else { // Next, try CNAME. found = node->getData()->find(RRType::CNAME()); @@ -840,7 +848,8 @@ struct InMemoryZoneFinder::InMemoryZoneFinderImpl { LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_CNAME).arg(name); return (createFindResult(CNAME, prepareRRset(name, found->second, - rename), rename)); + rename, options), + rename)); } } // No exact match or CNAME. Return NXRRSET. diff --git a/src/lib/datasrc/tests/memory_datasrc_unittest.cc b/src/lib/datasrc/tests/memory_datasrc_unittest.cc index 42acdd306b..e5ccdfa963 100644 --- a/src/lib/datasrc/tests/memory_datasrc_unittest.cc +++ b/src/lib/datasrc/tests/memory_datasrc_unittest.cc @@ -1104,6 +1104,7 @@ InMemoryZoneFinderTest::wildcardCheck( // If the zone is "signed" (detecting it by the NSEC/NSEC3 signed flags), // add RRSIGs to the records. + ZoneFinder::FindOptions find_options = ZoneFinder::FIND_DEFAULT; if ((expected_flags & ZoneFinder::RESULT_NSEC_SIGNED) != 0 || (expected_flags & ZoneFinder::RESULT_NSEC3_SIGNED) != 0) { // Convenience shortcut. The RDATA is not really validatable, but @@ -1111,6 +1112,7 @@ InMemoryZoneFinderTest::wildcardCheck( const char* const rrsig_common = "5 3 3600 " "20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"; + find_options = find_options | ZoneFinder::FIND_DNSSEC; rr_wild_->addRRsig(textToRRset("*.wild.example.org. 300 IN RRSIG A " + string(rrsig_common))); rr_cnamewild_->addRRsig(textToRRset("*.cnamewild.example.org. 300 IN " @@ -1130,14 +1132,15 @@ InMemoryZoneFinderTest::wildcardCheck( { SCOPED_TRACE("Search at parent"); findTest(Name("wild.example.org"), RRType::A(), ZoneFinder::NXRRSET, - true, ConstRRsetPtr(), expected_flags); + true, ConstRRsetPtr(), expected_flags, NULL, find_options); } // Search the original name of wildcard { SCOPED_TRACE("Search directly at *"); findTest(Name("*.wild.example.org"), RRType::A(), ZoneFinder::SUCCESS, - true, rr_wild_); + true, rr_wild_, ZoneFinder::RESULT_DEFAULT, NULL, + find_options); } // Search "created" name. { @@ -1145,11 +1148,12 @@ InMemoryZoneFinderTest::wildcardCheck( findTest(Name("a.wild.example.org"), RRType::A(), ZoneFinder::SUCCESS, false, rr_wild_, ZoneFinder::RESULT_WILDCARD | expected_flags, NULL, - ZoneFinder::FIND_DEFAULT, true); + find_options, true); // Wildcard match, but no data findTest(Name("a.wild.example.org"), RRType::AAAA(), ZoneFinder::NXRRSET, true, ConstRRsetPtr(), - ZoneFinder::RESULT_WILDCARD | expected_flags); + ZoneFinder::RESULT_WILDCARD | expected_flags, NULL, + find_options); } // Search name that has CNAME. @@ -1158,7 +1162,7 @@ InMemoryZoneFinderTest::wildcardCheck( findTest(Name("a.cnamewild.example.org"), RRType::A(), ZoneFinder::CNAME, false, rr_cnamewild_, ZoneFinder::RESULT_WILDCARD | expected_flags, NULL, - ZoneFinder::FIND_DEFAULT, true); + find_options, true); } // Search another created name, this time little bit lower @@ -1167,14 +1171,15 @@ InMemoryZoneFinderTest::wildcardCheck( findTest(Name("a.b.wild.example.org"), RRType::A(), ZoneFinder::SUCCESS, false, rr_wild_, ZoneFinder::RESULT_WILDCARD | expected_flags, NULL, - ZoneFinder::FIND_DEFAULT, true); + find_options, true); } EXPECT_EQ(SUCCESS, zone_finder_.add(rr_under_wild_)); { SCOPED_TRACE("Search under non-wildcard"); findTest(Name("bar.foo.wild.example.org"), RRType::A(), - ZoneFinder::NXDOMAIN, true, ConstRRsetPtr(), expected_flags); + ZoneFinder::NXDOMAIN, true, ConstRRsetPtr(), expected_flags, + NULL, find_options); } }