]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsdistdist/docs/reference/config.rst
Merge pull request #8456 from rgacogne/ddist-config-check-test
[thirdparty/pdns.git] / pdns / dnsdistdist / docs / reference / config.rst
1 .. highlight:: lua
2
3 Configuration Reference
4 =======================
5
6 This page lists all configuration options for dnsdist.
7
8 .. note::
9
10 When an IPv6 IP:PORT combination is needed, the bracketed syntax from :rfc:`RFC 3986 <3986#section-3.2.2>` should be used.
11 e.g. "[2001:DB8:14::C0FF:FEE]:5300".
12
13 Functions and Types
14 -------------------
15
16 Within dnsdist several core object types exist:
17
18 * :class:`Server`: generated with :func:`newServer`, represents a downstream server
19 * :class:`ComboAddress`: represents an IP address and port
20 * :class:`DNSName`: represents a domain name
21 * :class:`NetmaskGroup`: represents a group of netmasks
22 * :class:`QPSLimiter`: implements a QPS-based filter
23 * :class:`SuffixMatchNode`: represents a group of domain suffixes for rapid testing of membership
24 * :class:`DNSHeader`: represents the header of a DNS packet, see :ref:`DNSHeader`
25 * :class:`ClientState`: sometimes also called Bind or Frontend, represents the addresses and ports dnsdist is listening on
26
27 The existence of most of these objects can mostly be ignored, unless you plan to write your own hooks and policies, but it helps to understand an expressions like:
28
29 .. code-block:: lua
30
31 getServer(0).order=12 -- set order of server 0 to 12
32 getServer(0):addPool("abuse") -- add this server to the abuse pool
33
34 The ``.`` means ``order`` is a data member, while the ``:`` means ``addPool`` is a member function.
35
36 Global configuration
37 --------------------
38
39 .. function:: includeDirectory(path)
40
41 Include configuration files from ``path``.
42
43 :param str path: The directory to load configuration files from. Each file must end in ``.conf``.
44
45 .. function:: reloadAllCertificates()
46
47 .. versionadded:: 1.4.0
48
49 Reload all DNSCrypt and TLS certificates, along with their associated keys.
50
51 .. function:: setSyslogFacility(facility)
52
53 .. versionadded:: 1.4.0
54
55 Set the syslog logging facility to ``facility``.
56
57 :param int facility: The new facility as a numeric value. Defaults to LOG_DAEMON.
58
59 Listen Sockets
60 ~~~~~~~~~~~~~~
61
62 .. function:: addLocal(address[, options])
63
64 .. versionadded:: 1.2.0
65
66 .. versionchanged:: 1.3.0
67 Added ``cpus`` to the options.
68
69 .. versionchanged:: 1.4.0
70 Removed ``doTCP`` from the options. A listen socket on TCP is always created.
71
72 Add to the list of listen addresses.
73
74 :param str address: The IP Address with an optional port to listen on.
75 The default port is 53.
76 :param table options: A table with key: value pairs with listen options.
77
78 Options:
79
80 * ``doTCP=true``: bool - Also bind on TCP on ``address``. Removed in 1.4.0.
81 * ``reusePort=false``: bool - Set the ``SO_REUSEPORT`` socket option.
82 * ``tcpFastOpenQueueSize=0``: int - Set the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
83 * ``interface=""``: str - Set the network interface to use.
84 * ``cpus={}``: table - Set the CPU affinity for this listener thread, asking the scheduler to run it on a single CPU id, or a set of CPU ids. This parameter is only available if the OS provides the pthread_setaffinity_np() function.
85
86 .. code-block:: lua
87
88 addLocal('0.0.0.0:5300', { reusePort=true })
89
90 This will bind to both UDP and TCP on port 5300 with SO_REUSEPORT enabled.
91
92 .. function:: addLocal(address[[[,do_tcp], so_reuseport], tcp_fast_open_qsize])
93
94 .. deprecated:: 1.2.0
95
96 Add to the list of addresses listened on.
97
98 :param str address: The IP Address with an optional port to listen on.
99 The default port is 53.
100 :param bool do_tcp: Also bind a TCP port on ``address``, defaults to true.
101 :param bool so_reuseport: Use ``SO_REUSEPORT`` if it is available, defaults to false
102 :param int tcp_fast_open_qsize: The size of the TCP Fast Open queue. Set to a number
103 higher than 0 to enable TCP Fast Open when available.
104 Default is 0.
105
106 .. function:: addDOHLocal(address, [certFile(s) [, keyFile(s) [, urls [, options]]]])
107
108 .. versionadded:: 1.4.0
109
110 Listen on the specified address and TCP port for incoming DNS over HTTPS connections, presenting the specified X.509 certificate.
111 If no certificate (or key) files are specified, listen for incoming DNS over HTTP connections instead.
112
113 :param str address: The IP Address with an optional port to listen on.
114 The default port is 443.
115 :param str certFile(s): The path to a X.509 certificate file in PEM format, or a list of paths to such files.
116 :param str keyFile(s): The path to the private key file corresponding to the certificate, or a list of paths to such files, whose order should match the certFile(s) ones.
117 :param str-or-list urls: A base URL, or a list of base URLs, to accept queries on. Any query with a path under one of these will be treated as a DoH query. The default is /.
118 :param table options: A table with key: value pairs with listen options.
119
120 Options:
121
122 * ``reusePort=false``: bool - Set the ``SO_REUSEPORT`` socket option.
123 * ``tcpFastOpenQueueSize=0``: int - Set the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
124 * ``interface=""``: str - Set the network interface to use.
125 * ``cpus={}``: table - Set the CPU affinity for this listener thread, asking the scheduler to run it on a single CPU id, or a set of CPU ids. This parameter is only available if the OS provides the pthread_setaffinity_np() function.
126 * ``idleTimeout=30``: int - Set the idle timeout, in seconds.
127 * ``ciphers``: str - The TLS ciphers to use, in OpenSSL format. Ciphers for TLS 1.3 must be specified via ``ciphersTLS13``.
128 * ``ciphersTLS13``: str - The TLS ciphers to use for TLS 1.3, in OpenSSL format.
129 * ``serverTokens``: str - The content of the Server: HTTP header returned by dnsdist. The default is "h2o/dnsdist".
130 * ``customResponseHeaders={}``: table - Set custom HTTP header(s) returned by dnsdist.
131 * ``ocspResponses``: list - List of files containing OCSP responses, in the same order than the certificates and keys, that will be used to provide OCSP stapling responses.
132 * ``minTLSVersion``: str - Minimum version of the TLS protocol to support. Possible values are 'tls1.0', 'tls1.1', 'tls1.2' and 'tls1.3'. Default is to require at least TLS 1.0.
133 * ``numberOfTicketsKeys``: int - The maximum number of tickets keys to keep in memory at the same time. Only one key is marked as active and used to encrypt new tickets while the remaining ones can still be used to decrypt existing tickets after a rotation. Default to 5.
134 * ``ticketKeyFile``: str - The path to a file from where TLS tickets keys should be loaded, to support RFC 5077. These keys should be rotated often and never written to persistent storage to preserve forward secrecy. The default is to generate a random key. dnsdist supports several tickets keys to be able to decrypt existing sessions after the rotation.
135 * ``ticketsKeysRotationDelay``: int - Set the delay before the TLS tickets key is rotated, in seconds. Default is 43200 (12h).
136 * ``sessionTickets``: bool - Whether session resumption via session tickets is enabled. Default is true, meaning tickets are enabled.
137 * ``numberOfStoredSessions``: int - The maximum number of sessions kept in memory at the same time. Default is 20480. Setting this value to 0 disables stored session entirely.
138 * ``preferServerCiphers``: bool - Whether to prefer the order of ciphers set by the server instead of the one set by the client. Default is true, meaning that the order of the server is used.
139 * ``keyLogFile``: str - Write the TLS keys in the specified file so that an external program can decrypt TLS exchanges, in the format described in https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format.
140
141 .. function:: addTLSLocal(address, certFile(s), keyFile(s) [, options])
142
143 .. versionadded:: 1.3.0
144 .. versionchanged:: 1.3.1
145 ``certFile(s)`` and ``keyFile(s)`` parameters accept a list of files.
146 ``sessionTickets`` option added.
147 .. versionchanged:: 1.3.3
148 ``numberOfStoredSessions`` option added.
149 .. versionchanged:: 1.4.0
150 ``ciphersTLS13``, ``minTLSVersion``, ``ocspResponses``, ``preferServerCiphers``, ``keyLogFile`` options added.
151
152 Listen on the specified address and TCP port for incoming DNS over TLS connections, presenting the specified X.509 certificate.
153
154 :param str address: The IP Address with an optional port to listen on.
155 The default port is 853.
156 :param str certFile(s): The path to a X.509 certificate file in PEM format, or a list of paths to such files.
157 :param str keyFile(s): The path to the private key file corresponding to the certificate, or a list of paths to such files, whose order should match the certFile(s) ones.
158 :param table options: A table with key: value pairs with listen options.
159
160 Options:
161
162 * ``reusePort=false``: bool - Set the ``SO_REUSEPORT`` socket option.
163 * ``tcpFastOpenQueueSize=0``: int - Set the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
164 * ``interface=""``: str - Set the network interface to use.
165 * ``cpus={}``: table - Set the CPU affinity for this listener thread, asking the scheduler to run it on a single CPU id, or a set of CPU ids. This parameter is only available if the OS provides the pthread_setaffinity_np() function.
166 * ``provider``: str - The TLS library to use between GnuTLS and OpenSSL, if they were available and enabled at compilation time. Default is to use OpenSSL when available.
167 * ``ciphers``: str - The TLS ciphers to use. The exact format depends on the provider used. When the OpenSSL provder is used, ciphers for TLS 1.3 must be specified via ``ciphersTLS13``.
168 * ``ciphersTLS13``: str - The ciphers to use for TLS 1.3, when the OpenSSL provider is used. When the GnuTLS provider is used, ``ciphers`` applies regardless of the TLS protocol and this setting is not used.
169 * ``numberOfTicketsKeys``: int - The maximum number of tickets keys to keep in memory at the same time, if the provider supports it (GnuTLS doesn't, OpenSSL does). Only one key is marked as active and used to encrypt new tickets while the remaining ones can still be used to decrypt existing tickets after a rotation. Default to 5.
170 * ``ticketKeyFile``: str - The path to a file from where TLS tickets keys should be loaded, to support RFC 5077. These keys should be rotated often and never written to persistent storage to preserve forward secrecy. The default is to generate a random key. The OpenSSL provider supports several tickets keys to be able to decrypt existing sessions after the rotation, while the GnuTLS provider only supports one key.
171 * ``ticketsKeysRotationDelay``: int - Set the delay before the TLS tickets key is rotated, in seconds. Default is 43200 (12h).
172 * ``sessionTickets``: bool - Whether session resumption via session tickets is enabled. Default is true, meaning tickets are enabled.
173 * ``numberOfStoredSessions``: int - The maximum number of sessions kept in memory at the same time. At this time this is only supported by the OpenSSL provider, as stored sessions are not supported with the GnuTLS one. Default is 20480. Setting this value to 0 disables stored session entirely.
174 * ``ocspResponses``: list - List of files containing OCSP responses, in the same order than the certificates and keys, that will be used to provide OCSP stapling responses.
175 * ``minTLSVersion``: str - Minimum version of the TLS protocol to support. Possible values are 'tls1.0', 'tls1.1', 'tls1.2' and 'tls1.3'. Default is to require at least TLS 1.0. Note that this value is ignored when the GnuTLS provider is in use, and the ``ciphers`` option should be set accordingly instead. For example, 'NORMAL:!VERS-TLS1.0:!VERS-TLS1.1' will disable TLS 1.0 and 1.1.
176 * ``preferServerCiphers``: bool - Whether to prefer the order of ciphers set by the server instead of the one set by the client. Default is true, meaning that the order of the server is used.
177 * ``keyLogFile``: str - Write the TLS keys in the specified file so that an external program can decrypt TLS exchanges, in the format described in https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Key_Log_Format.
178
179 .. function:: setLocal(address[, options])
180
181 .. versionadded:: 1.2.0
182
183 Remove the list of listen addresses and add a new one.
184
185 :param str address: The IP Address with an optional port to listen on.
186 The default port is 53.
187 :param table options: A table with key: value pairs with listen options.
188
189 The options that can be set are the same as :func:`addLocal`.
190
191 .. function:: setLocal(address[[[,do_tcp], so_reuseport], tcp_fast_open_qsize])
192
193 .. deprecated:: 1.2.0
194
195 Remove the list of listen addresses and add a new one.
196
197 :param str address: The IP Address with an optional port to listen on.
198 The default port is 53.
199 :param bool do_tcp: Also bind a TCP port on ``address``, defaults to true.
200 :param bool so_reuseport: Use ``SO_REUSEPORT`` if it is available, defaults to false
201 :param int tcp_fast_open_qsize: The size of the TCP Fast Open queue. Set to a number
202 higher than 0 to enable TCP Fast Open when available.
203 Default is 0.
204
205 Control Socket, Console and Webserver
206 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
207
208 .. function:: addConsoleACL(netmask)
209
210 .. versionadded:: 1.3.0
211
212 Add a netmask to the existing console ACL, allowing remote clients to connect to the console. Please make sure that encryption
213 has been enabled with :func:`setKey` before doing so. The default is to only allow 127.0.0.1/8 and ::1/128.
214
215 :param str netmask: A CIDR netmask, e.g. ``"192.0.2.0/24"``. Without a subnetmask, only the specific address is allowed.
216
217 .. function:: controlSocket(address)
218
219 Bind to ``addr`` and listen for a connection for the console. Since 1.3.0 only connections from local users are allowed
220 by default, :func:`addConsoleACL` and :func:`setConsoleACL` can be used to enable remote connections. Please make sure
221 that encryption has been enabled with :func:`setKey` before doing so. Enabling encryption is also strongly advised for
222 local connections, since not enabling it allows any local user to connect to the console.
223
224 :param str address: An IP address with optional port. By default, the port is 5199.
225
226 .. function:: inClientStartup()
227
228 Returns true while the console client is parsing the configuration.
229
230 .. function:: inConfigCheck()
231
232 .. versionadded:: 1.5.0
233
234 Returns true while the configuration is being checked, ie when run with ``--check-config``.
235
236 .. function:: makeKey()
237
238 Generate and print an encryption key.
239
240 .. function:: setConsoleConnectionsLogging(enabled)
241
242 .. versionadded:: 1.2.0
243
244 Whether to log the opening and closing of console connections.
245
246 :param bool enabled: Default to true.
247
248 .. function:: setKey(key)
249
250 Use ``key`` as shared secret between the client and the server
251
252 :param str key: An encoded key, as generated by :func:`makeKey`
253
254 .. function:: setConsoleACL(netmasks)
255
256 .. versionadded:: 1.3.0
257
258 Remove the existing console ACL and add the netmasks from the table, allowing remote clients to connect to the console. Please make sure that encryption
259 has been enabled with :func:`setKey` before doing so.
260
261 :param {str} netmasks: A table of CIDR netmask, e.g. ``{"192.0.2.0/24", "2001:DB8:14::/56"}``. Without a subnetmask, only the specific address is allowed.
262
263 .. function:: showConsoleACL()
264
265 Print a list of all netmasks allowed to connect to the console.
266
267 .. function:: testCrypto()
268
269 Test the crypto code, will report errors when something is not ok.
270
271 .. function:: setConsoleOutputMaxMsgSize(size)
272
273 .. versionadded:: 1.3.3
274
275 Set the maximum size in bytes of a single console message, default set to 10 MB.
276
277 :param int size: The new maximum size.
278
279 Webserver configuration
280 ~~~~~~~~~~~~~~~~~~~~~~~
281
282 .. function:: webserver(listen_address, password[, apikey[, custom_headers]])
283
284 Launch the :doc:`../guides/webserver` with statistics and the API.
285
286 :param str listen_address: The IP address and Port to listen on
287 :param str password: The password required to access the webserver
288 :param str apikey: The key required to access the API
289 :param {[str]=str,...} custom_headers: Allows setting custom headers and removing the defaults
290
291 .. function:: setAPIWritable(allow [,dir])
292
293 Allow modifications via the API.
294 Optionally saving these changes to disk.
295 Modifications done via the API will not be written to the configuration by default and will not persist after a reload
296
297 :param bool allow: Set to true to allow modification through the API
298 :param str dir: A valid directory where the configuration files will be written by the API.
299
300 .. function:: setWebserverConfig(options)
301
302 .. versionadded:: 1.3.3
303
304 Setup webserver configuration. See :func:`webserver`.
305
306 :param table options: A table with key: value pairs with webserver options.
307
308 Options:
309
310 * ``password=newPassword``: string - Changes the API password
311 * ``apikey=newKey``: string - Changes the API Key (set to an empty string do disable it)
312 * ``custom_headers={[str]=str,...}``: map of string - Allows setting custom headers and removing the defaults.
313
314 Access Control Lists
315 ~~~~~~~~~~~~~~~~~~~~
316
317 .. function:: addACL(netmask)
318
319 Add a netmask to the existing ACL controlling which clients can send UDP, TCP, DNS over TLS and DNS over HTTPS queries. See :ref:`ACL` for more information.
320
321 :param str netmask: A CIDR netmask, e.g. ``"192.0.2.0/24"``. Without a subnetmask, only the specific address is allowed.
322
323 .. function:: setACL(netmasks)
324
325 Remove the existing ACL and add the netmasks from the table of those allowed to send UDP, TCP, DNS over TLS and DNS over HTTPS queries. See :ref:`ACL` for more information.
326
327 :param {str} netmasks: A table of CIDR netmask, e.g. ``{"192.0.2.0/24", "2001:DB8:14::/56"}``. Without a subnetmask, only the specific address is allowed.
328
329 .. function:: showACL()
330
331 Print a list of all netmasks allowed to send queries over UDP, TCP, DNS over TLS and DNS over HTTPS. See :ref:`ACL` for more information.
332
333 EDNS Client Subnet
334 ~~~~~~~~~~~~~~~~~~
335
336 .. function:: setECSOverride(bool)
337
338 When ``useClientSubnet`` in :func:`newServer` is set and dnsdist adds an EDNS Client Subnet Client option to the query, override an existing option already present in the query, if any
339
340 :param bool: Whether to override an existing EDNS Client Subnet option present in the query. Defaults to false
341
342 .. function:: setECSSourcePrefixV4(prefix)
343
344 When ``useClientSubnet`` in :func:`newServer` is set and dnsdist adds an EDNS Client Subnet Client option to the query, truncate the requestors IPv4 address to ``prefix`` bits
345
346 :param int prefix: The prefix length
347
348 .. function:: setECSSourcePrefixV6(prefix)
349
350 When ``useClientSubnet`` in :func:`newServer` is set and dnsdist adds an EDNS Client Subnet Client option to the query, truncate the requestor's IPv6 address to bits
351
352 :param int prefix: The prefix length
353
354 Ringbuffers
355 ~~~~~~~~~~~
356
357 .. function:: setRingBuffersLockRetries(num)
358
359 .. versionadded:: 1.3.0
360
361 Set the number of shards to attempt to lock without blocking before giving up and simply blocking while waiting for the next shard to be available
362
363 :param int num: The maximum number of attempts. Defaults to 5 if there is more than one shard, 0 otherwise.
364
365 .. function:: setRingBuffersSize(num [, numberOfShards])
366
367 .. versionchanged:: 1.3.0
368 ``numberOfShards`` optional parameter added.
369
370 Set the capacity of the ringbuffers used for live traffic inspection to ``num``, and the number of shards to ``numberOfShards`` if specified.
371
372 :param int num: The maximum amount of queries to keep in the ringbuffer. Defaults to 10000
373 :param int numberOfShards: the number of shards to use to limit lock contention. Defaults to 1
374
375 Servers
376 -------
377
378 .. function:: newServer(server_string)
379 newServer(server_table)
380
381 .. versionchanged:: 1.3.0
382 Added ``checkClass``, ``sockets`` and ``checkFunction`` to server_table.
383
384 .. versionchanged:: 1.4.0
385 Added ``checkInterval``, ``checkTimeout`` and ``rise`` to server_table.
386
387 Add a new backend server. Call this function with either a string::
388
389 newServer(
390 "IP:PORT" -- IP and PORT of the backend server
391 )
392
393 or a table::
394
395 newServer({
396 address="IP:PORT", -- IP and PORT of the backend server (mandatory)
397 id=STRING, -- Use a pre-defined UUID instead of a random one
398 qps=NUM, -- Limit the number of queries per second to NUM, when using the `firstAvailable` policy
399 order=NUM, -- The order of this server, used by the `leastOutstanding` and `firstAvailable` policies
400 weight=NUM, -- The weight of this server, used by the `wrandom`, `whashed` and `chashed` policies, default: 1
401 -- Supported values are a minimum of 1, and a maximum of 2147483647.
402 pool=STRING|{STRING}, -- The pools this server belongs to (unset or empty string means default pool) as a string or table of strings
403 retries=NUM, -- The number of TCP connection attempts to the backend, for a given query
404 tcpConnectTimeout=NUM, -- The timeout (in seconds) of a TCP connection attempt
405 tcpSendTimeout=NUM, -- The timeout (in seconds) of a TCP write attempt
406 tcpRecvTimeout=NUM, -- The timeout (in seconds) of a TCP read attempt
407 tcpFastOpen=BOOL, -- Whether to enable TCP Fast Open
408 ipBindAddrNoPort=BOOL, -- Whether to enable IP_BIND_ADDRESS_NO_PORT if available, default: true
409 name=STRING, -- The name associated to this backend, for display purpose
410 checkClass=NUM, -- Use NUM as QCLASS in the health-check query, default: DNSClass.IN
411 checkName=STRING, -- Use STRING as QNAME in the health-check query, default: "a.root-servers.net."
412 checkType=STRING, -- Use STRING as QTYPE in the health-check query, default: "A"
413 checkFunction=FUNCTION,-- Use this function to dynamically set the QNAME, QTYPE and QCLASS to use in the health-check query (see :ref:`Healthcheck`)
414 checkTimeout=NUM, -- The timeout (in milliseconds) of a health-check query, default: 1000 (1s)
415 setCD=BOOL, -- Set the CD (Checking Disabled) flag in the health-check query, default: false
416 maxCheckFailures=NUM, -- Allow NUM check failures before declaring the backend down, default: 1
417 checkInterval=NUM -- The time in seconds between health checks
418 mustResolve=BOOL, -- Set to true when the health check MUST return a RCODE different from NXDomain, ServFail and Refused. Default is false, meaning that every RCODE except ServFail is considered valid
419 useClientSubnet=BOOL, -- Add the client's IP address in the EDNS Client Subnet option when forwarding the query to this backend
420 source=STRING, -- The source address or interface to use for queries to this backend, by default this is left to the kernel's address selection
421 -- The following formats are supported:
422 -- "address", e.g. "192.0.2.2"
423 -- "interface name", e.g. "eth0"
424 -- "address@interface", e.g. "192.0.2.2@eth0"
425 addXPF=NUM, -- Add the client's IP address and port to the query, along with the original destination address and port,
426 -- using the experimental XPF record from `draft-bellis-dnsop-xpf <https://datatracker.ietf.org/doc/draft-bellis-dnsop-xpf/>`_ and the specified option code. Default is disabled (0)
427 sockets=NUM, -- Number of sockets (and thus source ports) used toward the backend server, defaults to a single one
428 disableZeroScope=BOOL, -- Disable the EDNS Client Subnet 'zero scope' feature, which does a cache lookup for an answer valid for all subnets (ECS scope of 0) before adding ECS information to the query and doing the regular lookup. This requires the ``parseECS`` option of the corresponding cache to be set to true
429 rise=NUM -- Require NUM consecutive successful checks before declaring the backend up, default: 1
430 })
431
432 :param str server_string: A simple IP:PORT string.
433 :param table server_table: A table with at least a 'name' key
434
435 .. function:: getServer(index) -> Server
436
437 Get a :class:`Server`
438
439 :param int index: The number of the server (as seen in :func:`showServers`).
440 :returns: The :class:`Server` object or nil
441
442 .. function:: getServers()
443
444 Returns a table with all defined servers.
445
446 .. function:: rmServer(index)
447 rmServer(server)
448
449 Remove a backend server.
450
451 :param int index: The number of the server (as seen in :func:`showServers`).
452 :param Server server: A :class:`Server` object as returned by e.g. :func:`getServer`.
453
454 Server Functions
455 ~~~~~~~~~~~~~~~~
456 A server object returned by :func:`getServer` can be manipulated with these functions.
457
458 .. class:: Server
459
460 This object represents a backend server. It has several methods.
461
462 .. method:: Server:addPool(pool)
463
464 Add this server to a pool.
465
466 :param str pool: The pool to add the server to
467
468 .. method:: Server:getName() -> string
469
470 Get the name of this server.
471
472 :returns: The name of the server, or an empty string if it does not have one
473
474 .. method:: Server:getNameWithAddr() -> string
475
476 Get the name plus IP address and port of the server
477
478 :returns: A string containing the server name if any plus the server address and port
479
480 .. method:: Server:getOutstanding() -> int
481
482 Get the number of outstanding queries for this server.
483
484 :returns: The number of outstanding queries
485
486 .. method:: Server:isUp() -> bool
487
488 Returns the up status of the server
489
490 :returns: true when the server is up, false otherwise
491
492 .. method:: Server:rmPool(pool)
493
494 Removes the server from the named pool
495
496 :param str pool: The pool to remove the server from
497
498 .. method:: Server:setAuto([status])
499
500 .. versionchanged:: 1.3.0
501 ``status`` optional parameter added.
502
503 Set the server in the default auto state.
504 This will enable health check queries that will set the server ``up`` and ``down`` appropriately.
505
506 :param bool status: Set the initial status of the server to ``up`` (true) or ``down`` (false) instead of using the last known status
507
508 .. method:: Server:setQPS(limit)
509
510 Limit the queries per second for this server.
511
512 :param int limit: The maximum number of queries per second
513
514 .. method:: Server:setDown()
515
516 Set the server in an ``DOWN`` state.
517 The server will not receive queries and the health checks are disabled
518
519 .. method:: Server:setUp()
520
521 Set the server in an ``UP`` state.
522 This server will still receive queries and health checks are disabled
523
524 Apart from the functions, a :class:`Server` object has these attributes:
525
526 .. attribute:: Server.name
527
528 The name of the server
529
530 .. attribute:: Server.upStatus
531
532 Whether or not this server is up or down
533
534 .. attribute:: Server.order
535
536 The order of the server
537
538 .. attribute:: Server.weight
539
540 The weight of the server
541
542 Pools
543 -----
544
545 :class:`Server`\ s can be part of any number of pools.
546 Pools are automatically created when a server is added to a pool (with :func:`newServer`), or can be manually created with :func:`addPool`.
547
548 .. function:: addPool(name) -> ServerPool
549
550 Returns a :class:`ServerPool`.
551
552 :param string name: The name of the pool to create
553
554 .. function:: getPool(name) -> ServerPool
555
556 Returns a :class:`ServerPool` or nil.
557
558 :param string name: The name of the pool
559
560 .. function:: getPoolServers(name) -> [ Server ]
561
562 Returns a list of :class:`Server`\ s or nil.
563
564 :param string name: The name of the pool
565
566 .. function:: showPools()
567
568 Display the name, associated cache, server policy and associated servers for every pool.
569
570 .. class:: ServerPool
571
572 This represents the pool where zero or more servers are part of.
573
574 .. method:: ServerPool:getCache() -> PacketCache
575
576 Returns the :class:`PacketCache` for this pool or nil.
577
578 .. method:: ServerPool:getECS()
579
580 .. versionadded:: 1.3.0
581
582 Whether dnsdist will add EDNS Client Subnet information to the query before looking up into the cache,
583 when all servers from this pool are down. For more information see :meth:`ServerPool:setECS`.
584
585 .. method:: ServerPool:setCache(cache)
586
587 Adds ``cache`` as the pool's cache.
588
589 :param PacketCache cache: The new cache to add to the pool
590
591 .. method:: ServerPool:unsetCache()
592
593 Removes the cache from this pool.
594
595 .. method:: ServerPool:setECS()
596
597 .. versionadded:: 1.3.0
598
599 Set to true if dnsdist should add EDNS Client Subnet information to the query before looking up into the cache,
600 when all servers from this pool are down. If at least one server is up, the preference of the
601 selected server is used, this parameter is only useful if all the backends in this pool are down
602 and have EDNS Client Subnet enabled, since the queries in the cache will have been inserted with
603 ECS information. Default is false.
604
605 PacketCache
606 ~~~~~~~~~~~
607
608 A Pool can have a packet cache to answer queries directly instead of going to the backend.
609 See :doc:`../guides/cache` for a how to.
610
611 .. function:: newPacketCache(maxEntries[, maxTTL=86400[, minTTL=0[, temporaryFailureTTL=60[, staleTTL=60[, dontAge=false[, numberOfShards=1[, deferrableInsertLock=true[, maxNegativeTTL=3600[, parseECS=false]]]]]]]) -> PacketCache
612
613 .. versionchanged:: 1.3.0
614 ``numberOfShards`` and ``deferrableInsertLock`` parameters added.
615
616 .. versionchanged:: 1.3.1
617 ``maxNegativeTTL`` and ``parseECS`` parameters added.
618
619 .. deprecated:: 1.4.0
620
621 Creates a new :class:`PacketCache` with the settings specified.
622
623 :param int maxEntries: The maximum number of entries in this cache
624 :param int maxTTL: Cap the TTL for records to his number
625 :param int minTTL: Don't cache entries with a TTL lower than this
626 :param int temporaryFailureTTL: On a SERVFAIL or REFUSED from the backend, cache for this amount of seconds
627 :param int staleTTL: When the backend servers are not reachable, and global configuration ``setStaleCacheEntriesTTL`` is set appropriately, TTL that will be used when a stale cache entry is returned
628 :param bool dontAge: Don't reduce TTLs when serving from the cache. Use this when :program:`dnsdist` fronts a cluster of authoritative servers
629 :param int numberOfShards: Number of shards to divide the cache into, to reduce lock contention
630 :param bool deferrableInsertLock: Whether the cache should give up insertion if the lock is held by another thread, or simply wait to get the lock
631 :param int maxNegativeTTL: Cache a NXDomain or NoData answer from the backend for at most this amount of seconds, even if the TTL of the SOA record is higher
632 :param bool parseECS: Whether any EDNS Client Subnet option present in the query should be extracted and stored to be able to detect hash collisions involving queries with the same qname, qtype and qclass but a different incoming ECS value. Enabling this option adds a parsing cost and only makes sense if at least one backend might send different responses based on the ECS value, so it's disabled by default
633
634 .. function:: newPacketCache(maxEntries, [options]) -> PacketCache
635
636 .. versionadded:: 1.4.0
637
638 Creates a new :class:`PacketCache` with the settings specified.
639
640 :param int maxEntries: The maximum number of entries in this cache
641
642 Options:
643
644 * ``deferrableInsertLock=true``: bool - Whether the cache should give up insertion if the lock is held by another thread, or simply wait to get the lock.
645 * ``dontAge=false``: bool - Don't reduce TTLs when serving from the cache. Use this when :program:`dnsdist` fronts a cluster of authoritative servers.
646 * ``keepStaleData=false``: bool - Whether to suspend the removal of expired entries from the cache when there is no backend available in at least one of the pools using this cache.
647 * ``maxNegativeTTL=3600``: int - Cache a NXDomain or NoData answer from the backend for at most this amount of seconds, even if the TTL of the SOA record is higher.
648 * ``maxTTL=86400``: int - Cap the TTL for records to his number.
649 * ``minTTL=0``: int - Don't cache entries with a TTL lower than this.
650 * ``numberOfShards=1``: int - Number of shards to divide the cache into, to reduce lock contention.
651 * ``parseECS=false``: bool - Whether any EDNS Client Subnet option present in the query should be extracted and stored to be able to detect hash collisions involving queries with the same qname, qtype and qclass but a different incoming ECS value. Enabling this option adds a parsing cost and only makes sense if at least one backend might send different responses based on the ECS value, so it's disabled by default. Enabling this option is required for the 'zero scope' option to work
652 * ``staleTTL=60``: int - When the backend servers are not reachable, and global configuration ``setStaleCacheEntriesTTL`` is set appropriately, TTL that will be used when a stale cache entry is returned.
653 * ``temporaryFailureTTL=60``: int - On a SERVFAIL or REFUSED from the backend, cache for this amount of seconds..
654
655 .. class:: PacketCache
656
657 Represents a cache that can be part of :class:`ServerPool`.
658
659 .. method:: PacketCache:dump(fname)
660
661 .. versionadded:: 1.3.1
662
663 Dump a summary of the cache entries to a file.
664
665 :param str fname: The path to a file where the cache summary should be dumped. Note that if the target file already exists, it will not be overwritten.
666
667 .. method:: PacketCache:expunge(n)
668
669 Remove entries from the cache, leaving at most ``n`` entries
670
671 :param int n: Number of entries to keep
672
673 .. method:: PacketCache:expungeByName(name [, qtype=DNSQType.ANY[, suffixMatch=false]])
674
675 .. versionchanged:: 1.2.0
676 ``suffixMatch`` parameter added.
677
678 Remove entries matching ``name`` and type from the cache.
679
680 :param DNSName name: The name to expunge
681 :param int qtype: The type to expunge, can be a pre-defined :ref:`DNSQType`
682 :param bool suffixMatch: When set to true, remove al entries under ``name``
683
684 .. method:: PacketCache:getStats()
685
686 .. versionadded:: 1.4.0
687
688 Return the cache stats (number of entries, hits, misses, deferred lookups, deferred inserts, lookup collisions, insert collisions and TTL too shorts) as a Lua table.
689
690 .. method:: PacketCache:isFull() -> bool
691
692 Return true if the cache has reached the maximum number of entries.
693
694 .. method:: PacketCache:printStats()
695
696 Print the cache stats (number of entries, hits, misses, deferred lookups, deferred inserts, lookup collisions, insert collisions and TTL too shorts).
697
698 .. method:: PacketCache:purgeExpired(n)
699
700 Remove expired entries from the cache until there is at most ``n`` entries remaining in the cache.
701
702 :param int n: Number of entries to keep
703
704 .. method:: PacketCache:toString() -> string
705
706 Return the number of entries in the Packet Cache, and the maximum number of entries
707
708 Client State
709 ------------
710
711 Also called frontend or bind, the Client State object returned by :func:`getBind` and listed with :func:`showBinds` represents an address and port dnsdist is listening on.
712
713 .. function:: getBind(index) -> ClientState
714
715 Return a :class:`ClientState` object.
716
717 :param int index: The object index
718
719 ClientState functions
720 ~~~~~~~~~~~~~~~~~~~~~
721
722 .. class:: ClientState
723
724 This object represents an address and port dnsdist is listening on. When ``reuseport`` is in use, several ClientState objects can be present for the same address and port.
725
726 .. method:: ClientState:attachFilter(filter)
727
728 Attach a BPF filter to this frontend.
729
730 :param BPFFilter filter: The filter to attach to this frontend
731
732 .. method:: ClientState:detachFilter()
733
734 Remove the BPF filter associated to this frontend, if any.
735
736 .. method:: ClientState:toString() -> string
737
738 Return the address and port this frontend is listening on.
739
740 :returns: The address and port this frontend is listening on
741
742 .. attribute:: ClientState.muted
743
744 If set to true, queries received on this frontend will be normally processed and sent to a backend if needed, but no response will be ever be sent to the client over UDP. TCP queries are processed normally and responses sent to the client.
745
746 Status, Statistics and More
747 ---------------------------
748
749 .. function:: dumpStats()
750
751 Print all statistics dnsdist gathers
752
753 .. function:: getDOHFrontend(idx)
754
755 .. versionadded:: 1.4.0
756
757 Return the DOHFrontend object for the DNS over HTTPS bind of index ``idx``.
758
759 .. function:: getTLSContext(idx)
760
761 .. versionadded:: 1.3.0
762
763 Return the TLSContext object for the context of index ``idx``.
764
765 .. function:: getTLSFrontend(idx)
766
767 .. versionadded:: 1.3.1
768
769 Return the TLSFrontend object for the TLS bind of index ``idx``.
770
771 .. function:: grepq(selector[, num])
772 grepq(selectors[, num])
773
774 Prints the last ``num`` queries matching ``selector`` or ``selectors``.
775
776 The selector can be:
777
778 * a netmask (e.g. '192.0.2.0/24')
779 * a DNS name (e.g. 'dnsdist.org')
780 * a response time (e.g. '100ms')
781
782 :param str selector: Select queries based on this property.
783 :param {str} selectors: A lua table of selectors. Only queries matching all selectors are shown
784 :param int num: Show a maximum of ``num`` recent queries, default is 10.
785
786 .. function:: setVerboseHealthChecks(verbose)
787
788 Set whether health check errors should be logged. This is turned off by default.
789
790 :param bool verbose: Set to true if you want to enable health check errors logging
791
792 .. function:: showBinds()
793
794 Print a list of all the current addresses and ports dnsdist is listening on, also called ``frontends``
795
796 .. function:: showDOHFrontends()
797
798 .. versionadded:: 1.4.0
799
800 Print the list of all availables DNS over HTTPS frontends.
801
802 .. function:: showDOHResponseCodes()
803
804 .. versionadded:: 1.4.0
805
806 Print the HTTP response codes statistics for all availables DNS over HTTPS frontends.
807
808 .. function:: showResponseLatency()
809
810 Show a plot of the response time latency distribution
811
812 .. function:: showServers([options])
813
814 .. versionchanged:: 1.4.0
815 ``options`` optional parameter added
816
817 This function shows all backend servers currently configured and some statistics.
818 These statics have the following fields:
819
820 * ``#`` - The number of the server, can be used as the argument for :func:`getServer`
821 * ``UUID`` - The UUID of the backend. Can be set with the ``id`` option of :func:`newServer`
822 * ``Address`` - The IP address and port of the server
823 * ``State`` - The current state of the server
824 * ``Qps`` - Current number of queries per second
825 * ``Qlim`` - Configured maximum number of queries per second
826 * ``Ord`` - The order number of the server
827 * ``Wt`` - The weight of the server
828 * ``Queries`` - Total amount of queries sent to this server
829 * ``Drops`` - Number of queries that were dropped by this server
830 * ``Drate`` - Number of queries dropped per second by this server
831 * ``Lat`` - The latency of this server in milliseconds
832 * ``Pools`` - The pools this server belongs to
833
834 :param table options: A table with key: value pairs with display options.
835
836 Options:
837
838 * ``showUUIDs=false``: bool - Whether to display the UUIDs, defaults to false.
839
840 .. function:: showTCPStats()
841
842 Show some statistics regarding TCP
843
844 .. function:: showTLSContexts()
845
846 .. versionadded:: 1.3.0
847
848 Print the list of all availables DNS over TLS contexts.
849
850 .. function:: showTLSErrorCounters()
851
852 .. versionadded:: 1.4.0
853
854 Display metrics about TLS handshake failures.
855
856 .. function:: showVersion()
857
858 Print the version of dnsdist
859
860 .. function:: topBandwidth([num])
861
862 Print the top ``num`` clients that consume the most bandwidth.
863
864 :param int num: Number to show, defaults to 10.
865
866 .. function:: topClients([num])
867
868 Print the top ``num`` clients sending the most queries over length of ringbuffer
869
870 :param int num: Number to show, defaults to 10.
871
872 .. function:: topQueries([num[, labels]])
873
874 Print the ``num`` most popular QNAMEs from queries.
875 Optionally grouped by the rightmost ``labels`` DNS labels.
876
877 :param int num: Number to show, defaults to 10
878 :param int label: Number of labels to cut down to
879
880 .. function:: topResponses([num[, rcode[, labels]]])
881
882 Print the ``num`` most seen responses with an RCODE of ``rcode``.
883 Optionally grouped by the rightmost ``labels`` DNS labels.
884
885 :param int num: Number to show, defaults to 10
886 :param int rcode: :ref:`Response code <DNSRCode>`, defaults to 0 (No Error)
887 :param int label: Number of labels to cut down to
888
889 .. function:: topSlow([num[, limit[, labels]]])
890
891 Print the ``num`` slowest queries that are slower than ``limit`` milliseconds.
892 Optionally grouped by the rightmost ``labels`` DNS labels.
893
894 :param int num: Number to show, defaults to 10
895 :param int limit: Show queries slower than this amount of milliseconds, defaults to 2000
896 :param int label: Number of labels to cut down to
897
898 .. _dynblocksref:
899
900 Dynamic Blocks
901 --------------
902
903 .. function:: addDynBlocks(addresses, message[, seconds=10[, action]])
904
905 .. versionchanged:: 1.2.0
906 ``action`` parameter added.
907
908 Block a set of addresses with ``message`` for (optionally) a number of seconds.
909 The default number of seconds to block for is 10.
910
911 :param addresses: set of Addresses as returned by an exceed function
912 :param string message: The message to show next to the blocks
913 :param int seconds: The number of seconds this block to expire
914 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to DNSAction.None, meaning the one set with :func:`setDynBlocksAction` is used)
915
916 Please see the documentation for :func:`setDynBlocksAction` to confirm which actions are supported by the action paramater.
917
918 .. function:: clearDynBlocks()
919
920 Remove all current dynamic blocks.
921
922 .. function:: showDynBlocks()
923
924 List all dynamic blocks in effect.
925
926 .. function:: setDynBlocksAction(action)
927
928 .. versionchanged:: 1.3.3
929 ``DNSAction.NXDomain`` action added.
930
931 Set which action is performed when a query is blocked.
932 Only DNSAction.Drop (the default), DNSAction.NoOp, DNSAction.NXDomain, DNSAction.Refused, DNSAction.Truncate and DNSAction.NoRecurse are supported.
933
934 .. _exceedfuncs:
935
936 Getting addresses that exceeded parameters
937 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
938
939 .. function:: exceedServFails(rate, seconds)
940
941 Get set of addresses that exceed ``rate`` servfails/s over ``seconds`` seconds
942
943 :param int rate: Number of Servfails per second to exceed
944 :param int seconds: Number of seconds the rate has been exceeded
945
946 .. function:: exceedNXDOMAINs(rate, seconds)
947
948 get set of addresses that exceed ``rate`` NXDOMAIN/s over ``seconds`` seconds
949
950 :param int rate: Number of NXDOMAIN per second to exceed
951 :param int seconds: Number of seconds the rate has been exceeded
952
953 .. function:: exceedRespByterate(rate, seconds)
954
955 get set of addresses that exceeded ``rate`` bytes/s answers over ``seconds`` seconds
956
957 :param int rate: Number of bytes per second to exceed
958 :param int seconds: Number of seconds the rate has been exceeded
959
960 .. function:: exceedQRate(rate, seconds)
961
962 Get set of address that exceed ``rate`` queries/s over ``seconds`` seconds
963
964 :param int rate: Number of queries per second to exceed
965 :param int seconds: Number of seconds the rate has been exceeded
966
967 .. function:: exceedQTypeRate(type, rate, seconds)
968
969 Get set of address that exceed ``rate`` queries/s for queries of QType ``type`` over ``seconds`` seconds
970
971 :param int type: QType
972 :param int rate: Number of QType queries per second to exceed
973 :param int seconds: Number of seconds the rate has been exceeded
974
975 DynBlockRulesGroup
976 ~~~~~~~~~~~~~~~~~~
977
978 Instead of using several `exceed*()` lines, dnsdist 1.3.0 introduced a new `DynBlockRulesGroup` object
979 which can be used to group dynamic block rules.
980
981 See :doc:`../guides/dynblocks` for more information about the case where using a `DynBlockRulesGroup` might be
982 faster than the existing rules.
983
984 .. function:: dynBlockRulesGroup() -> DynBlockRulesGroup
985
986 .. versionadded:: 1.3.0
987
988 Creates a new :class:`DynBlockRulesGroup` object.
989
990 .. class:: DynBlockRulesGroup
991
992 Represents a group of dynamic block rules.
993
994 .. method:: DynBlockRulesGroup:setQueryRate(rate, seconds, reason, blockingTime [, action [, warningRate]])
995
996 .. versionchanged:: 1.3.3
997 ``warningRate`` parameter added.
998
999 Adds a query rate-limiting rule, equivalent to:
1000 ```
1001 addDynBlocks(exceedQRate(rate, seconds), reason, blockingTime, action)
1002 ```
1003
1004 :param int rate: Number of queries per second to exceed
1005 :param int seconds: Number of seconds the rate has been exceeded
1006 :param string reason: The message to show next to the blocks
1007 :param int blockingTime: The number of seconds this block to expire
1008 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
1009 :param int warningRate: If set to a non-zero value, the rate above which a warning message will be issued and a no-op block inserted
1010
1011 .. method:: DynBlockRulesGroup:setRCodeRate(rcode, rate, seconds, reason, blockingTime [, action [, warningRate]])
1012
1013 .. versionchanged:: 1.3.3
1014 ``warningRate`` parameter added.
1015
1016 Adds a rate-limiting rule for responses of code ``rcode``, equivalent to:
1017 ```
1018 addDynBlocks(exceedServfails(rcode, rate, seconds), reason, blockingTime, action)
1019 ```
1020
1021 :param int rcode: The response code
1022 :param int rate: Number of responses per second to exceed
1023 :param int seconds: Number of seconds the rate has been exceeded
1024 :param string reason: The message to show next to the blocks
1025 :param int blockingTime: The number of seconds this block to expire
1026 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
1027 :param int warningRate: If set to a non-zero value, the rate above which a warning message will be issued and a no-op block inserted
1028
1029 .. method:: DynBlockRulesGroup:setRCodeRatio(rcode, ratio, seconds, reason, blockingTime, minimumNumberOfResponses [, action [, warningRate]])
1030
1031 .. versionadded:: 1.5.0
1032
1033 Adds a rate-limiting rule for the ratio of responses of code ``rcode`` over the total number of responses for a given client.
1034
1035 :param int rcode: The response code
1036 :param int ratio: Ratio of responses per second of the given rcode over the total number of responses for this client to exceed
1037 :param int seconds: Number of seconds the ratio has been exceeded
1038 :param string reason: The message to show next to the blocks
1039 :param int blockingTime: The number of seconds this block to expire
1040 :param int minimumNumberOfResponses: How many total responses is required for this rule to apply
1041 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
1042 :param int warningRatio: If set to a non-zero value, the ratio above which a warning message will be issued and a no-op block inserted
1043
1044 .. method:: DynBlockRulesGroup:setQTypeRate(qtype, rate, seconds, reason, blockingTime [, action [, warningRate]])
1045
1046 .. versionchanged:: 1.3.3
1047 ``warningRate`` parameter added.
1048
1049 Adds a rate-limiting rule for queries of type ``qtype``, equivalent to:
1050 ```
1051 addDynBlocks(exceedQTypeRate(type, rate, seconds), reason, blockingTime, action)
1052 ```
1053
1054 :param int qtype: The qtype
1055 :param int rate: Number of queries per second to exceed
1056 :param int seconds: Number of seconds the rate has been exceeded
1057 :param string reason: The message to show next to the blocks
1058 :param int blockingTime: The number of seconds this block to expire
1059 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
1060 :param int warningRate: If set to a non-zero value, the rate above which a warning message will be issued and a no-op block inserted
1061
1062 .. method:: DynBlockRulesGroup:setResponseByteRate(rate, seconds, reason, blockingTime [, action [, warningRate]])
1063
1064 .. versionchanged:: 1.3.3
1065 ``warningRate`` parameter added.
1066
1067 Adds a bandwidth rate-limiting rule for responses, equivalent to:
1068 ```
1069 addDynBlocks(exceedRespByterate(rate, seconds), reason, blockingTime, action)
1070 ```
1071
1072 :param int rate: Number of bytes per second to exceed
1073 :param int seconds: Number of seconds the rate has been exceeded
1074 :param string reason: The message to show next to the blocks
1075 :param int blockingTime: The number of seconds this block to expire
1076 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
1077 :param int warningRate: If set to a non-zero value, the rate above which a warning message will be issued and a no-op block inserted
1078
1079 .. method:: DynBlockRulesGroup:apply()
1080
1081 Walk the in-memory query and response ring buffers and apply the configured rate-limiting rules, adding dynamic blocks when the limits have been exceeded.
1082
1083 .. method:: DynBlockRulesGroup:setQuiet(quiet)
1084
1085 .. versionadded:: 1.4.0
1086
1087 Set whether newly blocked clients or domains should be logged.
1088
1089 :param bool quiet: True means that insertions will not be logged, false that they will. Default is false.
1090
1091 .. method:: DynBlockRulesGroup:excludeRange(netmasks)
1092
1093 .. versionadded:: 1.3.1
1094
1095 Exclude this range, or list of ranges, meaning that no dynamic block will ever be inserted for clients in that range. Default to empty, meaning rules are applied to all ranges. When used in combination with :meth:`DynBlockRulesGroup:includeRange`, the more specific entry wins.
1096
1097 :param int netmasks: A netmask, or list of netmasks, as strings, like for example "192.0.2.1/24"
1098
1099 .. method:: DynBlockRulesGroup:includeRange(netmasks)
1100
1101 .. versionadded:: 1.3.1
1102
1103 Include this range, or list of ranges, meaning that rules will be applied to this range. When used in combination with :meth:`DynBlockRulesGroup:excludeRange`, the more specific entry wins.
1104
1105 :param int netmasks: A netmask, or list of netmasks, as strings, like for example "192.0.2.1/24"
1106
1107 .. method:: DynBlockRulesGroup:toString()
1108
1109 .. versionadded:: 1.3.1
1110
1111 Return a string describing the rules and range exclusions of this DynBlockRulesGroup.
1112
1113 SuffixMatchNode
1114 ~~~~~~~~~~~~~~~
1115
1116 A SuffixMatchNode can be used to quickly check whether a given name belongs to a set or not. This is achieved
1117 using an efficient tree structure based on DNS labels, making lookups cheap.
1118 Be careful that Suffix Node matching will match for any sub-domain, regardless of the depth, under the name added to the set. For example,
1119 if 'example.com.' is added to the set, 'www.example.com.' and 'sub.www.example.com.' will match as well.
1120 If you are looking for exact name matching, your might want to consider using a :class:`DNSNameSet` instead.
1121
1122 .. function:: newSuffixMatchNode()
1123
1124 Creates a new :class:`SuffixMatchNode`.
1125
1126 .. class:: SuffixMatchNode
1127
1128 Represent a set of DNS suffixes for quick matching.
1129
1130 .. method:: SuffixMatchNode:add(name)
1131
1132 .. versionchanged:: 1.4.0
1133 This method now accepts strings, lists of DNSNames and lists of strings.
1134
1135 Add a suffix to the current set.
1136
1137 :param DNSName name: The suffix to add to the set.
1138 :param string name: The suffix to add to the set.
1139 :param table name: The suffixes to add to the set. Elements of the table should be of the same type, either DNSName or string.
1140
1141 .. method:: SuffixMatchNode:check(name) -> bool
1142
1143 Return true if the given name is a sub-domain of one of those in the set, and false otherwise.
1144
1145 :param DNSName name: The name to test against the set.
1146
1147 Other functions
1148 ---------------
1149
1150 .. function:: maintenance()
1151
1152 If this function exists, it is called every second to so regular tasks.
1153 This can be used for e.g. :doc:`Dynamic Blocks <../guides/dynblocks>`.
1154
1155 .. function:: setAllowEmptyResponse()
1156
1157 .. versionadded:: 1.4.0
1158
1159 Set to true (defaults to false) to allow empty responses (qdcount=0) with a NoError or NXDomain rcode (default) from backends. dnsdist drops these responses by default because it can't match them against the initial query since they don't contain the qname, qtype and qclass, and therefore the risk of collision is much higher than with regular responses.
1160
1161 .. function:: makeIPCipherKey(password) -> string
1162
1163 .. versionadded:: 1.4.0
1164
1165 Hashes the password to generate a 16-byte key that can be used to pseudonymize IP addresses with IP cipher.
1166
1167 .. function:: generateOCSPResponse(pathToServerCertificate, pathToCACertificate, pathToCAPrivateKey, outputFile, numberOfDaysOfValidity, numberOfMinutesOfValidity)
1168
1169 .. versionadded:: 1.4.0
1170
1171 When a local PKI is used to issue the certificate, or for testing purposes, :func:`generateOCSPResponse` can be used to generate an OCSP response file for a certificate, using the certificate and private key of the certification authority that signed that certificate.
1172 The resulting file can be directly used with the :func:`addDOHLocal` or the :func:`addTLSLocal` functions.
1173
1174 :param string pathToServerCertificate: Path to a file containing the certificate used by the server.
1175 :param string pathToCACertificate: Path to a file containing the certificate of the certification authority that was used to sign the server certificate.
1176 :param string pathToCAPrivateKey: Path to a file containing the private key corresponding to the certification authority certificate.
1177 :param string outputFile: Path to a file where the resulting OCSP response will be written to.
1178 :param int numberOfDaysOfValidity: Number of days this OCSP response should be valid.
1179 :param int numberOfMinutesOfValidity: Number of minutes this OCSP response should be valid, in addition to the number of days.
1180
1181 DOHFrontend
1182 ~~~~~~~~~~~
1183
1184 .. class:: DOHFrontend
1185
1186 .. versionadded:: 1.4.0
1187
1188 This object represents an address and port dnsdist is listening on for DNS over HTTPS queries.
1189
1190 .. method:: DOHFrontend:loadTicketsKeys(ticketsKeysFile)
1191
1192 Load new tickets keys from the selected file, replacing the existing ones. These keys should be rotated often and never written to persistent storage to preserve forward secrecy. The default is to generate a random key. dnsdist supports several tickets keys to be able to decrypt existing sessions after the rotation.
1193
1194 :param str ticketsKeysFile: The path to a file from where TLS tickets keys should be loaded.
1195
1196 .. method:: DOHFrontend:reloadCertificates()
1197
1198 Reload the current TLS certificate and key pairs.
1199
1200 .. method:: DOHFrontend:rotateTicketsKey()
1201
1202 Replace the current TLS tickets key by a new random one.
1203
1204 .. method:: DOHFrontend:setResponsesMap(rules)
1205
1206 Set a list of HTTP response rules allowing to intercept HTTP queries very early, before the DNS payload has been processed, and send custom responses including error pages, redirects and static content.
1207
1208 :param list of DOHResponseMapEntry objects rules: A list of DOHResponseMapEntry objects, obtained with :func:`newDOHResponseMapEntry`.
1209
1210
1211 .. function:: newDOHResponseMapEntry(regex, status, content [, headers]) -> DOHResponseMapEntry
1212
1213 .. versionadded:: 1.4.0
1214
1215 Return a DOHResponseMapEntry that can be used with :meth:`DOHFrontend.setResponsesMap`. Every query whose path matches the regular expression supplied in ``regex`` will be immediately answered with a HTTP response.
1216 The status of the HTTP response will be the one supplied by ``status``, and the content set to the one supplied by ``content``, except if the status is a redirection (3xx) in which case the content is expected to be the URL to redirect to.
1217
1218 :param str regex: A regular expression to match the path against.
1219 :param int status: The HTTP code to answer with.
1220 :param str content: The content of the HTTP response, or a URL if the status is a redirection (3xx).
1221 :param table of headers: The custom headers to set for the HTTP response, if any. The default is to use the value of the ``customResponseHeaders`` parameter passed to :func:`addDOHLocal`.
1222
1223 TLSContext
1224 ~~~~~~~~~~
1225
1226 .. class:: TLSContext
1227
1228 .. versionadded:: 1.3.0
1229
1230 This object represents an address and port dnsdist is listening on for DNS over TLS queries.
1231
1232 .. method:: TLSContext:rotateTicketsKey()
1233
1234 Replace the current TLS tickets key by a new random one.
1235
1236 .. method:: TLSContext:loadTicketsKeys(ticketsKeysFile)
1237
1238 Load new tickets keys from the selected file, replacing the existing ones. These keys should be rotated often and never written to persistent storage to preserve forward secrecy. The default is to generate a random key. The OpenSSL provider supports several tickets keys to be able to decrypt existing sessions after the rotation, while the GnuTLS provider only supports one key.
1239
1240 :param str ticketsKeysFile: The path to a file from where TLS tickets keys should be loaded.
1241
1242 TLSFrontend
1243 ~~~~~~~~~~~
1244
1245 .. class:: TLSFrontend
1246
1247 .. versionadded:: 1.3.1
1248
1249 This object represents the configuration of a listening frontend for DNS over TLS queries. To each frontend is associated a TLSContext.
1250
1251 .. method:: TLSContext:loadNewCertificatesAndKeys(certFile(s), keyFile(s))
1252
1253 Create and switch to a new TLS context using the same options than were passed to the corresponding `addTLSLocal()` directive, but loading new certificates and keys from the selected files, replacing the existing ones.
1254
1255 :param str certFile(s): The path to a X.509 certificate file in PEM format, or a list of paths to such files.
1256 :param str keyFile(s): The path to the private key file corresponding to the certificate, or a list of paths to such files, whose order should match the certFile(s) ones.
1257
1258 EDNS on Self-generated answers
1259 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1260
1261 There are several mechanisms in dnsdist that turn an existing query into an answer right away,
1262 without reaching out to the backend, including :func:`SpoofAction`, :func:`RCodeAction`, :func:`TCAction`
1263 and returning a response from ``Lua``. Those responses should, according to :rfc:`6891`, contain an ``OPT``
1264 record if the received request had one, which is the case by default and can be disabled using
1265 :func:`setAddEDNSToSelfGeneratedResponses`.
1266
1267 We must, however, provide a responder's maximum payload size in this record, and we can't easily know the
1268 maximum payload size of the actual backend so we need to provide one. The default value is 1500 and can be
1269 overriden using :func:`setPayloadSizeOnSelfGeneratedAnswers`.
1270
1271 .. function:: setAddEDNSToSelfGeneratedResponses(add)
1272
1273 .. versionadded:: 1.3.3
1274
1275 Whether to add EDNS to self-generated responses, provided that the initial query had EDNS.
1276
1277 :param bool add: Whether to add EDNS, default is true.
1278
1279 .. function:: setPayloadSizeOnSelfGeneratedAnswers(payloadSize)
1280
1281 .. versionadded:: 1.3.3
1282
1283 Set the UDP payload size advertised via EDNS on self-generated responses. In accordance with
1284 :rfc:`RFC 6891 <6891#section-6.2.5>`, values lower than 512 will be treated as equal to 512.
1285
1286 :param int payloadSize: The responder's maximum UDP payload size, in bytes. Default is 1500.
1287
1288 Security Polling
1289 ~~~~~~~~~~~~~~~~
1290
1291 PowerDNS products can poll the security status of their respective versions. This polling, naturally,
1292 happens over DNS. If the result is that a given version has a security problem, the software will
1293 report this at level ‘Error’ during startup, and repeatedly during operations, every
1294 :func:`setSecurityPollInterval` seconds.
1295
1296 By default, security polling happens on the domain ‘secpoll.powerdns.com’, but this can be changed with
1297 the :func:`setSecurityPollSuffix` function. If this setting is made empty, no polling will take place.
1298 Organizations wanting to host their own security zones can do so by changing this setting to a domain name
1299 under their control.
1300
1301 To enable distributors of PowerDNS to signal that they have backported versions, the PACKAGEVERSION
1302 compilation-time macro can be used to set a distributor suffix.
1303
1304 .. function:: setSecurityPollInterval(interval)
1305
1306 .. versionadded:: 1.3.3
1307
1308 Set the interval, in seconds, between two security pollings.
1309
1310 :param int interval: The interval, in seconds, between two pollings. Default is 3600.
1311
1312 .. function:: setSecurityPollSuffix(suffix)
1313
1314 .. versionadded:: 1.3.3
1315
1316 Domain name from which to query security update notifications. Setting this to an empty string disables secpoll.
1317
1318 :param string suffix: The suffix to use, default is 'secpoll.powerdns.com.'.