gettime(&queryRealTime, true);
std::shared_ptr<DNSCryptQuery> dnsCryptQuery = nullptr;
-#ifdef HAVE_DNSCRYPT
auto dnsCryptResponse = checkDNSCryptQuery(*ci.cs, query, qlen, dnsCryptQuery, queryRealTime.tv_sec, true);
if (dnsCryptResponse) {
handler.writeSizeAndMsg(reinterpret_cast<char*>(dnsCryptResponse->data()), static_cast<uint16_t>(dnsCryptResponse->size()), g_tcpSendTimeout);
continue;
}
-#endif
struct dnsheader* dh = reinterpret_cast<struct dnsheader*>(query);
if (!checkQueryHeaders(dh)) {
size_t responseSize = rlen;
uint16_t addRoom = 0;
-#ifdef HAVE_DNSCRYPT
if (dq.dnsCryptQuery && (UINT16_MAX - rlen) > static_cast<uint16_t>(DNSCRYPT_MAX_RESPONSE_PADDING_AND_MAC_SIZE)) {
addRoom = DNSCRYPT_MAX_RESPONSE_PADDING_AND_MAC_SIZE;
}
-#endif
+
responseSize += addRoom;
answerBuffer.resize(responseSize);
char* response = answerBuffer.data();
#ifdef HAVE_PROTOBUF
dr.uniqueId = std::move(dq.uniqueId);
#endif
-#ifdef HAVE_DNSCRYPT
if (dq.dnsCryptQuery) {
dr.dnsCryptQuery = std::move(dq.dnsCryptQuery);
}
-#endif
memcpy(&cleartextDH, dr.dh, sizeof(cleartextDH));
if (!processResponse(&response, &responseLen, &responseSize, localRespRulactions, dr, addRoom, rewrittenResponse, false)) {
vector<std::tuple<ComboAddress, bool, bool, int, string, std::set<int>>> g_locals;
std::vector<std::shared_ptr<TLSFrontend>> g_tlslocals;
-#ifdef HAVE_DNSCRYPT
std::vector<std::tuple<ComboAddress,std::shared_ptr<DNSCryptContext>,bool, int, string, std::set<int> >> g_dnsCryptLocals;
-#endif
#ifdef HAVE_EBPF
shared_ptr<BPFFilter> g_defaultBPFFilter;
std::vector<std::shared_ptr<DynBPFFilter> > g_dynBPFFilters;
}
return true;
}
-#endif
+#endif /* HAVE_DNSCRYPT */
static bool applyRulesToResponse(LocalStateHolder<vector<DNSDistResponseRuleAction> >& localRespRulactions, DNSResponse& dr)
{
return false;
}
}
-#endif
+#endif /* HAVE_DNSCRYPT */
return true;
}
try {
setThreadName("dnsdist/respond");
auto localRespRulactions = g_resprulactions.getLocal();
-#ifdef HAVE_DNSCRYPT
char packet[4096 + DNSCRYPT_MAX_RESPONSE_PADDING_AND_MAC_SIZE];
-#else
- char packet[4096];
-#endif
static_assert(sizeof(packet) <= UINT16_MAX, "Packet size should fit in a uint16_t");
/* when the answer is encrypted in place, we need to get a copy
of the original header before encryption to fill the ring buffer */
#ifdef HAVE_PROTOBUF
dr.uniqueId = std::move(ids->uniqueId);
#endif
-#ifdef HAVE_DNSCRYPT
if (ids->dnsCryptQuery) {
addRoom = DNSCRYPT_MAX_RESPONSE_PADDING_AND_MAC_SIZE;
dr.dnsCryptQuery = std::move(ids->dnsCryptQuery);
}
-#endif
memcpy(&cleartextDH, dr.dh, sizeof(cleartextDH));
if (!processResponse(&response, &responseLen, &responseSize, localRespRulactions, dr, addRoom, rewrittenResponse, ids->cs && ids->cs->muted)) {
return true;
}
-#ifdef HAVE_DNSCRYPT
boost::optional<std::vector<uint8_t>> checkDNSCryptQuery(const ClientState& cs, const char* query, uint16_t& len, std::shared_ptr<DNSCryptQuery>& dnsCryptQuery, time_t now, bool tcp)
{
if (cs.dnscryptCtx) {
+#ifdef HAVE_DNSCRYPT
vector<uint8_t> response;
uint16_t decryptedQueryLen = 0;
}
len = decryptedQueryLen;
+#endif /* HAVE_DNSCRYPT */
}
return boost::none;
}
-#endif /* HAVE_DNSCRYPT */
bool checkQueryHeaders(const struct dnsheader* dh)
{
/* in case a rule changed it */
dq.delayMsec = dr.delayMsec;
- if (!cs.muted) {
#ifdef HAVE_DNSCRYPT
+ if (!cs.muted) {
if (!encryptResponse(reinterpret_cast<char*>(dq.dh), &dq.len, dq.size, dq.tcp, dq.dnsCryptQuery, nullptr, nullptr)) {
return false;
}
-#endif
}
+#endif /* HAVE_DNSCRYPT */
if (cacheHit) {
++g_stats.cacheHits;
gettime(&queryRealTime, true);
std::shared_ptr<DNSCryptQuery> dnsCryptQuery = nullptr;
-#ifdef HAVE_DNSCRYPT
auto dnsCryptResponse = checkDNSCryptQuery(cs, query, len, dnsCryptQuery, queryRealTime.tv_sec, false);
if (dnsCryptResponse) {
sendUDPResponse(cs.udpFD, reinterpret_cast<char*>(dnsCryptResponse->data()), static_cast<uint16_t>(dnsCryptResponse->size()), 0, dest, remote);
return;
}
-#endif
struct dnsheader* dh = reinterpret_cast<struct dnsheader*>(query);
queryId = ntohs(dh->id);
ids->origDest = cs.local;
ids->destHarvested = false;
}
-#ifdef HAVE_DNSCRYPT
+
ids->dnsCryptQuery = std::move(dq.dnsCryptQuery);
-#endif
+
#ifdef HAVE_PROTOBUF
ids->uniqueId = std::move(dq.uniqueId);
#endif
tcpBindsCount++;
}
-#ifdef HAVE_DNSCRYPT
for(auto& dcLocal : g_dnsCryptLocals) {
ClientState* cs = new ClientState;
cs->local = std::get<0>(dcLocal);
g_frontends.push_back(cs);
tcpBindsCount++;
}
-#endif
for(auto& frontend : g_tlslocals) {
ClientState* cs = new ClientState;
ComboAddress origDest; // 28
StopWatch sentTime; // 16
DNSName qname; // 80
-#ifdef HAVE_DNSCRYPT
std::shared_ptr<DNSCryptQuery> dnsCryptQuery{nullptr};
-#endif
#ifdef HAVE_PROTOBUF
boost::optional<boost::uuids::uuid> uniqueId;
#endif
{
std::set<int> cpus;
ComboAddress local;
-#ifdef HAVE_DNSCRYPT
std::shared_ptr<DNSCryptContext> dnscryptCtx{nullptr};
-#endif
shared_ptr<TLSFrontend> tlsFrontend;
std::atomic<uint64_t> queries{0};
int udpFD{-1};
bool checkQueryHeaders(const struct dnsheader* dh);
-#ifdef HAVE_DNSCRYPT
extern std::vector<std::tuple<ComboAddress, std::shared_ptr<DNSCryptContext>, bool, int, std::string, std::set<int> > > g_dnsCryptLocals;
-
int handleDNSCryptQuery(char* packet, uint16_t len, std::shared_ptr<DNSCryptQuery> query, uint16_t* decryptedQueryLen, bool tcp, time_t now, std::vector<uint8_t>& response);
-
boost::optional<std::vector<uint8_t>> checkDNSCryptQuery(const ClientState& cs, const char* query, uint16_t& len, std::shared_ptr<DNSCryptQuery>& dnsCryptQuery, time_t now, bool tcp);
-#endif
bool addXPF(DNSQuestion& dq, uint16_t optionCode);