Parcourir la source

parkinglots zoneset now contains Names instead of strings,
made std:set an attribute instead of zoneset a subclass
Added a very temporary operator< to Name (this is the 'old' name), which was needed for zoneset.
Made the DS API interaction a bit smarter
parkinglot can now return NXDOMAIN if you ask for a subdomain of a known one (still returns SERVFAIL for unknown zones)



git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jelte-datasource1@496 e5f2f494-b856-4b98-b285-d166d9295462

Jelte Jansen il y a 15 ans
Parent
commit
845df07f81

+ 1 - 1
src/bin/parkinglot/Makefile.am

@@ -1,7 +1,7 @@
 AM_CPPFLAGS = -I$(top_srcdir)/src/lib -I$(top_srcdir)/ext
 
 bin_PROGRAMS = parkinglot
-parkinglot_SOURCES = common.cc common.h zoneset.h parkinglot.cc
+parkinglot_SOURCES = common.cc common.h zoneset.h zoneset.cc parkinglot.cc
 parkinglot_SOURCES += parkinglot.h ccsession.cc ccsession.h main.cc
 parkinglot_SOURCES += data_source_plot.h data_source_plot.cc
 parkinglot_LDADD = $(top_srcdir)/src/lib/dns/libdns.a $(top_srcdir)/src/lib/cc/cpp/libcc.a

+ 8 - 15
src/bin/parkinglot/data_source_plot.cc

@@ -60,13 +60,7 @@ DataSourceParkingLot::DataSourceParkingLot() {
 bool
 DataSourceParkingLot::hasZoneFor(const Name& name, Name &zone_name)
 {
-    if (zones.contains(name.toText(true))) {
-        zone_name = Name(name);
-        return true;
-    } else {
-        /* try 1 level higher? i.e. www.asdf.nl? */
-        return false;
-    }
+    return zones.findClosest(name, zone_name);
 }
 
 SearchResult
@@ -78,7 +72,6 @@ DataSourceParkingLot:: findRRsets(const isc::dns::Name& zone_name,
     Name authors_name("authors.bind");
     Name version_name("version.bind");
     
-    std::cout << "findRRset()" << std::endl;
     if (clas == RRClass::CH) {
         if (type == RRType::TXT) {
             if (name == authors_name) {
@@ -104,16 +97,13 @@ DataSourceParkingLot:: findRRsets(const isc::dns::Name& zone_name,
                 result.addRRset(rrset);
                 result.setStatus(SearchResult::success);
             } else {
-                std::cout << "ch txt but unknown name" << std::endl;
                 result.setStatus(SearchResult::name_not_found);
             }
         } else {
             result.setStatus(SearchResult::name_not_found);
         }
     } else if (clas == RRClass::IN) {
-        // make zoneset contain Name instead of string?
-        std::cout << "Finding zone for " << name.toText() << std::endl;
-        if (zones.contains(name.toText(true))) {
+        if (zones.contains(name)) {
             RRsetPtr rrset = RRsetPtr(new RRset(name, clas, type, TTL(3600)));
             result.setStatus(SearchResult::success);
             if (type == RRType::A) {
@@ -133,11 +123,14 @@ DataSourceParkingLot:: findRRsets(const isc::dns::Name& zone_name,
             }
             result.addRRset(rrset);
         } else {
-            std::cout << "zone not in zoneset" << std::endl;
-            result.setStatus(SearchResult::zone_not_found);
+            // we don't have the name itself. Do we have the zone?
+            if (zones.contains(zone_name)) {
+                result.setStatus(SearchResult::name_not_found);
+            } else {
+                result.setStatus(SearchResult::zone_not_found);
+            }
         }
     } else {
-        std::cout << "not ch or in" << std::endl;
         result.setStatus(SearchResult::zone_not_found);
     }
     return result;

+ 1 - 0
src/bin/parkinglot/parkinglot.cc

@@ -110,6 +110,7 @@ ParkingLot::processMessage() {
             status = data_source.addToMessage(msg, SECTION_ANSWER, zname, name, qclass, qtype);
             // rcode is based on this result?
             if (status == SearchResult::name_not_found) {
+                msg.setRcode(Message::RCODE_NXDOMAIN);
                 if (qtype != RRType::NS) {
                     status = data_source.addToMessage(msg, SECTION_AUTHORITY, zname, zname, qclass, RRType::SOA);
                 }

+ 36 - 16
src/bin/parkinglot/zoneset.h

@@ -18,23 +18,43 @@
 #define __ZONESET_H 1
 
 #include <set>
+#include <dns/buffer.h>
+#include <dns/name.h>
 
-class ZoneSet : std::set<std::string> {
-    public:
-        void serve(std::string s) {
-            std::cout << "now serving: " << s << std::endl;
-            this->insert(s);
-        }
-        void forget(std::string s) {
-            std::cout << "no longer serving: " << s << std::endl;
-            this->erase(s);
-        }
-        void clear_zones() {
-            this->clear();
-        }
-        bool contains(std::string s) {
-            return (this->find(s) != this->end());
-        }
+class ZoneSet {
+public:
+    void serve(const std::string& s) {
+        serve(isc::dns::Name(s));
+    }
+
+    void serve(const isc::dns::Name& n) {
+        elements.insert(n);
+    }
+    
+    void forget(const std::string& s) {
+        forget(isc::dns::Name(s));
+    }
+
+    void forget(const isc::dns::Name& n) {
+        elements.erase(n);
+    }
+
+    void clear_zones() {
+        elements.clear();
+    }
+
+    bool contains(const std::string& s) {
+        return contains(isc::dns::Name(s));
+    }
+
+    bool contains(const isc::dns::Name& n) {
+        return (elements.find(n) != elements.end());
+    }
+
+    bool findClosest(const isc::dns::Name& n, isc::dns::Name& closest);
+
+private:
+    std::set<isc::dns::Name> elements;
 };
 
 #endif // __ZONESET_H

+ 12 - 0
src/lib/dns/name.cc

@@ -550,3 +550,15 @@ operator<<(ostream& os, const Name& name)
     os << name.toText();
     return (os);
 }
+
+// temp (bad) comparison, compare not merged yet; needed for zoneset
+// in parkinglot, real version is in trunk, but currently incompatible
+// with this branch
+bool
+Name::operator<(const Name&other) const
+{
+    std::string a = toText();
+    std::string b = other.toText();
+    return a.compare(b);
+}
+