From: Pieter Lexis Date: Tue, 17 Apr 2018 14:40:48 +0000 (+0200) Subject: EDNS: rename Z to extFlags, use uints X-Git-Tag: dnsdist-1.3.1~50^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6c335abe5d9492485fdc7759392bb81eb2e65f7;p=pdns EDNS: rename Z to extFlags, use uints Also, constlify some EDNS related functions. --- diff --git a/pdns/dns.hh b/pdns/dns.hh index 46a1b3081..dff9a80df 100644 --- a/pdns/dns.hh +++ b/pdns/dns.hh @@ -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"); diff --git a/pdns/dnsdist-ecs.cc b/pdns/dnsdist-ecs.cc index eaaa6c8fc..5d5f06db7 100644 --- a/pdns/dnsdist-ecs.cc +++ b/pdns/dnsdist-ecs.cc @@ -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); diff --git a/pdns/dnspacket.cc b/pdns/dnspacket.cc index d0c93013d..8889a69c4 100644 --- a/pdns/dnspacket.cc +++ b/pdns/dnspacket.cc @@ -546,8 +546,8 @@ try */ d_ednsRawPacketSizeLimit=edo.d_packetsize; d_maxreplylen=std::min(std::max(static_cast(512), edo.d_packetsize), s_udpTruncationThreshold); -// cerr< >::const_iterator iter = edo.d_options.begin(); diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 298f27553..3788bbb62 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -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(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)); diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index ebbd553dc..4fcdd2382 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -788,14 +788,14 @@ struct EDNSOpts enum zFlags { DNSSECOK=32768 }; vector > 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(); diff --git a/pdns/dnsreplay.cc b/pdns/dnsreplay.cc index 44238f772..789180f63 100644 --- a/pdns/dnsreplay.cc +++ b/pdns/dnsreplay.cc @@ -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); diff --git a/pdns/dnsscope.cc b/pdns/dnsscope.cc index 4ad9976a8..7627b973d 100644 --- a/pdns/dnsscope.cc +++ b/pdns/dnsscope.cc @@ -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++; diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index 3b60a3ee9..95e0687bb 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -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 >& 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); } } diff --git a/pdns/dnswriter.hh b/pdns/dnswriter.hh index 6e7317a93..f21b6e543 100644 --- a/pdns/dnswriter.hh +++ b/pdns/dnswriter.hh @@ -71,7 +71,7 @@ public: /** Shorthand way to add an Opt-record, for example for EDNS0 purposes */ typedef vector > 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. diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index b198ae4d4..d808e55e0 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -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;