Commit 3ba9a889 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2107] introduce NSEC3Data::insertName() and test adding NSEC3 rdataset

parent aacf7cb7
......@@ -67,6 +67,7 @@ protected:
param_rdata_largesalt_;
const generic::NSEC3 nsec3_rdata_, nsec3_rdata_nosalt_,
nsec3_rdata_largesalt_;
RdataEncoder encoder_;
};
// Shared by both test cases using NSEC3 and NSEC3PARAM Rdata
......@@ -104,6 +105,23 @@ TEST_F(NSEC3DataTest, create) {
checkNSEC3Data(mem_sgmt_, nsec3_rdata_largesalt_);
}
TEST_F(NSEC3DataTest, addNSEC3) {
nsec3_data_ = NSEC3Data::create(mem_sgmt_, param_rdata_);
ZoneNode* node = NULL;
nsec3_data_->insertName(mem_sgmt_, Name("example.com"), &node);
ASSERT_NE(static_cast<ZoneNode*>(NULL), node);
EXPECT_TRUE(node->isEmpty()); // initially it should be empty
ConstRRsetPtr nsec3_rrset_ =
textToRRset("www.example.com. 3600 IN A 192.0.2.1");
RdataSet* rdataset_nsec3 =
RdataSet::create(mem_sgmt_, encoder_, nsec3_rrset_, ConstRRsetPtr());
node->setData(rdataset_nsec3);
// TearDown() will confirm there's no leak on destroy
}
TEST_F(NSEC3DataTest, throwOnCreate) {
// Note: below, we use our knowledge of how memory allocation happens
// within the NSEC3Data.
......
......@@ -107,6 +107,17 @@ NSEC3Data::destroy(util::MemorySegment& mem_sgmt, NSEC3Data* data,
mem_sgmt.deallocate(data, sizeof(NSEC3Data) + 1 + data->getSaltLen());
}
void
NSEC3Data::insertName(util::MemorySegment& mem_sgmt, const Name& name,
ZoneNode** node)
{
const ZoneTree::Result result = nsec3_tree_->insert(mem_sgmt, name, node);
// This should be ensured by the API:
assert((result == ZoneTree::SUCCESS ||
result == ZoneTree::ALREADYEXISTS) && node!= NULL);
}
ZoneData*
ZoneData::create(util::MemorySegment& mem_sgmt, const Name& zone_origin) {
// ZoneTree::insert() and ZoneData allocation can throw. See also
......
......@@ -62,10 +62,12 @@ public:
// created per zone, the overhead should be acceptable.
const ZoneTree* getNSEC3Tree() const { return (nsec3_tree_.get()); }
ZoneTree* getNSEC3Tree() { return (nsec3_tree_.get()); }
size_t getSaltLen() const { return (*getSaltBuf()); }
const uint8_t* getSaltData() const { return (getSaltBuf() + 1); }
void insertName(util::MemorySegment& mem_sgmt, const dns::Name& name,
ZoneNode** node);
private:
// Common subroutine for the public versions of create().
static NSEC3Data* create(util::MemorySegment& mem_sgmt, uint8_t hashalg,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment