From: Peter van Dijk Date: Fri, 27 Nov 2015 15:55:03 +0000 (+0100) Subject: teach getZoneRepresentation to optionally skip the trailing dot on non-root names X-Git-Tag: dnsdist-1.0.0-alpha1~159^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f21fc0aafaebecb97571d425da2ae9da1dc4ac4e;p=pdns teach getZoneRepresentation to optionally skip the trailing dot on non-root names --- diff --git a/pdns/dns.hh b/pdns/dns.hh index 24e40aa92..ae0a2033d 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -77,7 +77,7 @@ public: enum Place : uint8_t {QUESTION=0, ANSWER=1, AUTHORITY=2, ADDITIONAL=3}; //!< Type describing the positioning of a DNSResourceRecord within, say, a DNSPacket void setContent(const string& content); - string getZoneRepresentation() const; + string getZoneRepresentation(bool noDot=false) const; // data DNSName qname; //!< the name of this record, for example: www.powerdns.com diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index 5589ad8ff..03d4b1338 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -59,7 +59,7 @@ public: d_record.insert(d_record.end(), out.begin(), out.end()); } - string getZoneRepresentation() const override + string getZoneRepresentation(bool noDot) const override { ostringstream str; str<<"\\# "<<(unsigned int)d_record.size()<<" "; diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index b03600f21..50e241050 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -120,7 +120,7 @@ public: } - void xfrName(DNSName &name, bool compress=false) + void xfrName(DNSName &name, bool compress=false, bool noDot=false) { name=getName(); } @@ -165,7 +165,7 @@ public: static DNSRecordContent* mastermake(uint16_t qtype, uint16_t qclass, const string& zone); static std::unique_ptr makeunique(uint16_t qtype, uint16_t qclass, const string& content); - virtual std::string getZoneRepresentation() const = 0; + virtual std::string getZoneRepresentation(bool noDot=false) const = 0; virtual ~DNSRecordContent() {} virtual void toPacket(DNSPacketWriter& pw)=0; virtual string serialize(const DNSName& qname, bool canonic=false, bool lowerCase=false) // it would rock if this were const, but it is too hard diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 4829a1a54..8684c2d75 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -42,15 +42,18 @@ void DNSResourceRecord::setContent(const string &cont) { } } -string DNSResourceRecord::getZoneRepresentation() const { +string DNSResourceRecord::getZoneRepresentation(bool noDot) const { ostringstream ret; switch(qtype.getCode()) { case QType::SRV: case QType::MX: case QType::CNAME: case QType::NS: - if (*(content.rbegin()) != '.') - ret< void xfrPacket(Convertor& conv); + template void xfrPacket(Convertor& conv, bool noDot=false); class NAPTRRecordContent : public DNSRecordContent { @@ -469,7 +469,7 @@ public: static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); static DNSRecordContent* make(const string& content); - string getZoneRepresentation() const override; + string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint16_t getType() const override { @@ -490,7 +490,7 @@ public: static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); static DNSRecordContent* make(const string& content); - string getZoneRepresentation() const override; + string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint8_t d_algorithm, d_flags; @@ -521,7 +521,7 @@ public: static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); static DNSRecordContent* make(const string& content); - string getZoneRepresentation() const override; + string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint16_t getType() const override @@ -547,7 +547,7 @@ public: static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); static DNSRecordContent* make(const string& content); - string getZoneRepresentation() const override; + string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint8_t d_version, d_size, d_horizpre, d_vertpre; @@ -571,7 +571,7 @@ public: static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); static DNSRecordContent* make(const string& content); - string getZoneRepresentation() const override; + string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint32_t d_ip; @@ -586,7 +586,7 @@ public: static void report(void); static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); static DNSRecordContent* make(const string& zone); // FIXME400: DNSName& zone? - string getZoneRepresentation() const override; + string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint16_t getType() const override { return QType::EUI48; } private: @@ -601,7 +601,7 @@ public: static void report(void); static DNSRecordContent* make(const DNSRecord &dr, PacketReader& pr); static DNSRecordContent* make(const string& zone); // FIXME400: DNSName& zone? - string getZoneRepresentation() const override; + string getZoneRepresentation(bool noDot=false) const override; void toPacket(DNSPacketWriter& pw) override; uint16_t getType() const override { return QType::EUI64; } private: @@ -674,10 +674,10 @@ RNAME##RecordContent::RNAME##RecordContent(const string& zoneData) } \ } \ \ -string RNAME##RecordContent::getZoneRepresentation() const \ +string RNAME##RecordContent::getZoneRepresentation(bool noDot) const \ { \ string ret; \ - RecordTextWriter rtw(ret); \ + RecordTextWriter rtw(ret, noDot); \ const_cast(this)->xfrPacket(rtw); \ return ret; \ } @@ -686,7 +686,7 @@ string RNAME##RecordContent::getZoneRepresentation() const #define boilerplate_conv(RNAME, TYPE, CONV) \ boilerplate(RNAME, TYPE) \ template \ -void RNAME##RecordContent::xfrPacket(Convertor& conv) \ +void RNAME##RecordContent::xfrPacket(Convertor& conv, bool noDot) \ { \ CONV; \ if (conv.eof() == false) throw MOADNSException("All data was not consumed"); \ diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index dc03874be..d7e58374a 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -203,7 +203,7 @@ DNSPacketWriter::lmap_t::iterator find(DNSPacketWriter::lmap_t& nmap, const DNSN // } // this is the absolute hottest function in the pdns recursor -void DNSPacketWriter::xfrName(const DNSName& name, bool compress) +void DNSPacketWriter::xfrName(const DNSName& name, bool compress, bool) { //cerr<<"xfrName: name=["<