return true;
}
-static bool slowParseEDNSOptions(const PacketBuffer& packet, std::shared_ptr<std::map<uint16_t, EDNSOptionView> >& options)
+static bool slowParseEDNSOptions(const PacketBuffer& packet, std::map<uint16_t, EDNSOptionView>& options)
{
if (packet.size() < sizeof(dnsheader)) {
return false;
}
/* if we survive this call, we can parse it safely */
dpm.skipRData();
- return getEDNSOptions(reinterpret_cast<const char*>(&packet.at(offset)), packet.size() - offset, *options) == 0;
+ return getEDNSOptions(reinterpret_cast<const char*>(&packet.at(offset)), packet.size() - offset, options) == 0;
}
else {
dpm.skipRData();
return true;
}
- dq.ednsOptions = std::make_shared<std::map<uint16_t, EDNSOptionView> >();
+ dq.ednsOptions = std::make_unique<std::map<uint16_t, EDNSOptionView> >();
if (ntohs(dh->arcount) == 0) {
/* nothing in additional so no EDNS */
}
if (ntohs(dh->ancount) != 0 || ntohs(dh->nscount) != 0 || ntohs(dh->arcount) > 1) {
- return slowParseEDNSOptions(dq.getData(), dq.ednsOptions);
+ return slowParseEDNSOptions(dq.getData(), *dq.ednsOptions);
}
size_t remaining = 0;
return false;
}
-bool getEDNS0Record(const DNSQuestion& dq, EDNS0Record& edns0)
+bool getEDNS0Record(const PacketBuffer& packet, EDNS0Record& edns0)
{
uint16_t optStart;
size_t optLen = 0;
bool last = false;
- const auto& packet = dq.getData();
int res = locateEDNSOptRR(packet, &optStart, &optLen, &last);
if (res != 0) {
// no EDNS OPT RR
int getEDNSZ(const DNSQuestion& dq);
bool queryHasEDNS(const DNSQuestion& dq);
-bool getEDNS0Record(const DNSQuestion& dq, EDNS0Record& edns0);
+bool getEDNS0Record(const PacketBuffer& packet, EDNS0Record& edns0);
bool setEDNSOption(DNSQuestion& dq, uint16_t ednsCode, const std::string& data);
std::shared_ptr<DNSDistPacketCache> packetCache{nullptr}; // 16
std::unique_ptr<DNSCryptQuery> dnsCryptQuery{nullptr}; // 8
std::unique_ptr<QTag> qTag{nullptr}; // 8
- boost::optional<uint32_t> tempFailureTTL; // 8
+ boost::optional<uint32_t> tempFailureTTL{boost::none}; // 8
ClientState* cs{nullptr}; // 8
std::unique_ptr<DOHUnit, void (*)(DOHUnit*)> du; // 8
uint32_t cacheKey{0}; // 4
InternalQueryState& ids;
std::unique_ptr<Netmask> ecs{nullptr};
std::string sni; /* Server Name Indication, if any (DoT or DoH) */
- mutable std::shared_ptr<std::map<uint16_t, EDNSOptionView> > ednsOptions;
+ mutable std::unique_ptr<std::map<uint16_t, EDNSOptionView> > ednsOptions; /* this needs to be mutable because it is parsed just in time, when DNSQuestion is read-only */
std::unique_ptr<std::vector<ProxyProtocolValue>> proxyProtocolValues{nullptr};
uint16_t ecsPrefixLength;
uint8_t ednsRCode{0};
}
EDNS0Record edns0;
- if (!getEDNS0Record(*dq, edns0)) {
+ if (!getEDNS0Record(dq->getData(), edns0)) {
return false;
}
bool matches(const DNSQuestion* dq) const override
{
EDNS0Record edns0;
- if (!getEDNS0Record(*dq, edns0)) {
+ if (!getEDNS0Record(dq->getData(), edns0)) {
return false;
}
BOOST_CHECK_EQUAL(mdp.d_answers.at(0).first.d_name, g_rootdnsname);
EDNS0Record edns0;
- BOOST_REQUIRE(getEDNS0Record(dq, edns0));
+ BOOST_REQUIRE(getEDNS0Record(dq.getData(), edns0));
BOOST_CHECK_EQUAL(edns0.version, 0U);
BOOST_CHECK_EQUAL(edns0.extRCode, 0U);
BOOST_CHECK_EQUAL(edns0.extFlags, EDNS_HEADER_FLAG_DO);