Browse Source

[trac471] set listen on to localhost if nothing is set

(on the initial configuration)

also added a special case for the 'version' config element in the configuration checker (this caused the configuration to be rejected, while for the purposes of validation it should either be ignored or cause a different validation path)
Jelte Jansen 14 years ago
parent
commit
13a3fcfa3f

+ 17 - 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);
@@ -574,6 +585,11 @@ Resolver::updateConfig(ConstElementPtr config) {
 }
 
 void
+Resolver::setConfigured() {
+    configured_ = true;
+}
+
+void
 Resolver::setForwardAddresses(const AddressList& addresses)
 {
     impl_->setForwardAddresses(addresses, dnss_);

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

@@ -119,6 +119,13 @@ public:
     asiolink::SimpleCallback* getCheckinProvider() { return (checkin_); }
 
     /**
+     * \brief Tell the Resolver that is should has already been
+     *        configured (used by updateConfig() and tests, so
+     *        that it will only set some defaults the first time
+     */
+    void setConfigured();
+
+    /**
      * \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);
 };

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

@@ -372,9 +372,14 @@ 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) {
+            found = true;
+        } else {
+            BOOST_FOREACH(ConstElementPtr cur_spec_el, spec->listValue()) {
+                if (cur_spec_el->get("item_name")->stringValue().compare(m.first) == 0) {
+                    found = true;
+                }
             }
         }
         if (!found) {