xref: /freebsd/contrib/unbound/util/config_file.h (revision b2efd602aea8b3cbc3fb215b9611946d04fceb10)
1 /*
2  * util/config_file.h - reads and stores the config file for unbound.
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 /**
37  * \file
38  *
39  * This file contains functions for the config file.
40  */
41 
42 #ifndef UTIL_CONFIG_FILE_H
43 #define UTIL_CONFIG_FILE_H
44 #include "sldns/rrdef.h"
45 struct config_stub;
46 struct config_auth;
47 struct config_view;
48 struct config_strlist;
49 struct config_str2list;
50 struct config_str3list;
51 struct config_strbytelist;
52 struct module_qstate;
53 struct sock_list;
54 struct ub_packed_rrset_key;
55 struct regional;
56 
57 /** Default value for PROBE_MAXRTO */
58 #define PROBE_MAXRTO_DEFAULT 12000
59 
60 /** List head for strlist processing, used for append operation. */
61 struct config_strlist_head {
62 	/** first in list of text items */
63 	struct config_strlist* first;
64 	/** last in list of text items */
65 	struct config_strlist* last;
66 };
67 
68 /**
69  * The configuration options.
70  * Strings are malloced.
71  */
72 struct config_file {
73 	/** verbosity level as specified in the config file */
74 	int verbosity;
75 
76 	/** statistics interval (in seconds) */
77 	int stat_interval;
78 	/** if false, statistics values are reset after printing them */
79 	int stat_cumulative;
80 	/** if true, the statistics are kept in greater detail */
81 	int stat_extended;
82 	/** if true, inhibits a lot of =0 lines from the extended stats output */
83 	int stat_inhibit_zero;
84 
85 	/** number of threads to create */
86 	int num_threads;
87 
88 	/** port on which queries are answered. */
89 	int port;
90 	/** do ip4 query support. */
91 	int do_ip4;
92 	/** do ip6 query support. */
93 	int do_ip6;
94 	/** do nat64 on queries */
95 	int do_nat64;
96 	/** prefer ip4 upstream queries. */
97 	int prefer_ip4;
98 	/** prefer ip6 upstream queries. */
99 	int prefer_ip6;
100 	/** do udp query support. */
101 	int do_udp;
102 	/** do tcp query support. */
103 	int do_tcp;
104 	/** max number of queries on a reuse connection. */
105 	size_t max_reuse_tcp_queries;
106 	/** timeout for REUSE entries in milliseconds. */
107 	int tcp_reuse_timeout;
108 	/** timeout in milliseconds for TCP queries to auth servers. */
109 	int tcp_auth_query_timeout;
110 	/** tcp upstream queries (no UDP upstream queries) */
111 	int tcp_upstream;
112 	/** udp upstream enabled when no UDP downstream is enabled (do_udp no)*/
113 	int udp_upstream_without_downstream;
114 	/** maximum segment size of tcp socket which queries are answered */
115 	int tcp_mss;
116 	/** maximum segment size of tcp socket for outgoing queries */
117 	int outgoing_tcp_mss;
118 	/** tcp idle timeout, in msec */
119 	int tcp_idle_timeout;
120 	/** do edns tcp keepalive */
121 	int do_tcp_keepalive;
122 	/** tcp keepalive timeout, in msec */
123 	int tcp_keepalive_timeout;
124 	/** timeout of packets sitting in the socket queue */
125 	int sock_queue_timeout;
126 	/** proxy protocol ports */
127 	struct config_strlist* proxy_protocol_port;
128 
129 	/** private key file for dnstcp-ssl service (enabled if not NULL) */
130 	char* ssl_service_key;
131 	/** public key file for dnstcp-ssl service */
132 	char* ssl_service_pem;
133 	/** port on which to provide ssl service */
134 	int ssl_port;
135 	/** if outgoing tcp connections use SSL */
136 	int ssl_upstream;
137 	/** cert bundle for outgoing connections */
138 	char* tls_cert_bundle;
139 	/** should the system certificate store get added to the cert bundle */
140 	int tls_win_cert;
141 	/** additional tls ports */
142 	struct config_strlist* tls_additional_port;
143 	/** secret key used to encrypt and decrypt TLS session ticket */
144 	struct config_strlist_head tls_session_ticket_keys;
145 	/** TLS ciphers */
146 	char* tls_ciphers;
147 	/** TLS chiphersuites (TLSv1.3) */
148 	char* tls_ciphersuites;
149 	/** if SNI is to be used */
150 	int tls_use_sni;
151 
152 	/** port on which to provide DNS over HTTPS service */
153 	int https_port;
154 	/** endpoint for HTTP service */
155 	char* http_endpoint;
156 	/** MAX_CONCURRENT_STREAMS HTTP/2 setting */
157 	uint32_t http_max_streams;
158 	/** maximum size of all HTTP2 query buffers combined. */
159 	size_t http_query_buffer_size;
160 	/** maximum size of all HTTP2 response buffers combined. */
161 	size_t http_response_buffer_size;
162 	/** set TCP_NODELAY option for http sockets */
163 	int http_nodelay;
164 	/** Disable TLS for http sockets downstream */
165 	int http_notls_downstream;
166 
167 	/** port on which to provide DNS over QUIC service */
168 	int quic_port;
169 	/** size of the quic data, max bytes */
170 	size_t quic_size;
171 
172 	/** outgoing port range number of ports (per thread) */
173 	int outgoing_num_ports;
174 	/** number of outgoing tcp buffers per (per thread) */
175 	size_t outgoing_num_tcp;
176 	/** number of incoming tcp buffers per (per thread) */
177 	size_t incoming_num_tcp;
178 	/** allowed udp port numbers, array with 0 if not allowed */
179 	int* outgoing_avail_ports;
180 
181 	/** EDNS buffer size to use */
182 	size_t edns_buffer_size;
183 	/** size of the stream wait buffers, max */
184 	size_t stream_wait_size;
185 	/** number of bytes buffer size for DNS messages */
186 	size_t msg_buffer_size;
187 	/** size of the message cache */
188 	size_t msg_cache_size;
189 	/** slabs in the message cache. */
190 	size_t msg_cache_slabs;
191 	/** number of queries every thread can service */
192 	size_t num_queries_per_thread;
193 	/** number of msec to wait before items can be jostled out */
194 	size_t jostle_time;
195 	/** size of the rrset cache */
196 	size_t rrset_cache_size;
197 	/** slabs in the rrset cache */
198 	size_t rrset_cache_slabs;
199 	/** host cache ttl in seconds */
200 	int host_ttl;
201 	/** number of slabs in the infra host cache */
202 	size_t infra_cache_slabs;
203 	/** max number of hosts in the infra cache */
204 	size_t infra_cache_numhosts;
205 	/** min value for infra cache rtt (min retransmit timeout) */
206 	int infra_cache_min_rtt;
207 	/** max value for infra cache rtt (max retransmit timeout) */
208 	int infra_cache_max_rtt;
209 	/** keep probing hosts that are down */
210 	int infra_keep_probing;
211 	/** delay close of udp-timeouted ports, if 0 no delayclose. in msec */
212 	int delay_close;
213 	/** udp_connect enable uses UDP connect to mitigate ICMP side channel */
214 	int udp_connect;
215 
216 	/** the target fetch policy for the iterator */
217 	char* target_fetch_policy;
218 	/** percent*10, how many times in 1000 to pick from the fastest
219 	 * destinations */
220 	int fast_server_permil;
221 	/** number of fastest server to select from */
222 	size_t fast_server_num;
223 
224 	/** automatic interface for incoming messages. Uses ipv6 remapping,
225 	 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */
226 	int if_automatic;
227 	/** extra ports to open if if_automatic enabled, or NULL for default */
228 	char* if_automatic_ports;
229 	/** SO_RCVBUF size to set on port 53 UDP socket */
230 	size_t so_rcvbuf;
231 	/** SO_SNDBUF size to set on port 53 UDP socket */
232 	size_t so_sndbuf;
233 	/** SO_REUSEPORT requested on port 53 sockets */
234 	int so_reuseport;
235 	/** IP_TRANSPARENT socket option requested on port 53 sockets */
236 	int ip_transparent;
237 	/** IP_FREEBIND socket option request on port 53 sockets */
238 	int ip_freebind;
239 	/** IP_TOS socket option requested on port 53 sockets */
240 	int ip_dscp;
241 
242 	/** number of interfaces to open. If 0 default all interfaces. */
243 	int num_ifs;
244 	/** interface description strings (IP addresses) */
245 	char **ifs;
246 
247 	/** number of outgoing interfaces to open.
248 	 * If 0 default all interfaces. */
249 	int num_out_ifs;
250 	/** outgoing interface description strings (IP addresses) */
251 	char **out_ifs;
252 
253 	/** the root hints */
254 	struct config_strlist* root_hints;
255 	/** the stub definitions, linked list */
256 	struct config_stub* stubs;
257 	/** the forward zone definitions, linked list */
258 	struct config_stub* forwards;
259 	/** the auth zone definitions, linked list */
260 	struct config_auth* auths;
261 	/** the views definitions, linked list */
262 	struct config_view* views;
263 	/** list of donotquery addresses, linked list */
264 	struct config_strlist* donotqueryaddrs;
265 #ifdef CLIENT_SUBNET
266 	/** list of servers we send edns-client-subnet option to and
267 	 * accept option from, linked list */
268 	struct config_strlist* client_subnet;
269 	/** list of zones we send edns-client-subnet option for */
270 	struct config_strlist* client_subnet_zone;
271 	/** opcode assigned by IANA for edns0-client-subnet option */
272 	uint16_t client_subnet_opcode;
273 	/** Do not check whitelist if incoming query contains an ECS record */
274 	int client_subnet_always_forward;
275 	/** Subnet length we are willing to give up privacy for */
276 	uint8_t max_client_subnet_ipv4;
277 	uint8_t max_client_subnet_ipv6;
278 	/** Minimum subnet length we are willing to answer */
279 	uint8_t min_client_subnet_ipv4;
280 	uint8_t min_client_subnet_ipv6;
281 	/** Max number of nodes in the ECS radix tree */
282 	uint32_t max_ecs_tree_size_ipv4;
283 	uint32_t max_ecs_tree_size_ipv6;
284 #endif
285 	/** list of access control entries, linked list */
286 	struct config_str2list* acls;
287 	/** use default localhost donotqueryaddr entries */
288 	int donotquery_localhost;
289 
290 	/** list of tcp connection limitss, linked list */
291 	struct config_str2list* tcp_connection_limits;
292 
293 	/** harden against very small edns buffer sizes */
294 	int harden_short_bufsize;
295 	/** harden against very large query sizes */
296 	int harden_large_queries;
297 	/** harden against spoofed glue (out of zone data) */
298 	int harden_glue;
299 	/** harden against unverified glue */
300 	int harden_unverified_glue;
301 	/** harden against receiving no DNSSEC data for trust anchor */
302 	int harden_dnssec_stripped;
303 	/** harden against queries that fall under known nxdomain names */
304 	int harden_below_nxdomain;
305 	/** harden the referral path, query for NS,A,AAAA and validate */
306 	int harden_referral_path;
307 	/** harden against algorithm downgrade */
308 	int harden_algo_downgrade;
309 	/** harden against unknown records in the authority section and in
310 	 * the additional section */
311 	int harden_unknown_additional;
312 	/** use 0x20 bits in query as random ID bits */
313 	int use_caps_bits_for_id;
314 	/** 0x20 whitelist, domains that do not use capsforid */
315 	struct config_strlist* caps_whitelist;
316 	/** strip away these private addrs from answers, no DNS Rebinding */
317 	struct config_strlist* private_address;
318 	/** allow domain (and subdomains) to use private address space */
319 	struct config_strlist* private_domain;
320 	/** what threshold for unwanted action. */
321 	size_t unwanted_threshold;
322 	/** the number of seconds maximal TTL used for RRsets and messages */
323 	int max_ttl;
324 	/** the number of seconds minimum TTL used for RRsets and messages */
325 	int min_ttl;
326 	/** the number of seconds maximal negative TTL for SOA in auth */
327 	int max_negative_ttl;
328 	/** the number of seconds minimal negative TTL for SOA in auth */
329 	int min_negative_ttl;
330 	/** if prefetching of messages should be performed. */
331 	int prefetch;
332 	/** if prefetching of DNSKEYs should be performed. */
333 	int prefetch_key;
334 	/** deny queries of type ANY with an empty answer */
335 	int deny_any;
336 
337 	/** chrootdir, if not "" or chroot will be done */
338 	char* chrootdir;
339 	/** username to change to, if not "". */
340 	char* username;
341 	/** working directory */
342 	char* directory;
343 	/** filename to log to. */
344 	char* logfile;
345 	/** pidfile to write pid to. */
346 	char* pidfile;
347 
348 	/** should log messages be sent to syslogd */
349 	int use_syslog;
350 	/** log timestamp in ascii UTC */
351 	int log_time_ascii;
352 	/** log timestamp in ISO8601 format */
353 	int log_time_iso;
354 	/** log queries with one line per query */
355 	int log_queries;
356 	/** log replies with one line per reply */
357 	int log_replies;
358 	/** tag log_queries and log_replies for filtering */
359 	int log_tag_queryreply;
360 	/** log every local-zone hit **/
361 	int log_local_actions;
362 	/** log servfails with a reason */
363 	int log_servfail;
364 	/** log identity to report */
365 	char* log_identity;
366 	/** log dest addr for log_replies */
367 	int log_destaddr;
368 
369 	/** do not report identity (id.server, hostname.bind) */
370 	int hide_identity;
371 	/** do not report version (version.server, version.bind) */
372 	int hide_version;
373 	/** do not report trustanchor (trustanchor.unbound) */
374 	int hide_trustanchor;
375 	/** do not report the User-Agent HTTP header */
376 	int hide_http_user_agent;
377 	/** identity, hostname is returned if "". */
378 	char* identity;
379 	/** version, package version returned if "". */
380 	char* version;
381 	/** User-Agent for HTTP header */
382 	char* http_user_agent;
383 	/** nsid */
384 	char *nsid_cfg_str;
385 	uint8_t *nsid;
386 	uint16_t nsid_len;
387 
388 	/** the module configuration string */
389 	char* module_conf;
390 
391 	/** files with trusted DS and DNSKEYs in zonefile format, list */
392 	struct config_strlist* trust_anchor_file_list;
393 	/** list of trustanchor keys, linked list */
394 	struct config_strlist* trust_anchor_list;
395 	/** files with 5011 autotrust tracked keys */
396 	struct config_strlist* auto_trust_anchor_file_list;
397 	/** files with trusted DNSKEYs in named.conf format, list */
398 	struct config_strlist* trusted_keys_file_list;
399 	/** insecure domain list */
400 	struct config_strlist* domain_insecure;
401 	/** send key tag query */
402 	int trust_anchor_signaling;
403 	/** enable root key sentinel */
404 	int root_key_sentinel;
405 
406 	/** if not 0, this value is the validation date for RRSIGs */
407 	int32_t val_date_override;
408 	/** the minimum for signature clock skew */
409 	int32_t val_sig_skew_min;
410 	/** the maximum for signature clock skew */
411 	int32_t val_sig_skew_max;
412 	/** max number of query restarts, number of IPs to probe */
413 	int32_t val_max_restart;
414 	/** this value sets the number of seconds before revalidating bogus */
415 	int bogus_ttl;
416 	/** should validator clean additional section for secure msgs */
417 	int val_clean_additional;
418 	/** log bogus messages by the validator */
419 	int val_log_level;
420 	/** squelch val_log_level to log - this is library goes to callback */
421 	int val_log_squelch;
422 	/** should validator allow bogus messages to go through */
423 	int val_permissive_mode;
424 	/** use cached NSEC records to synthesise (negative) answers */
425 	int aggressive_nsec;
426 	/** ignore the CD flag in incoming queries and refuse them bogus data */
427 	int ignore_cd;
428 	/** disable EDNS DO flag in outgoing requests */
429 	int disable_edns_do;
430 	/** serve expired entries and prefetch them */
431 	int serve_expired;
432 	/** serve expired entries until TTL after expiration */
433 	int serve_expired_ttl;
434 	/** reset serve expired TTL after failed update attempt */
435 	int serve_expired_ttl_reset;
436 	/** TTL for the serve expired replies */
437 	int serve_expired_reply_ttl;
438 	/** serve expired entries only after trying to update the entries and this
439 	 *  timeout (in milliseconds) is reached */
440 	int serve_expired_client_timeout;
441 	/** serve original TTLs rather than decrementing ones */
442 	int serve_original_ttl;
443 	/** nsec3 maximum iterations per key size, string */
444 	char* val_nsec3_key_iterations;
445 	/** if zonemd failures are permitted, only logged */
446 	int zonemd_permissive_mode;
447 	/** autotrust add holddown time, in seconds */
448 	unsigned int add_holddown;
449 	/** autotrust del holddown time, in seconds */
450 	unsigned int del_holddown;
451 	/** autotrust keep_missing time, in seconds. 0 is forever. */
452 	unsigned int keep_missing;
453 	/** permit small holddown values, allowing 5011 rollover very fast */
454 	int permit_small_holddown;
455 
456 	/** size of the key cache */
457 	size_t key_cache_size;
458 	/** slabs in the key cache. */
459 	size_t key_cache_slabs;
460 	/** size of the neg cache */
461 	size_t neg_cache_size;
462 
463 	/** local zones config */
464 	struct config_str2list* local_zones;
465 	/** local zones nodefault list */
466 	struct config_strlist* local_zones_nodefault;
467 #ifdef USE_IPSET
468 	/** local zones ipset list */
469 	struct config_strlist* local_zones_ipset;
470 #endif
471 	/** do not add any default local zone */
472 	int local_zones_disable_default;
473 	/** local data RRs configured */
474 	struct config_strlist* local_data;
475 	/** local zone override types per netblock */
476 	struct config_str3list* local_zone_overrides;
477 	/** unblock lan zones (reverse lookups for AS112 zones) */
478 	int unblock_lan_zones;
479 	/** insecure lan zones (don't validate AS112 zones) */
480 	int insecure_lan_zones;
481 	/** list of zonename, tagbitlist */
482 	struct config_strbytelist* local_zone_tags;
483 	/** list of aclname, tagbitlist */
484 	struct config_strbytelist* acl_tags;
485 	/** list of aclname, tagname, localzonetype */
486 	struct config_str3list* acl_tag_actions;
487 	/** list of aclname, tagname, redirectdata */
488 	struct config_str3list* acl_tag_datas;
489 	/** list of aclname, view*/
490 	struct config_str2list* acl_view;
491 	/** list of interface action entries, linked list */
492 	struct config_str2list* interface_actions;
493 	/** list of interface, tagbitlist */
494 	struct config_strbytelist* interface_tags;
495 	/** list of interface, tagname, localzonetype */
496 	struct config_str3list* interface_tag_actions;
497 	/** list of interface, tagname, redirectdata */
498 	struct config_str3list* interface_tag_datas;
499 	/** list of interface, view*/
500 	struct config_str2list* interface_view;
501 	/** list of IP-netblock, tagbitlist */
502 	struct config_strbytelist* respip_tags;
503 	/** list of response-driven access control entries, linked list */
504 	struct config_str2list* respip_actions;
505 	/** RRs configured for response-driven access controls */
506 	struct config_str2list* respip_data;
507 	/** tag list, array with tagname[i] is malloced string */
508 	char** tagname;
509 	/** number of items in the taglist */
510 	int num_tags;
511 
512 	/** remote control section. enable toggle. */
513 	int remote_control_enable;
514 	/** the interfaces the remote control should listen on */
515 	struct config_strlist_head control_ifs;
516 	/** if the use-cert option is set */
517 	int control_use_cert;
518 	/** port number for the control port */
519 	int control_port;
520 	/** private key file for server */
521 	char* server_key_file;
522 	/** certificate file for server */
523 	char* server_cert_file;
524 	/** private key file for unbound-control */
525 	char* control_key_file;
526 	/** certificate file for unbound-control */
527 	char* control_cert_file;
528 
529 	/** Python script file */
530 	struct config_strlist* python_script;
531 
532 	/** Dynamic library file */
533 	struct config_strlist* dynlib_file;
534 
535 	/** Use systemd socket activation. */
536 	int use_systemd;
537 
538 	/** daemonize, i.e. fork into the background. */
539 	int do_daemonize;
540 
541 	/* minimal response when positive answer */
542 	int minimal_responses;
543 
544 	/* RRSet roundrobin */
545 	int rrset_roundrobin;
546 
547 	/* wait time for unknown server in msec */
548 	int unknown_server_time_limit;
549 
550 	/** Wait time to drop recursion replies */
551 	int discard_timeout;
552 
553 	/** Wait limit for number of replies per IP address */
554 	int wait_limit;
555 
556 	/** Wait limit for number of replies per IP address with cookie */
557 	int wait_limit_cookie;
558 
559 	/** wait limit per netblock */
560 	struct config_str2list* wait_limit_netblock;
561 
562 	/** wait limit with cookie per netblock */
563 	struct config_str2list* wait_limit_cookie_netblock;
564 
565 	/* maximum UDP response size */
566 	size_t max_udp_size;
567 
568 	/* DNS64 prefix */
569 	char* dns64_prefix;
570 
571 	/* Synthetize all AAAA record despite the presence of an authoritative one */
572 	int dns64_synthall;
573 	/** ignore AAAAs for these domain names and use A record anyway */
574 	struct config_strlist* dns64_ignore_aaaa;
575 
576 	/* NAT64 prefix; if unset defaults to dns64_prefix */
577 	char* nat64_prefix;
578 
579 	/** true to enable dnstap support */
580 	int dnstap;
581 	/** using bidirectional frame streams if true */
582 	int dnstap_bidirectional;
583 	/** dnstap socket path */
584 	char* dnstap_socket_path;
585 	/** dnstap IP */
586 	char* dnstap_ip;
587 	/** dnstap TLS enable */
588 	int dnstap_tls;
589 	/** dnstap tls server authentication name */
590 	char* dnstap_tls_server_name;
591 	/** dnstap server cert bundle */
592 	char* dnstap_tls_cert_bundle;
593 	/** dnstap client key for client authentication */
594 	char* dnstap_tls_client_key_file;
595 	/** dnstap client cert for client authentication */
596 	char* dnstap_tls_client_cert_file;
597 	/** true to send "identity" via dnstap */
598 	int dnstap_send_identity;
599 	/** true to send "version" via dnstap */
600 	int dnstap_send_version;
601 	/** dnstap "identity", hostname is used if "". */
602 	char* dnstap_identity;
603 	/** dnstap "version", package version is used if "". */
604 	char* dnstap_version;
605 	/** dnstap sample rate */
606 	int dnstap_sample_rate;
607 
608 	/** true to log dnstap RESOLVER_QUERY message events */
609 	int dnstap_log_resolver_query_messages;
610 	/** true to log dnstap RESOLVER_RESPONSE message events */
611 	int dnstap_log_resolver_response_messages;
612 	/** true to log dnstap CLIENT_QUERY message events */
613 	int dnstap_log_client_query_messages;
614 	/** true to log dnstap CLIENT_RESPONSE message events */
615 	int dnstap_log_client_response_messages;
616 	/** true to log dnstap FORWARDER_QUERY message events */
617 	int dnstap_log_forwarder_query_messages;
618 	/** true to log dnstap FORWARDER_RESPONSE message events */
619 	int dnstap_log_forwarder_response_messages;
620 
621 	/** true to disable DNSSEC lameness check in iterator */
622 	int disable_dnssec_lame_check;
623 
624 	/** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */
625 	int ip_ratelimit;
626 	/** ratelimit for ip addresses with a valid DNS Cookie. 0 is off,
627 	 *  otherwise qps (unless overridden) */
628 	int ip_ratelimit_cookie;
629 	/** number of slabs for ip_ratelimit cache */
630 	size_t ip_ratelimit_slabs;
631 	/** memory size in bytes for ip_ratelimit cache */
632 	size_t ip_ratelimit_size;
633 	/** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
634 	int ip_ratelimit_factor;
635 	/** ratelimit backoff, when on, if the limit is reached it is
636 	 *  considered an attack and it backs off until 'demand' decreases over
637 	 *  the RATE_WINDOW. */
638 	int ip_ratelimit_backoff;
639 
640 	/** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */
641 	int ratelimit;
642 	/** number of slabs for ratelimit cache */
643 	size_t ratelimit_slabs;
644 	/** memory size in bytes for ratelimit cache */
645 	size_t ratelimit_size;
646 	/** ratelimits for domain (exact match) */
647 	struct config_str2list* ratelimit_for_domain;
648 	/** ratelimits below domain */
649 	struct config_str2list* ratelimit_below_domain;
650 	/** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
651 	int ratelimit_factor;
652 	/** ratelimit backoff, when on, if the limit is reached it is
653 	 *  considered an attack and it backs off until 'demand' decreases over
654 	 *  the RATE_WINDOW. */
655 	int ratelimit_backoff;
656 
657 	/** number of retries on outgoing queries */
658 	int outbound_msg_retry;
659 	/** max sent queries per qstate; resets on query restarts (e.g.,
660 	 *  CNAMES) and referrals */
661 	int max_sent_count;
662 	/** max number of query restarts; determines max length of CNAME chain */
663 	int max_query_restarts;
664 	/** minimise outgoing QNAME and hide original QTYPE if possible */
665 	int qname_minimisation;
666 	/** minimise QNAME in strict mode, minimise according to RFC.
667 	 *  Do not apply fallback */
668 	int qname_minimisation_strict;
669 	/** SHM data - true if shm is enabled */
670 	int shm_enable;
671 	/** SHM data - key for the shm */
672 	int shm_key;
673 
674 	/** list of EDNS client string entries, linked list */
675 	struct config_str2list* edns_client_strings;
676 	/** EDNS opcode to use for EDNS client strings */
677 	uint16_t edns_client_string_opcode;
678 
679 	/** DNSCrypt */
680 	/** true to enable dnscrypt */
681 	int dnscrypt;
682 	/** port on which to provide dnscrypt service */
683 	int dnscrypt_port;
684 	/** provider name 2.dnscrypt-cert.example.com */
685 	char* dnscrypt_provider;
686 	/** dnscrypt secret keys 1.key */
687 	struct config_strlist* dnscrypt_secret_key;
688 	/** dnscrypt provider certs 1.cert */
689 	struct config_strlist* dnscrypt_provider_cert;
690 	/** dnscrypt provider certs 1.cert which have been rotated and should not be
691 	* advertised through DNS's providername TXT record but are required to be
692 	* able to handle existing traffic using the old cert. */
693 	struct config_strlist* dnscrypt_provider_cert_rotated;
694 	/** memory size in bytes for dnscrypt shared secrets cache */
695 	size_t dnscrypt_shared_secret_cache_size;
696 	/** number of slabs for dnscrypt shared secrets cache */
697 	size_t dnscrypt_shared_secret_cache_slabs;
698 	/** memory size in bytes for dnscrypt nonces cache */
699 	size_t dnscrypt_nonce_cache_size;
700 	/** number of slabs for dnscrypt nonces cache */
701 	size_t dnscrypt_nonce_cache_slabs;
702 
703 	/** EDNS padding according to RFC7830 and RFC8467 */
704 	/** true to enable padding of responses (default: on) */
705 	int pad_responses;
706 	/** block size with which to pad encrypted responses (default: 468) */
707 	size_t pad_responses_block_size;
708 	/** true to enable padding of queries (default: on) */
709 	int pad_queries;
710 	/** block size with which to pad encrypted queries (default: 128) */
711 	size_t pad_queries_block_size;
712 
713 	/** IPsec module */
714 #ifdef USE_IPSECMOD
715 	/** false to bypass the IPsec module */
716 	int ipsecmod_enabled;
717 	/** whitelisted domains for ipsecmod */
718 	struct config_strlist* ipsecmod_whitelist;
719 	/** path to external hook */
720 	char* ipsecmod_hook;
721 	/** true to proceed even with a bogus IPSECKEY */
722 	int ipsecmod_ignore_bogus;
723 	/** max TTL for the A/AAAA records that call the hook */
724 	int ipsecmod_max_ttl;
725 	/** false to proceed even when ipsecmod_hook fails */
726 	int ipsecmod_strict;
727 #endif
728 
729 	/* cachedb module */
730 #ifdef USE_CACHEDB
731 	/** backend DB name */
732 	char* cachedb_backend;
733 	/** secret seed for hash key calculation */
734 	char* cachedb_secret;
735 	/** cachedb that does not store, but only reads from database, if on */
736 	int cachedb_no_store;
737 	/** cachedb check before serving serve-expired response */
738 	int cachedb_check_when_serve_expired;
739 #ifdef USE_REDIS
740 	/** redis server's IP address or host name */
741 	char* redis_server_host;
742 	char* redis_replica_server_host;
743 	/** redis server's TCP port */
744 	int redis_server_port;
745 	int redis_replica_server_port;
746 	/** redis server's unix path. Or "", NULL if unused */
747 	char* redis_server_path;
748 	char* redis_replica_server_path;
749 	/** redis server's AUTH password. Or "", NULL if unused */
750 	char* redis_server_password;
751 	char* redis_replica_server_password;
752 	/** timeout (in ms) for communication with the redis server */
753 	int redis_timeout;
754 	int redis_replica_timeout;
755 	/** timeout (in ms) for redis commands */
756 	int redis_command_timeout;
757 	int redis_replica_command_timeout;
758 	/** timeout (in ms) for redis connection set up */
759 	int redis_connect_timeout;
760 	int redis_replica_connect_timeout;
761 	/** set timeout on redis records based on DNS response ttl */
762 	int redis_expire_records;
763 	/** set the redis logical database upon connection */
764 	int redis_logical_db;
765 	int redis_replica_logical_db;
766 #endif
767 #endif
768 	/** Downstream DNS Cookies */
769 	/** do answer with server cookie when request contained cookie option */
770 	int do_answer_cookie;
771 	/** cookie secret */
772 	uint8_t cookie_secret[40];
773 	/** cookie secret length */
774 	size_t  cookie_secret_len;
775 	/** path to cookie secret store */
776 	char* cookie_secret_file;
777 
778 	/* ipset module */
779 #ifdef USE_IPSET
780 	char* ipset_name_v4;
781 	char* ipset_name_v6;
782 #endif
783 	/** respond with Extended DNS Errors (RFC8914) */
784 	int ede;
785 	/** serve EDE code 3 - Stale Answer (RFC8914) for expired entries */
786 	int ede_serve_expired;
787 	/** send DNS Error Reports to upstream reporting agent (RFC9567) */
788 	int dns_error_reporting;
789 	/** limit on NS RRs in RRset for the iterator scrubber. */
790 	size_t iter_scrub_ns;
791 	/** limit on CNAME, DNAME RRs in answer for the iterator scrubber. */
792 	int iter_scrub_cname;
793 	/** limit on upstream queries for an incoming query and subqueries. */
794 	int max_global_quota;
795 };
796 
797 /** from cfg username, after daemonize setup performed */
798 extern uid_t cfg_uid;
799 /** from cfg username, after daemonize setup performed */
800 extern gid_t cfg_gid;
801 /** debug and enable small timeouts */
802 extern int autr_permit_small_holddown;
803 /** size (in bytes) of stream wait buffers max */
804 extern size_t stream_wait_max;
805 /** size (in bytes) of all total HTTP2 query buffers max */
806 extern size_t http2_query_buffer_max;
807 /** size (in bytes) of all total HTTP2 response buffers max */
808 extern size_t http2_response_buffer_max;
809 
810 /**
811  * Stub config options
812  */
813 struct config_stub {
814 	/** next in list */
815 	struct config_stub* next;
816 	/** domain name (in text) of the stub apex domain */
817 	char* name;
818 	/** list of stub nameserver hosts (domain name) */
819 	struct config_strlist* hosts;
820 	/** list of stub nameserver addresses (IP address) */
821 	struct config_strlist* addrs;
822 	/** if stub-prime is set */
823 	int isprime;
824 	/** if forward-first is set (failover to without if fails) */
825 	int isfirst;
826 	/** use tcp for queries to this stub */
827 	int tcp_upstream;
828 	/** use SSL for queries to this stub */
829 	int ssl_upstream;
830 	/*** no cache */
831 	int no_cache;
832 };
833 
834 /**
835  * Auth config options
836  */
837 struct config_auth {
838 	/** next in list */
839 	struct config_auth* next;
840 	/** domain name (in text) of the auth apex domain */
841 	char* name;
842 	/** list of masters */
843 	struct config_strlist* masters;
844 	/** list of urls */
845 	struct config_strlist* urls;
846 	/** list of allow-notify */
847 	struct config_strlist* allow_notify;
848 	/** zonefile (or NULL) */
849 	char* zonefile;
850 	/** provide downstream answers */
851 	int for_downstream;
852 	/** provide upstream answers */
853 	int for_upstream;
854 	/** fallback to recursion to authorities if zone expired and other
855 	 * reasons perhaps (like, query bogus) */
856 	int fallback_enabled;
857 	/** this zone is used to create local-zone policies */
858 	int isrpz;
859 	/** rpz tags (or NULL) */
860 	uint8_t* rpz_taglist;
861 	/** length of the taglist (in bytes) */
862 	size_t rpz_taglistlen;
863 	/** Override RPZ action for this zone, regardless of zone content */
864 	char* rpz_action_override;
865 	/** Log when this RPZ policy is applied */
866 	int rpz_log;
867 	/** Display this name in the log when RPZ policy is applied */
868 	char* rpz_log_name;
869 	/** Always reply with this CNAME target if the cname override action is
870 	 * used */
871 	char* rpz_cname;
872 	/** signal nxdomain block with unset RA */
873 	int rpz_signal_nxdomain_ra;
874 	/** Check ZONEMD records for this zone */
875 	int zonemd_check;
876 	/** Reject absence of ZONEMD records, zone must have one */
877 	int zonemd_reject_absence;
878 };
879 
880 /**
881  * View config options
882  */
883 struct config_view {
884 	/** next in list */
885 	struct config_view* next;
886 	/** view name */
887 	char* name;
888 	/** local zones */
889 	struct config_str2list* local_zones;
890 	/** local data RRs */
891 	struct config_strlist* local_data;
892 	/** local zones nodefault list */
893 	struct config_strlist* local_zones_nodefault;
894 #ifdef USE_IPSET
895 	/** local zones ipset list */
896 	struct config_strlist* local_zones_ipset;
897 #endif
898 	/** Fallback to global local_zones when there is no match in the view
899 	 * view specific tree. 1 for yes, 0 for no */
900 	int isfirst;
901 	/** predefined actions for particular IP address responses */
902 	struct config_str2list* respip_actions;
903 	/** data complementing the 'redirect' response IP actions */
904 	struct config_str2list* respip_data;
905 };
906 
907 /**
908  * List of strings for config options
909  */
910 struct config_strlist {
911 	/** next item in list */
912 	struct config_strlist* next;
913 	/** config option string */
914 	char* str;
915 };
916 
917 /**
918  * List of two strings for config options
919  */
920 struct config_str2list {
921 	/** next item in list */
922 	struct config_str2list* next;
923 	/** first string */
924 	char* str;
925 	/** second string */
926 	char* str2;
927 };
928 
929 /**
930  * List of three strings for config options
931  */
932 struct config_str3list {
933 	/** next item in list */
934 	struct config_str3list* next;
935 	/** first string */
936 	char* str;
937 	/** second string */
938 	char* str2;
939 	/** third string */
940 	char* str3;
941 };
942 
943 
944 /**
945  * List of string, bytestring for config options
946  */
947 struct config_strbytelist {
948 	/** next item in list */
949 	struct config_strbytelist* next;
950 	/** first string */
951 	char* str;
952 	/** second bytestring */
953 	uint8_t* str2;
954 	size_t str2len;
955 };
956 
957 /**
958  * Create config file structure. Filled with default values.
959  * @return: the new structure or NULL on memory error.
960  */
961 struct config_file* config_create(void);
962 
963 /**
964  * Create config file structure for library use. Filled with default values.
965  * @return: the new structure or NULL on memory error.
966  */
967 struct config_file* config_create_forlib(void);
968 
969 /**
970  * If _slabs values are not explicitly configured, 0 value, put them in a
971  * pow2 value close to the number of threads used.
972  * Starts at the current default 4.
973  * If num_threads is in between two pow2 values, 1/3 of the way stays with
974  * the lower pow2 value.
975  * Exported for unit testing.
976  * @param config: where the _slabs values reside.
977  */
978 void config_auto_slab_values(struct config_file* config);
979 
980 /**
981  * Read the config file from the specified filename.
982  * @param config: where options are stored into, must be freshly created.
983  * @param filename: name of configfile. If NULL nothing is done.
984  * @param chroot: if not NULL, the chroot dir currently in use (for include).
985  * @return: false on error. In that case errno is set, ENOENT means
986  * 	file not found.
987  */
988 int config_read(struct config_file* config, const char* filename,
989 	const char* chroot);
990 
991 /**
992  * Destroy the config file structure.
993  * @param config: to delete.
994  */
995 void config_delete(struct config_file* config);
996 
997 /**
998  * Apply config to global constants; this routine is called in single thread.
999  * @param config: to apply. Side effect: global constants change.
1000  */
1001 void config_apply(struct config_file* config);
1002 
1003 /** Apply the relevant changes that rely upon RTT_MAX_TIMEOUT;
1004  *  exported for unit test */
1005 int config_apply_max_rtt(int max_rtt);
1006 
1007 /**
1008  * Find username, sets cfg_uid and cfg_gid.
1009  * @param config: the config structure.
1010  */
1011 void config_lookup_uid(struct config_file* config);
1012 
1013 /**
1014  * Set the given keyword to the given value.
1015  * @param config: where to store config
1016  * @param option: option name, including the ':' character.
1017  * @param value: value, this string is copied if needed, or parsed.
1018  * 	The caller owns the value string.
1019  * @return 0 on error (malloc or syntax error).
1020  */
1021 int config_set_option(struct config_file* config, const char* option,
1022 	const char* value);
1023 
1024 /**
1025  * Call print routine for the given option.
1026  * @param cfg: config.
1027  * @param opt: option name without trailing :.
1028  *	This is different from config_set_option.
1029  * @param func: print func, called as (str, arg) for every data element.
1030  * @param arg: user argument for print func.
1031  * @return false if the option name is not supported (syntax error).
1032  */
1033 int config_get_option(struct config_file* cfg, const char* opt,
1034 	void (*func)(char*,void*), void* arg);
1035 
1036 /**
1037  * Get an option and return strlist
1038  * @param cfg: config file
1039  * @param opt: option name.
1040  * @param list: list is returned here. malloced, caller must free it.
1041  * @return 0=OK, 1=syntax error, 2=malloc failed.
1042  */
1043 int config_get_option_list(struct config_file* cfg, const char* opt,
1044 	struct config_strlist** list);
1045 
1046 /**
1047  * Get an option and collate results into string
1048  * @param cfg: config file
1049  * @param opt: option name.
1050  * @param str: string. malloced, caller must free it.
1051  * @return 0=OK, 1=syntax error, 2=malloc failed.
1052  */
1053 int config_get_option_collate(struct config_file* cfg, const char* opt,
1054 	char** str);
1055 
1056 /**
1057  * function to print to a file, use as func with config_get_option.
1058  * @param line: text to print. \n appended.
1059  * @param arg: pass a FILE*, like stdout.
1060  */
1061 void config_print_func(char* line, void* arg);
1062 
1063 /**
1064  * function to collate the text strings into a strlist_head.
1065  * @param line: text to append.
1066  * @param arg: pass a strlist_head structure. zeroed on start.
1067  */
1068 void config_collate_func(char* line, void* arg);
1069 
1070 /**
1071  * take a strlist_head list and return a malloc string. separated with newline.
1072  * @param list: strlist first to collate. zeroes return "".
1073  * @return NULL on malloc failure. Or if malloc failure happened in strlist.
1074  */
1075 char* config_collate_cat(struct config_strlist* list);
1076 
1077 /**
1078  * Append text at end of list.
1079  * @param list: list head. zeroed at start.
1080  * @param item: new item. malloced by caller. if NULL the insertion fails.
1081  * @return true on success.
1082  * on fail the item is free()ed.
1083  */
1084 int cfg_strlist_append(struct config_strlist_head* list, char* item);
1085 
1086 /**
1087  * Searches the end of a string list and appends the given text.
1088  * @param head: pointer to strlist head variable.
1089  * @param item: new item. malloced by caller. if NULL the insertion fails.
1090  * @return true on success.
1091  */
1092 int cfg_strlist_append_ex(struct config_strlist** head, char* item);
1093 
1094 /**
1095  * Find string in strlist.
1096  * @param head: pointer to strlist head variable.
1097  * @param item: the item to search for.
1098  * @return: the element in the list when found, NULL otherwise.
1099  */
1100 struct config_strlist* cfg_strlist_find(struct config_strlist* head,
1101 	const char* item);
1102 
1103 /**
1104  * Insert string into strlist.
1105  * @param head: pointer to strlist head variable.
1106  * @param item: new item. malloced by caller. If NULL the insertion fails.
1107  * @return: true on success.
1108  * on fail, the item is free()d.
1109  */
1110 int cfg_strlist_insert(struct config_strlist** head, char* item);
1111 
1112 /** insert with region for allocation. */
1113 int cfg_region_strlist_insert(struct regional* region,
1114 	struct config_strlist** head, char* item);
1115 
1116 /**
1117  * Insert string into str2list.
1118  * @param head: pointer to str2list head variable.
1119  * @param item: new item. malloced by caller. If NULL the insertion fails.
1120  * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
1121  * @return: true on success.
1122  * on fail, the item and i2 are free()d.
1123  */
1124 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);
1125 
1126 /**
1127  * Insert string into str3list.
1128  * @param head: pointer to str3list head variable.
1129  * @param item: new item. malloced by caller. If NULL the insertion fails.
1130  * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
1131  * @param i3: 3rd string, malloced by caller. If NULL the insertion fails.
1132  * @return: true on success.
1133  */
1134 int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2,
1135 	char* i3);
1136 
1137 /**
1138  * Insert string into strbytelist.
1139  * @param head: pointer to strbytelist head variable.
1140  * @param item: new item. malloced by caller. If NULL the insertion fails.
1141  * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
1142  * @param i2len: length of the i2 bytestring.
1143  * @return: true on success.
1144  */
1145 int cfg_strbytelist_insert(struct config_strbytelist** head, char* item,
1146 	uint8_t* i2, size_t i2len);
1147 
1148 /**
1149  * Find stub in config list, also returns prevptr (for deletion).
1150  * @param pp: call routine with pointer to a pointer to the start of the list,
1151  * 	if the stub is found, on exit, the value contains a pointer to the
1152  * 	next pointer that points to the found element (or to the list start
1153  * 	pointer if it is the first element).
1154  * @param nm: name of stub to find.
1155  * @return: pointer to config_stub if found, or NULL if not found.
1156  */
1157 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm);
1158 
1159 /**
1160  * Delete items in config string list.
1161  * @param list: list.
1162  */
1163 void config_delstrlist(struct config_strlist* list);
1164 
1165 /**
1166  * Delete items in config double string list.
1167  * @param list: list.
1168  */
1169 void config_deldblstrlist(struct config_str2list* list);
1170 
1171 /**
1172  * Delete items in config triple string list.
1173  * @param list: list.
1174  */
1175 void config_deltrplstrlist(struct config_str3list* list);
1176 
1177 /** delete string array */
1178 void config_del_strarray(char** array, int num);
1179 
1180 /** delete stringbytelist */
1181 void config_del_strbytelist(struct config_strbytelist* list);
1182 
1183 /**
1184  * Delete a stub item
1185  * @param p: stub item
1186  */
1187 void config_delstub(struct config_stub* p);
1188 
1189 /**
1190  * Delete items in config stub list.
1191  * @param list: list.
1192  */
1193 void config_delstubs(struct config_stub* list);
1194 
1195 /**
1196  * Delete an auth item
1197  * @param p: auth item
1198  */
1199 void config_delauth(struct config_auth* p);
1200 
1201 /**
1202  * Delete items in config auth list.
1203  * @param list: list.
1204  */
1205 void config_delauths(struct config_auth* list);
1206 
1207 /**
1208  * Delete a view item
1209  * @param p: view item
1210  */
1211 void config_delview(struct config_view* p);
1212 
1213 /**
1214  * Delete items in config view list.
1215  * @param list: list.
1216  */
1217 void config_delviews(struct config_view* list);
1218 
1219 /** check if config for remote control turns on IP-address interface
1220  * with certificates or a named pipe without certificates. */
1221 int options_remote_is_address(struct config_file* cfg);
1222 
1223 /**
1224  * Convert 14digit to time value
1225  * @param str: string of 14 digits
1226  * @return time value or 0 for error.
1227  */
1228 time_t cfg_convert_timeval(const char* str);
1229 
1230 /**
1231  * Count number of values in the string.
1232  * format ::= (sp num)+ sp
1233  * num ::= [-](0-9)+
1234  * sp ::= (space|tab)*
1235  *
1236  * @param str: string
1237  * @return: 0 on parse error, or empty string, else
1238  *	number of integer values in the string.
1239  */
1240 int cfg_count_numbers(const char* str);
1241 
1242 /**
1243  * Convert a 'nice' memory or file size into a bytecount
1244  * From '100k' to 102400. and so on. Understands kKmMgG.
1245  * k=1024, m=1024*1024, g=1024*1024*1024.
1246  * @param str: string
1247  * @param res: result is stored here, size in bytes.
1248  * @return: true if parsed correctly, or 0 on a parse error (and an error
1249  * is logged).
1250  */
1251 int cfg_parse_memsize(const char* str, size_t* res);
1252 
1253 /**
1254  * Parse nsid from string into binary nsid. nsid is either a hexadecimal
1255  * string or an ascii string prepended with ascii_ in which case the
1256  * characters after ascii_ are simply copied.
1257  * @param str: the string to parse.
1258  * @param nsid_len: returns length of nsid in bytes.
1259  * @return malloced bytes or NULL on parse error or malloc failure.
1260  */
1261 uint8_t* cfg_parse_nsid(const char* str, uint16_t* nsid_len);
1262 
1263 /**
1264  * Add a tag name to the config.  It is added at the end with a new ID value.
1265  * @param cfg: the config structure.
1266  * @param tag: string (which is copied) with the name.
1267  * @return: false on alloc failure.
1268  */
1269 int config_add_tag(struct config_file* cfg, const char* tag);
1270 
1271 /**
1272  * Find tag ID in the tag list.
1273  * @param cfg: the config structure.
1274  * @param tag: string with tag name to search for.
1275  * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found.
1276  */
1277 int find_tag_id(struct config_file* cfg, const char* tag);
1278 
1279 /**
1280  * parse taglist from string into bytestring with bitlist.
1281  * @param cfg: the config structure (with tagnames)
1282  * @param str: the string to parse.  Parse puts 0 bytes in string.
1283  * @param listlen: returns length of in bytes.
1284  * @return malloced bytes with a bitlist of the tags.  or NULL on parse error
1285  * or malloc failure.
1286  */
1287 uint8_t* config_parse_taglist(struct config_file* cfg, char* str,
1288 	size_t* listlen);
1289 
1290 /**
1291  * convert tag bitlist to a malloced string with tag names.  For debug output.
1292  * @param cfg: the config structure (with tagnames)
1293  * @param taglist: the tag bitlist.
1294  * @param len: length of the tag bitlist.
1295  * @return malloced string or NULL.
1296  */
1297 char* config_taglist2str(struct config_file* cfg, uint8_t* taglist,
1298 	size_t len);
1299 
1300 /**
1301  * see if two taglists intersect (have tags in common).
1302  * @param list1: first tag bitlist.
1303  * @param list1len: length in bytes of first list.
1304  * @param list2: second tag bitlist.
1305  * @param list2len: length in bytes of second list.
1306  * @return true if there are tags in common, 0 if not.
1307  */
1308 int taglist_intersect(uint8_t* list1, size_t list1len, const uint8_t* list2,
1309 	size_t list2len);
1310 
1311 /**
1312  * Parse local-zone directive into two strings and register it in the config.
1313  * @param cfg: to put it in.
1314  * @param val: argument strings to local-zone, "example.com nodefault".
1315  * @return: false on failure
1316  */
1317 int cfg_parse_local_zone(struct config_file* cfg, const char* val);
1318 
1319 /**
1320  * Mark "number" or "low-high" as available or not in ports array.
1321  * @param str: string in input
1322  * @param allow: give true if this range is permitted.
1323  * @param avail: the array from cfg.
1324  * @param num: size of the array (65536).
1325  * @return: true if parsed correctly, or 0 on a parse error (and an error
1326  * is logged).
1327  */
1328 int cfg_mark_ports(const char* str, int allow, int* avail, int num);
1329 
1330 /**
1331  * Get a condensed list of ports returned. allocated.
1332  * @param cfg: config file.
1333  * @param avail: the available ports array is returned here.
1334  * @return: number of ports in array or 0 on error.
1335  */
1336 int cfg_condense_ports(struct config_file* cfg, int** avail);
1337 
1338 /**
1339  * Apply system specific port range policy.
1340  * @param cfg: config file.
1341  * @param num: size of the array (65536).
1342  */
1343 void cfg_apply_local_port_policy(struct config_file* cfg, int num);
1344 
1345 /**
1346  * Scan ports available
1347  * @param avail: the array from cfg.
1348  * @param num: size of the array (65536).
1349  * @return the number of ports available for use.
1350  */
1351 int cfg_scan_ports(int* avail, int num);
1352 
1353 /**
1354  * Convert a filename to full pathname in original filesys
1355  * @param fname: the path name to convert.
1356  *      Must not be null or empty.
1357  * @param cfg: config struct for chroot and chdir (if set).
1358  * @param use_chdir: if false, only chroot is applied.
1359  * @return pointer to malloced buffer which is: [chroot][chdir]fname
1360  *      or NULL on malloc failure.
1361  */
1362 char* fname_after_chroot(const char* fname, struct config_file* cfg,
1363 	int use_chdir);
1364 
1365 /**
1366  * Convert a ptr shorthand into a full reverse-notation PTR record.
1367  * @param str: input string, "IP name"
1368  * @return: malloced string "reversed-ip-name PTR name"
1369  */
1370 char* cfg_ptr_reverse(char* str);
1371 
1372 /**
1373  * Used during options parsing
1374  */
1375 struct config_parser_state {
1376 	/** name of file being parser */
1377 	char* filename;
1378 	/** line number in the file, starts at 1 */
1379 	int line;
1380 	/** number of errors encountered */
1381 	int errors;
1382 	/** the result of parsing is stored here. */
1383 	struct config_file* cfg;
1384 	/** the current chroot dir (or NULL if none) */
1385 	const char* chroot;
1386 	/** if we are started in a toplevel, or not, after a force_toplevel */
1387 	int started_toplevel;
1388 };
1389 
1390 /** global config parser object used during config parsing */
1391 extern struct config_parser_state* cfg_parser;
1392 /** init lex state */
1393 void init_cfg_parse(void);
1394 /** lex in file */
1395 extern FILE* ub_c_in;
1396 /** lex out file */
1397 extern FILE* ub_c_out;
1398 /** the yacc lex generated parse function */
1399 int ub_c_parse(void);
1400 /** the lexer function */
1401 int ub_c_lex(void);
1402 /** wrap function */
1403 int ub_c_wrap(void);
1404 /** parsing helpers: print error with file and line numbers */
1405 void ub_c_error(const char* msg);
1406 /** parsing helpers: print error with file and line numbers */
1407 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
1408 
1409 #ifdef UB_ON_WINDOWS
1410 /**
1411  * Obtain registry string (if it exists).
1412  * @param key: key string
1413  * @param name: name of value to fetch.
1414  * @return malloced string with the result or NULL if it did not
1415  * 	exist on an error (logged with log_err) was encountered.
1416  */
1417 char* w_lookup_reg_str(const char* key, const char* name);
1418 
1419 /** Modify directory in options for module file name */
1420 void w_config_adjust_directory(struct config_file* cfg);
1421 #endif /* UB_ON_WINDOWS */
1422 
1423 /** debug option for unit tests. */
1424 extern int fake_dsa, fake_sha1;
1425 
1426 /** Return true if interface will listen to specific port(s).
1427  * @param ifname: the interface as configured in the configuration file.
1428  * @param default_port: the default port to use as the interface port if ifname
1429  *	does not include a port via the '@' notation.
1430  * @param port: port to check for, if 0 it will not be checked.
1431  * @param additional_ports: additional configured ports, if any (nonNULL) to
1432  *	be checked against.
1433  * @return true if one of (port, additional_ports) matches the interface port.
1434  */
1435 int if_listens_on(const char* ifname, int default_port, int port,
1436 	struct config_strlist* additional_ports);
1437 
1438 /** see if interface will listen on https;
1439  *  its port number == the https port number */
1440 int if_is_https(const char* ifname, int default_port, int https_port);
1441 
1442 /** see if interface will listen on ssl;
1443  *  its port number == the ssl port number or any of the additional ports */
1444 int if_is_ssl(const char* ifname, int default_port, int ssl_port,
1445 	struct config_strlist* tls_additional_port);
1446 
1447 /** see if interface will listen on PROXYv2;
1448  *  its port number == any of the proxy ports number */
1449 int if_is_pp2(const char* ifname, int default_port,
1450 	struct config_strlist* proxy_protocol_port);
1451 
1452 /** see if interface will listen on DNSCRYPT;
1453  *  its port number == the dnscrypt port number */
1454 int if_is_dnscrypt(const char* ifname, int default_port, int dnscrypt_port);
1455 
1456 /** see if interface will listen on quic;
1457  *  its port number == the quic port number */
1458 int if_is_quic(const char* ifname, int default_port, int quic_port);
1459 
1460 /**
1461  * Return true if the config contains settings that enable https.
1462  * @param cfg: config information.
1463  * @return true if https ports are used for server.
1464  */
1465 int cfg_has_https(struct config_file* cfg);
1466 
1467 /**
1468  * Return true if the config contains settings that enable quic.
1469  * @param cfg: config information.
1470  * @return true if quic ports are used for server.
1471  */
1472 int cfg_has_quic(struct config_file* cfg);
1473 
1474 #ifdef USE_LINUX_IP_LOCAL_PORT_RANGE
1475 #define LINUX_IP_LOCAL_PORT_RANGE_PATH "/proc/sys/net/ipv4/ip_local_port_range"
1476 #endif
1477 
1478 /** get memory for string */
1479 size_t getmem_str(char* str);
1480 
1481 #endif /* UTIL_CONFIG_FILE_H */
1482