BIND 10 trac2386, updated. 219a7b2b14bdff5b2765fac9297dadf246ccac09 [2386] Check that origin argument is used for relative names

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Feb 22 07:35:00 UTC 2013


The branch, trac2386 has been updated
       via  219a7b2b14bdff5b2765fac9297dadf246ccac09 (commit)
       via  3fc36f8abae80e834e9ae7aa58905be4599febae (commit)
      from  ad2a32699444b7f09ebcb8c5406a818ee2f5fe55 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 219a7b2b14bdff5b2765fac9297dadf246ccac09
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Feb 22 13:04:46 2013 +0530

    [2386] Check that origin argument is used for relative names

commit 3fc36f8abae80e834e9ae7aa58905be4599febae
Author: Mukund Sivaraman <muks at isc.org>
Date:   Fri Feb 22 12:59:46 2013 +0530

    [2386] Add NSEC implementation

-----------------------------------------------------------------------

Summary of changes:
 src/lib/dns/gen-rdatacode.py.in                 |    1 +
 src/lib/dns/rdata/generic/detail/nsec_bitmap.cc |   53 +++++++++++++++++++++++
 src/lib/dns/rdata/generic/detail/nsec_bitmap.h  |   22 ++++++++++
 src/lib/dns/rdata/generic/nsec_47.cc            |   13 ++++++
 src/lib/dns/tests/rdata_nsec_unittest.cc        |    6 +++
 5 files changed, 95 insertions(+)

-----------------------------------------------------------------------
diff --git a/src/lib/dns/gen-rdatacode.py.in b/src/lib/dns/gen-rdatacode.py.in
index db9a0df..b6e0f88 100755
--- a/src/lib/dns/gen-rdatacode.py.in
+++ b/src/lib/dns/gen-rdatacode.py.in
@@ -41,6 +41,7 @@ new_rdata_factory_users = [('aaaa', 'in'),
                            ('naptr', 'generic'),
                            ('mx', 'generic'),
                            ('ns', 'generic'),
+                           ('nsec', 'generic'),
                            ('ptr', 'generic'),
                            ('soa', 'generic'),
                            ('spf', 'generic'),
diff --git a/src/lib/dns/rdata/generic/detail/nsec_bitmap.cc b/src/lib/dns/rdata/generic/detail/nsec_bitmap.cc
index bb48705..44752d9 100644
--- a/src/lib/dns/rdata/generic/detail/nsec_bitmap.cc
+++ b/src/lib/dns/rdata/generic/detail/nsec_bitmap.cc
@@ -118,6 +118,59 @@ buildBitmapsFromText(const char* const rrtype_name,
     }
 }
 
+// Note: this function shares common code with buildBitmapsFromText()
+// above, but it is expected that buildBitmapsFromText() will be deleted
+// entirely once the transition to MasterLexer is done for all dependent
+// RR types. So a common method is not made from the two.
+void
+buildBitmapsFromLexer(const char* const rrtype_name,
+                      MasterLexer& lexer, vector<uint8_t>& typebits)
+{
+    uint8_t bitmap[8 * 1024];       // 64k bits
+    memset(bitmap, 0, sizeof(bitmap));
+
+    bool have_rrtypes = false;
+    while (true) {
+        const MasterToken& token = lexer.getNextToken();
+        if (token.getType() == MasterToken::END_OF_FILE) {
+            break;
+        }
+
+        have_rrtypes = true;
+        std::string type_str;
+        try {
+            type_str = token.getString();
+            const int code = RRType(type_str).getCode();
+            bitmap[code / 8] |= (0x80 >> (code % 8));
+        } catch (const InvalidRRType&) {
+            isc_throw(InvalidRdataText, "Invalid RRtype in "
+                      << rrtype_name << " bitmap: " << type_str);
+        }
+    }
+
+    if (!have_rrtypes) {
+         isc_throw(InvalidRdataText,
+                   rrtype_name << " record does not end with RR type string");
+    }
+
+    for (int window = 0; window < 256; ++window) {
+        int octet;
+        for (octet = 31; octet >= 0; octet--) {
+            if (bitmap[window * 32 + octet] != 0) {
+                break;
+            }
+        }
+        if (octet < 0) {
+            continue;
+        }
+        typebits.push_back(window);
+        typebits.push_back(octet + 1);
+        for (int i = 0; i <= octet; ++i) {
+            typebits.push_back(bitmap[window * 32 + i]);
+        }
+    }
+}
+
 void
 bitmapsToText(const vector<uint8_t>& typebits, ostringstream& oss) {
     // In the following loop we use string::at() rather than operator[].
diff --git a/src/lib/dns/rdata/generic/detail/nsec_bitmap.h b/src/lib/dns/rdata/generic/detail/nsec_bitmap.h
index 0b2102f..ea5cad0 100644
--- a/src/lib/dns/rdata/generic/detail/nsec_bitmap.h
+++ b/src/lib/dns/rdata/generic/detail/nsec_bitmap.h
@@ -15,6 +15,8 @@
 #ifndef NSECBITMAP_H
 #define NSECBITMAP_H 1
 
+#include <dns/master_lexer.h>
+
 #include <stdint.h>
 
 #include <sstream>
@@ -75,6 +77,26 @@ void buildBitmapsFromText(const char* const rrtype_name,
                           std::istringstream& iss,
                           std::vector<uint8_t>& typebits);
 
+/// \brief Convert textual sequence of RR types read from a lexer into
+/// type bitmaps.
+///
+/// See the other variant above for description.
+///
+/// \exception InvalidRdataText Data read from the given lexer does not
+/// meet the assumption (e.g. including invalid form of RR type, not
+/// ending with an RR type string).
+///
+/// \param rrtype_name Either "NSEC" or "NSEC3"; used as part of exception
+/// messages.
+/// \param lexer MasterLexer that provides consists of a complete
+/// sequence of textual lexemes of RR types for which the corresponding
+/// bits are set.
+/// \param typebits A placeholder for the resulting bitmaps.  Expected to be
+/// empty, but it's not checked.
+void buildBitmapsFromLexer(const char* const rrtype_name,
+                           isc::dns::MasterLexer& lexer,
+                           std::vector<uint8_t>& typebits);
+
 /// \brief Convert type bitmaps to textual sequence of RR types.
 ///
 /// This function converts wire-format data of type bitmaps for NSEC/NSEC3
diff --git a/src/lib/dns/rdata/generic/nsec_47.cc b/src/lib/dns/rdata/generic/nsec_47.cc
index b21a87d..c55be1a 100644
--- a/src/lib/dns/rdata/generic/nsec_47.cc
+++ b/src/lib/dns/rdata/generic/nsec_47.cc
@@ -27,6 +27,7 @@
 #include <dns/rdata.h>
 #include <dns/rdataclass.h>
 #include <dns/rdata/generic/detail/nsec_bitmap.h>
+#include <dns/rdata/generic/detail/lexer_util.h>
 
 #include <stdio.h>
 #include <time.h>
@@ -35,6 +36,7 @@ using namespace std;
 using namespace isc::util;
 using namespace isc::util::encode;
 using namespace isc::dns::rdata::generic::detail::nsec;
+using isc::dns::rdata::generic::detail::createNameFromLexer;
 
 // BEGIN_ISC_NAMESPACE
 // BEGIN_RDATA_NAMESPACE
@@ -87,6 +89,17 @@ NSEC::NSEC(InputBuffer& buffer, size_t rdata_len) {
     impl_ = new NSECImpl(nextname, typebits);
 }
 
+NSEC::NSEC(MasterLexer& lexer, const Name* origin, MasterLoader::Options,
+           MasterLoaderCallbacks&)
+{
+    const Name origin_name(createNameFromLexer(lexer, origin));
+
+    vector<uint8_t> typebits;
+    buildBitmapsFromLexer("NSEC", lexer, typebits);
+
+    impl_ = new NSECImpl(origin_name, typebits);
+}
+
 NSEC::NSEC(const NSEC& source) :
     Rdata(), impl_(new NSECImpl(*source.impl_))
 {}
diff --git a/src/lib/dns/tests/rdata_nsec_unittest.cc b/src/lib/dns/tests/rdata_nsec_unittest.cc
index 4092c6d..ba06d74 100644
--- a/src/lib/dns/tests/rdata_nsec_unittest.cc
+++ b/src/lib/dns/tests/rdata_nsec_unittest.cc
@@ -72,6 +72,12 @@ TEST_F(Rdata_NSEC_Test, createFromLexer_NSEC) {
         *test::createRdataUsingLexer(RRType::NSEC(), RRClass::IN(),
                                      nsec_txt)));
 
+    // test::createRdataUsingLexer() constructs relative to
+    // "example.org." origin.
+    EXPECT_EQ(0, generic::NSEC("www2.example.org. CNAME RRSIG NSEC").compare(
+        *test::createRdataUsingLexer(RRType::NSEC(), RRClass::IN(),
+                                     "www2 CNAME RRSIG NSEC")));
+
     // Exceptions cause NULL to be returned.
     EXPECT_FALSE(test::createRdataUsingLexer(RRType::NSEC(), RRClass::IN(),
                                              "www.isc.org."));



More information about the bind10-changes mailing list