]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsdist.hh
Merge pull request #4269 from j0ju/master
[thirdparty/pdns.git] / pdns / dnsdist.hh
1 #pragma once
2 #include "config.h"
3 #include "ext/luawrapper/include/LuaContext.hpp"
4 #include <time.h>
5 #include "misc.hh"
6 #include "iputils.hh"
7 #include "dnsname.hh"
8 #include <atomic>
9 #include <boost/circular_buffer.hpp>
10 #include <boost/variant.hpp>
11 #include <mutex>
12 #include <thread>
13 #include <unistd.h>
14 #include "sholder.hh"
15 #include "dnscrypt.hh"
16 #include "dnsdist-cache.hh"
17 #include "gettime.hh"
18 #include "dnsdist-dynbpf.hh"
19 #include "bpf-filter.hh"
20
21 #ifdef HAVE_PROTOBUF
22 #include <boost/uuid/uuid.hpp>
23 #include <boost/uuid/uuid_generators.hpp>
24 #endif
25
26 void* carbonDumpThread();
27 uint64_t uptimeOfProcess(const std::string& str);
28
29 struct DynBlock
30 {
31 DynBlock& operator=(const DynBlock& rhs)
32 {
33 reason=rhs.reason;
34 until=rhs.until;
35 domain=rhs.domain;
36 blocks.store(rhs.blocks);
37 return *this;
38 }
39
40 string reason;
41 struct timespec until;
42 DNSName domain;
43 mutable std::atomic<unsigned int> blocks;
44 };
45
46 extern GlobalStateHolder<NetmaskTree<DynBlock>> g_dynblockNMG;
47
48 extern vector<pair<struct timeval, std::string> > g_confDelta;
49
50 struct DNSDistStats
51 {
52 using stat_t=std::atomic<uint64_t>; // aww yiss ;-)
53 stat_t responses{0};
54 stat_t servfailResponses{0};
55 stat_t queries{0};
56 stat_t nonCompliantQueries{0};
57 stat_t nonCompliantResponses{0};
58 stat_t rdQueries{0};
59 stat_t emptyQueries{0};
60 stat_t aclDrops{0};
61 stat_t blockFilter{0};
62 stat_t dynBlocked{0};
63 stat_t ruleDrop{0};
64 stat_t ruleNXDomain{0};
65 stat_t selfAnswered{0};
66 stat_t downstreamTimeouts{0};
67 stat_t downstreamSendErrors{0};
68 stat_t truncFail{0};
69 stat_t noPolicy{0};
70 stat_t cacheHits{0};
71 stat_t cacheMisses{0};
72 stat_t latency0_1{0}, latency1_10{0}, latency10_50{0}, latency50_100{0}, latency100_1000{0}, latencySlow{0};
73
74 double latencyAvg100{0}, latencyAvg1000{0}, latencyAvg10000{0}, latencyAvg1000000{0};
75 typedef std::function<uint64_t(const std::string&)> statfunction_t;
76 typedef boost::variant<stat_t*, double*, statfunction_t> entry_t;
77 std::vector<std::pair<std::string, entry_t>> entries{
78 {"responses", &responses}, {"servfail-responses", &servfailResponses},
79 {"queries", &queries}, {"acl-drops", &aclDrops},
80 {"block-filter", &blockFilter}, {"rule-drop", &ruleDrop},
81 {"rule-nxdomain", &ruleNXDomain}, {"self-answered", &selfAnswered},
82 {"downstream-timeouts", &downstreamTimeouts}, {"downstream-send-errors", &downstreamSendErrors},
83 {"trunc-failures", &truncFail}, {"no-policy", &noPolicy},
84 {"latency0-1", &latency0_1}, {"latency1-10", &latency1_10},
85 {"latency10-50", &latency10_50}, {"latency50-100", &latency50_100},
86 {"latency100-1000", &latency100_1000}, {"latency-slow", &latencySlow},
87 {"latency-avg100", &latencyAvg100}, {"latency-avg1000", &latencyAvg1000},
88 {"latency-avg10000", &latencyAvg10000}, {"latency-avg1000000", &latencyAvg1000000},
89 {"uptime", uptimeOfProcess},
90 {"real-memory-usage", getRealMemoryUsage},
91 {"noncompliant-queries", &nonCompliantQueries},
92 {"noncompliant-responses", &nonCompliantResponses},
93 {"rdqueries", &rdQueries},
94 {"empty-queries", &emptyQueries},
95 {"cache-hits", &cacheHits},
96 {"cache-misses", &cacheMisses},
97 {"cpu-user-msec", getCPUTimeUser},
98 {"cpu-sys-msec", getCPUTimeSystem},
99 {"fd-usage", getOpenFileDescriptors}, {"dyn-blocked", &dynBlocked},
100 {"dyn-block-nmg-size", [](const std::string&) { return g_dynblockNMG.getLocal()->size(); }}
101 };
102 };
103
104
105 extern struct DNSDistStats g_stats;
106
107
108 struct StopWatch
109 {
110 StopWatch(bool realTime=false): d_needRealTime(realTime)
111 {
112 }
113 struct timespec d_start{0,0};
114 bool d_needRealTime{false};
115
116 void start() {
117 if(gettime(&d_start, d_needRealTime) < 0)
118 unixDie("Getting timestamp");
119
120 }
121
122 double udiff() const {
123 struct timespec now;
124 if(gettime(&now, d_needRealTime) < 0)
125 unixDie("Getting timestamp");
126
127 return 1000000.0*(now.tv_sec - d_start.tv_sec) + (now.tv_nsec - d_start.tv_nsec)/1000.0;
128 }
129
130 double udiffAndSet() {
131 struct timespec now;
132 if(gettime(&now, d_needRealTime) < 0)
133 unixDie("Getting timestamp");
134
135 auto ret= 1000000.0*(now.tv_sec - d_start.tv_sec) + (now.tv_nsec - d_start.tv_nsec)/1000.0;
136 d_start = now;
137 return ret;
138 }
139
140 };
141
142 class QPSLimiter
143 {
144 public:
145 QPSLimiter()
146 {
147 }
148
149 QPSLimiter(unsigned int rate, unsigned int burst) : d_rate(rate), d_burst(burst), d_tokens(burst)
150 {
151 d_passthrough=false;
152 d_prev.start();
153 }
154
155 unsigned int getRate() const
156 {
157 return d_passthrough? 0 : d_rate;
158 }
159
160 int getPassed() const
161 {
162 return d_passed;
163 }
164 int getBlocked() const
165 {
166 return d_blocked;
167 }
168
169 bool check() const // this is not quite fair
170 {
171 if(d_passthrough)
172 return true;
173 auto delta = d_prev.udiffAndSet();
174
175 d_tokens += 1.0*d_rate * (delta/1000000.0);
176
177 if(d_tokens > d_burst)
178 d_tokens = d_burst;
179
180 bool ret=false;
181 if(d_tokens >= 1.0) { // we need this because burst=1 is weird otherwise
182 ret=true;
183 --d_tokens;
184 d_passed++;
185 }
186 else
187 d_blocked++;
188
189 return ret;
190 }
191 private:
192 bool d_passthrough{true};
193 unsigned int d_rate;
194 unsigned int d_burst;
195 mutable double d_tokens;
196 mutable StopWatch d_prev;
197 mutable unsigned int d_passed{0};
198 mutable unsigned int d_blocked{0};
199 };
200
201 struct IDState
202 {
203 IDState() : origFD(-1), sentTime(true), delayMsec(0) { origDest.sin4.sin_family = 0;}
204 IDState(const IDState& orig)
205 {
206 origFD = orig.origFD;
207 origID = orig.origID;
208 origRemote = orig.origRemote;
209 origDest = orig.origDest;
210 delayMsec = orig.delayMsec;
211 age.store(orig.age.load());
212 }
213
214 int origFD; // set to <0 to indicate this state is empty // 4
215
216 ComboAddress origRemote; // 28
217 ComboAddress origDest; // 28
218 StopWatch sentTime; // 16
219 DNSName qname; // 80
220 #ifdef HAVE_DNSCRYPT
221 std::shared_ptr<DnsCryptQuery> dnsCryptQuery{0};
222 #endif
223 #ifdef HAVE_PROTOBUF
224 boost::uuids::uuid uniqueId;
225 #endif
226 std::shared_ptr<DNSDistPacketCache> packetCache{nullptr};
227 uint32_t cacheKey; // 8
228 std::atomic<uint16_t> age; // 4
229 uint16_t qtype; // 2
230 uint16_t qclass; // 2
231 uint16_t origID; // 2
232 uint16_t origFlags; // 2
233 int delayMsec;
234 bool ednsAdded{false};
235 bool ecsAdded{false};
236 bool skipCache{false};
237 };
238
239 struct Rings {
240 Rings()
241 {
242 queryRing.set_capacity(10000);
243 respRing.set_capacity(10000);
244 pthread_rwlock_init(&queryLock, 0);
245 }
246 struct Query
247 {
248 struct timespec when;
249 ComboAddress requestor;
250 DNSName name;
251 uint16_t size;
252 uint16_t qtype;
253 struct dnsheader dh;
254 };
255 boost::circular_buffer<Query> queryRing;
256 struct Response
257 {
258 struct timespec when;
259 ComboAddress requestor;
260 DNSName name;
261 uint16_t qtype;
262 unsigned int usec;
263 unsigned int size;
264 struct dnsheader dh;
265 ComboAddress ds; // who handled it
266 };
267 boost::circular_buffer<Response> respRing;
268 std::mutex respMutex;
269 pthread_rwlock_t queryLock;
270
271 std::unordered_map<int, vector<boost::variant<string,double> > > getTopBandwidth(unsigned int numentries);
272 size_t numDistinctRequestors();
273 };
274
275 extern Rings g_rings;
276
277 struct ClientState
278 {
279 ComboAddress local;
280 #ifdef HAVE_DNSCRYPT
281 DnsCryptContext* dnscryptCtx{0};
282 #endif
283 std::atomic<uint64_t> queries{0};
284 int udpFD{-1};
285 int tcpFD{-1};
286 };
287
288 class TCPClientCollection {
289 std::vector<int> d_tcpclientthreads;
290 std::atomic<uint64_t> d_pos{0};
291 public:
292 std::atomic<uint64_t> d_queued{0}, d_numthreads{0};
293 uint64_t d_maxthreads{0};
294
295 TCPClientCollection(size_t maxThreads)
296 {
297 d_maxthreads = maxThreads;
298 d_tcpclientthreads.reserve(maxThreads);
299 }
300
301 int getThread()
302 {
303 uint64_t pos = d_pos++;
304 ++d_queued;
305 return d_tcpclientthreads[pos % d_numthreads];
306 }
307 void addTCPClientThread();
308 };
309
310 extern std::shared_ptr<TCPClientCollection> g_tcpclientthreads;
311
312 struct DownstreamState
313 {
314 DownstreamState(const ComboAddress& remote_, const ComboAddress& sourceAddr_, unsigned int sourceItf);
315 DownstreamState(const ComboAddress& remote_): DownstreamState(remote_, ComboAddress(), 0) {}
316 ~DownstreamState()
317 {
318 if (fd >= 0)
319 close(fd);
320 }
321
322 int fd{-1};
323 std::thread tid;
324 ComboAddress remote;
325 QPSLimiter qps;
326 vector<IDState> idStates;
327 ComboAddress sourceAddr;
328 DNSName checkName{"a.root-servers.net."};
329 QType checkType{QType::A};
330 std::atomic<uint64_t> idOffset{0};
331 std::atomic<uint64_t> sendErrors{0};
332 std::atomic<uint64_t> outstanding{0};
333 std::atomic<uint64_t> reuseds{0};
334 std::atomic<uint64_t> queries{0};
335 struct {
336 std::atomic<uint64_t> sendErrors{0};
337 std::atomic<uint64_t> reuseds{0};
338 std::atomic<uint64_t> queries{0};
339 } prev;
340 string name;
341 double queryLoad{0.0};
342 double dropRate{0.0};
343 double latencyUsec{0.0};
344 int order{1};
345 int weight{1};
346 int tcpRecvTimeout{30};
347 int tcpSendTimeout{30};
348 unsigned int sourceItf{0};
349 uint16_t retries{5};
350 uint8_t currentCheckFailures{0};
351 uint8_t maxCheckFailures{1};
352 StopWatch sw;
353 set<string> pools;
354 enum class Availability { Up, Down, Auto} availability{Availability::Auto};
355 bool mustResolve{false};
356 bool upStatus{false};
357 bool useECS{false};
358 bool isUp() const
359 {
360 if(availability == Availability::Down)
361 return false;
362 if(availability == Availability::Up)
363 return true;
364 return upStatus;
365 }
366 void setUp() { availability = Availability::Up; }
367 void setDown() { availability = Availability::Down; }
368 void setAuto() { availability = Availability::Auto; }
369 string getName() const {
370 if (name.empty()) {
371 return remote.toStringWithPort();
372 }
373 return name;
374 }
375 string getNameWithAddr() const {
376 if (name.empty()) {
377 return remote.toStringWithPort();
378 }
379 return name + " (" + remote.toStringWithPort()+ ")";
380 }
381
382 };
383 using servers_t =vector<std::shared_ptr<DownstreamState>>;
384
385 struct DNSQuestion
386 {
387 DNSQuestion(const DNSName* name, uint16_t type, uint16_t class_, const ComboAddress* lc, const ComboAddress* rem, struct dnsheader* header, size_t bufferSize, uint16_t queryLen, bool isTcp): qname(name), qtype(type), qclass(class_), local(lc), remote(rem), dh(header), size(bufferSize), len(queryLen), tcp(isTcp) { }
388
389 #ifdef HAVE_PROTOBUF
390 boost::uuids::uuid uniqueId;
391 #endif
392 const DNSName* qname;
393 const uint16_t qtype;
394 const uint16_t qclass;
395 const ComboAddress* local;
396 const ComboAddress* remote;
397 struct dnsheader* dh;
398 size_t size;
399 uint16_t len;
400 const bool tcp;
401 bool skipCache{false};
402 };
403
404 struct DNSResponse : DNSQuestion
405 {
406 DNSResponse(const DNSName* name, uint16_t type, uint16_t class_, const ComboAddress* lc, const ComboAddress* rem, struct dnsheader* header, size_t bufferSize, uint16_t queryLen, bool isTcp, const struct timespec* queryTime_): DNSQuestion(name, type, class_, lc, rem, header, bufferSize, queryLen, isTcp), queryTime(queryTime_) { }
407
408 const struct timespec* queryTime;
409 };
410
411 typedef std::function<bool(const DNSQuestion*)> blockfilter_t;
412 template <class T> using NumberedVector = std::vector<std::pair<unsigned int, T> >;
413
414 void* responderThread(std::shared_ptr<DownstreamState> state);
415 extern std::mutex g_luamutex;
416 extern LuaContext g_lua;
417 extern std::string g_outputBuffer; // locking for this is ok, as locked by g_luamutex
418
419 class DNSRule
420 {
421 public:
422 virtual bool matches(const DNSQuestion* dq) const =0;
423 virtual string toString() const = 0;
424 mutable std::atomic<uint64_t> d_matches{0};
425 };
426
427 /* so what could you do:
428 drop,
429 fake up nxdomain,
430 provide actual answer,
431 allow & and stop processing,
432 continue processing,
433 modify header: (servfail|refused|notimp), set TC=1,
434 send to pool */
435
436 class DNSAction
437 {
438 public:
439 enum class Action { Drop, Nxdomain, Spoof, Allow, HeaderModify, Pool, Delay, None};
440 virtual Action operator()(DNSQuestion*, string* ruleresult) const =0;
441 virtual string toString() const = 0;
442 virtual std::unordered_map<string, double> getStats() const
443 {
444 return {{}};
445 }
446 };
447
448 class DNSResponseAction
449 {
450 public:
451 enum class Action { None };
452 virtual Action operator()(DNSResponse*, string* ruleresult) const =0;
453 virtual string toString() const = 0;
454 };
455
456 using NumberedServerVector = NumberedVector<shared_ptr<DownstreamState>>;
457 typedef std::function<shared_ptr<DownstreamState>(const NumberedServerVector& servers, const DNSQuestion*)> policyfunc_t;
458
459 struct ServerPolicy
460 {
461 string name;
462 policyfunc_t policy;
463 };
464
465 struct ServerPool
466 {
467 const std::shared_ptr<DNSDistPacketCache> getCache() const { return packetCache; };
468
469 NumberedVector<shared_ptr<DownstreamState>> servers;
470 std::shared_ptr<DNSDistPacketCache> packetCache{nullptr};
471 };
472 using pools_t=map<std::string,std::shared_ptr<ServerPool>>;
473 void addServerToPool(pools_t& pools, const string& poolName, std::shared_ptr<DownstreamState> server);
474 void removeServerFromPool(pools_t& pools, const string& poolName, std::shared_ptr<DownstreamState> server);
475
476 struct CarbonConfig
477 {
478 ComboAddress server;
479 std::string ourname;
480 unsigned int interval;
481 };
482
483 enum ednsHeaderFlags {
484 EDNS_HEADER_FLAG_NONE = 0,
485 EDNS_HEADER_FLAG_DO = 32768
486 };
487
488 /* Quest in life: serve as a rapid block list. If you add a DNSName to a root SuffixMatchNode,
489 anything part of that domain will return 'true' in check */
490 template<typename T>
491 struct SuffixMatchTree
492 {
493 SuffixMatchTree(const std::string& name_="", bool endNode_=false) : name(name_), endNode(endNode_)
494 {}
495
496 SuffixMatchTree(const SuffixMatchTree& rhs)
497 {
498 name = rhs.name;
499 d_human = rhs.d_human;
500 children = rhs.children;
501 endNode = rhs.endNode;
502 d_value = rhs.d_value;
503 }
504 std::string name;
505 std::string d_human;
506 mutable std::set<SuffixMatchTree> children;
507 mutable bool endNode;
508 mutable T d_value;
509 bool operator<(const SuffixMatchTree& rhs) const
510 {
511 return strcasecmp(name.c_str(), rhs.name.c_str()) < 0;
512 }
513 typedef SuffixMatchTree value_type;
514
515 template<typename V>
516 void visit(const V& v) const {
517 for(const auto& c : children)
518 c.visit(v);
519 if(endNode)
520 v(*this);
521 }
522
523 void add(const DNSName& name, const T& t)
524 {
525 add(name.getRawLabels(), t);
526 }
527
528 void add(std::vector<std::string> labels, const T& value) const
529 {
530 if(labels.empty()) { // this allows insertion of the root
531 endNode=true;
532 d_value=value;
533 }
534 else if(labels.size()==1) {
535 SuffixMatchTree newChild(*labels.begin(), true);
536 newChild.d_value=value;
537 children.insert(newChild);
538 }
539 else {
540 SuffixMatchTree newnode(*labels.rbegin(), false);
541 auto res=children.insert(newnode);
542 if(!res.second) {
543 children.erase(newnode);
544 res=children.insert(newnode);
545 }
546 labels.pop_back();
547 res.first->add(labels, value);
548 }
549 }
550
551 T* lookup(const DNSName& name) const
552 {
553 if(children.empty()) { // speed up empty set
554 if(endNode)
555 return &d_value;
556 return 0;
557 }
558 return lookup(name.getRawLabels());
559 }
560
561 T* lookup(std::vector<std::string> labels) const
562 {
563 if(labels.empty()) { // optimization
564 if(endNode)
565 return &d_value;
566 return 0;
567 }
568
569 SuffixMatchTree smn(*labels.rbegin());
570 auto child = children.find(smn);
571 if(child == children.end()) {
572 if(endNode)
573 return &d_value;
574 return 0;
575 }
576 labels.pop_back();
577 return child->lookup(labels);
578 }
579
580 };
581
582 extern GlobalStateHolder<SuffixMatchTree<DynBlock>> g_dynblockSMT;
583
584 extern GlobalStateHolder<vector<CarbonConfig> > g_carbon;
585 extern GlobalStateHolder<ServerPolicy> g_policy;
586 extern GlobalStateHolder<servers_t> g_dstates;
587 extern GlobalStateHolder<pools_t> g_pools;
588 extern GlobalStateHolder<vector<pair<std::shared_ptr<DNSRule>, std::shared_ptr<DNSAction> > > > g_rulactions;
589 extern GlobalStateHolder<vector<pair<std::shared_ptr<DNSRule>, std::shared_ptr<DNSResponseAction> > > > g_resprulactions;
590 extern GlobalStateHolder<NetmaskGroup> g_ACL;
591
592 extern ComboAddress g_serverControl; // not changed during runtime
593
594 extern std::vector<std::tuple<ComboAddress, bool, bool, int>> g_locals; // not changed at runtime (we hope XXX)
595 extern vector<ClientState*> g_frontends;
596 extern std::string g_key; // in theory needs locking
597 extern bool g_truncateTC;
598 extern bool g_fixupCase;
599 extern int g_tcpRecvTimeout;
600 extern int g_tcpSendTimeout;
601 extern uint16_t g_maxOutstanding;
602 extern std::atomic<bool> g_configurationDone;
603 extern uint64_t g_maxTCPClientThreads;
604 extern uint64_t g_maxTCPQueuedConnections;
605 extern std::atomic<uint16_t> g_cacheCleaningDelay;
606 extern uint16_t g_ECSSourcePrefixV4;
607 extern uint16_t g_ECSSourcePrefixV6;
608 extern bool g_ECSOverride;
609 extern bool g_verboseHealthChecks;
610 extern uint32_t g_staleCacheEntriesTTL;
611
612 struct ConsoleKeyword {
613 std::string name;
614 bool function;
615 std::string parameters;
616 std::string description;
617 std::string toString() const
618 {
619 std::string res(name);
620 if (function) {
621 res += "(" + parameters + ")";
622 }
623 res += ": ";
624 res += description;
625 return res;
626 }
627 };
628 extern const std::vector<ConsoleKeyword> g_consoleKeywords;
629
630 #ifdef HAVE_EBPF
631 extern shared_ptr<BPFFilter> g_defaultBPFFilter;
632 #endif /* HAVE_EBPF */
633
634 struct dnsheader;
635
636 void controlThread(int fd, ComboAddress local);
637 vector<std::function<void(void)>> setupLua(bool client, const std::string& config);
638 std::shared_ptr<ServerPool> getPool(const pools_t& pools, const std::string& poolName);
639 std::shared_ptr<ServerPool> createPoolIfNotExists(pools_t& pools, const string& poolName);
640 const NumberedServerVector& getDownstreamCandidates(const pools_t& pools, const std::string& poolName);
641
642 std::shared_ptr<DownstreamState> firstAvailable(const NumberedServerVector& servers, const DNSQuestion* dq);
643
644 std::shared_ptr<DownstreamState> leastOutstanding(const NumberedServerVector& servers, const DNSQuestion* dq);
645 std::shared_ptr<DownstreamState> wrandom(const NumberedServerVector& servers, const DNSQuestion* dq);
646 std::shared_ptr<DownstreamState> whashed(const NumberedServerVector& servers, const DNSQuestion* dq);
647 std::shared_ptr<DownstreamState> roundrobin(const NumberedServerVector& servers, const DNSQuestion* dq);
648 int getEDNSZ(const char* packet, unsigned int len);
649 void spoofResponseFromString(DNSQuestion& dq, const string& spoofContent);
650 uint16_t getEDNSOptionCode(const char * packet, size_t len);
651 void dnsdistWebserverThread(int sock, const ComboAddress& local, const string& password, const string& apiKey, const boost::optional<std::map<std::string, std::string> >&);
652 bool getMsgLen32(int fd, uint32_t* len);
653 bool putMsgLen32(int fd, uint32_t len);
654 void* tcpAcceptorThread(void* p);
655
656 void moreLua(bool client);
657 void doClient(ComboAddress server, const std::string& command);
658 void doConsole();
659 void controlClientThread(int fd, ComboAddress client);
660 extern "C" {
661 char** my_completion( const char * text , int start, int end);
662 }
663 void setLuaNoSideEffect(); // if nothing has been declared, set that there are no side effects
664 void setLuaSideEffect(); // set to report a side effect, cancelling all _no_ side effect calls
665 bool getLuaNoSideEffect(); // set if there were only explicit declarations of _no_ side effect
666 void resetLuaSideEffect(); // reset to indeterminate state
667
668 bool responseContentMatches(const char* response, const uint16_t responseLen, const DNSName& qname, const uint16_t qtype, const uint16_t qclass, const ComboAddress& remote);
669 bool processQuery(LocalStateHolder<NetmaskTree<DynBlock> >& localDynBlockNMG,
670 LocalStateHolder<SuffixMatchTree<DynBlock> >& localDynBlockSMT, LocalStateHolder<vector<pair<std::shared_ptr<DNSRule>, std::shared_ptr<DNSAction> > > >& localRulactions, blockfilter_t blockFilter, DNSQuestion& dq, string& poolname, int* delayMsec, const struct timespec& now);
671 bool processResponse(LocalStateHolder<vector<pair<std::shared_ptr<DNSRule>, std::shared_ptr<DNSResponseAction> > > >& localRespRulactions, DNSResponse& dr);
672 bool fixUpResponse(char** response, uint16_t* responseLen, size_t* responseSize, const DNSName& qname, uint16_t origFlags, bool ednsAdded, bool ecsAdded, std::vector<uint8_t>& rewrittenResponse, uint16_t addRoom);
673 void restoreFlags(struct dnsheader* dh, uint16_t origFlags);
674
675 #ifdef HAVE_DNSCRYPT
676 extern std::vector<std::tuple<ComboAddress,DnsCryptContext,bool,int>> g_dnsCryptLocals;
677
678 int handleDnsCryptQuery(DnsCryptContext* ctx, char* packet, uint16_t len, std::shared_ptr<DnsCryptQuery>& query, uint16_t* decryptedQueryLen, bool tcp, std::vector<uint8_t>& reponse);
679 bool encryptResponse(char* response, uint16_t* responseLen, size_t responseSize, bool tcp, std::shared_ptr<DnsCryptQuery> dnsCryptQuery);
680 #endif