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