Browse Source

[2429] warn when no default TTL is available and the TTL of the last RR is used

JINMEI Tatuya 12 years ago
parent
commit
e5336c30e0
2 changed files with 30 additions and 4 deletions
  1. 12 4
      src/lib/dns/master_loader.cc
  2. 18 0
      src/lib/dns/tests/master_loader_unittest.cc

+ 12 - 4
src/lib/dns/master_loader.cc

@@ -64,7 +64,8 @@ public:
         many_errors_((options & MANY_ERRORS) != 0),
         many_errors_((options & MANY_ERRORS) != 0),
         source_count_(0),
         source_count_(0),
         complete_(false),
         complete_(false),
-        seen_error_(false)
+        seen_error_(false),
+        warn_rfc1035_ttl_(true)
     {}
     {}
 
 
     void reportError(const std::string& filename, size_t line,
     void reportError(const std::string& filename, size_t line,
@@ -234,6 +235,8 @@ public:
     bool complete_;             // All work done.
     bool complete_;             // All work done.
     bool seen_error_;           // Was there at least one error during the
     bool seen_error_;           // Was there at least one error during the
                                 // load?
                                 // load?
+    bool warn_rfc1035_ttl_;     // should warn if implicit TTL determination
+                                // from the previous RR is used.
 };
 };
 
 
 bool
 bool
@@ -341,9 +344,14 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) {
                     }
                     }
                 } else if (!explicit_ttl && default_ttl_) {
                 } else if (!explicit_ttl && default_ttl_) {
                     setCurrentTTL(*default_ttl_);
                     setCurrentTTL(*default_ttl_);
-                } else if (!explicit_ttl) {
-                    ;           // warn it
-                }               // else, explicit_ttl, that's used
+                } else if (!explicit_ttl && warn_rfc1035_ttl_) {
+                    // Omitted (class and) TTL values are default to the last
+                    // explicitly stated values (RFC 1035, Sec. 5.1).
+                    callbacks_.warning(lexer_.getSourceName(),
+                                       lexer_.getSourceLine(),
+                                       "using RFC1035 TTL semantics");
+                    warn_rfc1035_ttl_ = false; // we only warn about it once
+                }
 
 
                 add_callback_(name, rrclass, rrtype, *current_ttl_, data);
                 add_callback_(name, rrclass, rrtype, *current_ttl_, data);
 
 

+ 18 - 0
src/lib/dns/tests/master_loader_unittest.cc

@@ -426,6 +426,24 @@ TEST_F(MasterLoaderTest, ttlFromSOA) {
                   "no TTL specified; using SOA MINTTL instead"));
                   "no TTL specified; using SOA MINTTL instead"));
 }
 }
 
 
+TEST_F(MasterLoaderTest, ttlFromPrevious) {
+    // No available default TTL.  2nd and 3rd RR will use the TTL of the
+    // 1st RR.  This will result in a warning, but only for the first time.
+    stringstream zone_stream("a.example.org. 1800 IN A 192.0.2.1\n"
+                             "b.example.org. IN A 192.0.2.2\n"
+                             "c.example.org. IN A 192.0.2.3\n");
+    setLoader(zone_stream, Name("example.org."), RRClass::IN(),
+              MasterLoader::DEFAULT);
+    loader_->load();
+    EXPECT_TRUE(loader_->loadedSucessfully());
+    checkRR("a.example.org", RRType::A(), "192.0.2.1", RRTTL(1800));
+    checkRR("b.example.org", RRType::A(), "192.0.2.2", RRTTL(1800));
+    checkRR("c.example.org", RRType::A(), "192.0.2.3", RRTTL(1800));
+
+    EXPECT_EQ(1, warnings_.size());
+    EXPECT_EQ(0, warnings_.at(0).find("using RFC1035 TTL semantics"));
+}
+
 // Test the constructor rejects empty add callback.
 // Test the constructor rejects empty add callback.
 TEST_F(MasterLoaderTest, emptyCallback) {
 TEST_F(MasterLoaderTest, emptyCallback) {
     EXPECT_THROW(MasterLoader(TEST_DATA_SRCDIR "/example.org",
     EXPECT_THROW(MasterLoader(TEST_DATA_SRCDIR "/example.org",