]> granicus.if.org Git - pdns/commitdiff
centralise constant
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 9 Jul 2019 09:27:18 +0000 (11:27 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Wed, 10 Jul 2019 08:07:20 +0000 (10:07 +0200)
(cherry picked from commit 43f038d7d1931bf499d8b03435b99feecea4d170)

pdns/dnswriter.cc

index ca95cc2435199c21d5a2a890eae78fa72880f44a..82ddce707367178b49dac2d05531515996fdce61 100644 (file)
@@ -201,6 +201,7 @@ void DNSPacketWriter::xfrUnquotedText(const string& text, bool lenField)
 
 
 static constexpr bool l_verbose=false;
+static constexpr uint16_t maxCompressionOffset=16384;
 uint16_t DNSPacketWriter::lookupName(const DNSName& name, uint16_t* matchLen)
 {
   // iterate over the written labels, see if we find a match
@@ -268,7 +269,7 @@ uint16_t DNSPacketWriter::lookupName(const DNSName& name, uint16_t* matchLen)
         if(!c)
           break;
         auto offset = iter - d_content.cbegin();
-        if (offset >= 16384) break; // compression pointers cannot point here
+        if (offset >= maxCompressionOffset) break; // compression pointers cannot point here
         pvect.push_back(offset);
         iter+=*iter+1;
       }
@@ -328,14 +329,14 @@ void DNSPacketWriter::xfrName(const DNSName& name, bool compress, bool)
 
   uint16_t li=0;
   uint16_t matchlen=0;
-  if(d_compress && compress && (li=lookupName(name, &matchlen)) && li < 16384) {
+  if(d_compress && compress && (li=lookupName(name, &matchlen)) && li < maxCompressionOffset) {
     const auto& dns=name.getStorage(); 
     if(l_verbose)
       cout<<"Found a substring of "<<matchlen<<" bytes from the back, offset: "<<li<<", dnslen: "<<dns.size()<<endl;
     // found a substring, if www.powerdns.com matched powerdns.com, we get back matchlen = 13
 
     unsigned int pos=d_content.size();
-    if(pos < 16384 && matchlen != dns.size()) {
+    if(pos < maxCompressionOffset && matchlen != dns.size()) {
       if(l_verbose)
         cout<<"Inserting pos "<<pos<<" for "<<name<<" for compressed case"<<endl;
       d_namepositions.push_back(pos);
@@ -354,7 +355,7 @@ void DNSPacketWriter::xfrName(const DNSName& name, bool compress, bool)
     unsigned int pos=d_content.size();
     if(l_verbose)
       cout<<"Found nothing, we are at pos "<<pos<<", inserting whole name"<<endl;
-    if(pos < 16384) {
+    if(pos < maxCompressionOffset) {
       if(l_verbose)
         cout<<"Inserting pos "<<pos<<" for "<<name<<" for uncompressed case"<<endl;
       d_namepositions.push_back(pos);