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