]> granicus.if.org Git - pdns/commitdiff
rec: Define NSECBitmap::nbTypes instead of using 65536 directly
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 31 Dec 2018 09:29:12 +0000 (10:29 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 31 Dec 2018 09:29:12 +0000 (10:29 +0100)
pdns/dnsrecords.hh
pdns/nsecrecords.cc
pdns/test-dnsrecords_cc.cc

index 67d77f34f42fae77f99b7f74313f153fa473f024..a8d5bb421a0220a2ed938e7d4f1814feba0b8f48 100644 (file)
@@ -580,10 +580,13 @@ public:
   void toPacket(DNSPacketWriter& pw);
   std::string getZoneRepresentation() const;
 
+  static constexpr size_t const nbTypes = 65536;
+
 private:
+
   void migrateToBitSet()
   {
-    d_bitset = std::unique_ptr<std::bitset<65536>>(new std::bitset<65536>());
+    d_bitset = std::unique_ptr<std::bitset<nbTypes>>(new std::bitset<nbTypes>());
     for (const auto& type : d_set) {
       d_bitset->set(type);
     }
@@ -594,7 +597,7 @@ private:
      when there are a lot of them.
      So we start with the set, but allocate and switch to a bitset
      if the number of covered types increases a lot */
-  std::unique_ptr<std::bitset<65536>> d_bitset;
+  std::unique_ptr<std::bitset<nbTypes>> d_bitset;
   std::set<uint16_t> d_set;
 };
 
index 8149a9346e34ee0665ebe4913a2ce2d254774428..25132682e33b5eb02b1487f48bdfd12549ed1656 100644 (file)
@@ -76,7 +76,7 @@ void NSECBitmap::toPacket(DNSPacketWriter& pw)
   if (d_bitset) {
     size_t count = d_bitset->count();
     size_t found = 0;
-    for(size_t idx = 0; idx < 65535 && found < count; ++idx){
+    for(size_t idx = 0; idx < nbTypes && found < count; ++idx){
       if (!d_bitset->test(idx)) {
         continue;
       }
@@ -138,7 +138,7 @@ string NSECBitmap::getZoneRepresentation() const
   if (d_bitset) {
     size_t count = d_bitset->count();
     size_t found = 0;
-    for(size_t idx = 0; idx < 65535 && found < count; ++idx) {
+    for(size_t idx = 0; idx < nbTypes && found < count; ++idx) {
       if (!d_bitset->test(idx)) {
         continue;
       }
index e28104721ae02ee58cb33ea2d5c64c744147ba92..764d8fdf367343b08c2ac14e6f64ba7e760ba851 100644 (file)
@@ -493,30 +493,39 @@ BOOST_AUTO_TEST_CASE(test_nsec_records_types) {
 BOOST_AUTO_TEST_CASE(test_nsec3_records_types) {
 
   {
-    auto validNSEC3 = DNSRecordContent::mastermake(QType::NSEC3, QClass::IN, "1 1 12 aabbccdd 2vptu5timamqttgl4luu9kg21e0aor3s A MX RRSIG NSEC3 TYPE1234");
+    const std::string str = "1 1 12 aabbccdd 2vptu5timamqttgl4luu9kg21e0aor3s a mx rrsig nsec3 type1234 type65535";
+    auto validNSEC3 = DNSRecordContent::mastermake(QType::NSEC3, QClass::IN, str);
     auto nsec3Content = std::dynamic_pointer_cast<NSEC3RecordContent>(validNSEC3);
     BOOST_REQUIRE(nsec3Content);
 
-    for (const auto type : { QType::A, QType::MX, QType::RRSIG, QType::NSEC3, static_cast<QType::typeenum>(1234) }) {
+    for (const auto type : { QType::A, QType::MX, QType::RRSIG, QType::NSEC3, static_cast<QType::typeenum>(1234), static_cast<QType::typeenum>(65535) }) {
       BOOST_CHECK(nsec3Content->isSet(type));
     }
     BOOST_CHECK_EQUAL(nsec3Content->isSet(QType::NSEC), false);
-    BOOST_CHECK_EQUAL(nsec3Content->numberOfTypesSet(), 5);
+    BOOST_CHECK_EQUAL(nsec3Content->numberOfTypesSet(), 6);
+    auto str2 = nsec3Content->getZoneRepresentation();
+    boost::to_lower(str2);
+    BOOST_CHECK_EQUAL(str2, str);
   }
 
   {
-    auto nsec3Content = std::make_shared<NSEC3RecordContent>();
+    std::string str = "1 1 12 aabbccdd 2vptu5timamqttgl4luu9kg21e0aor3s";
+    auto nsec3Content = std::make_shared<NSEC3RecordContent>(str);
     BOOST_CHECK_EQUAL(nsec3Content->numberOfTypesSet(), 0);
     BOOST_CHECK_EQUAL(nsec3Content->isSet(QType::NSEC), false);
 
     for (size_t idx = 0; idx < 65536; idx++) {
       nsec3Content->set(idx);
+      str += " " + toLower(DNSRecordContent::NumberToType(idx));
     }
     BOOST_CHECK_EQUAL(nsec3Content->isSet(QType::NSEC), true);
     BOOST_CHECK_EQUAL(nsec3Content->numberOfTypesSet(), 65536);
     for (size_t idx = 0; idx < 65536; idx++) {
       BOOST_CHECK(nsec3Content->isSet(idx));
     }
+    auto str2 = nsec3Content->getZoneRepresentation();
+    boost::to_lower(str2);
+    BOOST_CHECK_EQUAL(str2, str);
   }
 
   {