Browse Source

Merge branch 'trac471'

Jelte Jansen 14 years ago
parent
commit
1960b5becb

+ 12 - 1
src/bin/resolver/resolver.cc

@@ -333,7 +333,8 @@ Resolver::Resolver() :
     impl_(new ResolverImpl()),
     checkin_(new ConfigCheck(this)),
     dns_lookup_(new MessageLookup(this)),
-    dns_answer_(new MessageAnswer)
+    dns_answer_(new MessageAnswer),
+    configured_(false)
 {}
 
 Resolver::~Resolver() {
@@ -548,6 +549,15 @@ Resolver::updateConfig(ConstElementPtr config) {
         if (listenAddressesE) {
             setListenAddresses(listenAddresses);
             need_query_restart = true;
+        } else {
+            if (!configured_) {
+                // TODO: ModuleSpec needs getDefault()
+                AddressList initial_addresses;
+                initial_addresses.push_back(AddressPair("127.0.0.1", 53));
+                initial_addresses.push_back(AddressPair("::1", 53));
+                setListenAddresses(initial_addresses);
+                need_query_restart = true;
+            }
         }
         if (forwardAddressesE) {
             setForwardAddresses(forwardAddresses);
@@ -566,6 +576,7 @@ Resolver::updateConfig(ConstElementPtr config) {
             impl_->queryShutdown();
             impl_->querySetup(*dnss_, *nsas_, *cache_);
         }
+        setConfigured();
         return (isc::config::createAnswer());
     } catch (const isc::Exception& error) {
         dlog(string("error in config: ") + error.what(),true);

+ 11 - 0
src/bin/resolver/resolver.h

@@ -119,6 +119,13 @@ public:
     asiolink::SimpleCallback* getCheckinProvider() { return (checkin_); }
 
     /**
+     * \brief Tell the Resolver that is has already been configured
+     *        so that it will only set some defaults the first time
+     *        (used by updateConfig() and tests)
+     */
+    void setConfigured() { configured_ = true; };
+
+    /**
      * \brief Specify the list of upstream servers.
      *
      * Specify the list off addresses of upstream servers to forward queries
@@ -229,6 +236,10 @@ private:
     asiolink::DNSAnswer* dns_answer_;
     isc::nsas::NameserverAddressStore* nsas_;
     isc::cache::ResolverCache* cache_;
+    // This value is initally false, and will be set to true
+    // when the initial configuration is done (updateConfig
+    // should act a tiny bit different on the very first call)
+    bool configured_;
 };
 
 #endif // __RESOLVER_H

+ 1 - 0
src/bin/resolver/tests/resolver_config_unittest.cc

@@ -42,6 +42,7 @@ class ResolverConfig : public ::testing::Test {
             dnss(ios, NULL, NULL, NULL)
         {
             server.setDNSService(dnss);
+            server.setConfigured();
         }
         void invalidTest(const string &JSON, const string& name);
 };

+ 11 - 8
src/lib/config/module_spec.cc

@@ -372,15 +372,18 @@ ModuleSpec::validateSpecList(ConstElementPtr spec, ConstElementPtr data,
     
     BOOST_FOREACH(maptype m, data->mapValue()) {
         bool found = false;
-        BOOST_FOREACH(ConstElementPtr cur_spec_el, spec->listValue()) {
-            if (cur_spec_el->get("item_name")->stringValue().compare(m.first) == 0) {
-                found = true;
+        // Ignore 'version' as a config element
+        if (m.first.compare("version") != 0) {
+            BOOST_FOREACH(ConstElementPtr cur_spec_el, spec->listValue()) {
+                if (cur_spec_el->get("item_name")->stringValue().compare(m.first) == 0) {
+                    found = true;
+                }
             }
-        }
-        if (!found) {
-            validated = false;
-            if (errors) {
-                errors->add(Element::create("Unknown item " + m.first));
+            if (!found) {
+                validated = false;
+                if (errors) {
+                    errors->add(Element::create("Unknown item " + m.first));
+                }
             }
         }
     }

+ 4 - 0
src/lib/config/tests/module_spec_unittests.cc

@@ -162,6 +162,10 @@ TEST(ModuleSpec, DataValidation) {
     EXPECT_FALSE(dataTest(dd, "data22_8.data"));
     EXPECT_FALSE(dataTest(dd, "data22_9.data"));
 
+    // Test if "version" is allowed in config data
+    // (same data as 22_7, but added "version")
+    EXPECT_TRUE(dataTest(dd, "data22_10.data"));
+
     ElementPtr errors = Element::createList();
     EXPECT_FALSE(dataTestWithErrors(dd, "data22_8.data", errors));
     EXPECT_EQ("[ \"Type mismatch\" ]", errors->str());

+ 11 - 0
src/lib/config/tests/testdata/data22_10.data

@@ -0,0 +1,11 @@
+{
+    "version": 123,
+    "value1": 1,
+    "value2": 2.3,
+    "value3": true,
+    "value4": "foo",
+    "value5": [ 1, 2, 3 ],
+    "value6": { "v61": "bar", "v62": true },
+    "value8": [ { "a": "d" }, { "a": "e" } ],
+    "value9": { "v91": "hi", "v92": { "v92a": "Hi", "v92b": 3 } }
+}