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