Browse Source

[2429] added getMinimum() method for SOA Rdata; needed for TTL-guess handling.

JINMEI Tatuya 12 years ago
parent
commit
606ba69e36

+ 11 - 0
src/lib/dns/rdata/generic/soa_6.cc

@@ -16,6 +16,7 @@
 
 
 #include <string>
 #include <string>
 
 
+#include <boost/static_assert.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/lexical_cast.hpp>
 
 
 #include <exceptions/exceptions.h>
 #include <exceptions/exceptions.h>
@@ -112,6 +113,16 @@ SOA::getSerial() const {
     return (Serial(b.readUint32()));
     return (Serial(b.readUint32()));
 }
 }
 
 
+uint32_t
+SOA::getMinimum() const {
+    // Make sure the buffer access is safe.
+    BOOST_STATIC_ASSERT(sizeof(numdata_) ==
+                        sizeof(uint32_t) * 4 + sizeof(uint32_t));
+
+    InputBuffer b(&numdata_[sizeof(uint32_t) * 4], sizeof(uint32_t));
+    return (b.readUint32());
+}
+
 string
 string
 SOA::toText() const {
 SOA::toText() const {
     InputBuffer b(numdata_, sizeof(numdata_));
     InputBuffer b(numdata_, sizeof(numdata_));

+ 4 - 0
src/lib/dns/rdata/generic/soa_6.h

@@ -35,8 +35,12 @@ public:
     SOA(const Name& mname, const Name& rname, uint32_t serial,
     SOA(const Name& mname, const Name& rname, uint32_t serial,
         uint32_t refresh, uint32_t retry, uint32_t expire,
         uint32_t refresh, uint32_t retry, uint32_t expire,
         uint32_t minimum);
         uint32_t minimum);
+
     /// \brief Returns the serial stored in the SOA.
     /// \brief Returns the serial stored in the SOA.
     Serial getSerial() const;
     Serial getSerial() const;
+
+    /// brief Returns the minimum TTL field value of the SOA.
+    uint32_t getMinimum() const;
 private:
 private:
     /// Note: this is a prototype version; we may reconsider
     /// Note: this is a prototype version; we may reconsider
     /// this representation later.
     /// this representation later.

+ 15 - 4
src/lib/dns/tests/rdata_soa_unittest.cc

@@ -32,12 +32,14 @@ using namespace isc::dns::rdata;
 
 
 namespace {
 namespace {
 class Rdata_SOA_Test : public RdataTest {
 class Rdata_SOA_Test : public RdataTest {
-    // there's nothing to specialize
+protected:
+    Rdata_SOA_Test() : rdata_soa(Name("ns.example.com"),
+                                 Name("root.example.com"),
+                                 2010012601, 3600, 300, 3600000, 1200)
+    {}
+    const generic::SOA rdata_soa;
 };
 };
 
 
-const generic::SOA rdata_soa(Name("ns.example.com"), Name("root.example.com"),
-                             2010012601, 3600, 300, 3600000, 1200);
-
 TEST_F(Rdata_SOA_Test, createFromText) {
 TEST_F(Rdata_SOA_Test, createFromText) {
     //TBD
     //TBD
 }
 }
@@ -86,4 +88,13 @@ TEST_F(Rdata_SOA_Test, getSerial) {
     EXPECT_EQ(2010012601, rdata_soa.getSerial().getValue());
     EXPECT_EQ(2010012601, rdata_soa.getSerial().getValue());
 }
 }
 
 
+TEST_F(Rdata_SOA_Test, getMinimum) {
+    EXPECT_EQ(1200, rdata_soa.getMinimum());
+
+    // Also check with a very large number (with the MSB being 1).
+    EXPECT_EQ(2154848336u, generic::SOA(Name("ns.example.com"),
+                                        Name("root.example.com"),
+                                        0, 0, 0, 0, 0x80706050).getMinimum());
+}
+
 }
 }