]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Remove d_place from DNSResourceRecord
authorChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Fri, 7 Oct 2016 01:08:55 +0000 (03:08 +0200)
committerChristian Hofstaedtler <christian.hofstaedtler@deduktiva.com>
Thu, 8 Dec 2016 16:53:45 +0000 (17:53 +0100)
Now that DNSResourceRecords are only supposed to be created by backends, they certainly have no say in the DNSPacket positioning.

12 files changed:
modules/geoipbackend/geoipbackend.cc
modules/randombackend/randombackend.cc
pdns/dns.cc
pdns/dns.hh
pdns/dnsparser.cc
pdns/dnsrecords.cc
pdns/misc.hh
pdns/qtype.hh
pdns/rfc2136handler.cc
pdns/slavecommunicator.cc
pdns/tcpreceiver.cc
pdns/zoneparser-tng.cc

index 6cde555427ae805e1ee12842b845613a8939e54d..da21e5cdb50730394ccba26dfc78465f60c4bdc2 100644 (file)
@@ -178,7 +178,6 @@ void GeoIPBackend::initialize() {
           rr.weight = 100;
         } 
         rr.auth = 1;
-        rr.d_place = DNSResourceRecord::ANSWER;
         rrs.push_back(rr);
       }
       std::swap(dom.records[qname], rrs);
@@ -232,7 +231,6 @@ void GeoIPBackend::initialize() {
           rr.auth = 1;
           rr.weight = 100;
           rr.has_weight = false;
-          rr.d_place = DNSResourceRecord::ANSWER;
           rrs.push_back(rr);
           std::swap(dom.records[name], rrs);
         }
@@ -255,7 +253,6 @@ void GeoIPBackend::initialize() {
           rr.auth = 1;
           rr.weight = 100;
           rr.has_weight = false;
-          rr.d_place = DNSResourceRecord::ANSWER;
           rrs.push_back(rr);
           std::swap(dom.records[name], rrs);
         }
index 53a2428e2292c0d9b99cc7cec61c6b69360ae2b7..7e433048f0fc2efa31d4dc1e6d99f6ac8c7d941c 100644 (file)
@@ -69,37 +69,24 @@ public:
     }
   }
 
-  bool get(DNSZoneRecord &zrr)
+  bool get(DNSResourceRecord &rr)
   {
-    if(!d_answer.empty()) {
-      if(d_answer.find("ns1.") == 0){
-        zrr.dr.d_name=d_ourdomain;
-        zrr.dr.d_type=QType::SOA;
-      } else {
-        zrr.dr.d_name=d_ourname;
-        zrr.dr.d_type=QType::A;
-      }
-      zrr.dr.d_ttl=5;             // 5 seconds
-      zrr.auth = 1;          // it may be random.. but it is auth!
-      zrr.dr.d_content = std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(zrr.dr.d_type, 1, d_answer));
-
-      d_answer.clear();          // this was the last answer
-      return true;
-    }
-    return false;
-  }
-
-  bool get(DNSResourceRecord &rr) 
-  {
-    DNSZoneRecord dzr;
-    if(!this->get(dzr)) {
+    if(d_answer.empty())
       return false;
+
+    if(d_answer.find("ns1.") == 0){
+      rr.qname=d_ourdomain;
+      rr.qtype=QType::SOA;
+    } else {
+      rr.qname=d_ourname;
+      rr.qtype=QType::A;
     }
+    rr.qclass=QClass::IN;   // Internet class randomness.
+    rr.ttl=5;               // 5 seconds
+    rr.auth = 1;            // it may be random.. but it is auth!
+    rr.content = d_answer;
 
-    rr=DNSResourceRecord(dzr.dr);
-    rr.auth = dzr.auth;
-    rr.domain_id = dzr.domain_id;
-    rr.scopeMask = dzr.scopeMask;
+    d_answer.clear();       // this was the last answer
     return true;
   }
 
index 727a4a9f0be6f9f34cbf40296b4475474def8c38..051e27aef78a58c4104e3c8fbfe1d7e1b191d1c0 100644 (file)
@@ -123,19 +123,3 @@ string& attodot(string &str)
    }
    return str;
 }
-
-vector<DNSResourceRecord> convertRRS(const vector<DNSRecord>& in)
-{
-  vector<DNSResourceRecord> out;
-  for(const auto& d : in) {
-    DNSResourceRecord rr;
-    rr.qname = d.d_name;
-    rr.qtype = QType(d.d_type);
-    rr.ttl = d.d_ttl;
-    rr.content = d.d_content->getZoneRepresentation();
-    rr.auth = false;
-    rr.qclass = d.d_class;
-    out.push_back(rr);
-  }
-  return out;
-}
index 11c1b9b5db2adf5c827b588dad34c897c299fd16..88a658c5a52ff384a06382bbd4b7998d101d2b78 100644 (file)
@@ -30,6 +30,7 @@
 #include <time.h>
 #include <sys/types.h>
 class DNSBackend;
+struct DNSRecord;
 
 struct SOAData
 {
@@ -70,11 +71,11 @@ namespace PolicyDecision { enum returnTypes { PASS=-1, DROP=-2, TRUNCATE=-3 }; }
 class DNSResourceRecord
 {
 public:
-  DNSResourceRecord() : last_modified(0), ttl(0), signttl(0), domain_id(-1), qclass(1), d_place(ANSWER), scopeMask(0), auth(1), disabled(0) {};
-  explicit DNSResourceRecord(const struct DNSRecord&);
+  DNSResourceRecord() : last_modified(0), ttl(0), signttl(0), domain_id(-1), qclass(1), scopeMask(0), auth(1), disabled(0) {};
   ~DNSResourceRecord(){};
+  static DNSResourceRecord fromWire(const DNSRecord& d);
 
-  enum Place : uint8_t {QUESTION=0, ANSWER=1, AUTHORITY=2, ADDITIONAL=3}; //!< Type describing the positioning of a DNSResourceRecord within, say, a DNSPacket
+  enum Place : uint8_t {QUESTION=0, ANSWER=1, AUTHORITY=2, ADDITIONAL=3}; //!< Type describing the positioning within, say, a DNSPacket
 
   void setContent(const string& content);
   string getZoneRepresentation(bool noDot=false) const;
@@ -95,27 +96,10 @@ public:
   QType qtype; //!< qtype of this record, ie A, CNAME, MX etc
   uint16_t qclass; //!< class of this record
 
-  Place d_place; //!< This specifies where a record goes within the packet
   uint8_t scopeMask;
   bool auth;
   bool disabled;
 
-  template<class Archive>
-  void serialize(Archive & ar, const unsigned int version)
-  {
-    ar & qtype;
-    ar & qclass;
-    ar & qname;
-    ar & wildcardname;
-    ar & content;
-    ar & ttl;
-    ar & domain_id;
-    ar & last_modified;
-    ar & d_place;
-    ar & auth;
-    ar & disabled;
-  }
-
   bool operator==(const DNSResourceRecord& rhs);
 
   bool operator<(const DNSResourceRecord &b) const
@@ -255,5 +239,3 @@ struct TSIGTriplet
 /** for use by DNSPacket, converts a SOAData class to a ascii line again */
 string serializeSOAData(const SOAData &data);
 string &attodot(string &str);  //!< for when you need to insert an email address in the SOA
-
-vector<DNSResourceRecord> convertRRS(const vector<DNSRecord>& in);
index ebdcf0a067821a7c5cbe24cd9672c38283ce8e61..3ec4c566d5be10c6e3413bd173a5199c31d7a84a 100644 (file)
@@ -193,7 +193,6 @@ DNSRecordContent::t2namemap_t& DNSRecordContent::getT2Namemap()
   return t2namemap;
 }
 
-
 DNSRecordContent::zmakermap_t& DNSRecordContent::getZmakermap()
 {
   static DNSRecordContent::zmakermap_t zmakermap;
@@ -206,11 +205,23 @@ DNSRecord::DNSRecord(const DNSResourceRecord& rr)
   d_type = rr.qtype.getCode();
   d_ttl = rr.ttl;
   d_class = rr.qclass;
-  d_place = rr.d_place;
+  d_place = DNSResourceRecord::ANSWER;
   d_clen = 0;
   d_content = std::shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(d_type, rr.qclass, rr.content));
 }
 
+// If you call this and you are not parsing a packet coming from a socket, you are doing it wrong.
+DNSResourceRecord DNSResourceRecord::fromWire(const DNSRecord& d) {
+  DNSResourceRecord rr;
+  rr.qname = d.d_name;
+  rr.qtype = QType(d.d_type);
+  rr.ttl = d.d_ttl;
+  rr.content = d.d_content->getZoneRepresentation();
+  rr.auth = false;
+  rr.qclass = d.d_class;
+  return rr;
+}
+
 void MOADNSParser::init(const char *packet, unsigned int len)
 {
   if(len < sizeof(dnsheader))
index b0d5b5948983589194b0e32de8cc6fa6b1b7082d..11fc94a9207a456969b07dfff171d70104ebefab 100644 (file)
@@ -75,26 +75,6 @@ bool DNSResourceRecord::operator==(const DNSResourceRecord& rhs)
     tie(rhs.qname, rhs.qtype, rcontent, rhs.ttl);
 }
 
-DNSResourceRecord::DNSResourceRecord(const DNSRecord &p) {
-  auth=true;
-  qclass = p.d_class;
-  disabled=false;
-  qname = p.d_name;
-  d_place = p.d_place;
-  // if(!qname.empty())
-  //   boost::erase_tail(qname, 1); // strip .
-
-  qtype = p.d_type;
-  ttl = p.d_ttl;
-  setContent(p.d_content->getZoneRepresentation());
-  last_modified = 0;
-  signttl = 0;
-  domain_id = -1;
-  qclass = p.d_class;
-  d_place = p.d_place;
-  scopeMask = 0;
-}
-
 boilerplate_conv(A, QType::A, conv.xfrIP(d_ip));
 
 ARecordContent::ARecordContent(uint32_t ip) 
index fa3104d55dd4e60f7c5ae329c31bd5f757162434..f045a8ff3d13880282674019f0068bb6a454b05a 100644 (file)
@@ -305,8 +305,9 @@ inline void unixDie(const string &why)
 }
 
 string makeHexDump(const string& str);
-void shuffle(vector<DNSRecord>& rrs);
+struct DNSRecord;
 struct DNSZoneRecord;
+void shuffle(vector<DNSRecord>& rrs);
 void shuffle(vector<DNSZoneRecord>& rrs);
 
 void orderAndShuffle(vector<DNSRecord>& rrs);
index 1514e04e8bb5dbed7181d2ce6086f436a2594035..ffc51c4bc3cf026b28047d83d74ecf9303871bb5 100644 (file)
@@ -64,12 +64,6 @@ public:
     return code < rhs.code;
   }
 
-  template<class Archive>
-  void serialize(Archive &ar, const unsigned int version)
-  {
-    ar & code;
-  }
-
   const string getName() const; //!< Get a string representation of this type
   uint16_t getCode() const; //!< Get the integer representation of this type
   bool isSupportedType();
index 9c08f8f8b33257f250a9f96637e188ab9f910dec..3a59c96ae5f3f8c62d89abcba86908c58fdab33f 100644 (file)
@@ -268,7 +268,7 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr,
     if (! foundRecord) {
       L<<Logger::Notice<<msgPrefix<<"Adding record "<<rr->d_name<<"|"<<rrType.getName()<<endl;
       delnonterm.insert(rr->d_name); // always remove any ENT's in the place where we're going to add a record.
-      DNSResourceRecord newRec(*rr);
+      auto newRec = DNSResourceRecord::fromWire(*rr);
       newRec.domain_id = di->id;
       newRec.auth = (rr->d_name == di->zone || rrType.getCode() != QType::NS);
       di->backend->feedRecord(newRec);
@@ -803,8 +803,8 @@ int PacketHandler::processUpdate(DNSPacket *p) {
   typedef vector<DNSResourceRecord> rrVector_t;
   typedef std::map<rrSetKey_t, rrVector_t> RRsetMap_t;
   RRsetMap_t preReqRRsets;
-  for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i != mdp.d_answers.end(); ++i) {
-    const DNSRecord *rr = &i->first;
+  for(const auto& i : mdp.d_answers) {
+    const DNSRecord* rr = &i.first;
     if (rr->d_place == DNSResourceRecord::ANSWER) {
       // Last line of 3.2.3
       if (rr->d_class != QClass::IN && rr->d_class != QClass::NONE && rr->d_class != QClass::ANY)
@@ -813,7 +813,7 @@ int PacketHandler::processUpdate(DNSPacket *p) {
       if (rr->d_class == QClass::IN) {
         rrSetKey_t key = make_pair(rr->d_name, QType(rr->d_type));
         rrVector_t *vec = &preReqRRsets[key];
-        vec->push_back(DNSResourceRecord(*rr));
+        vec->push_back(DNSResourceRecord::fromWire(*rr));
       }
     }
   }
index 9e481abb35163df11abb5be2fb735afca50f3815..eb01d49c50c7244029cbf7defcbcae0e2cb986e0 100644 (file)
@@ -155,17 +155,17 @@ void CommunicatorClass::ixfrSuck(const DNSName &domain, const TSIGTriplet& tt, c
         }
 
         vector<DNSResourceRecord> replacement;
-        for(const auto& x : rrset) {
-          DNSResourceRecord dr(x);
-          dr.qname += domain;
-          dr.domain_id = di.id;
-          if(x.d_type == QType::SOA) {
+        for(const auto& dr : rrset) {
+          auto rr = DNSResourceRecord::fromWire(dr);
+          rr.qname += domain;
+          rr.domain_id = di.id;
+          if(dr.d_type == QType::SOA) {
             //            cout<<"New SOA: "<<x.d_content->getZoneRepresentation()<<endl;
-            auto sr = getRR<SOARecordContent>(x);
+            auto sr = getRR<SOARecordContent>(dr);
             zs.soa_serial=sr->d_st.serial;
           }
           
-          replacement.push_back(dr);
+          replacement.push_back(rr);
         }
 
         di.backend->replaceRRSet(di.id, g.first.first+domain, QType(g.first.second), replacement);
@@ -388,7 +388,7 @@ void CommunicatorClass::suck(const DNSName &domain, const string &remote)
           bool firstNSEC3=true;
           rrs.reserve(axfr.size());
           for(const auto& dr : axfr) {
-            DNSResourceRecord rr(dr);
+            auto rr = DNSResourceRecord::fromWire(dr);
             rr.qname += domain;
             rr.domain_id = zs.domain_id;
             if(!processRecordForZS(domain, firstNSEC3, rr, zs))
index 995cdb465fedc93e09b509e2155d35cc9dc8d85b..44be1789fa11e7016b1343b0558b99e92eddacb1 100644 (file)
@@ -520,7 +520,6 @@ namespace {
     soa.ttl=sd.ttl;
     soa.domain_id=sd.domain_id;
     soa.auth = true;
-    soa.d_place=DNSResourceRecord::ANSWER;
     return soa;
   }
 
index 16afed667561d087190c2a3e177fb6d942e6813c..eabe08ce498b455b5f84ef2397d1448656e56bae 100644 (file)
@@ -271,8 +271,7 @@ pair<string,int> ZoneParserTNG::getLineNumAndFile()
   return {d_filestates.top().d_filename, d_filestates.top().d_lineno};
 }
 
-// ODD: this function never fills out the prio field! rest of pdns compensates though
-bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment) 
+bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
 {
  retry:;
   if(!getTemplateLine() && !getLine())
@@ -482,8 +481,6 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
     break;
   default:;
   }
-
-  rr.d_place=DNSResourceRecord::ANSWER;
   return true;
 }