Now that DNSResourceRecords are only supposed to be created by backends, they certainly have no say in the DNSPacket positioning.
rr.weight = 100;
}
rr.auth = 1;
- rr.d_place = DNSResourceRecord::ANSWER;
rrs.push_back(rr);
}
std::swap(dom.records[qname], rrs);
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);
}
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);
}
}
}
- 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;
}
}
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;
-}
#include <time.h>
#include <sys/types.h>
class DNSBackend;
+struct DNSRecord;
struct SOAData
{
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;
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
/** 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);
return t2namemap;
}
-
DNSRecordContent::zmakermap_t& DNSRecordContent::getZmakermap()
{
static DNSRecordContent::zmakermap_t zmakermap;
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))
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)
}
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);
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();
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);
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)
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));
}
}
}
}
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);
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))
soa.ttl=sd.ttl;
soa.domain_id=sd.domain_id;
soa.auth = true;
- soa.d_place=DNSResourceRecord::ANSWER;
return soa;
}
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())
break;
default:;
}
-
- rr.d_place=DNSResourceRecord::ANSWER;
return true;
}