]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/README-dnsdist.md
Merge pull request #4533 from rgacogne/dnsdist-clang-bsd
[thirdparty/pdns.git] / pdns / README-dnsdist.md
1 dnsdist
2 -------
3 `dnsdist` is a highly DNS-, DoS- and abuse-aware loadbalancer. Its goal in
4 life is to route traffic to the best server, delivering top performance
5 to legitimate users while shunting or blocking abusive traffic.
6
7 `dnsdist` is dynamic, in the sense that its configuration can be changed at
8 runtime, and that its statistics can be queried from a console-like
9 interface.
10
11 Compiling
12 ---------
13 `dnsdist` depends on boost, Lua or LuaJIT and a pretty recent C++
14 compiler (g++ 4.8 or higher, clang 3.5 or higher). It can optionally use libsodium
15 for encrypted communications with its client, protobuf for remote logging and re2
16 for regular expression matching.
17
18 Should `dnsdist` be run on a system with systemd, it is highly recommended to have
19 the systemd header files (`libsystemd-dev` on debian and `systemd-devel` on CentOS)
20 installed to have `dnsdist` support systemd-notify.
21
22 To compile on CentOS 6 / RHEL6, use this script to install a working compiler:
23
24 ```
25 wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
26 yum install devtoolset-2
27 scl enable devtoolset-2 bash
28 ./configure
29 make
30 ```
31
32 To build on OS X, `./configure LIBEDIT_LIBS='-L/usr/lib -ledit' LIBEDIT_CFLAGS=-I/usr/include/editline`
33
34 To build on OpenBSD, `./configure CXX=eg++ CPP=ecpp LIBEDIT_LIBS='-ledit -lcurses' LIBEDIT_CFLAGS=' '`
35
36 On other recent platforms, installing a Lua and the system C++ compiler should be enough.
37
38 `dnsdist` can drop privileges using the `--uid` and `--gid` commandline-switches
39 to ensure it does not run with root privileges after binding its listen-sockets.
40 It is highly recommended to create a system user and group for `dnsdist`. Note that
41 most packaged versions of `dnsdist` already create this user.
42
43 Packaged
44 --------
45 We build packages for `dnsdist` on our [repositories](https://repo.powerdns.com). In addition
46 `dnsdist` has been packaged for FreeBSD and can be found on https://freshports.org/dns/dnsdist
47
48 Examples
49 --------
50
51 The absolute minimum configuration:
52
53 ```
54 # dnsdist 2001:4860:4860::8888 8.8.8.8
55 ```
56
57 This will listen on 0.0.0.0:53 and forward queries to the two listed IP
58 addresses, with a sensible load balancing policy.
59
60 Here is a more complete configuration:
61
62 ```
63 $ cat /etc/dnsdist.conf
64 newServer({address="2001:4860:4860::8888", qps=1})
65 newServer({address="2001:4860:4860::8844", qps=1})
66 newServer({address="2620:0:ccc::2", qps=10})
67 newServer({address="2620:0:ccd::2", name="dns1", qps=10})
68 newServer("192.168.1.2")
69 setServerPolicy(firstAvailable) -- first server within its QPS limit
70
71 $ dnsdist --local=0.0.0.0:5200
72 Marking downstream [2001:4860:4860::8888]:53 as 'up'
73 Marking downstream [2001:4860:4860::8844]:53 as 'up'
74 Marking downstream [2620:0:ccc::2]:53 as 'up'
75 Marking downstream [2620:0:ccd::2]:53 as 'up'
76 Marking downstream 192.168.1.2:53 as 'up'
77 Listening on 0.0.0.0:5200
78 >
79 ```
80
81 We can now send queries to port 5200, and get answers:
82
83 ```
84 $ dig -t aaaa powerdns.com @127.0.0.1 -p 5200 +short
85 2001:888:2000:1d::2
86 ```
87
88 Note that `dnsdist` offered us a prompt above, and on it we can get some
89 statistics:
90
91 ```
92 > showServers()
93 # Address State Qps Qlim Ord Wt Queries Drops Drate Lat Pools
94 0 [2001:4860:4860::8888]:53 up 0.0 1 1 1 1 0 0.0 0.0
95 1 [2001:4860:4860::8844]:53 up 0.0 1 1 1 0 0 0.0 0.0
96 2 [2620:0:ccc::2]:53 up 0.0 10 1 1 0 0 0.0 0.0
97 3 [2620:0:ccd::2]:53 up 0.0 10 1 1 0 0 0.0 0.0
98 4 192.168.1.2:53 up 0.0 0 1 1 0 0 0.0 0.0
99 All 0.0 1 0
100 ```
101
102 Here we also see our configuration. 5 downstream servers have been configured, of
103 which the first 4 have a QPS limit (of 1, 1, 10 and 10 queries per second,
104 respectively). The final server has no limit, which we can easily test:
105
106 ```
107 $ for a in {0..1000}; do dig powerdns.com @127.0.0.1 -p 5200 +noall > /dev/null; done
108 > showServers()
109 # Address State Qps Qlim Ord Wt Queries Drops Drate Lat Pools
110 0 [2001:4860:4860::8888]:53 up 1.0 1 1 1 7 0 0.0 1.6
111 1 [2001:4860:4860::8844]:53 up 1.0 1 1 1 6 0 0.0 0.6
112 2 [2620:0:ccc::2]:53 up 10.3 10 1 1 64 0 0.0 2.4
113 3 [2620:0:ccd::2]:53 up 10.3 10 1 1 63 0 0.0 2.4
114 4 192.168.1.2:53 up 125.8 0 1 1 671 0 0.0 0.4
115 All 145.0 811 0
116 ```
117
118 Note that the first 4 servers were all limited to near their configured QPS,
119 and that our final server was taking up most of the traffic. No queries were
120 dropped, and all servers remain up.
121
122 To force a server down, try:
123
124 ```
125 > getServer(0):setDown()
126 > showServers()
127 # Address State Qps Qlim Ord Wt Queries Drops Drate Lat Pools
128 0 [2001:4860:4860::8888]:53 DOWN 0.0 1 1 1 8 0 0.0 0.0
129 ...
130 ```
131
132 The 'DOWN' in all caps means it was forced down. A lower case 'down'
133 would've meant that `dnsdist` itself had concluded the server was down.
134 Similarly, setUp() forces a server to be up, and setAuto() returns it to the
135 default availability-probing.
136
137 To change the QPS for a server:
138 ```
139 > getServer(0):setQPS(1000)
140 ```
141
142 By default, the availability of a downstream server is checked by regularly
143 sending an A query for "a.root-servers.net.". A different query type and target
144 can be specified by passing, respectively, the `checkType` and `checkName`
145 parameters to `newServer`. The default behavior is to consider any valid response
146 with a RCODE different from ServFail as valid. If the `mustResolve` parameter
147 of `newServer` is set to true, a response will only be considered valid if
148 its RCODE differs from NXDomain, ServFail and Refused.
149 The number of health check failures before a server is considered down is
150 configurable via the`maxCheckFailures` parameter, defaulting to 1.
151 The `CD` flag can be set on the query by setting `setCD` to true.
152
153 ```
154 newServer({address="192.0.2.1", checkType="AAAA", checkName="a.root-servers.net.", mustResolve=true})
155 ```
156
157 In order to provide the downstream server with the address of the real client,
158 or at least the one talking to `dnsdist`, the `useClientSubnet` parameter can be used
159 when declaring a new server. This parameter indicates whether an EDNS Client Subnet option
160 should be added to the request. If the incoming request already contains an EDNS Client Subnet value,
161 it will not be overriden unless `setECSOverride()` is set to true.
162 The default source prefix-length is 24 for IPv4 and 56 for IPv6, meaning that for a query
163 received from 192.0.2.42, the EDNS Client Subnet value sent to the backend will
164 be 192.0.2.0. This can be changed with:
165 ```
166 > setECSSourcePrefixV4(24)
167 > setECSSourcePrefixV6(56)
168 ```
169
170 In addition to the global settings, rules and Lua bindings can alter this behavior per query:
171
172 * calling `DisableECSAction()` or setting `dq.useECS` to false prevent the sending of the ECS option
173 * calling `ECSOverrideAction(bool)` or setting `dq.ecsOverride` will override the global `setECSOverride()` value
174 * calling `ECSPrefixLengthAction(v4, v6)` or setting `dq.ecsPrefixLength` will override the global
175 `setECSSourcePrefixV4()` and `setECSSourcePrefixV6()` values
176
177 In effect this means that for the EDNS Client Subnet option to be added to the request, `useClientSubnet`
178 should be set to true for the backend used (default to false) and ECS should not have been disabled by calling
179 `DisableECSAction()` or setting `dq.useECS` to false (default to true).
180
181 TCP timeouts
182 ------------
183
184 By default, a 2 seconds timeout is enforced on the TCP connection from the client,
185 meaning that a connection will be closed if the query can't be read in less than 2s
186 or if the answer can't be sent in less than 2s. This can be configured with:
187 ```
188 > setTCPRecvTimeout(5)
189 > setTCPSendTimeout(5)
190 ```
191
192 The same kind of timeouts is enforced on the TCP connections to the downstream servers.
193 The default value of 30s can be modified by passing the `tcpRecvTimeout` and `tcpSendTimeout`
194 parameters to `newServer`. If the TCP connection to a downstream server fails, `dnsdist`
195 will try to establish a new one up to `retries` times before giving up.
196 ```
197 newServer({address="192.0.2.1", tcpRecvTimeout=10, tcpSendTimeout=10, retries=5})
198 ```
199
200 Source address
201 --------------
202
203 In multi-homed setups, it can be useful to be able to select the source address or the outgoing
204 interface used by `dnsdist` to contact a downstream server.
205 This can be done by using the `source` parameter:
206 ```
207 newServer({address="192.0.2.1", source="192.0.2.127"})
208 newServer({address="192.0.2.1", source="eth1"})
209 newServer({address="192.0.2.1", source="192.0.2.127@eth1"})
210 ```
211
212 The supported values for `source` are:
213
214 * an IPv4 or IPv6 address, which must exist on the system
215 * an interface name
216 * an IPv4 or IPv6 address followed by '@' then an interface name
217
218 Specifying the interface name is only supported on system having IP_PKTINFO.
219
220
221 Configuration management
222 ------------------------
223 At startup, configuration is read from the command line and the
224 configuration file. The config can also be inspected and changed from the
225 console. Sadly, our architecture does not allow us to serialize the running
226 configuration for you. However, we do try to offer the next best thing:
227 `delta()`.
228
229 `delta()` shows all commands entered that changed the configuration. So
230 adding a new downstream server with `newServer()` would show up, but
231 `showServers()` or even `delta()` itself would not.
232
233 It is suggested to study the output of `delta()` carefully before appending
234 it to your configuration file.
235
236 ```
237 > setACL("192.0.2.0/24")
238 > showACL()
239 192.0.2.0/24
240 > delta()
241 -- Wed Dec 23 2015 15:15:35 CET
242 setACL("192.0.2.0/24")
243 > addACL("127.0.0.1/8")
244 > showACL()
245 192.0.2.0/24
246 127.0.0.1/8
247 > delta()
248 -- Wed Dec 23 2015 15:15:35 CET
249 setACL("192.0.2.0/24")
250 -- Wed Dec 23 2015 15:15:44 CET
251 addACL("127.0.0.1/8")
252 >
253 ```
254
255
256 Webserver
257 ---------
258 To visually interact with `dnsdist`, try adding:
259 ```
260 webserver("127.0.0.1:8083", "supersecretpassword", "supersecretAPIkey")
261 ```
262
263 to the configuration, and point your browser at http://127.0.0.1:8083 and
264 log in with any username, and that password. Enjoy!
265
266 By default, our web server sends some security-related headers:
267
268 * X-Content-Type-Options: nosniff
269 * X-Frame-Options: deny
270 * X-Permitted-Cross-Domain-Policies: none
271 * X-XSS-Protection: 1; mode=block
272 * Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline'
273
274 You can override those headers, or add custom headers by using the last parameter to
275 `webserver()`. For example, to remove the `X-Frame-Options` header and add a
276 `X-Custom` one:
277 ```
278 webserver("127.0.0.1:8080", "supersecret", "apikey", {["X-Frame-Options"]= "", ["X-Custom"]="custom"})
279 ```
280
281
282 Server pools
283 ------------
284 Now for some cool stuff. Let's say we know we're getting a whole bunch of
285 traffic for a domain used in DoS attacks, for example 'sh43354.cn'. We can
286 do two things with this kind of traffic. Either we block it outright, like
287 this:
288
289 ```
290 > addDomainBlock("sh43354.cn.")
291 ```
292
293 Or we configure a server pool dedicated to receiving the nasty stuff:
294
295 ```
296 > newServer({address="192.168.1.3", pool="abuse"})
297 > addPoolRule({"sh43353.cn.", "ezdns.it."}, "abuse")
298 ```
299
300 The wonderful thing about this last solution is that it can also be used for
301 things where a domain might possibly be legit, but it is still causing load
302 on the system and slowing down the internet for everyone. With such an abuse
303 server, 'bad traffic' still gets a chance of an answer, but without
304 impacting the rest of the world (too much).
305
306 We can similarly add clients to the abuse server:
307
308 ```
309 > addPoolRule({"192.168.12.0/24", "192.168.13.14"}, "abuse")
310 ```
311
312 To define a pool that should receive only a QPS-limited amount of traffic, do:
313
314 ```
315 > addQPSPoolRule("com.", 10000, "gtld-cluster")
316 ```
317
318 Traffic exceeding the QPS limit will not match that rule, and subsequent
319 rules will apply normally.
320
321 Both `addDomainBlock` and `addPoolRule` end up the list of Rules
322 and Actions (for which see below).
323
324 Servers can be added or removed to pools with:
325 ```
326 > getServer(7):addPool("abuse")
327 > getServer(4):rmPool("abuse")
328 ```
329
330
331 Rules
332 -----
333 Rules can be inspected with `showRules()`, and can be deleted with
334 `rmRule()`. Rules are evaluated in order, and this order can be changed
335 with `mvRule(from, to)` (see below for exact semantics).
336
337 Rules have selectors and actions. Current selectors are:
338
339 * Source address
340 * Query type
341 * Query domain
342 * QPS Limit total
343 * QPS Limit per IP address or subnet
344 * QClass (QClassRule)
345 * QType (QTypeRule)
346 * RegexRule on query name
347 * RE2Rule on query name (optional)
348 * Response code
349 * Packet requests DNSSEC processing
350 * Query received over UDP or TCP
351 * Opcode (OpcodeRule)
352 * Number of entries in a given section (RecordsCountRule)
353 * Number of entries of a specific type in a given section (RecordsTypeCountRule)
354 * Presence of trailing data (TrailingDataRule)
355 * Number of labels in the qname (QNameLabelsCountRule)
356 * Wire length of the qname (QNameWireLengthRule)
357
358 Special rules are:
359
360 * `AndRule{rule1, rule2}`, which only matches if all of its subrules match
361 * `OrRule{rule1, rule2}`, which matches if at least one of its subrules match
362 * `NotRule(rule)`, which matches if its subrule does not match
363
364 Current actions are:
365
366 * Drop (DropAction)
367 * Route to a pool (PoolAction)
368 * Return with TC=1 (truncated, ie, instruction to retry with TCP)
369 * Force a ServFail, NotImp or Refused answer
370 * Send out a crafted response (NXDOMAIN or "real" data)
371 * Delay a response by n milliseconds (DelayAction), over UDP only
372 * Modify query to clear the RD or CD bit
373 * Add the source MAC address to the query (MacAddrAction)
374 * Skip the cache, if any
375 * Log query content to a remote server (RemoteLogAction)
376 * Alter the EDNS Client Subnet parameters (DisableECSAction, ECSOverrideAction, ECSPrefixLengthAction)
377
378 Current response actions are:
379
380 * Allow (AllowResponseAction)
381 * Delay a response by n milliseconds (DelayResponseAction), over UDP only
382 * Drop (DropResponseAction)
383 * Log response content to a remote server (RemoteLogResponseAction)
384
385 Rules can be added via:
386
387 * addAction(DNS rule, DNS Action)
388 * addAnyTCRule()
389 * addDelay(DNS rule, delay in milliseconds)
390 * addDisableValidationRule(DNS rule)
391 * addDomainBlock(domain)
392 * addDomainSpoof(domain, IPv4[, IPv6]) or addDomainSpoof(domain, {IP, IP, IP..})
393 * addDomainCNAMESpoof(domain, CNAME)
394 * addLuaAction(DNS rule, lua function)
395 * addNoRecurseRule(DNS rule)
396 * addPoolRule(DNS rule, destination pool)
397 * addQPSLimit(DNS rule, qps limit)
398 * addQPSPoolRule(DNS rule, qps limit, destination pool)
399
400 Response rules can be added via:
401
402 * addResponseAction(DNS rule, DNS Response Action)
403
404 A DNS rule can be:
405
406 * an AllRule
407 * an AndRule
408 * a MaxQPSIPRule
409 * a MaxQPSRule
410 * a NetmaskGroupRule
411 * a NotRule
412 * an OpcodeRule
413 * an OrRule
414 * a QClassRule
415 * a QNameLabelsCountRule
416 * a QNameWireLengthRule
417 * a QTypeRule
418 * a RCodeRule
419 * a RegexRule
420 * a RE2Rule
421 * a RecordsCountRule
422 * a RecordsTypeCountRule
423 * a SuffixMatchNodeRule
424 * a TCPRule
425 * a TrailingDataRule
426
427 Some specific actions do not stop the processing when they match, contrary to all other actions:
428
429 * Delay
430 * DisableECS
431 * Disable Validation
432 * ECSOverride
433 * ECSPrefixLength
434 * Log
435 * MacAddr
436 * No Recurse
437 * and of course None
438
439 A convenience function `makeRule()` is supplied which will make a NetmaskGroupRule for you or a SuffixMatchNodeRule
440 depending on how you call it. `makeRule("0.0.0.0/0")` will for example match all IPv4 traffic, `makeRule({"be","nl","lu"})` will
441 match all Benelux DNS traffic.
442
443 All the current rules can be removed at once with:
444
445 ```
446 > clearRules()
447 ```
448
449 It is also possible to replace the current rules by a list of new ones in a
450 single operation with `setRules()`:
451
452 ```
453 > setRules( { newRuleAction(TCPRule(), AllowAction()), newRuleAction(AllRule(), DropAction()) } )
454 ```
455
456
457 More power
458 ----------
459 More powerful things can be achieved by defining a function called
460 `blockFilter()` in the configuration file, which can decide to drop traffic
461 on any reason it wants. If you return 'true' from there, the query will get
462 blocked.
463
464 A demo on how to do this and many other things can be found on
465 https://github.com/powerdns/pdns/blob/master/pdns/dnsdistconf.lua and
466 the exact definition of `blockFilter()` is at the end of this document.
467
468 ANY or whatever to TC
469 ---------------------
470 The `blockFilter()` also gets passed read/writable copy of the DNS Header,
471 via `dq.dh`.
472 If you invoke setQR(1) on that, `dnsdist` knows you turned the packet into
473 a response, and will send the answer directly to the original client.
474
475 If you also called setTC(1), this will tell the remote client to move to
476 TCP, and in this way you can implement ANY-to-TCP even for downstream
477 servers that lack this feature.
478
479 Note that calling `addAnyTCRule()` achieves the same thing, without
480 involving Lua.
481
482 Rules for traffic exceeding QPS limits
483 --------------------------------------
484 Traffic that exceeds a QPS limit, in total or per IP (subnet) can be matched by a rule.
485
486 For example:
487
488 ```
489 addDelay(MaxQPSIPRule(5, 32, 48), 100)
490 ```
491
492 This measures traffic per IPv4 address and per /48 of IPv6, and if traffic for such
493 an address (range) exceeds 5 qps, it gets delayed by 100ms.
494
495 As another example:
496
497 ```
498 addAction(MaxQPSIPRule(5), NoRecurseAction())
499 ```
500
501 This strips the Recursion Desired (RD) bit from any traffic per IPv4 or IPv6 /64
502 that exceeds 5 qps. This means any those traffic bins is allowed to make a recursor do 'work'
503 for only 5 qps.
504
505 If this is not enough, try:
506
507 ```
508 addAction(MaxQPSIPRule(5), DropAction())
509 -- or
510 addAction(MaxQPSIPRule(5), TCAction())
511 ```
512
513 This will respectively drop traffic exceeding that 5 QPS limit per IP or range, or return it with TC=1, forcing
514 clients to fall back to TCP.
515
516 To turn this per IP or range limit into a global limit, use NotRule(MaxQPSRule(5000)) instead of MaxQPSIPRule.
517
518 TeeAction
519 ---------
520 This action sends off a copy of a UDP query to another server, and keeps statistics
521 on the responses received. Sample use:
522
523 ```
524 > addAction(AllRule(), TeeAction("192.168.1.54"))
525 > getAction(0):printStats()
526 refuseds 0
527 nxdomains 0
528 noerrors 0
529 servfails 0
530 recv-errors 0
531 tcp-drops 0
532 responses 0
533 other-rcode 0
534 send-errors 0
535 queries 0
536 ```
537
538 It is also possible to share a TeeAction between several rules. Statistics
539 will be combined in that case.
540
541 Lua actions in rules
542 --------------------
543 While we can pass every packet through the `blockFilter()` functions, it is also
544 possible to configure `dnsdist` to only hand off some packets for Lua inspection.
545 If you think Lua is too slow for your query load, or if you are doing heavy processing in Lua,
546 this may make sense.
547
548 To select specific packets for Lua attention, use `addLuaAction(x, func)`,
549 where x is either a netmask, or a domain suffix, or a table of netmasks or a
550 table of domain suffixes. This is identical to how `addPoolRule()` selects.
551
552 The function should look like this:
553 ```
554 function luarule(dq)
555 if(dq.qtype==35) -- NAPTR
556 then
557 return DNSAction.Pool, "abuse" -- send to abuse pool
558 else
559 return DNSAction.None, "" -- no action
560 end
561 end
562 ```
563
564 Valid return values for `LuaAction` functions are:
565
566 * DNSAction.Allow: let the query pass, skipping other rules
567 * DNSAction.Delay: delay the response for the specified milliseconds (UDP-only), continue to the next rule
568 * DNSAction.Drop: drop the query
569 * DNSAction.HeaderModify: indicate that the query has been turned into a response
570 * DNSAction.None: continue to the next rule
571 * DNSAction.Nxdomain: return a response with a NXDomain rcode
572 * DNSAction.Pool: use the specified pool to forward this query
573 * DNSAction.Spoof: spoof the response using the supplied IPv4 (A), IPv6 (AAAA) or string (CNAME) value
574
575 DNSSEC
576 ------
577 To provide DNSSEC service from a separate pool, try:
578 ```
579 newServer({address="2001:888:2000:1d::2", pool="dnssec"})
580 newServer({address="2a01:4f8:110:4389::2", pool="dnssec"})
581 setDNSSECPool("dnssec")
582 topRule()
583 ```
584
585 This routes all queries with a DNSSEC OK (DO) or CD bit set to on to the "dnssec" pool.
586 The final `topRule()` command moves this rule to the top, so it gets evaluated first.
587
588 Regular Expressions
589 -------------------
590 `RegexRule()` matches a regular expression on the query name, and it works like this:
591
592 ```
593 addAction(RegexRule("[0-9]{5,}"), DelayAction(750)) -- milliseconds
594 addAction(RegexRule("[0-9]{4,}\\.cn$"), DropAction())
595 ```
596
597 This delays any query for a domain name with 5 or more consecutive digits in it.
598 The second rule drops anything with more than 4 consecutive digits within a .CN domain.
599
600 Note that the query name is presented without a trailing dot to the regex.
601 The regex is applied case insensitively.
602
603 Alternatively, if compiled in, RE2Rule provides similar functionality, but against libre2.
604
605 Inspecting live traffic
606 -----------------------
607 This is still much in flux, but for now, try:
608
609 * `grepq(Netmask|DNS Name|100ms [, n])`: shows the last n queries and responses matching the specified client address or range (Netmask), or the specified DNS Name, or slower than 100ms
610 * `grepq({"::1", "powerdns.com", "100ms"} [, n])`: shows the last n queries and responses matching the specified client address AND range (Netmask) AND the specified DNS Name AND slower than 100ms
611 * `topBandwidth(top)`: show top-`top` clients that consume the most bandwidth over length of ringbuffer
612 * `topClients(n)`: show top-`n` clients sending the most queries over length of ringbuffer
613 * `topQueries(20)`: shows the top-20 queries
614 * `topQueries(20,2)`: shows the top-20 two-level domain queries (so `topQueries(20,1)` only shows TLDs)
615 * `topResponses(20, 2)`: top-20 servfail responses (use ,3 for NXDOMAIN)
616 * `topSlow([top][, limit][, labels])`: show `top` queries slower than `limit` milliseconds, grouped by last `labels` labels
617
618 For example:
619 ```
620 > grepq("127.0.0.1/24")
621 Time Client Server ID Name Type Lat. TC RD AA Rcode
622 -11.9 127.0.0.1:52599 16127 nxdomain.powerdns.com. A RD Question
623 -11.7 127.0.0.1:52599 127.0.0.1:53 16127 nxdomain.powerdns.com. A 175.6 RD Non-Existent domain
624 > grepq("powerdns.com")
625 Time Client Server ID Name Type Lat. TC RD AA Rcode
626 -38.7 127.0.0.1:52599 16127 nxdomain.powerdns.com. A RD Question
627 -38.6 127.0.0.1:52599 127.0.0.1:53 16127 nxdomain.powerdns.com. A 175.6 RD Non-Existent domain
628 ```
629
630 Live histogram of latency
631 -------------------------
632 ```
633 > showResponseLatency()
634 Average response latency: 78.84 msec
635 msec
636 0.10
637 0.20 .
638 0.40 **********************
639 0.80 ***********
640 1.60 .
641 3.20
642 6.40 .
643 12.80 *
644 25.60 *
645 51.20 *
646 102.40 **********************************************************************
647 204.80 *************************
648 409.60 **
649 819.20 :
650 1638.40 .
651 ```
652
653 Where : stands for 'half a star' and . for 'less than half a star, but
654 something was there'.
655
656 Per domain or subnet QPS limiting
657 ---------------------------------
658 If certain domains or source addresses are generating onerous amounts of
659 traffic, you can put ceilings on the amount of traffic you are willing to
660 forward:
661
662 ```
663 > addQPSLimit("h4xorbooter.xyz.", 10)
664 > addQPSLimit({"130.161.0.0/16", "145.14.0.0/16"} , 20)
665 > addQPSLimit({"nl.", "be."}, 1)
666 > showRules()
667 # Matches Rule Action
668 0 0 h4xorbooter.xyz. qps limit to 10
669 1 0 130.161.0.0/16, 145.14.0.0/16 qps limit to 20
670 2 0 nl., be. qps limit to 1
671 ```
672
673 To delete a limit (or a rule in general):
674 ```
675 > rmRule(1)
676 > showRules()
677 # Matches Rule Action
678 0 0 h4xorbooter.xyz. qps limit to 10
679 1 0 nl., be. qps limit to 1
680 ```
681
682 Delaying answers
683 ----------------
684 Sometimes, runaway scripts will hammer your servers with back-to-back
685 queries. While it is possible to drop such packets, this may paradoxically
686 lead to more traffic.
687
688 An attractive middleground is to delay answers to such back-to-back queries,
689 causing a slowdown on the side of the source of the traffic.
690
691 To do so, use:
692 ```
693 > addDelay("yourdomain.in.ua.", 500)
694 > addDelay({"65.55.37.0/24"}, 500)
695 ```
696 This will delay responses for questions to the mentioned domain, or coming
697 from the configured subnet, by half a second.
698
699 Like the QPSLimits and other rules, the delaying instructions can be
700 inspected or edited using showRule(), rmRule(), topRule(), mvRule() etc.
701
702 Dynamic load balancing
703 ----------------------
704 The default load balancing policy is called `leastOutstanding`, which means
705 we pick the server with the least queries 'in the air' (and within those,
706 the one with the lowest `order`, and within those, the one with the lowest latency).
707
708 Another policy, `firstAvailable`, picks the server with the lowest `order` that has not
709 exceeded its QPS limit. For now this is the only policy using the QPS limit.
710
711 A further policy, `wrandom` assigns queries randomly, but based on the
712 `weight` parameter passed to `newServer`. `whashed` is a similar weighted policy,
713 but assigns questions with identical hash to identical servers, allowing for
714 better cache concentration ('sticky queries').
715
716 If you don't like the default policies you can create your own, like this
717 for example:
718
719 ```
720 counter=0
721 function luaroundrobin(servers, dq)
722 counter=counter+1
723 return servers[1+(counter % #servers)]
724 end
725
726 setServerPolicyLua("luaroundrobin", luaroundrobin)
727 ```
728
729 Incidentally, this is similar to setting: `setServerPolicy(roundrobin)`
730 which uses the C++ based roundrobin policy.
731
732 Lua server policies
733 -------------------
734 If the built in rules do not suffice to pick a server pool, full flexibility is available from Lua. For example:
735
736 ```
737 newServer("192.168.1.2")
738 newServer({address="8.8.4.4", pool="numbered"})
739
740 function splitSetup(servers, dq)
741 if(string.match(dq.qname:toString(), "%d"))
742 then
743 print("numbered pool")
744 return leastOutstanding.policy(getPoolServers("numbered"), dq)
745 else
746 print("standard pool")
747 return leastOutstanding.policy(servers, dq)
748 end
749 end
750
751 setServerPolicyLua("splitsetup", splitSetup)
752 ```
753
754 This will forward queries containing a number to the pool of "numbered"
755 servers, and will apply the default load balancing policy to all other
756 queries.
757
758 Dynamic Rule Generation
759 -----------------------
760 To set dynamic rules, based on recent traffic, define a function called `maintenance()` in Lua. It will
761 get called every second, and from this function you can set rules to block traffic based on statistics.
762
763 As an example:
764
765 ```
766 function maintenance()
767 addDynBlocks(exceedQRate(20, 10), "Exceeded query rate", 60)
768 end
769 ```
770
771 This will dynamically block all hosts that exceeded 20 queries/s as measured
772 over the past 10 seconds, and the dynamic block will last for 60 seconds.
773
774 Dynamic blocks in force are displayed with `showDynBlocks()` and can be cleared
775 with `clearDynBlocks()`. Full set of `exceed` functions is listed in the table of
776 all functions below.
777
778
779 Running it for real
780 -------------------
781 First run on the command line, and generate a key:
782
783 ```
784 # dnsdist
785 > makeKey()
786 setKey("sepuCcHcQnSAZgNbNPCCpDWbujZ5esZJmrt/wh6ldkQ=")
787 ```
788
789 Now add this setKey line to `dnsdistconf.lua`, and also add:
790
791 ```
792 controlSocket("0.0.0.0") -- or add portnumber too
793 ```
794
795 Then start `dnsdist` as a daemon, and then connect to it:
796 ```
797 # dnsdist --daemon
798 # dnsdist --client
799 >
800 ```
801
802 Please note that, without libsodium support, 'makeKey()' will return
803 setKey("plaintext") and the communication between the client and the
804 server will not be encrypted.
805
806 Some versions of libedit, notably the CentOS 6 one, may require the following
807 addition to ~/.editrc in order to support searching through the history:
808
809 ```
810 bind "^R" em-inc-search-prev
811 ```
812
813 ACL, who can use dnsdist
814 ------------------------
815 For safety reasons, by default only private networks can use `dnsdist`, see below
816 how to query and change the ACL:
817
818 ```
819 > showACL()
820 127.0.0.0/8
821 10.0.0.0/8
822 (...)
823 ::1/128
824 fc00::/7
825 fe80::/10
826 > addACL("130.161.0.0/16")
827 > setACL({"::/0"}) -- resets the list to this array
828 > showACL()
829 ::/0
830 ```
831
832 Caching
833 -------
834 `dnsdist` implements a simple but effective packet cache, not enabled by default.
835 It is enabled per-pool, but the same cache can be shared between several pools.
836 The first step is to define a cache, then to assign that cache to the chosen pool,
837 the default one being represented by the empty string:
838
839 ```
840 pc = newPacketCache(10000, 86400, 0, 60, 60)
841 getPool(""):setCache(pc)
842 ```
843
844 The first parameter is the maximum number of entries stored in the cache, and is the
845 only one required. All the others parameters are optional and in seconds.
846 The second one is the maximum lifetime of an entry in the cache, the third one is
847 the minimum TTL an entry should have to be considered for insertion in the cache,
848 the fourth one is the TTL used for a Server Failure response. The last one is the
849 TTL that will be used when a stale cache entry is returned.
850
851 The `setStaleCacheEntriesTTL(n)` directive can be used to allow `dnsdist` to use
852 expired entries from the cache when no backend is available. Only entries that have
853 expired for less than `n` seconds will be used, and the returned TTL can be set
854 when creating a new cache with `newPacketCache()`.
855
856 A reference to the cache affected to a specific pool can be retrieved with:
857
858 ```
859 getPool("poolname"):getCache()
860 ```
861
862 And removed with:
863
864 ```
865 getPool("poolname"):unsetCache()
866 ```
867
868 Cache usage stats (hits, misses, deferred inserts and lookups, collisions)
869 can be displayed by using the `printStats()` method:
870
871 ```
872 getPool("poolname"):getCache():printStats()
873 ```
874
875 Expired cached entries can be removed from a cache using the `purgeExpired(n)`
876 method, which will remove expired entries from the cache until at least `n`
877 entries remain in the cache. For example, to remove all expired entries:
878
879 ```
880 getPool("poolname"):getCache():purgeExpired(0)
881 ```
882
883 Specific entries can also be removed using the `expungeByName(DNSName [, qtype=ANY])`
884 method.
885
886 ```
887 getPool("poolname"):getCache():expungeByName(newDNSName("powerdns.com"), dnsdist.A)
888 ```
889
890 Finally, the `expunge(n)` method will remove all entries until at most `n`
891 entries remain in the cache:
892
893 ```
894 getPool("poolname"):getCache():expunge(0)
895 ```
896
897
898 Performance tuning
899 ------------------
900 First, a few words about `dnsdist` architecture:
901
902 * Each local bind has its own thread listening for incoming UDP queries
903 * and its own thread listening for incoming TCP connections,
904 dispatching them right away to a pool of threads
905 * Each backend has its own thread listening for UDP responses
906 * A maintenance thread calls the `maintenance()` Lua function every second
907 if any, and is responsible for cleaning the cache
908 * A health check thread checks the backends availability
909 * A control thread handles console connections
910 * A carbon thread exports statistics to carbon servers if needed
911 * One or more webserver threads handle queries to the internal webserver
912
913 The maximum number of threads in the TCP pool is controlled by the
914 `setMaxTCPClientThreads()` directive, and defaults to 10. This number can be
915 increased to handle a large number of simultaneous TCP connections.
916 If all the TCP threads are busy, new TCP connections are queued while
917 they wait to be picked up. The maximum number of queued connections
918 can be configured with `setMaxTCPQueuedConnections()`, and any value other
919 than 0 (the default) will cause new connections to be dropped if there
920 are already too many queued.
921
922 When dispatching UDP queries to backend servers, `dnsdist` keeps track of at
923 most `n` outstanding queries for each backend. This number `n` can be tuned by
924 the `setMaxUDPOutstanding()` directive, defaulting to 10240, with a maximum
925 value of 65535. Large installations are advised to increase the default value
926 at the cost of a slightly increased memory usage.
927
928 Most of the query processing is done in C++ for maximum performance,
929 but some operations are executed in Lua for maximum flexibility:
930
931 * the `blockfilter()` function
932 * rules added by `addLuaAction()`
933 * server selection policies defined via `setServerPolicyLua()` or `newServerPolicy()`
934
935 While Lua is fast, its use should be restricted to the strict necessary in order
936 to achieve maximum performance, it might be worth considering using LuaJIT instead
937 of Lua. When Lua inspection is needed, the best course of action is to restrict
938 the queries sent to Lua inspection by using `addLuaAction()` instead of inspecting
939 all queries in the `blockfilter()` function.
940
941 `dnsdist` design choices mean that the processing of UDP queries is done by only
942 one thread per local bind. This is great to keep lock contention to a low level,
943 but might not be optimal for setups using a lot of processing power, caused for
944 example by a large number of complicated rules. To be able to use more CPU cores
945 for UDP queries processing, it is possible to use the `reuseport` parameter of
946 the `addLocal()` and `setLocal()` directives to be able to add several identical
947 local binds to `dnsdist`:
948
949 ```
950 addLocal("192.0.2.1:53", true, true)
951 addLocal("192.0.2.1:53", true, true)
952 addLocal("192.0.2.1:53", true, true)
953 addLocal("192.0.2.1:53", true, true)
954 ```
955
956 `dnsdist` will then add four identical local binds as if they were different IPs
957 or ports, start four threads to handle incoming queries and let the kernel load
958 balance those randomly to the threads, thus using four CPU cores for rules
959 processing. Note that this require SO_REUSEPORT support in the underlying
960 operating system (added for example in Linux 3.9).
961 Please also be aware that doing so will increase lock contention and might not
962 therefore scale linearly. This is especially true for Lua-intensive setups,
963 because Lua processing in `dnsdist` is serialized by an unique lock for all
964 threads.
965
966 Another possibility is to use the reuseport option to run several `dnsdist`
967 processes in parallel on the same host, thus avoiding the lock contention issue
968 at the cost of having to deal with the fact that the different processes will
969 not share informations, like statistics or DDoS offenders.
970
971 The UDP threads handling the responses from the backends do not use a lot of CPU,
972 but if needed it is also possible to add the same backend several times to the
973 `dnsdist` configuration to distribute the load over several responder threads.
974
975 ```
976 newServer({address="192.0.2.127:53", name="Backend1"})
977 newServer({address="192.0.2.127:53", name="Backend2"})
978 newServer({address="192.0.2.127:53", name="Backend3"})
979 newServer({address="192.0.2.127:53", name="Backend4"})
980 ```
981
982
983 Carbon/Graphite/Metronome
984 -------------------------
985 To emit metrics to Graphite, or any other software supporting the Carbon protocol, use:
986 ```
987 carbonServer('ip-address-of-carbon-server', 'ourname', 30)
988 ```
989
990 Where 'ourname' can be used to override your hostname, and '30' is the
991 reporting interval in seconds. The last two arguments can be omitted. The
992 latest version of [PowerDNS
993 Metronome](https://github.com/ahupowerdns/metronome) comes with attractive
994 graphs for `dnsdist` by default.
995
996 Query counters
997 -------------
998 When using `carbonServer`, it is also possible to send per-records statistics of
999 the amount of queries by using `setQueryCount(true)`. With query counting enabled,
1000 `dnsdist` will increase a counter for every unique record or the behaviour you define
1001 in a custom Lua function by setting `setQueryCountFilter(func)`. This filter can decide
1002 whether to keep count on a query at all or rewrite for which query the counter will be
1003 increased.
1004 An example of a `QueryCountFilter` would be:
1005
1006 ```
1007 function filter(dq)
1008 qname = dq.qname:toString()
1009
1010 -- don't count PTRs at all
1011 if(qname:match('in%-addr.arpa$')) then
1012 return false, ""
1013 end
1014
1015 -- count these queries as if they were queried without leading www.
1016 if(qname:match('^www.')) then
1017 qname = qname:gsub('^www.', '')
1018 end
1019
1020 -- count queries by default
1021 return true, qname
1022 end
1023
1024 setQueryCountFilter(filter)
1025 ```
1026
1027 Valid return values for `QueryCountFilter` functions are:
1028
1029 * `true`: count the specified query
1030 * `false`: don't count the query
1031
1032 Note that the query counters are buffered and flushed each time statistics are
1033 sent to the carbon server. The current content of the buffer can be inspected
1034 with `getQueryCounters()`. If you decide to enable query counting without
1035 `carbonServer`, make sure you implement clearing the log from `maintenance()`
1036 by issuing `clearQueryCounters()`.
1037
1038 DNSCrypt
1039 --------
1040 `dnsdist`, when compiled with --enable-dnscrypt, can be used as a DNSCrypt server,
1041 uncurving queries before forwarding them to downstream servers and curving responses back.
1042 To make `dnsdist` listen to incoming DNSCrypt queries on 127.0.0.1 port 8443,
1043 with a provider name of "2.providername", using a resolver certificate and associated key
1044 stored respectively in the `resolver.cert` and `resolver.key` files, the `addDnsCryptBind()`
1045 directive can be used:
1046
1047 ```
1048 addDNSCryptBind("127.0.0.1:8443", "2.providername", "/path/to/resolver.cert", "/path/to/resolver.key")
1049 ```
1050
1051 To generate the provider and resolver certificates and keys, you can simply do:
1052
1053 ```
1054 > generateDNSCryptProviderKeys("/path/to/providerPublic.key", "/path/to/providerPrivate.key")
1055 Provider fingerprint is: E1D7:2108:9A59:BF8D:F101:16FA:ED5E:EA6A:9F6C:C78F:7F91:AF6B:027E:62F4:69C3:B1AA
1056 > generateDNSCryptCertificate("/path/to/providerPrivate.key", "/path/to/resolver.cert", "/path/to/resolver.key", serial, validFrom, validUntil)
1057 ```
1058
1059 Ideally, the certificates and keys should be generated on an offline dedicated hardware and not on the resolver.
1060 The resolver key should be regularly rotated and should never touch persistent storage, being stored in a tmpfs
1061 with no swap configured.
1062
1063 You can display the currently configured DNSCrypt binds with:
1064 ```
1065 > showDNSCryptBinds()
1066 # Address Provider Name Serial Validity P. Serial P. Validity
1067 0 127.0.0.1:8443 2.name 14 2016-04-10 08:14:15 0 -
1068 ```
1069
1070 If you forgot to write down the provider fingerprint value after generating the provider keys, you can use `printDNSCryptProviderFingerprint()` to retrieve it later:
1071 ```
1072 > printDNSCryptProviderFingerprint("/path/to/providerPublic.key")
1073 Provider fingerprint is: E1D7:2108:9A59:BF8D:F101:16FA:ED5E:EA6A:9F6C:C78F:7F91:AF6B:027E:62F4:69C3:B1AA
1074 ```
1075
1076 AXFR, IXFR and NOTIFY
1077 ---------------------
1078 When `dnsdist` is deployed in front of a master authoritative server, it might
1079 receive AXFR or IXFR queries destined to this master. There are two issues
1080 that can arise in this kind of setup:
1081
1082 * If the master is part of a pool of servers, the first SOA query can be directed
1083 by `dnsdist` to a different server than the following AXFR/IXFR one, which might
1084 fail if the servers are not perfectly synchronised.
1085 * If the master only allows AXFR/IXFR based on the source address of the requestor,
1086 it might be confused by the fact that the source address will be the one from
1087 the `dnsdist` server.
1088
1089 The first issue can be solved by routing SOA, AXFR and IXFR requests explicitely
1090 to the master:
1091
1092 ```
1093 > newServer({address="192.168.1.2", name="master", pool={"master", "otherpool"}})
1094 > addAction(OrRule({QTypeRule(dnsdist.SOA), QTypeRule(dnsdist.AXFR), QTypeRule(dnsdist.IXFR)}), PoolAction("master"))
1095 ```
1096
1097 The second one might require allowing AXFR/IXFR from the `dnsdist` source address
1098 and moving the source address check on `dnsdist`'s side:
1099
1100 ```
1101 > addAction(AndRule({OrRule({QTypeRule(dnsdist.AXFR), QTypeRule(dnsdist.IXFR)}), NotRule(makeRule("192.168.1.0/24"))}), RCodeAction(dnsdist.REFUSED))
1102 ```
1103
1104 When `dnsdist` is deployed in front of slaves, however, an issue might arise with NOTIFY
1105 queries, because the slave will receive a notification coming from the `dnsdist` address,
1106 and not the master's one. One way to fix this issue is to allow NOTIFY from the `dnsdist`
1107 address on the slave side (for example with PowerDNS's `trusted-notification-proxy`) and
1108 move the address check on `dnsdist`'s side:
1109
1110 ```
1111 > addAction(AndRule({OpcodeRule(DNSOpcode.Notify), NotRule(makeRule("192.168.1.0/24"))}), RCodeAction(dnsdist.REFUSED))
1112 ```
1113
1114 eBPF Socket Filtering
1115 ---------------------
1116 `dnsdist` can use eBPF socket filtering on recent Linux kernels (4.1+) built with eBPF
1117 support (`CONFIG_BPF`, `CONFIG_BPF_SYSCALL`, ideally `CONFIG_BPF_JIT`).
1118 This feature might require an increase of the memory limit associated to a socket, via
1119 the `sysctl` setting `net.core.optmem_max`. When attaching an eBPF program to a socket,
1120 the size of the program is checked against this limit, and the default value might not be
1121 enough. Large map sizes might also require an increase of `RLIMIT_MEMLOCK`.
1122
1123 This feature allows `dnsdist` to ask the kernel to discard incoming packets in kernel-space
1124 instead of them being copied to userspace just to be dropped, thus being a lot of faster.
1125
1126 The BPF filter can be used to block incoming queries manually:
1127
1128 ```
1129 > bpf = newBPFFilter(1024, 1024, 1024)
1130 > bpf:attachToAllBinds()
1131 > bpf:block(newCA("2001:DB8::42"))
1132 > bpf:blockQName(newDNSName("evildomain.com"), 255)
1133 > bpf:getStats()
1134 [2001:DB8::42]: 0
1135 evildomain.com. 255: 0
1136 > bpf:unblock(newCA("2001:DB8::42"))
1137 > bpf:unblockQName(newDNSName("evildomain.com"), 255)
1138 > bpf:getStats()
1139 >
1140 ```
1141
1142 The `blockQName()` method can be used to block queries based on the exact qname supplied,
1143 in a case-insensitive way, and an optional qtype. Using the 255 (ANY) qtype will block all
1144 queries for the qname, regardless of the qtype.
1145 Contrary to source address filtering, qname filtering only works over UDP. TCP qname
1146 filtering can be done the usual way:
1147
1148 ```
1149 > addAction(AndRule({TCPRule(true), makeRule("evildomain.com")}), DropAction())
1150 ```
1151
1152 The `attachToAllBinds()` method attaches the filter to every existing bind at runtime,
1153 but it's also possible to define a default BPF filter at configuration time, so
1154 it's automatically attached to every bind:
1155
1156 ```
1157 bpf = newBPFFilter(1024, 1024, 1024)
1158 setDefaultBPFFilter(bpf)
1159 ```
1160
1161 Finally, it's also possible to attach it to specific binds at runtime:
1162
1163 ```
1164 > bpf = newBPFFilter(1024, 1024, 1024)
1165 > showBinds()
1166 # Address Protocol Queries
1167 0 [::]:53 UDP 0
1168 1 [::]:53 TCP 0
1169 > bd = getBind(0)
1170 > bd:attachFilter(bpf)
1171 ```
1172
1173 `dnsdist` also supports adding dynamic, expiring blocks to a BPF filter:
1174
1175 ```
1176 bpf = newBPFFilter(1024, 1024, 1024)
1177 setDefaultBPFFilter(bpf)
1178 dbpf = newDynBPFFilter(bpf)
1179 function maintenance()
1180 addBPFFilterDynBlocks(exceedQRate(20, 10), dbpf, 60)
1181 dbpf:purgeExpired()
1182 end
1183 ```
1184
1185 This will dynamically block all hosts that exceeded 20 queries/s as measured
1186 over the past 10 seconds, and the dynamic block will last for 60 seconds.
1187
1188 This feature has been successfully tested on Arch Linux, Arch Linux ARM,
1189 Fedora Core 23 and Ubuntu Xenial.
1190
1191 All functions and types
1192 -----------------------
1193 Within `dnsdist` several core object types exist:
1194
1195 * Server: generated with newServer, represents a downstream server
1196 * ComboAddress: represents an IP address and port
1197 * DNSName: represents a domain name
1198 * NetmaskGroup: represents a group of netmasks
1199 * QPSLimiter: implements a QPS-based filter
1200 * SuffixMatchNode: represents a group of domain suffixes for rapid testing of membership
1201 * DNSHeader: represents the header of a DNS packet
1202
1203 The existence of most of these objects can mostly be ignored, unless you
1204 plan to write your own hooks and policies, but it helps to understand an
1205 expressions like:
1206
1207 ```
1208 > getServer(0).order=12 -- set order of server 0 to 12
1209 > getServer(0):addPool("abuse") -- add this server to the abuse pool
1210 ```
1211 The '.' means 'order' is a data member, while the ':' meand addPool is a member function.
1212
1213 Here are all functions:
1214
1215 * Practical
1216 * `shutdown()`: shut down `dnsdist`
1217 * quit or ^D: exit the console
1218 * `webserver(address:port, password [, apiKey [, customHeaders ]])`: launch a webserver with stats on that address with that password
1219 * ACL related:
1220 * `addACL(netmask)`: add to the ACL set who can use this server
1221 * `setACL({netmask, netmask})`: replace the ACL set with these netmasks. Use `setACL({})` to reset the list, meaning no one can use us
1222 * `showACL()`: show our ACL set
1223 * ClientState related:
1224 * function `showBinds()`: list every local bind
1225 * function `getBind(n)`: return the corresponding `ClientState` object
1226 * member `attachFilter(BPFFilter)`: attach a BPF Filter to this bind
1227 * member `detachFilter()`: detach the BPF Filter attached to this bind, if any
1228 * member `toString()`: print the address this bind listens to
1229 * Network related:
1230 * `addLocal(netmask, [true], [false], [TCP Fast Open queue size])`: add to addresses we listen on. Second optional parameter sets TCP or not. Third optional parameter sets SO_REUSEPORT when available. Last parameter sets the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
1231 * `setLocal(netmask, [true], [false], [TCP Fast Open queue size])`: reset list of addresses we listen on to this address. Second optional parameter sets TCP or not. Third optional parameter sets SO_REUSEPORT when available. Last parameter sets the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
1232 * Blocking related:
1233 * `addDomainBlock(domain)`: block queries within this domain
1234 * Carbon/Graphite/Metronome statistics related:
1235 * `carbonServer(serverIP, [ourname], [interval])`: report statistics to serverIP using our hostname, or 'ourname' if provided, every 'interval' seconds
1236 * Query counting related:
1237 * `clearQueryCounters()`: clears the query counter buffer.
1238 * `getQueryCounters([max])`: show current buffer of query counters, limited by `max` if provided.
1239 * `setQueryCount(bool)`: set whether queries should be counted.
1240 * `setQueryCountFilter(func)`: filter queries that would be counted, where `func` is a function with parameter `dq` which decides whether a query should and how it should be counted.
1241 * Control socket related:
1242 * `makeKey()`: generate a new server access key, emit configuration line ready for pasting
1243 * `setKey(key)`: set access key to that key.
1244 * `testCrypto()`: test of the crypto all works
1245 * `controlSocket(addr)`: open a control socket on this address / connect to this address in client mode
1246 * Diagnostics and statistics
1247 * `dumpStats()`: print all statistics we gather
1248 * `grepq(Netmask|DNS Name|100ms [, n])`: shows the last n queries and responses matching the specified client address or range (Netmask), or the specified DNS Name, or slower than 100ms
1249 * `grepq({"::1", "powerdns.com", "100ms"} [, n])`: shows the last n queries and responses matching the specified client address AND range (Netmask) AND the specified DNS Name AND slower than 100ms
1250 * `topQueries(n[, labels])`: show top 'n' queries, as grouped when optionally cut down to 'labels' labels
1251 * `topResponses(n, kind[, labels])`: show top 'n' responses with RCODE=kind (0=NO Error, 2=ServFail, 3=ServFail), as grouped when optionally cut down to 'labels' labels
1252 * `topSlow([top][, limit][, labels])`: show `top` queries slower than `limit` milliseconds, grouped by last `labels` labels
1253 * `topBandwidth(top)`: show top-`top` clients that consume the most bandwidth over length of ringbuffer
1254 * `topClients(n)`: show top-`n` clients sending the most queries over length of ringbuffer
1255 * `showResponseLatency()`: show a plot of the response time latency distribution
1256 * `showTCPStats()`: show some statistics regarding TCP
1257 * `showVersion()`: show the current version of dnsdist
1258 * Logging related
1259 * `infolog(string)`: log at level info
1260 * `warnlog(string)`: log at level warning
1261 * `errlog(string)`: log at level error
1262 * `setVerboseHealthChecks(bool)`: set whether health check errors will be logged
1263 * Server related:
1264 * `newServer("ip:port")`: instantiate a new downstream server with default settings
1265 * `newServer({address="ip:port", qps=1000, order=1, weight=10, pool="abuse", retries=5, tcpSendTimeout=30, tcpRecvTimeout=30, checkName="a.root-servers.net.", checkType="A", setCD=false, maxCheckFailures=1, mustResolve=false, useClientSubnet=true, source="address|interface name|address@interface"})`:
1266 instantiate a server with additional parameters
1267 * `showServers()`: output all servers
1268 * `getServer(n)`: returns server with index n
1269 * `getServers()`: returns a table with all defined servers
1270 * `rmServer(n)`: remove server with index n
1271 * `rmServer(server)`: remove this server object
1272 * Server member functions:
1273 * `addPool(pool)`: add this server to that pool
1274 * `getName()`: return the server name if any
1275 * `getNameWithAddr()`: return a string containing the server name if any plus the server address and port
1276 * `getOutstanding()`: this *returns* the number of outstanding queries (doesn't print it!)
1277 * `rmPool(pool)`: remove server from that pool
1278 * `setQPS(n)`: set the QPS setting to n
1279 * `setAuto()`: set this server to automatic availability testing
1280 * `setDown()`: force this server to be down
1281 * `setUp()`: force this server to be UP
1282 * `isUp()`: if this server is available
1283 * Server member data:
1284 * `upStatus`: if `dnsdist` considers this server available (overridden by `setDown()` and `setUp()`)
1285 * `name`: name of the server
1286 * `order`: order of this server in order-based server selection policies
1287 * `weight`: weight of this server in weighted server selection policies
1288 * Rule related:
1289 * `AllRule()`: matches all traffic
1290 * `AndRule()`: matches if all sub-rules matches
1291 * `DNSSECRule()`: matches queries with the DO flag set
1292 * `MaxQPSIPRule(qps, v4Mask=32, v6Mask=64)`: matches traffic exceeding the qps limit per subnet
1293 * `MaxQPSRule(qps)`: matches traffic **not** exceeding this qps limit
1294 * `NetmaskGroupRule(nmg, [src-bool])`: matches traffic from the specified network range. Pass `false` as second parameter to match NetmaskGroup against destination address instead of source address
1295 * `NotRule()`: matches if the sub-rule does not match
1296 * `OrRule()`: matches if at least one of the sub-rules matches
1297 * `OpcodeRule()`: matches queries with the specified opcode
1298 * `QClassRule(qclass)`: matches queries with the specified qclass (numeric)
1299 * `QNameLabelsCountRule(min, max)`: matches if the qname has less than `min` or more than `max` labels
1300 * `QNameWireLengthRule(min, max)`: matches if the qname's length on the wire is less than `min` or more than `max` bytes
1301 * `QTypeRule(qtype)`: matches queries with the specified qtype
1302 * `RCodeRule(rcode)`: matches queries or responses the specified rcode
1303 * `RegexRule(regex)`: matches the query name against the supplied regex
1304 * `RecordsCountRule(section, minCount, maxCount)`: matches if there is at least `minCount` and at most `maxCount` records in the `section` section
1305 * `RecordsTypeCountRule(section, type, minCount, maxCount)`: matches if there is at least `minCount` and at most `maxCount` records of type `type` in the `section` section
1306 * `RE2Rule(regex)`: matches the query name against the supplied regex using the RE2 engine
1307 * `SuffixMatchNodeRule(smn, [quiet-bool])`: matches based on a group of domain suffixes for rapid testing of membership. Pass `true` as second parameter to prevent listing of all domains matched.
1308 * `TCPRule(tcp)`: matches question received over TCP if `tcp` is true, over UDP otherwise
1309 * `TrailingDataRule()`: matches if the query has trailing data
1310 * Rule management related:
1311 * `clearRules()`: remove all current rules
1312 * `getAction(num)`: returns the Action associate with rule 'num'.
1313 * `mvResponseRule(from, to)`: move response rule 'from' to a position where it is in front of 'to'. 'to' can be one larger than the largest rule,
1314 in which case the rule will be moved to the last position.
1315 * `mvRule(from, to)`: move rule 'from' to a position where it is in front of 'to'. 'to' can be one larger than the largest rule,
1316 in which case the rule will be moved to the last position.
1317 * `newRuleAction(DNS Rule, DNS Action)`: return a pair of DNS Rule and DNS Action, to be used with `setRules()`
1318 * `rmResponseRule(n)`: remove response rule n
1319 * `rmRule(n)`: remove rule n
1320 * `setRules(list)`: replace the current rules with the supplied list of pairs of DNS Rules and DNS Actions (see `newRuleAction()`)
1321 * `showResponseRules()`: show all defined response rules
1322 * `showRules()`: show all defined rules
1323 * `topResponseRule()`: move the last response rule to the first position
1324 * `topRule()`: move the last rule to the first position
1325 * Built-in Actions for Rules:
1326 * `AllowAction()`: let these packets go through
1327 * `AllowResponseAction()`: let these packets go through
1328 * `DelayAction(milliseconds)`: delay the response by the specified amount of milliseconds (UDP-only)
1329 * `DelayResponseAction(milliseconds)`: delay the response by the specified amount of milliseconds (UDP-only)
1330 * `DisableECSAction()`: disable the sending of ECS to the backend
1331 * `DisableValidationAction()`: set the CD bit in the question, let it go through
1332 * `DropAction()`: drop these packets
1333 * `DropResponseAction()`: drop these packets
1334 * `ECSOverrideAction(bool)`: whether an existing ECS value should be overriden (true) or not (false)
1335 * `ECSPrefixLengthAction(v4, v6)`: set the ECS prefix length
1336 * `LogAction([filename], [binary], [append], [buffered])`: Log a line for each query, to the specified file if any, to the console (require verbose) otherwise. When logging to a file, the `binary` optional parameter specifies whether we log in binary form (default) or in textual form, the `append` optional parameter specifies whether we open the file for appending or truncate each time (default), and the `buffered` optional parameter specifies whether writes to the file are buffered (default) or not.
1337 * `NoRecurseAction()`: strip RD bit from the question, let it go through
1338 * `PoolAction(poolname)`: set the packet into the specified pool
1339 * `QPSPoolAction(maxqps, poolname)`: set the packet into the specified pool only if it **does not** exceed the specified QPS limits, letting the subsequent rules apply otherwise
1340 * `QPSAction(rule, maxqps)`: drop these packets if the QPS limits are exceeded
1341 * `RCodeAction(rcode)`: reply immediatly by turning the query into a response with the specified rcode
1342 * `RemoteLogAction(RemoteLogger [, alterFunction])`: send the content of this query to a remote logger via Protocol Buffer. `alterFunction` is a callback, receiving a DNSQuestion and a DNSDistProtoBufMessage, that can be used to modify the Protocol Buffer content, for example for anonymization purposes
1343 * `RemoteLogResponseAction(RemoteLogger [,alterFunction])`: send the content of this response to a remote logger via Protocol Buffer. `alterFunction` is the same callback than the one in `RemoteLogAction`
1344 * `SkipCacheAction()`: don't lookup the cache for this query, don't store the answer
1345 * `SpoofAction(ip[, ip])` or `SpoofAction({ip, ip, ..}): forge a response with the specified IPv4 (for an A query) or IPv6 (for an AAAA). If you specify multiple addresses, all that match the query type (A, AAAA or ANY) will get spoofed in
1346 * `SpoofCNAMEAction(cname)`: forge a response with the specified CNAME value
1347 * `TCAction()`: create answer to query with TC and RD bits set, to move to TCP
1348 * `TeeAction(remote[, addECS])`: send copy of query to remote, keep stats on responses. If `addECS` is set to `true`, EDNS Client Subnet information will be added to the query
1349 * Specialist rule generators
1350 * `addAnyTCRule()`: generate TC=1 answers to ANY queries received over UDP, moving them to TCP
1351 * `addDomainSpoof(domain, ip[, ip6])` or `addDomainSpoof(domain, {IP, IP, IP..})`: generate answers for A/AAAA/ANY queries using the ip parameters
1352 * `addDomainCNAMESpoof(domain, cname)`: generate CNAME answers for queries using the specified value
1353 * `addDisableValidationRule(domain)`: set the CD flags to 1 for all queries matching the specified domain
1354 * `addNoRecurseRule(domain)`: clear the RD flag for all queries matching the specified domain
1355 * `setDNSSECPool(pool)`: move queries requesting DNSSEC processing to this pool
1356 * Policy member data:
1357 * `name`: the policy name
1358 * `policy`: the policy function
1359 * Pool related:
1360 * `addPoolRule(domain, pool)`: send queries to this domain to that pool
1361 * `addPoolRule({domain, domain}, pool)`: send queries to these domains to that pool
1362 * `addPoolRule(netmask, pool)`: send queries to this netmask to that pool
1363 * `addPoolRule({netmask, netmask}, pool)`: send queries to these netmasks to that pool
1364 * `addQPSPoolRule(x, limit, pool)`: like `addPoolRule`, but only select at most 'limit' queries/s for this pool, letting the subsequent rules apply otherwise
1365 * `getPool(poolname)`: return the ServerPool named `poolname`
1366 * `getPoolServers(pool)`: return servers part of this pool
1367 * `showPools()`: list the current server pools
1368 * Lua Action related:
1369 * `addLuaAction(x, func)`: where 'x' is all the combinations from `addPoolRule`, and func is a
1370 function with the parameter `dq`, which returns an action to be taken on this packet.
1371 Good for rare packets but where you want to do a lot of processing.
1372 * Server selection policy related:
1373 * `setServerPolicy(policy)`: set server selection policy to that policy
1374 * `setServerPolicyLua(name, function)`: set server selection policy to one named 'name' and provided by 'function'
1375 * `showServerPolicy()`: show name of currently operational server selection policy
1376 * `newServerPolicy(name, function)`: create a policy object from a Lua function
1377 * Available policies:
1378 * `firstAvailable`: Pick first server that has not exceeded its QPS limit, ordered by the server 'order' parameter
1379 * `whashed`: Weighted hashed ('sticky') distribution over available servers, based on the server 'weight' parameter
1380 * `wrandom`: Weighted random over available servers, based on the server 'weight' parameter
1381 * `roundrobin`: Simple round robin over available servers
1382 * `leastOutstanding`: Send traffic to downstream server with least outstanding queries, with the lowest 'order', and within that the lowest recent latency
1383 * Shaping related:
1384 * `addQPSLimit(domain, n)`: limit queries within that domain to n per second
1385 * `addQPSLimit({domain, domain}, n)`: limit queries within those domains (together) to n per second
1386 * `addQPSLimit(netmask, n)`: limit queries within that netmask to n per second
1387 * `addQPSLimit({netmask, netmask}, n)`: limit queries within those netmasks (together) to n per second
1388 * Delaying related:
1389 * `addDelay(domain, n)`: delay answers within that domain by n milliseconds
1390 * `addDelay({domain, domain}, n)`: delay answers within those domains (together) by n milliseconds
1391 * `addDelay(netmask, n)`: delay answers within that netmask by n milliseconds
1392 * `addDelay({netmask, netmask}, n)`: delay answers within those netmasks (together) by n milliseconds
1393 * Answer changing functions:
1394 * `truncateTC(bool)`: if set (default) truncate TC=1 answers so they are actually empty. Fixes an issue for PowerDNS Authoritative Server 2.9.22.
1395 * `fixupCase(bool)`: if set (default to no), rewrite the first qname of the question part of the answer to match the one from the query. It is only useful when you have a downstream server that messes up the case of the question qname in the answer
1396 * Dynamic Block related:
1397 * `maintenance()`: called every second by dnsdist if defined, call functions below from it
1398 * `clearDynBlocks()`: clear all dynamic blocks
1399 * `showDynBlocks()`: show dynamic blocks in force
1400 * `addDynBlocks(addresses, message[, seconds])`: block the set of addresses with message `msg`, for `seconds` seconds (10 by default)
1401 * `addBPFFilterDynBlocks(addresses, DynBPFFilter[, seconds])`: block the set of addresses using the supplied BPF Filter, for `seconds` seconds (10 by default)
1402 * `exceedServFails(rate, seconds)`: get set of addresses that exceed `rate` servails/s over `seconds` seconds
1403 * `exceedNXDOMAINs(rate, seconds)`: get set of addresses that exceed `rate` NXDOMAIN/s over `seconds` seconds
1404 * `exceedRespByterate(rate, seconds)`: get set of addresses that exeeded `rate` bytes/s answers over `seconds` seconds
1405 * `exceedQRate(rate, seconds)`: get set of address that exceed `rate` queries/s over `seconds` seconds
1406 * `exceedQTypeRate(type, rate, seconds)`: get set of address that exceed `rate` queries/s for queries of type `type` over `seconds` seconds
1407 * ServerPool related:
1408 * `getCache()`: return the current packet cache, if any
1409 * `setCache(PacketCache)`: set the cache for this pool
1410 * `unsetCache()`: remove the packet cache from this pool
1411 * PacketCache related:
1412 * `expunge(n)`: remove entries from the cache, leaving at most `n` entries
1413 * `expungeByName(DNSName [, qtype=ANY])`: remove entries matching the supplied DNSName and type from the cache
1414 * `isFull()`: return true if the cache has reached the maximum number of entries
1415 * `newPacketCache(maxEntries[, maxTTL=86400, minTTL=0, servFailTTL=60, stateTTL=60])`: return a new PacketCache
1416 * `printStats()`: print the cache stats (hits, misses, deferred lookups and deferred inserts)
1417 * `purgeExpired(n)`: remove expired entries from the cache until there is at most `n` entries remaining in the cache
1418 * `toString()`: return the number of entries in the Packet Cache, and the maximum number of entries
1419 * Advanced functions for writing your own policies and hooks
1420 * ComboAddress related:
1421 * `newCA(address)`: return a new ComboAddress
1422 * `getPort()`: return the port number
1423 * `isIPv4()`: return true if the address is an IPv4, false otherwise
1424 * `isIPv6()`: return true if the address is an IPv6, false otherwise
1425 * `isMappedIPv4()`: return true if the address is an IPv4 mapped into an IPv6, false otherwise
1426 * `mapToIPv4()`: convert an IPv4 address mapped in a v6 one into an IPv4
1427 * `tostring()`: return in human-friendly format
1428 * `toString()`: alias for `tostring()`
1429 * `tostringWithPort()`: return in human-friendly format, with port number
1430 * `toStringWithPort()`: alias for `tostringWithPort()`
1431 * `truncate(bits)`: truncate the address to the specified number of bits
1432 * DNSName related:
1433 * `newDNSName(name)`: make a DNSName based on this .-terminated name
1434 * member `countLabels()`: return the number of labels
1435 * member `isPartOf(dnsname)`: is this dnsname part of that dnsname
1436 * member `tostring()`: return as a human friendly . terminated string
1437 * member `toString()`: alias for `tostring()`
1438 * member `wirelength()`: return the length on the wire
1439 * DNSQuestion related:
1440 * member `dh`: DNSHeader
1441 * member `ecsOverride`: whether an existing ECS value should be overriden (settable)
1442 * member `ecsPrefixLength`: the ECS prefix length to use (settable)
1443 * member `len`: the question length
1444 * member `localaddr`: ComboAddress of the local bind this question was received on
1445 * member `opcode`: the question opcode
1446 * member `qname`: DNSName of this question
1447 * member `qclass`: QClass (as an unsigned integer) of this question
1448 * member `qtype`: QType (as an unsigned integer) of this question
1449 * member `remoteaddr`: ComboAddress of the remote client
1450 * member `rcode`: RCode of this question
1451 * member `size`: the total size of the buffer starting at `dh`
1452 * member `skipCache`: whether to skip cache lookup / storing the answer for this question (settable)
1453 * member `tcp`: whether this question was received over a TCP socket
1454 * member `useECS`: whether to send ECS to the backend (settable)
1455 * DNSHeader related
1456 * member `getRD()`: get recursion desired flag
1457 * member `setRD(bool)`: set recursion desired flag
1458 * member `setTC(bool)`: set truncation flag (TC)
1459 * member `setQR(bool)`: set Query Response flag (setQR(true) indicates an *answer* packet)
1460 * member `getCD()`: get checking disabled flag
1461 * member `setCD(bool)`: set checking disabled flag
1462 * NetmaskGroup related
1463 * function `newNMG()`: returns a NetmaskGroup
1464 * member `addMask(mask)`: adds `mask` to the NetmaskGroup
1465 * member `match(ComboAddress)`: checks if ComboAddress is matched by this NetmaskGroup
1466 * member `clear()`: clears the NetmaskGroup
1467 * member `size()`: returns number of netmasks in this NetmaskGroup
1468 * QPSLimiter related:
1469 * `newQPSLimiter(rate, burst)`: configure a QPS limiter with that rate and that burst capacity
1470 * member `check()`: check if this QPSLimiter has a token for us. If yes, you must use it.
1471 * SuffixMatchNode related:
1472 * `newSuffixMatchNode()`: returns a new SuffixMatchNode
1473 * member `check(DNSName)`: returns true if DNSName is matched by this group
1474 * member `add(DNSName)`: add this DNSName to the node
1475 * Tuning related:
1476 * `setTCPRecvTimeout(n)`: set the read timeout on TCP connections from the client, in seconds
1477 * `setTCPSendTimeout(n)`: set the write timeout on TCP connections from the client, in seconds
1478 * `setMaxTCPClientThreads(n)`: set the maximum of TCP client threads, handling TCP connections
1479 * `setMaxTCPQueuedConnections(n)`: set the maximum number of TCP connections queued (waiting to be picked up by a client thread)
1480 * `setMaxUDPOutstanding(n)`: set the maximum number of outstanding UDP queries to a given backend server. This can only be set at configuration time and defaults to 10240
1481 * `setCacheCleaningDelay(n)`: set the interval in seconds between two runs of the cache cleaning algorithm, removing expired entries
1482 * `setStaleCacheEntriesTTL(n)`: allows using cache entries expired for at most `n` seconds when no backend available to answer for a query
1483 * DNSCrypt related:
1484 * `addDNSCryptBind("127.0.0.1:8443", "provider name", "/path/to/resolver.cert", "/path/to/resolver.key", [false], [TCP Fast Open queue size]):` listen to incoming DNSCrypt queries on 127.0.0.1 port 8443, with a provider name of "provider name", using a resolver certificate and associated key stored respectively in the `resolver.cert` and `resolver.key` files. The fifth optional parameter sets SO_REUSEPORT when available. The last parameter sets the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
1485 * `generateDNSCryptProviderKeys("/path/to/providerPublic.key", "/path/to/providerPrivate.key"):` generate a new provider keypair
1486 * `generateDNSCryptCertificate("/path/to/providerPrivate.key", "/path/to/resolver.cert", "/path/to/resolver.key", serial, validFrom, validUntil):` generate a new resolver private key and related certificate, valid from the `validFrom` timestamp until the `validUntil` one, signed with the provider private key
1487 * `printDNSCryptProviderFingerprint("/path/to/providerPublic.key")`: display the fingerprint of the provided resolver public key
1488 * `showDNSCryptBinds():`: display the currently configured DNSCrypt binds
1489 * BPFFilter related:
1490 * function `newBPFFilter(maxV4, maxV6, maxQNames)`: return a new eBPF socket filter with a maximum of maxV4 IPv4, maxV6 IPv6 and maxQNames qname entries in the block tables
1491 * function `setDefaultBPFFilter(BPFFilter)`: when used at configuration time, the corresponding BPFFilter will be attached to every bind
1492 * member `attachToAllBinds()`: attach this filter to every bind already defined. This is the run-time equivalent of `setDefaultBPFFilter(bpf)`
1493 * member `block(ComboAddress)`: block this address
1494 * member `blockQName(DNSName [, qtype=255])`: block queries for this exact qname. An optional qtype can be used, default to 255
1495 * member `getStats()`: print the block tables
1496 * member `unblock(ComboAddress)`: unblock this address
1497 * member `unblockQName(DNSName [, qtype=255])`: remove this qname from the block list
1498 * DNSDistProtoBufMessage related:
1499 * member `setBytes(bytes)`: set the size of the query
1500 * member `setEDNSSubnet(Netmask)`: set the EDNS Subnet
1501 * member `setQueryTime(sec, usec)`: in a response message, set the time at which the query has been received
1502 * member `setQuestion(DNSName, qtype, qclass)`: set the question
1503 * member `setRequestor(ComboAddress)`: set the requestor
1504 * member `setRequestorFromString(string)`: set the requestor
1505 * member `setResponder(ComboAddress)`: set the responder
1506 * member `setResponderFromString(string)`: set the responder
1507 * member `setResponseCode(rcode)`: set the response code
1508 * member `setTime(sec, usec)`: set the time at which the query or response has been received
1509 * member `toDebugString()`: return an string containing the content of the message
1510 * DynBPFFilter related:
1511 * function `newDynBPFFilter(BPFFilter)`: return a new DynBPFFilter object using this BPF Filter
1512 * member `block(ComboAddress[, seconds]): add this address to the underlying BPF Filter for `seconds` seconds (default to 10 seconds)
1513 * member `purgeExpired()`: remove expired entries
1514 * function `registerDynBPFFilter(DynBPFFilter)`: register this dynamic BPF filter into the web interface so that its counters are displayed
1515 * function `unregisterDynBPFFilter(DynBPFFilter)`: unregister this dynamic BPF filter
1516 * RemoteLogger related:
1517 * `newRemoteLogger(address:port [, timeout=2, maxQueuedEntries=100, reconnectWaitTime=1])`: create a Remote Logger object, to use with `RemoteLogAction()` and `RemoteLogResponseAction()`
1518
1519 All hooks
1520 ---------
1521 `dnsdist` can call Lua per packet if so configured, and will do so with the following hooks:
1522
1523 * `bool blockFilter(dq)`: if defined, called for every packet. If this
1524 returns true, the packet is dropped. If false is returned, `dnsdist` will check if the DNSHeader indicates
1525 the packet is now a query response. If so, `dnsdist` will answer the client directly with the modified packet.
1526 * `server policy(candidates, DNSQuestion)`: if configured with `setServerPolicyLua()`
1527 gets called for every packet. Candidates is a table of potential servers to pick from, ComboAddress is the
1528 address of the requestor, DNSName and qtype describe name and type of query. DNSHeader meanwhile is available for
1529 your inspection.
1530
1531
1532