]> granicus.if.org Git - pdns/commitdiff
EDNS: rename Z to extFlags, use uints
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 17 Apr 2018 14:40:48 +0000 (16:40 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Wed, 30 May 2018 08:00:52 +0000 (10:00 +0200)
Also, constlify some EDNS related functions.

pdns/dns.hh
pdns/dnsdist-ecs.cc
pdns/dnspacket.cc
pdns/dnsrecords.cc
pdns/dnsrecords.hh
pdns/dnsreplay.cc
pdns/dnsscope.cc
pdns/dnswriter.cc
pdns/dnswriter.hh
pdns/pdns_recursor.cc

index 46a1b3081a3e1e82684e92109953ec026e9976e0..dff9a80dfd7e9791aee593d1150f2a5964307185 100644 (file)
@@ -132,10 +132,10 @@ struct dnsrecordheader
   uint16_t d_clen;
 } GCCPACKATTRIBUTE;
 
-struct EDNS0Record 
-{ 
-        uint8_t extRCode, version; 
-        uint16_t Z; 
+struct EDNS0Record
+{
+  uint8_t extRCode{0}, version{0};
+  uint16_t extFlags{0};
 } GCCPACKATTRIBUTE;
 
 static_assert(sizeof(EDNS0Record) == 4, "EDNS0Record size must be 4");
index eaaa6c8fc8ac3884c3352043e32f682c7e26c8e0..5d5f06db71f4dc545c3fbf57efc3be45e88b9fe2 100644 (file)
@@ -247,7 +247,7 @@ void generateOptRR(const std::string& optRData, string& res)
   EDNS0Record edns0;
   edns0.extRCode = 0;
   edns0.version = 0;
-  edns0.Z = 0;
+  edns0.extFlags = 0;
   
   dh.d_type = htons(QType::OPT);
   dh.d_class = htons(g_EdnsUDPPayloadSize);
index d0c93013dddd40bfeb4878a679e81f2552508064..8889a69c4b78b280d2148c437f5e0b415bd1b5ce 100644 (file)
@@ -546,8 +546,8 @@ try
     */
     d_ednsRawPacketSizeLimit=edo.d_packetsize;
     d_maxreplylen=std::min(std::max(static_cast<uint16_t>(512), edo.d_packetsize), s_udpTruncationThreshold);
-//    cerr<<edo.d_Z<<endl;
-    if(edo.d_Z & EDNSOpts::DNSSECOK)
+//    cerr<<edo.d_extFlags<<endl;
+    if(edo.d_extFlags & EDNSOpts::DNSSECOK)
       d_dnssecOk=true;
 
     for(vector<pair<uint16_t, string> >::const_iterator iter = edo.d_options.begin();
index 298f2755333db5c52cd3ad0fdc2d3a5964d691e3..3788bbb62d5b5056e6e874e98d283abc3c378723 100644 (file)
@@ -543,7 +543,7 @@ uint16_t DNSKEYRecordContent::getTag()
  */
 bool getEDNSOpts(const MOADNSParser& mdp, EDNSOpts* eo)
 {
-  eo->d_Z=0;
+  eo->d_extFlags=0;
   if(mdp.d_header.arcount && !mdp.d_answers.empty()) {
     for(const MOADNSParser::answers_t::value_type& val :  mdp.d_answers) {
       if(val.first.d_place == DNSResourceRecord::ADDITIONAL && val.first.d_type == QType::OPT) {
@@ -556,7 +556,7 @@ bool getEDNSOpts(const MOADNSParser& mdp, EDNSOpts* eo)
         
         eo->d_extRCode=stuff.extRCode;
         eo->d_version=stuff.version;
-        eo->d_Z = ntohs(stuff.Z);
+        eo->d_extFlags = ntohs(stuff.extFlags);
         OPTRecordContent* orc = 
           dynamic_cast<OPTRecordContent*>(val.first.d_content.get());
         if(!orc)
@@ -569,12 +569,12 @@ bool getEDNSOpts(const MOADNSParser& mdp, EDNSOpts* eo)
   return false;
 }
 
-DNSRecord makeOpt(int udpsize, int extRCode, int Z)
+DNSRecord makeOpt(const uint16_t udpsize, const uint16_t extRCode, const uint16_t extFlags)
 {
   EDNS0Record stuff;
   stuff.extRCode=0;
   stuff.version=0;
-  stuff.Z=htons(Z);
+  stuff.extFlags=htons(extFlags);
   DNSRecord dr;
   static_assert(sizeof(EDNS0Record) == sizeof(dr.d_ttl), "sizeof(EDNS0Record) must match sizeof(DNSRecord.d_ttl)");
   memcpy(&dr.d_ttl, &stuff, sizeof(stuff));
index ebbd553dc10d824fe86d3d15af968b6985f36ae2..4fcdd2382d83c77ab94697eeb1fc04691eadd3d6 100644 (file)
@@ -788,14 +788,14 @@ struct EDNSOpts
   enum zFlags { DNSSECOK=32768 };
   vector<pair<uint16_t, string> > d_options;
   uint16_t d_packetsize{0};
-  uint16_t d_Z{0};
+  uint16_t d_extFlags{0};
   uint8_t d_extRCode, d_version;
 };
 //! Convenience function that fills out EDNS0 options, and returns true if there are any
 
 class MOADNSParser;
 bool getEDNSOpts(const MOADNSParser& mdp, EDNSOpts* eo);
-DNSRecord makeOpt(int udpsize, int extRCode, int Z);
+DNSRecord makeOpt(const uint16_t udpsize, const uint16_t extRCode, const uint16_t extFlags);
 void reportBasicTypes();
 void reportOtherTypes();
 void reportAllTypes();
index 44238f7725f82d7ae6a82ff456e4bab859900b80..789180f63a37f73aaa081b3533cd406e866b86f8 100644 (file)
@@ -558,7 +558,7 @@ static void generateOptRR(const std::string& optRData, string& res)
   EDNS0Record edns0;
   edns0.extRCode = 0;
   edns0.version = 0;
-  edns0.Z = 0;
+  edns0.extFlags = 0;
   
   dh.d_type = htons(QType::OPT);
   dh.d_class = htons(1280);
index 4ad9976a8ce48a8a8a9b16c4fb98d89b2c18ecd2..7627b973d58e7e9f82845ab4819a02060a91abc4 100644 (file)
@@ -225,7 +225,7 @@ try
 
          if(!mdp.d_header.qr && getEDNSOpts(mdp, &edo)) {
            edns++;
-           if(edo.d_Z & EDNSOpts::DNSSECOK)
+           if(edo.d_extFlags & EDNSOpts::DNSSECOK)
              dnssecOK++;
            if(mdp.d_header.cd)
              dnssecCD++;
index 3b60a3ee9dca8ebe363493e3d7accd448eed438a..95e0687bb9d84ca11032206aad7a3a3337fd5eaa 100644 (file)
@@ -94,14 +94,14 @@ void DNSPacketWriter::startRecord(const DNSName& name, uint16_t qtype, uint32_t
   d_sor=d_content.size(); // this will remind us where to stuff the record size
 }
 
-void DNSPacketWriter::addOpt(uint16_t udpsize, uint16_t extRCode, int Z, const vector<pair<uint16_t,string> >& options, uint8_t version)
+void DNSPacketWriter::addOpt(const uint16_t udpsize, const uint16_t extRCode, const uint16_t ednsFlags, const optvect_t& options, const uint8_t version)
 {
   uint32_t ttl=0;
 
   EDNS0Record stuff;
 
-  stuff.version=version;
-  stuff.Z=htons(Z);
+  stuff.version = version;
+  stuff.extFlags = htons(ednsFlags);
 
   /* RFC 6891 section 4 on the Extended RCode wire format
    *    EXTENDED-RCODE
@@ -109,6 +109,7 @@ void DNSPacketWriter::addOpt(uint16_t udpsize, uint16_t extRCode, int Z, const v
    *        4 bits defined in [RFC1035].  Note that EXTENDED-RCODE value 0
    *        indicates that an unextended RCODE is in use (values 0 through 15).
    */
+  // XXX Should be check for extRCode > 1<<12 ?
   stuff.extRCode = extRCode>>4;
   if (extRCode != 0) { // As this trumps the existing RCODE
     getHeader()->rcode = extRCode;
@@ -120,10 +121,10 @@ void DNSPacketWriter::addOpt(uint16_t udpsize, uint16_t extRCode, int Z, const v
   ttl=ntohl(ttl); // will be reversed later on
 
   startRecord(g_rootdnsname, QType::OPT, ttl, udpsize, DNSResourceRecord::ADDITIONAL, false);
-  for(optvect_t::const_iterator iter = options.begin(); iter != options.end(); ++iter) {
-    xfr16BitInt(iter->first);
-    xfr16BitInt(iter->second.length());
-    xfrBlob(iter->second);
+  for(auto const &option : options) {
+    xfr16BitInt(option.first);
+    xfr16BitInt(option.second.length());
+    xfrBlob(option.second);
   }
 }
 
index 6e7317a93fb6e19347ae94575ec000f5fe56967c..f21b6e543f2d108ea48a5ac8afe11f93ad8fa7ba 100644 (file)
@@ -71,7 +71,7 @@ public:
 
   /** Shorthand way to add an Opt-record, for example for EDNS0 purposes */
   typedef vector<pair<uint16_t,std::string> > optvect_t;
-  void addOpt(uint16_t udpsize, uint16_t extRCode, int Z, const optvect_t& options=optvect_t(), uint8_t version=0);
+  void addOpt(const uint16_t udpsize, const uint16_t extRCode, const uint16_t ednsFlags, const optvect_t& options=optvect_t(), const uint8_t version=0);
 
   /** needs to be called after the last record is added, but can be called again and again later on. Is called internally by startRecord too.
       The content of the vector<> passed to the constructor is inconsistent until commit is called.
index b198ae4d47fe3cd49f77fe1da1e48850b819afd6..d808e55e02979d99369eeb3a577654455c149f63 100644 (file)
@@ -951,7 +951,7 @@ static void startDoResolve(void *p)
       sr.setDoDNSSEC(true);
 
       // Does the requestor want DNSSEC records?
-      if(edo.d_Z & EDNSOpts::DNSSECOK) {
+      if(edo.d_extFlags & EDNSOpts::DNSSECOK) {
         DNSSECOK=true;
         g_stats.dnssecQueries++;
       }
@@ -977,7 +977,7 @@ static void startDoResolve(void *p)
     DNSFilterEngine::Policy appliedPolicy;
     DNSRecord spoofed;
     RecursorLua4::DNSQuestion dq(dc->d_source, dc->d_destination, dc->d_mdp.d_qname, dc->d_mdp.d_qtype, dc->d_tcp, variableAnswer, wantsRPZ);
-    dq.ednsFlags = &edo.d_Z;
+    dq.ednsFlags = &edo.d_extFlags;
     dq.ednsOptions = &ednsOpts;
     dq.tag = dc->d_tag;
     dq.discardedPolicies = &sr.d_discardedPolicies;