]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/dnsdistdist/docs/reference/config.rst
dnsdist: Fix a typo in the documentation of addTLSLocal()'s options
[thirdparty/pdns.git] / pdns / dnsdistdist / docs / reference / config.rst
CommitLineData
20d81666
PL
1.. highlight:: lua
2
3Configuration Reference
4=======================
5
6This 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
13Functions and Types
14-------------------
15
16Within 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
98650fde 24* :class:`DNSHeader`: represents the header of a DNS packet, see :ref:`DNSHeader`
bd51e34c 25* :class:`ClientState`: sometimes also called Bind or Frontend, represents the addresses and ports dnsdist is listening on
20d81666
PL
26
27The 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
34The ``.`` means ``order`` is a data member, while the ``:`` means ``addPool`` is a member function.
35
36Global configuration
37--------------------
38
39.. function:: includeDirectory(path)
40
41 Include configuration files from ``path``.
42
43 :param str path: The directory to load the configuration from
44
45Listen Sockets
46~~~~~~~~~~~~~~
47
48.. function:: addLocal(address[, options])
49
50 .. versionadded:: 1.2.0
51
87cb3110
PL
52 .. versionchanged:: 1.3.0
53 Added ``cpus`` to the options.
54
20d81666
PL
55 Add to the list of listen addresses.
56
57 :param str address: The IP Address with an optional port to listen on.
58 The default port is 53.
59 :param table options: A table with key: value pairs with listen options.
60
61 Options:
62
63 * ``doTCP=true``: bool - Also bind on TCP on ``address``.
64 * ``reusePort=false``: bool - Set the ``SO_REUSEPORT`` socket option.
4bc167b8
RG
65 * ``tcpFastOpenSize=0``: int - Set the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
66 * ``interface=""``: str - Set the network interface to use.
67 * ``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.
20d81666
PL
68
69 .. code-block:: lua
70
71 addLocal('0.0.0.0:5300', { doTCP=true, reusePort=true })
72
73 This will bind to both UDP and TCP on port 5300 with SO_REUSEPORT enabled.
74
75.. function:: addLocal(address[[[,do_tcp], so_reuseport], tcp_fast_open_qsize])
76
77 .. deprecated:: 1.2.0
78
79 Add to the list of addresses listened on.
80
81 :param str address: The IP Address with an optional port to listen on.
82 The default port is 53.
83 :param bool do_tcp: Also bind a TCP port on ``address``, defaults to true.
84 :param bool so_reuseport: Use ``SO_REUSEPORT`` if it is available, defaults to false
5d31a326
RG
85 :param int tcp_fast_open_qsize: The size of the TCP Fast Open queue. Set to a number
86 higher than 0 to enable TCP Fast Open when available.
87 Default is 0.
20d81666 88
fa974ada 89.. function:: addTLSLocal(address, certFile(s), keyFile(s) [, options])
a227f47d
RG
90
91 .. versionadded:: 1.3.0
fa974ada
RG
92 .. versionchanged:: 1.3.1
93 ``certFile(s)`` and ``keyFile(s)`` parameters accept a list of files.
c8d7b468 94 ``disableTickets`` option added.
a227f47d
RG
95
96 Listen on the specified address and TCP port for incoming DNS over TLS connections, presenting the specified X.509 certificate.
97
98 :param str address: The IP Address with an optional port to listen on.
99 The default port is 853.
fa974ada
RG
100 :param str certFile(s): The path to a X.509 certificate file in PEM format, or a list of paths to such files.
101 :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.
a227f47d
RG
102 :param table options: A table with key: value pairs with listen options.
103
104 Options:
105
106 * ``doTCP=true``: bool - Also bind on TCP on ``address``.
107 * ``reusePort=false``: bool - Set the ``SO_REUSEPORT`` socket option.
108 * ``tcpFastOpenSize=0``: int - Set the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
109 * ``interface=""``: str - Set the network interface to use.
110 * ``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.
111 * ``provider``: str - The TLS library to use between GnuTLS and OpenSSL, if they were available and enabled at compilation time.
112 * ``ciphers``: str - The TLS ciphers to use. The exact format depends on the provider used.
113 * ``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.
114 * ``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.
115 * ``ticketsKeysRotationDelay``: int - Set the delay before the TLS tickets key is rotated, in seconds. Default is 43200 (12h).
25f97099 116 * ``disableTickets``: bool - Disable the use of session resumption via session tickets. Default is false, meaning tickets are enabled.
a227f47d 117
20d81666
PL
118.. function:: setLocal(address[, options])
119
120 .. versionadded:: 1.2.0
121
122 Remove the list of listen addresses and add a new one.
123
124 :param str address: The IP Address with an optional port to listen on.
125 The default port is 53.
126 :param table options: A table with key: value pairs with listen options.
127
128 The options that can be set are the same as :func:`addLocal`.
129
130.. function:: setLocal(address[[[,do_tcp], so_reuseport], tcp_fast_open_qsize])
131
132 .. deprecated:: 1.2.0
133
134 Remove the list of listen addresses and add a new one.
135
136 :param str address: The IP Address with an optional port to listen on.
137 The default port is 53.
138 :param bool do_tcp: Also bind a TCP port on ``address``, defaults to true.
139 :param bool so_reuseport: Use ``SO_REUSEPORT`` if it is available, defaults to false
5d31a326
RG
140 :param int tcp_fast_open_qsize: The size of the TCP Fast Open queue. Set to a number
141 higher than 0 to enable TCP Fast Open when available.
142 Default is 0.
20d81666
PL
143
144Control Socket, Console and Webserver
145~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146
b5521206
RG
147.. function:: addConsoleACL(netmask)
148
149 .. versionadded:: 1.3.0
150
151 Add a netmask to the existing console ACL, allowing remote clients to connect to the console. Please make sure that encryption
c29d4db8 152 has been enabled with :func:`setKey` before doing so. The default is to only allow 127.0.0.1/8 and ::1/128.
b5521206
RG
153
154 :param str netmask: A CIDR netmask, e.g. ``"192.0.2.0/24"``. Without a subnetmask, only the specific address is allowed.
155
20d81666
PL
156.. function:: controlSocket(address)
157
b5521206
RG
158 Bind to ``addr`` and listen for a connection for the console. Since 1.3.0 only connections from local users are allowed
159 by default, :func:`addConsoleACL` and :func:`setConsoleACL` can be used to enable remote connections. Please make sure
350c690a
RG
160 that encryption has been enabled with :func:`setKey` before doing so. Enabling encryption is also strongly advised for
161 local connections, since not enabling it allows any local user to connect to the console.
20d81666
PL
162
163 :param str address: An IP address with optional port. By default, the port is 5199.
164
6f2a4580
PD
165.. function:: inClientStartup()
166
167 Returns true while the console client is parsing the configuration.
168
20d81666
PL
169.. function:: makeKey()
170
171 Generate and print an encryption key.
172
506bb661
RG
173.. function:: setConsoleConnectionsLogging(enabled)
174
175 .. versionadded:: 1.2.0
176
177 Whether to log the opening and closing of console connections.
178
179 :param bool enabled: Default to true.
180
20d81666
PL
181.. function:: setKey(key)
182
183 Use ``key`` as shared secret between the client and the server
184
185 :param str key: An encoded key, as generated by :func:`makeKey`
186
b5521206
RG
187.. function:: setConsoleACL(netmasks)
188
189 .. versionadded:: 1.3.0
190
191 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
192 has been enabled with :func:`setKey` before doing so.
193
194 :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.
195
196.. function:: showConsoleACL()
197
198 Print a list of all netmasks allowed to connect to the console.
199
20d81666
PL
200.. function:: testCrypto()
201
202 Test the crypto code, will report errors when something is not ok.
203
204Webserver
205~~~~~~~~~
206
207.. function:: webServer(listen_address, password[, apikey[, custom_headers]])
208
209 Launch the :doc:`../guides/webserver` with statistics and the API.
210
211 :param str listen_address: The IP address and Port to listen on
212 :param str password: The password required to access the webserver
213 :param str apikey: The key required to access the API
214 :param {[str]=str,...} custom_headers: Allows setting custom headers and removing the defaults
215
216.. function:: setAPIWritable(allow [,dir])
217
218 Allow modifications via the API.
219 Optionally saving these changes to disk.
220 Modifications done via the API will not be written to the configuration by default and will not persist after a reload
221
222 :param bool allow: Set to true to allow modification through the API
223 :param str dir: A valid directory where the configuration files will be written by the API.
224
225Access Control Lists
226~~~~~~~~~~~~~~~~~~~~
227
228.. function:: addACL(netmask)
229
c29d4db8 230 Add a netmask to the existing ACL controlling which clients can send UDP and TCP queries. See :ref:`ACL` for more information.
20d81666
PL
231
232 :param str netmask: A CIDR netmask, e.g. ``"192.0.2.0/24"``. Without a subnetmask, only the specific address is allowed.
233
234.. function:: setACL(netmasks)
235
c29d4db8 236 Remove the existing ACL and add the netmasks from the table of those allowed to send UDP and TCP queries. See :ref:`ACL` for more information.
20d81666
PL
237
238 :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.
239
b5521206
RG
240.. function:: showACL()
241
c29d4db8 242 Print a list of all netmasks allowed to send queries over UDP and TCP. See :ref:`ACL` for more information.
b5521206 243
20d81666
PL
244EDNS Client Subnet
245~~~~~~~~~~~~~~~~~~
246
247.. function:: setECSSourcePrefixV4(prefix)
248
249 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
250
251 :param int prefix: The prefix length
252
253.. function:: setECSSourcePrefixV6(prefix)
254
255 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
256
257 :param int prefix: The prefix length
258
259Ringbuffers
260~~~~~~~~~~~
261
a609acdb
RG
262.. function:: setRingBuffersLockRetries(num)
263 .. versionadded:: 1.3.0
264
265 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
266
267 :param int num: The maximum number of attempts. Defaults to 5 if there are more than one shard, 0 otherwise.
268
269.. function:: setRingBuffersSize(num [, numberOfShards])
270 .. versionchanged:: 1.3.0
271 ``numberOfShards`` optional parameter added.
20d81666 272
a609acdb 273 Set the capacity of the ringbuffers used for live traffic inspection to ``num``, and the number of shards to ``numberOfShards`` if specified.
20d81666
PL
274
275 :param int num: The maximum amount of queries to keep in the ringbuffer. Defaults to 10000
a609acdb 276 :param int numberOfShards: the number of shards to use to limit lock contention. Defaults to 1
20d81666
PL
277
278Servers
279-------
280
281.. function:: newServer(server_string)
282 newServer(server_table)
283
98650fde 284 .. versionchanged:: 1.3.0
87cb3110
PL
285 - Added ``checkClass`` to server_table.
286 - Added ``sockets`` to server_table
287 - Added ``checkFunction`` to server_table
288
98650fde 289
20d81666
PL
290 Add a new backend server. Call this function with either a string::
291
292 newServer(
293 "IP:PORT" -- IP and PORT of the backend server
294 )
295
296 or a table::
297
298 newServer({
299 address="IP:PORT", -- IP and PORT of the backend server (mandatory)
c19aa18d
RG
300 qps=NUM, -- Limit the number of queries per second to NUM, when using the `firstAvailable` policy
301 order=NUM, -- The order of this server, used by the `leastOustanding` and `firstAvailable` policies
278403d3
DM
302 weight=NUM, -- The weight of this server, used by the `wrandom` and `whashed` policies, default: 1
303 -- Supported values are a minimum of 1, and a maximum of 2147483647.
5d31a326
RG
304 pool=STRING|{STRING}, -- The pools this server belongs to (unset or empty string means default pool) as a string or table of strings
305 retries=NUM, -- The number of TCP connection attempts to the backend, for a given query
306 tcpConnectTimeout=NUM, -- The timeout (in seconds) of a TCP connection attempt
307 tcpSendTimeout=NUM, -- The timeout (in seconds) of a TCP write attempt
308 tcpRecvTimeout=NUM, -- The timeout (in seconds) of a TCP read attempt
309 tcpFastOpen=BOOL, -- Whether to enable TCP Fast Open
c0e7123d 310 ipBindAddrNoPort=BOOL, -- Whether to enable IP_BIND_ADDRESS_NO_PORT if available, default: true
5d31a326 311 name=STRING, -- The name associated to this backend, for display purpose
de9f7157 312 checkClass=NUM, -- Use NUM as QCLASS in the health-check query, default: DNSClass.IN
20d81666
PL
313 checkName=STRING, -- Use STRING as QNAME in the health-check query, default: "a.root-servers.net."
314 checkType=STRING, -- Use STRING as QTYPE in the health-check query, default: "A"
98650fde 315 checkFunction=FUNCTION -- Use this function to dynamically set the QNAME, QTYPE and QCLASS to use in the health-check query (see :ref:`Healthcheck`)
20d81666 316 setCD=BOOL, -- Set the CD (Checking Disabled) flag in the health-check query, default: false
fc1e69ee 317 maxCheckFailures=NUM, -- Allow NUM check failures before declaring the backend down, default: 1
20d81666
PL
318 mustResolve=BOOL, -- Set to true when the health check MUST return a NOERROR RCODE and an answer
319 useClientSubnet=BOOL, -- Add the client's IP address in the EDNS Client Subnet option when forwarding the query to this backend
18f707fa 320 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
20d81666
PL
321 -- The following formats are supported:
322 -- "address", e.g. "192.0.2.2"
323 -- "interface name", e.g. "eth0"
324 -- "address@interface", e.g. "192.0.2.2@eth0"
150105a2 325 addXPF=NUM, -- Add the client's IP address and port to the query, along with the original destination address and port,
c85f69a8 326 -- 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)
150105a2 327 sockets=NUM -- Number of sockets (and thus source ports) used toward the backend server, defaults to a single one
20d81666
PL
328 })
329
330 :param str server_string: A simple IP:PORT string.
331 :param table server_table: A table with at least a 'name' key
332
333.. function:: getServer(index) -> Server
334
335 Get a :class:`Server`
336
337 :param int index: The number of the server (as seen in :func:`showServers`).
338 :returns: The :class:`Server` object or nil
339
340.. function:: getServers()
341
342 Returns a table with all defined servers.
343
344.. function:: rmServer(index)
345 rmServer(server)
346
347 Remove a backend server.
348
349 :param int index: The number of the server (as seen in :func:`showServers`).
350 :param Server server: A :class:`Server` object as returned by e.g. :func:`getServer`.
351
352Server Functions
353~~~~~~~~~~~~~~~~
354A server object returned by :func:`getServer` can be manipulated with these functions.
355
356.. class:: Server
357
358 This object represents a backend server. It has several methods.
359
d9018741 360 .. method:: Server:addPool(pool)
20d81666 361
d9018741 362 Add this server to a pool.
20d81666 363
d9018741 364 :param str pool: The pool to add the server to
20d81666 365
d9018741 366 .. method:: Server:getName() -> string
20d81666 367
d9018741 368 Get the name of this server.
20d81666 369
d9018741 370 :returns: The name of the server, or an empty string if it does not have one
20d81666 371
d9018741 372 .. method:: Server:getNameWithAddr() -> string
20d81666 373
d9018741 374 Get the name plus IP address and port of the server
20d81666 375
d9018741 376 :returns: A string containing the server name if any plus the server address and port
20d81666 377
d9018741 378 .. method:: Server:getOutstanding() -> int
20d81666 379
d9018741 380 Get the number of outstanding queries for this server.
20d81666 381
d9018741 382 :returns: The number of outstanding queries
20d81666 383
d9018741 384 .. method:: Server:isUp() -> bool
20d81666 385
d9018741 386 Returns the up status of the server
20d81666 387
d9018741 388 :returns: true when the server is up, false otherwise
20d81666 389
d9018741 390 .. method:: Server:rmPool(pool)
20d81666 391
d9018741 392 Removes the server from the named pool
20d81666 393
d9018741 394 :param str pool: The pool to remove the server from
20d81666 395
d9018741 396 .. method:: Server:setAuto([status])
d92708ed 397
d9018741
PL
398 .. versionchanged:: 1.3.0
399 ``status`` optional parameter added.
20d81666 400
d9018741
PL
401 Set the server in the default auto state.
402 This will enable health check queries that will set the server ``up`` and ``down`` appropriately.
d92708ed 403
d9018741 404 :param bool status: Set the initial status of the server to ``up`` (true) or ``down`` (false) instead of using the last known status
20d81666 405
d9018741 406 .. method:: Server:setQPS(limit)
20d81666 407
d9018741 408 Limit the queries per second for this server.
20d81666 409
d9018741 410 :param int limit: The maximum number of queries per second
20d81666 411
d9018741 412 .. method:: Server:setDown()
20d81666 413
d9018741
PL
414 Set the server in an ``DOWN`` state.
415 The server will not receive queries and the health checks are disabled
20d81666 416
d9018741 417 .. method:: Server:setUp()
20d81666 418
d9018741
PL
419 Set the server in an ``UP`` state.
420 This server will still receive queries and health checks are disabled
20d81666 421
d9018741 422 Apart from the functions, a :class:`Server` object has these attributes:
20d81666 423
d9018741 424 .. attribute:: Server.name
20d81666 425
d9018741 426 The name of the server
20d81666 427
d9018741 428 .. attribute:: Server.upStatus
20d81666 429
d9018741 430 Whether or not this server is up or down
20d81666 431
d9018741 432 .. attribute:: Server.order
20d81666 433
d9018741 434 The order of the server
20d81666 435
d9018741 436 .. attribute:: Server.weight
20d81666 437
d9018741 438 The weight of the server
20d81666
PL
439
440Pools
441-----
442
443:class:`Server`\ s can be part of any number of pools.
5d31a326
RG
444Pools are automatically created when a server is added to a pool (with :func:`newServer`), or can be manually created with :func:`addPool`.
445
446.. function:: addPool(name) -> ServerPool
447
448 Returns a :class:`ServerPool`.
449
450 :param string name: The name of the pool to create
20d81666
PL
451
452.. function:: getPool(name) -> ServerPool
453
454 Returns a :class:`ServerPool` or nil.
455
456 :param string name: The name of the pool
457
5d31a326
RG
458.. function:: rmPool(name)
459
460 Remove the pool named `name`.
461
462 :param string name: The name of the pool to remove
463
20d81666
PL
464.. function:: getPoolServers(name) -> [ Server ]
465
466 Returns a list of :class:`Server`\ s or nil.
467
468 :param string name: The name of the pool
469
470.. class:: ServerPool
471
472 This represents the pool where zero or more servers are part of.
473
d9018741 474 .. method:: ServerPool:getCache() -> PacketCache
20d81666 475
d9018741 476 Returns the :class:`PacketCache` for this pool or nil.
20d81666 477
7e687744
RG
478 .. method:: ServerPool:getECS()
479
480 .. versionadded:: 1.3.0
481
482 Whether dnsdist will add EDNS Client Subnet information to the query before looking up into the cache,
483 when all servers from this pool are down. For more information see :meth:`ServerPool:setECS`.
484
d9018741 485 .. method:: ServerPool:setCache(cache)
20d81666 486
d9018741 487 Adds ``cache`` as the pool's cache.
20d81666 488
d9018741 489 :param PacketCache cache: The new cache to add to the pool
20d81666 490
d9018741 491 .. method:: ServerPool:unsetCache()
20d81666 492
d9018741 493 Removes the cache from this pool.
20d81666 494
7e687744
RG
495 .. method:: ServerPool:setECS()
496
497 .. versionadded:: 1.3.0
498
499 Set to true if dnsdist should add EDNS Client Subnet information to the query before looking up into the cache,
500 when all servers from this pool are down. If at least one server is up, the preference of the
501 selected server is used, this parameter is only useful if all the backends in this pool are down
502 and have EDNS Client Subnet enabled, since the queries in the cache will have been inserted with
503 ECS information. Default is false.
504
20d81666
PL
505PacketCache
506~~~~~~~~~~~
507
508A Pool can have a packet cache to answer queries directly in stead of going to the backend.
509See :doc:`../guides/cache` for a how to.
510
47698274 511.. function:: newPacketCache(maxEntries[, maxTTL=86400[, minTTL=0[, temporaryFailureTTL=60[, staleTTL=60[, dontAge=false[, numberOfShards=1[, deferrableInsertLock=true[, maxNegativeTTL=3600]]]]]]]) -> PacketCache
4bc167b8 512
87cb3110
PL
513 .. versionchanged:: 1.3.0
514 ``numberOfShards`` and ``deferrableInsertLock`` parameters added.
20d81666 515
47698274
RG
516 .. versionchanged:: 1.3.1
517 ``maxNegativeTTL`` parameter added.
518
20d81666
PL
519 Creates a new :class:`PacketCache` with the settings specified.
520
521 :param int maxEntries: The maximum number of entries in this cache
522 :param int maxTTL: Cap the TTL for records to his number
523 :param int minTTL: Don't cache entries with a TTL lower than this
524 :param int temporaryFailureTTL: On a SERVFAIL or REFUSED from the backend, cache for this amount of seconds
525 :param int staleTTL: When the backend servers are not reachable, send responses if the cache entry is expired at most this amount of seconds
4bc167b8
RG
526 :param bool dontAge: Don't reduce TTLs when serving from the cache. Use this when :program:`dnsdist` fronts a cluster of authoritative servers
527 :param int numberOfShards: Number of shards to divide the cache into, to reduce lock contention
528 :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
47698274 529 :param bool 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
20d81666
PL
530
531.. class:: PacketCache
532
533 Represents a cache that can be part of :class:`ServerPool`.
534
d9018741 535 .. method:: PacketCache:expunge(n)
20d81666 536
d9018741 537 Remove entries from the cache, leaving at most ``n`` entries
20d81666 538
d9018741 539 :param int n: Number of entries to keep
20d81666 540
d9018741 541 .. method:: PacketCache:expungeByName(name [, qtype=dnsdist.ANY[, suffixMatch=false]])
20d81666 542
d9018741
PL
543 .. versionchanged:: 1.2.0
544 ``suffixMatch`` parameter added.
20d81666 545
d9018741 546 Remove entries matching ``name`` and type from the cache.
20d81666 547
d9018741
PL
548 :param DNSName name: The name to expunge
549 :param int qtype: The type to expunge
550 :param bool suffixMatch: When set to true, remove al entries under ``name``
20d81666 551
d9018741 552 .. method:: PacketCache:isFull() -> bool
20d81666 553
d9018741 554 Return true if the cache has reached the maximum number of entries.
20d81666 555
d9018741 556 .. method:: PacketCache:printStats()
20d81666 557
d9018741 558 Print the cache stats (hits, misses, deferred lookups and deferred inserts).
20d81666 559
d9018741 560 .. method:: PacketCache:purgeExpired(n)
20d81666 561
d9018741 562 Remove expired entries from the cache until there is at most ``n`` entries remaining in the cache.
20d81666 563
d9018741 564 :param int n: Number of entries to keep
20d81666 565
d9018741 566 .. method:: PacketCache:toString() -> string
20d81666 567
d9018741 568 Return the number of entries in the Packet Cache, and the maximum number of entries
20d81666 569
bd51e34c
RG
570Client State
571------------
572
573Also 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.
574
575.. function:: getBind(index) -> ClientState
576
d9018741 577 Return a :class:`ClientState` object.
bd51e34c
RG
578
579 :param int index: The object index
580
581ClientState functions
582~~~~~~~~~~~~~~~~~~~~~
583
584.. class:: ClientState
585
586 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.
587
d9018741 588 .. method:: ClientState:attachFilter(filter)
bd51e34c 589
d9018741 590 Attach a BPF filter to this frontend.
bd51e34c 591
d9018741 592 :param BPFFilter filter: The filter to attach to this frontend
bd51e34c 593
d9018741 594 .. method:: ClientState:detachFilter()
bd51e34c 595
d9018741 596 Remove the BPF filter associated to this frontend, if any.
bd51e34c 597
d9018741 598 .. method:: ClientState:toString() -> string
bd51e34c 599
d9018741 600 Return the address and port this frontend is listening on.
bd51e34c 601
d9018741 602 :returns: The address and port this frontend is listening on
bd51e34c 603
d9018741 604 .. attribute:: ClientState.muted
bd51e34c 605
d9018741 606 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.
bd51e34c 607
20d81666
PL
608Status, Statistics and More
609---------------------------
610
611.. function:: dumpStats()
612
613 Print all statistics dnsdist gathers
614
a227f47d 615.. function:: getTLSContext(idx)
d9018741 616
a227f47d
RG
617 .. versionadded:: 1.3.0
618
619 Return the TLSContext object for the context of index ``idx``.
620
8ef43a02
RG
621.. function:: getTLSFrontend(idx)
622
623 .. versionadded:: 1.3.1
624
625 Return the TLSFrontend object for the TLS bind of index ``idx``.
626
20d81666
PL
627.. function:: grepq(selector[, num])
628 grepq(selectors[, num])
629
630 Prints the last ``num`` queries matching ``selector`` or ``selectors``.
631
632 The selector can be:
633
634 * a netmask (e.g. '192.0.2.0/24')
635 * a DNS name (e.g. 'dnsdist.org')
636 * a response time (e.g. '100ms')
637
638 :param str selector: Select queries based on this property.
639 :param {str} selectors: A lua table of selectors. Only queries matching all selectors are shown
640 :param int num: Show a maximum of ``num`` recent queries, default is 10.
641
0fb7654e
CHB
642.. function:: setVerboseHealthChecks(verbose)
643
644 Set whether health check errors should be logged. This is turned off by default.
645
646 :param bool verbose: Set to true if you want to enable health check errors logging
647
77d43b54
RG
648.. function:: showBinds()
649
650 Print a list of all the current addresses and ports dnsdist is listening on, also called ``frontends``
651
20d81666
PL
652.. function:: showResponseLatency()
653
77d43b54 654 Show a plot of the response time latency distribution
20d81666
PL
655
656.. function:: showServers()
657
658 This function shows all backend servers currently configured and some statistics.
659 These statics have the following fields:
660
661 * ``#`` - The number of the server, can be used as the argument for :func:`getServer`
662 * ``Address`` - The IP address and port of the server
663 * ``State`` - The current state of the server
664 * ``Qps`` - Current number of queries per second
665 * ``Qlim`` - Configured maximum number of queries per second
666 * ``Ord`` - The order number of the server
667 * ``Wt`` - The weight of the server
668 * ``Queries`` - Total amount of queries sent to this server
669 * ``Drops`` - Number of queries that were dropped by this server
670 * ``Drate`` - Number of queries dropped per second by this server
671 * ``Lat`` - The latency of this server in milliseconds
672 * ``Pools`` - The pools this server belongs to
673
674.. function:: showTCPStats()
675
77d43b54 676 Show some statistics regarding TCP
20d81666 677
a227f47d 678.. function:: showTLSContexts()
d9018741 679
a227f47d
RG
680 .. versionadded:: 1.3.0
681
682 Print the list of all availables DNS over TLS contexts.
683
20d81666
PL
684.. function:: showVersion()
685
686 Print the version of dnsdist
687
688.. function:: topBandwidth([num])
689
690 Print the top ``num`` clients that consume the most bandwidth.
691
692 :param int num: Number to show, defaults to 10.
693
694.. function:: topClients([num])
695
696 Print the top ``num`` clients sending the most queries over length of ringbuffer
697
698 :param int num: Number to show, defaults to 10.
699
700.. function:: topQueries([num[, labels]])
701
702 Print the ``num`` most popular QNAMEs from queries.
703 Optionally grouped by the rightmost ``labels`` DNS labels.
704
705 :param int num: Number to show, defaults to 10
706 :param int label: Number of labels to cut down to
707
708.. function:: topResponses([num[, rcode[, labels]]])
709
967f6a7f 710 Print the ``num`` most seen responses with an RCODE of ``rcode``.
20d81666
PL
711 Optionally grouped by the rightmost ``labels`` DNS labels.
712
713 :param int num: Number to show, defaults to 10
967f6a7f 714 :param int rcode: :ref:`Response code <DNSRCode>`, defaults to 0 (No Error)
20d81666
PL
715 :param int label: Number of labels to cut down to
716
717.. function:: topSlow([num[, limit[, labels]]])
718
719 Print the ``num`` slowest queries that are slower than ``limit`` milliseconds.
720 Optionally grouped by the rightmost ``labels`` DNS labels.
721
722 :param int num: Number to show, defaults to 10
af4b7afb 723 :param int limit: Show queries slower than this amount of milliseconds, defaults to 2000
20d81666
PL
724 :param int label: Number of labels to cut down to
725
726.. _dynblocksref:
727
728Dynamic Blocks
729--------------
730
731.. function:: addDynBlocks(addresses, message[, seconds=10[, action]])
732
733 .. versionchanged:: 1.2.0
734 ``action`` parameter added.
735
736 Block a set of addresses with ``message`` for (optionally) a number of seconds.
737 The default number of seconds to block for is 10.
738
739 :param addresses: set of Addresses as returned by an exceed function
740 :param string message: The message to show next to the blocks
741 :param int seconds: The number of seconds this block to expire
742 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
743
744.. function:: clearDynBlocks()
745
746 Remove all current dynamic blocks.
747
748.. function:: showDynBlocks()
749
750 List all dynamic blocks in effect.
751
752.. function:: setDynBlocksAction(action)
753
754 Set which action is performed when a query is blocked.
752d505b 755 Only DNSAction.Drop (the default), DNSAction.Refused and DNSAction.Truncate are supported.
20d81666 756
20d81666
PL
757.. _exceedfuncs:
758
759Getting addresses that exceeded parameters
760~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
761
762.. function:: exceedServFails(rate, seconds)
763
764 Get set of addresses that exceed ``rate`` servfails/s over ``seconds`` seconds
765
766 :param int rate: Number of Servfails per second to exceed
767 :param int seconds: Number of seconds the rate has been exceeded
768
769.. function:: exceedNXDOMAINs(rate, seconds)
770
771 get set of addresses that exceed ``rate`` NXDOMAIN/s over ``seconds`` seconds
772
773 :param int rate: Number of NXDOMAIN per second to exceed
774 :param int seconds: Number of seconds the rate has been exceeded
775
776.. function:: exceedRespByterate(rate, seconds)
777
778 get set of addresses that exceeded ``rate`` bytes/s answers over ``seconds`` seconds
779
780 :param int rate: Number of bytes per second to exceed
781 :param int seconds: Number of seconds the rate has been exceeded
782
783.. function:: exceedQRate(rate, seconds)
784
785 Get set of address that exceed ``rate`` queries/s over ``seconds`` seconds
786
787 :param int rate: Number of queries per second to exceed
788 :param int seconds: Number of seconds the rate has been exceeded
789
790.. function:: exceedQTypeRate(type, rate, seconds)
791
792 Get set of address that exceed ``rate`` queries/s for queries of QType ``type`` over ``seconds`` seconds
793
794 :param int type: QType
795 :param int rate: Number of QType queries per second to exceed
796 :param int seconds: Number of seconds the rate has been exceeded
797
dc2fd93a
RG
798DynBlockRulesGroup
799~~~~~~~~~~~~~~~~~~
800
801Instead of using several `exceed*()` lines, dnsdist 1.3.0 introduced a new `DynBlockRulesGroup` object
802which can be used to group dynamic block rules.
803
804See :doc:`../guides/dynblocks` for more information about the case where using a `DynBlockRulesGroup` might be
805faster than the existing rules.
806
807.. function:: dynBlockRulesGroup() -> DynBlockRulesGroup
808
ad9344ba 809 .. versionadded:: 1.3.0
dc2fd93a
RG
810
811 Creates a new :class:`DynBlockRulesGroup` object.
812
813.. class:: DynBlockRulesGroup
814
815 Represents a group of dynamic block rules.
816
817 .. method:: DynBlockRulesGroup:setQueryRate(rate, seconds, reason, blockingTime [, action])
818
819 Adds a query rate-limiting rule, equivalent to:
820 ```
821 addDynBlocks(exceedQRate(rate, seconds), reason, blockingTime, action)
822 ```
823
824 :param int rate: Number of queries per second to exceed
825 :param int seconds: Number of seconds the rate has been exceeded
826 :param string reason: The message to show next to the blocks
827 :param int blockingTime: The number of seconds this block to expire
828 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
829
830 .. method:: DynBlockRulesGroup:setRCodeRate(rcode, rate, seconds, reason, blockingTime [, action])
831
832 Adds a rate-limiting rule for responses of code ``rcode``, equivalent to:
833 ```
834 addDynBlocks(exceedServfails(rcode, rate, seconds), reason, blockingTime, action)
835 ```
836
837 :param int rcode: The response code
838 :param int rate: Number of responses per second to exceed
839 :param int seconds: Number of seconds the rate has been exceeded
840 :param string reason: The message to show next to the blocks
841 :param int blockingTime: The number of seconds this block to expire
842 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
843
844 .. method:: DynBlockRulesGroup:setQTypeRate(qtype, rate, seconds, reason, blockingTime [, action])
845
846 Adds a rate-limiting rule for queries of type ``qtype``, equivalent to:
847 ```
848 addDynBlocks(exceedQTypeRate(type, rate, seconds), reason, blockingTime, action)
849 ```
850
851 :param int qtype: The qtype
852 :param int rate: Number of queries per second to exceed
853 :param int seconds: Number of seconds the rate has been exceeded
854 :param string reason: The message to show next to the blocks
855 :param int blockingTime: The number of seconds this block to expire
856 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
857
858 .. method:: DynBlockRulesGroup:setRespByteRate(rate, seconds, reason, blockingTime [, action])
859
860 Adds a bandwidth rate-limiting rule for responses, equivalent to:
861 ```
862 addDynBlocks(exceedRespByterate(rate, seconds), reason, blockingTime, action)
863 ```
864
865 :param int rate: Number of bytes per second to exceed
866 :param int seconds: Number of seconds the rate has been exceeded
867 :param string reason: The message to show next to the blocks
868 :param int blockingTime: The number of seconds this block to expire
869 :param int action: The action to take when the dynamic block matches, see :ref:`here <DNSAction>`. (default to the one set with :func:`setDynBlocksAction`)
870
871 .. method:: DynBlockRulesGroup:apply()
872
873 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.
874
20d81666
PL
875Other functions
876---------------
877
878.. function:: maintenance()
879
880 If this function exists, it is called every second to so regular tasks.
881 This can be used for e.g. :doc:`Dynamic Blocks <../guides/dynblocks>`.
a227f47d
RG
882
883TLSContext
884~~~~~~~~~~
885
886.. class:: TLSContext
d9018741 887
a227f47d
RG
888 .. versionadded:: 1.3.0
889
890 This object represents an address and port dnsdist is listening on for DNS over TLS queries.
891
d9018741 892 .. method:: TLSContext:rotateTicketsKey()
a227f47d 893
d9018741 894 Replace the current TLS tickets key by a new random one.
a227f47d 895
d9018741 896 .. method:: TLSContext:loadTicketsKeys(ticketsKeysFile)
a227f47d 897
d9018741 898 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.
a227f47d 899
d9018741 900 :param str ticketsKeysFile: The path to a file from where TLS tickets keys should be loaded.
8ef43a02
RG
901
902TLSFrontend
903~~~~~~~~~~
904
905.. class:: TLSFrontend
906
907 .. versionadded:: 1.3.1
908
909 This object represents the configuration of a listening frontend for DNS over TLS queries. To each frontend is associated a TLSContext.
910
911 .. method:: TLSContext:loadNewCertificatesAndKeys(certFile(s), keyFile(s))
912
913 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.
914
915 :param str certFile(s): The path to a X.509 certificate file in PEM format, or a list of paths to such files.
916 :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.