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