]> granicus.if.org Git - pdns/commitdiff
switch from getLabelFromContent() to DNSName()
authorKees Monshouwer <mind04@monshouwer.org>
Fri, 17 Apr 2015 07:23:39 +0000 (07:23 +0000)
committermind04 <mind04@monshouwer.org>
Tue, 21 Apr 2015 19:43:03 +0000 (21:43 +0200)
modules/remotebackend/Makefile.am
pdns/Makefile-recursor
pdns/Makefile.am
pdns/dist-recursor
pdns/dnsparser.cc
pdns/dnsparser.hh
pdns/dnswriter.cc

index 34f046847150ff8566cc0a32d011d4e228e5aecf..4f832d44dfb93b459a710774584757ec289a6515 100644 (file)
@@ -98,6 +98,7 @@ libtestremotebackend_la_SOURCES = \
        ../../pdns/base64.cc \
        ../../pdns/dnsbackend.hh ../../pdns/dnsbackend.cc \
        ../../pdns/dnslabeltext.cc \
+       ../../pdns/dnsname.cc ../../pdns/dnsname.hh \
        ../../pdns/dnspacket.cc \
        ../../pdns/dnsparser.cc \
        ../../pdns/dnsrecords.cc \
index 3aa0a0ed8226afd03ac2bb22e93f9a12f87de2d6..275a10077aca1a278b43d6e2c77a183d690b94e2 100644 (file)
@@ -24,7 +24,7 @@ dns_random.o pubsuffix.o ext/polarssl/library/aes.o ext/polarssl/library/base64.
 lua-pdns.o lua-recursor.o randomhelper.o recpacketcache.o dns.o \
 reczones.o base32.o nsecrecords.o json.o ws-recursor.o ws-api.o \
 version.o responsestats.o webserver.o ext/yahttp/yahttp/reqresp.o ext/yahttp/yahttp/router.o \
-rec-carbon.o secpoll-recursor.o lua-iputils.o iputils.o
+rec-carbon.o secpoll-recursor.o lua-iputils.o iputils.o dnsname.o
 
 REC_CONTROL_OBJECTS=rec_channel.o rec_control.o arguments.o misc.o \
        unix_utility.o logger.o qtype.o
index 33dd7bba63ef03d7c21cf2ff79cf712e89ec199f..9a3571d594c464f6bddcd760b109d42e4f85ca63 100644 (file)
@@ -138,6 +138,7 @@ pdns_server_SOURCES = \
        dns_random.cc dns_random.hh \
        dnsbackend.cc dnsbackend.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnspacket.cc dnspacket.hh \
        dnsparser.cc \
        dnsproxy.cc dnsproxy.hh \
@@ -255,6 +256,7 @@ pdnssec_SOURCES = \
        dnsbackend.cc \
        dns.cc \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnspacket.cc \
        dnsparser.cc dnsparser.hh \
        dns_random.cc \
@@ -342,6 +344,7 @@ zone2sql_SOURCES = \
        bindparserclasses.hh \
        dns.cc \
        dns_random.cc \
+       dnsname.cc dnsname.hh \
        dnslabeltext.cc \
        dnsparser.cc \
        dnsrecords.cc \
@@ -369,6 +372,7 @@ zone2json_SOURCES = \
        bindparser.yy \
        bindparserclasses.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc \
        dnsrecords.cc \
        dnswriter.cc \
@@ -402,6 +406,7 @@ zone2ldap_SOURCES = \
        bindparser.yy \
        bindparserclasses.hh \
        dns_random.cc \
+       dnsname.cc dnsname.hh \
        dnslabeltext.cc \
        dnsparser.cc \
        dnsrecords.cc \
@@ -433,6 +438,7 @@ zone2lmdb_SOURCES = \
        dns.cc \
        dns_random.cc \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc \
        dnsrecords.cc \
        dnswriter.cc \
@@ -456,6 +462,7 @@ sdig_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
        dnswriter.cc dnswriter.hh \
@@ -477,6 +484,7 @@ calidns_SOURCES = \
        base64.cc base64.hh \
        calidns.cc \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
        dnswriter.cc dnswriter.hh \
@@ -507,6 +515,7 @@ saxfr_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
        dnssecinfra.cc \
@@ -533,6 +542,7 @@ dnstcpbench_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
        dnstcpbench.cc \
@@ -585,6 +595,7 @@ dnsdist_LDADD = \
 nsec3dig_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
+       dnsname.cc dnsname.hh \
        dnslabeltext.cc \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
@@ -612,6 +623,7 @@ toysdig_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
        dns_random.cc \
+       dnsname.cc dnsname.hh \
        dnslabeltext.cc \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
@@ -638,6 +650,7 @@ tsig_tests_SOURCES = \
        dns.cc \
        dns_random.cc dns_random.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
        dnssecinfra.cc \
@@ -666,6 +679,7 @@ speedtest_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
        dnswriter.cc dnswriter.hh \
@@ -697,6 +711,7 @@ dnsbulktest_SOURCES = \
        base64.cc \
        dnsbulktest.cc \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc \
        dnsrecords.cc \
        dnswriter.cc \
@@ -722,6 +737,7 @@ dnsscan_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnspcap.cc dnspcap.hh \
        dnsrecords.cc \
@@ -744,6 +760,7 @@ dnsreplay_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnspcap.cc dnspcap.hh \
        dnsrecords.cc \
@@ -771,6 +788,7 @@ nproxy_SOURCES = \
        base32.cc \
        base64.cc base64.hh \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
        dnswriter.cc dnswriter.hh \
@@ -800,6 +818,7 @@ notify_SOURCES = \
        base64.cc base64.hh \
        dns.cc \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnsrecords.cc \
        dnswriter.cc dnswriter.hh \
@@ -828,6 +847,7 @@ dnsscope_SOURCES = \
        base64.cc base64.hh \
        dns.cc \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnspcap.cc dnspcap.hh \
        dnsrecords.cc \
@@ -856,6 +876,7 @@ dnsgram_SOURCES = \
        base64.cc base64.hh \
        dnsgram.cc \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnspcap.cc dnspcap.hh \
        dnsrecords.cc \
@@ -877,6 +898,7 @@ dnsdemog_SOURCES = \
        base64.cc base64.hh \
        dnsdemog.cc \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc dnsparser.hh \
        dnspcap.cc dnspcap.hh \
        dnsrecords.cc \
@@ -980,6 +1002,7 @@ pdns_recursor_SOURCES = \
        dns.cc \
        dns_random.cc \
        dnslabeltext.cc \
+       dnsname.cc dnsname.hh \
        dnsparser.cc \
        dnsrecords.cc dnsrecords.hh \
        dnswriter.cc dnswriter.hh \
index 1b2ddc326c1f5535e87204f65f913ad1c746ce25..2ddfeab9c6d0354ec5928be9b357671653bf20d6 100755 (executable)
@@ -31,7 +31,7 @@ mplexer.hh pubsuffix.hh \
 dns_random.hh lua-pdns.hh lua-recursor.hh namespaces.hh \
 recpacketcache.hh base32.hh cachecleaner.hh json.hh version.hh \
 ws-recursor.hh ws-api.hh secpoll-recursor.hh \
-responsestats.hh webserver.hh"
+responsestats.hh webserver.hh dnsname.hh"
 
 CFILES="syncres.cc iputils.cc  misc.cc unix_utility.cc qtype.cc \
 logger.cc arguments.cc  lwres.cc pdns_recursor.cc lua-iputils.cc \
@@ -41,7 +41,7 @@ selectmplexer.cc epollmplexer.cc kqueuemplexer.cc portsmplexer.cc pdns_hw.cc \
 sillyrecords.cc pubsuffix.cc lua-pdns.cc lua-recursor.cc randomhelper.cc \
 devpollmplexer.cc recpacketcache.cc dns.cc reczones.cc base32.cc nsecrecords.cc \
 dnslabeltext.cc json.cc ws-recursor.cc ws-api.cc version.cc dns_random.cc \
-responsestats.cc webserver.cc rec-carbon.cc secpoll-recursor.cc"
+responsestats.cc webserver.cc rec-carbon.cc secpoll-recursor.cc dnsname.cc"
 
 ./mkpubsuffixcc
 
index 354daa9bc0940398b9716bbf47e168c387e69332..ecc5c4a4f2edcd25f78393879bb9eccaec60960e 100644 (file)
@@ -399,11 +399,15 @@ uint8_t PacketReader::get8BitInt()
   return d_content.at(d_pos++);
 }
 
-string PacketReader::getLabel(unsigned int recurs)
+string PacketReader::getLabel()
 {
-  string ret;
-  ret.reserve(40);
-  getLabelFromContent(d_content, d_pos, ret, recurs++);
+  unsigned int consumed;
+  vector<uint8_t> content(d_content);
+  content.insert(content.begin(), sizeof(dnsheader), 0);
+
+  string ret = DNSName((const char*) content.data(), content.size(), d_pos + sizeof(dnsheader), true /* uncompress */, 0 /* qtype */, 0 /* qclass */, &consumed).toString();
+
+  d_pos+=consumed;
   return ret;
 }
 
@@ -452,49 +456,6 @@ string PacketReader::getText(bool multi)
   return ret;
 }
 
-
-void PacketReader::getLabelFromContent(const vector<uint8_t>& content, uint16_t& frompos, string& ret, int recurs) 
-{
-  if(recurs > 1000) // the forward reference-check below should make this test 100% obsolete
-    throw MOADNSException("Loop");
-  // it is tempting to call reserve on ret, but it turns out it creates a malloc/free storm in the loop
-  for(;;) {
-    unsigned char labellen=content.at(frompos++);
-
-    if(!labellen) {
-      if(ret.empty())
-              ret.append(1,'.');
-      break;
-    }
-    else if((labellen & 0xc0) == 0xc0) {
-      uint16_t offset=256*(labellen & ~0xc0) + (unsigned int)content.at(frompos++) - sizeof(dnsheader);
-      //        cout<<"This is an offset, need to go to: "<<offset<<endl;
-
-      if(offset >= frompos-2)
-        throw MOADNSException("forward reference during label decompression");
-      return getLabelFromContent(content, offset, ret, ++recurs);
-    }
-    else if(labellen > 63) 
-      throw MOADNSException("Overly long label during label decompression ("+lexical_cast<string>((unsigned int)labellen)+")");
-    else {
-      // XXX FIXME THIS MIGHT BE VERY SLOW!
-
-      for(string::size_type n = 0 ; n < labellen; ++n, frompos++) {
-        if(content.at(frompos)=='.' || content.at(frompos)=='\\') {
-          ret.append(1, '\\');
-          ret.append(1, content[frompos]);
-        }
-        else if(content.at(frompos)==' ') {
-          ret+="\\032";
-        }
-        else 
-          ret.append(1, content[frompos]);
-      }
-      ret.append(1,'.');
-    }
-  }
-}
-
 void PacketReader::xfrBlob(string& blob)
 try
 {
@@ -534,7 +495,7 @@ void PacketReader::xfrHexBlob(string& blob, bool keepReading)
 string simpleCompress(const string& elabel, const string& root)
 {
   string label=elabel;
-  // FIXME: this relies on the semi-canonical escaped output from getLabelFromContent
+  // FIXME: this relies on the semi-canonical escaped output from getLabel
   if(strchr(label.c_str(), '\\')) {
     boost::replace_all(label, "\\.", ".");
     boost::replace_all(label, "\\032", " ");
index 5dedb9a1d806356d7e82a65a2bdc3a1fbc698b95..5f0de674b2afe511214153ee3a2169d218282aea 100644 (file)
@@ -37,6 +37,8 @@
 #include <boost/tuple/tuple_comparison.hpp>
 #include "dns.hh"
 #include "dnswriter.hh"
+#include "dnsname.hh"
+#include "pdnsexception.hh"
 
 /** DNS records have three representations:
     1) in the packet
@@ -133,13 +135,12 @@ public:
   void xfrHexBlob(string& blob, bool keepReading=false);
 
   static uint16_t get16BitInt(const vector<unsigned char>&content, uint16_t& pos);
-  static void getLabelFromContent(const vector<uint8_t>& content, uint16_t& frompos, string& ret, int recurs);
 
   void getDnsrecordheader(struct dnsrecordheader &ah);
   void copyRecord(vector<unsigned char>& dest, uint16_t len);
   void copyRecord(unsigned char* dest, uint16_t len);
 
-  string getLabel(unsigned int recurs=0);
+  string getLabel();
   string getText(bool multi);
 
   uint16_t d_pos;
index e38055ba5db01eda79097fb64d6958b9cdd33222..d6fb037437286614fbb444932cb2e56a5c0df0ce 100644 (file)
@@ -246,7 +246,7 @@ void DNSPacketWriter::xfrLabel(const string& Label, bool compress)
     if(unescaped) {
       string part(label.c_str() + i -> first, i->second - i->first);
 
-      // FIXME: this relies on the semi-canonical escaped output from getLabelFromContent
+      // FIXME: this relies on the semi-canonical escaped output from getLabel
       boost::replace_all(part, "\\.", ".");
       boost::replace_all(part, "\\032", " ");
       boost::replace_all(part, "\\\\", "\\");