Also, constlify some EDNS related functions.
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");
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);
*/
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();
*/
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) {
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)
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));
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();
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);
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++;
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
* 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;
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);
}
}
/** 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.
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++;
}
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;