From: Christian Hofstaedtler Date: Fri, 7 Oct 2016 01:08:55 +0000 (+0200) Subject: Remove d_place from DNSResourceRecord X-Git-Tag: rec-4.1.0-alpha1~253^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4950b140211729828aa632c9064cb585bc124cc3;p=thirdparty%2Fpdns.git Remove d_place from DNSResourceRecord Now that DNSResourceRecords are only supposed to be created by backends, they certainly have no say in the DNSPacket positioning. --- diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index 6cde555427..da21e5cdb5 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -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); } diff --git a/modules/randombackend/randombackend.cc b/modules/randombackend/randombackend.cc index 53a2428e22..7e433048f0 100644 --- a/modules/randombackend/randombackend.cc +++ b/modules/randombackend/randombackend.cc @@ -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::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; } diff --git a/pdns/dns.cc b/pdns/dns.cc index 727a4a9f0b..051e27aef7 100644 --- a/pdns/dns.cc +++ b/pdns/dns.cc @@ -123,19 +123,3 @@ string& attodot(string &str) } return str; } - -vector convertRRS(const vector& in) -{ - vector 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; -} diff --git a/pdns/dns.hh b/pdns/dns.hh index 11c1b9b5db..88a658c5a5 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -30,6 +30,7 @@ #include #include 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 - 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 convertRRS(const vector& in); diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index ebdcf0a067..3ec4c566d5 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -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::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)) diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index b0d5b59489..11fc94a920 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -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) diff --git a/pdns/misc.hh b/pdns/misc.hh index fa3104d55d..f045a8ff3d 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -305,8 +305,9 @@ inline void unixDie(const string &why) } string makeHexDump(const string& str); -void shuffle(vector& rrs); +struct DNSRecord; struct DNSZoneRecord; +void shuffle(vector& rrs); void shuffle(vector& rrs); void orderAndShuffle(vector& rrs); diff --git a/pdns/qtype.hh b/pdns/qtype.hh index 1514e04e8b..ffc51c4bc3 100644 --- a/pdns/qtype.hh +++ b/pdns/qtype.hh @@ -64,12 +64,6 @@ public: return code < rhs.code; } - template - 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(); diff --git a/pdns/rfc2136handler.cc b/pdns/rfc2136handler.cc index 9c08f8f8b3..3a59c96ae5 100644 --- a/pdns/rfc2136handler.cc +++ b/pdns/rfc2136handler.cc @@ -268,7 +268,7 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr, if (! foundRecord) { L<d_name<<"|"<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 rrVector_t; typedef std::map 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)); } } } diff --git a/pdns/slavecommunicator.cc b/pdns/slavecommunicator.cc index 9e481abb35..eb01d49c50 100644 --- a/pdns/slavecommunicator.cc +++ b/pdns/slavecommunicator.cc @@ -155,17 +155,17 @@ void CommunicatorClass::ixfrSuck(const DNSName &domain, const TSIGTriplet& tt, c } vector 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: "<getZoneRepresentation()<(x); + auto sr = getRR(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)) diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index 995cdb465f..44be1789fa 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -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; } diff --git a/pdns/zoneparser-tng.cc b/pdns/zoneparser-tng.cc index 16afed6675..eabe08ce49 100644 --- a/pdns/zoneparser-tng.cc +++ b/pdns/zoneparser-tng.cc @@ -271,8 +271,7 @@ pair 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; }