1933707f3Ssthen /* 2933707f3Ssthen * util/config_file.h - reads and stores the config file for unbound. 3933707f3Ssthen * 4933707f3Ssthen * Copyright (c) 2007, NLnet Labs. All rights reserved. 5933707f3Ssthen * 6933707f3Ssthen * This software is open source. 7933707f3Ssthen * 8933707f3Ssthen * Redistribution and use in source and binary forms, with or without 9933707f3Ssthen * modification, are permitted provided that the following conditions 10933707f3Ssthen * are met: 11933707f3Ssthen * 12933707f3Ssthen * Redistributions of source code must retain the above copyright notice, 13933707f3Ssthen * this list of conditions and the following disclaimer. 14933707f3Ssthen * 15933707f3Ssthen * Redistributions in binary form must reproduce the above copyright notice, 16933707f3Ssthen * this list of conditions and the following disclaimer in the documentation 17933707f3Ssthen * and/or other materials provided with the distribution. 18933707f3Ssthen * 19933707f3Ssthen * Neither the name of the NLNET LABS nor the names of its contributors may 20933707f3Ssthen * be used to endorse or promote products derived from this software without 21933707f3Ssthen * specific prior written permission. 22933707f3Ssthen * 23933707f3Ssthen * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 245d76a658Ssthen * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 255d76a658Ssthen * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 265d76a658Ssthen * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 275d76a658Ssthen * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 285d76a658Ssthen * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 295d76a658Ssthen * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 305d76a658Ssthen * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 315d76a658Ssthen * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 325d76a658Ssthen * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 335d76a658Ssthen * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34933707f3Ssthen */ 35933707f3Ssthen 36933707f3Ssthen /** 37933707f3Ssthen * \file 38933707f3Ssthen * 39933707f3Ssthen * This file contains functions for the config file. 40933707f3Ssthen */ 41933707f3Ssthen 42933707f3Ssthen #ifndef UTIL_CONFIG_FILE_H 43933707f3Ssthen #define UTIL_CONFIG_FILE_H 440bdb4f62Ssthen #include "sldns/rrdef.h" 45933707f3Ssthen struct config_stub; 46bdfc4d55Sflorian struct config_auth; 4777079be7Ssthen struct config_view; 48933707f3Ssthen struct config_strlist; 49933707f3Ssthen struct config_str2list; 5077079be7Ssthen struct config_str3list; 512ee382b6Ssthen struct config_strbytelist; 52933707f3Ssthen struct module_qstate; 53933707f3Ssthen struct sock_list; 54933707f3Ssthen struct ub_packed_rrset_key; 5577079be7Ssthen struct regional; 56933707f3Ssthen 5720237c55Ssthen /** List head for strlist processing, used for append operation. */ 5820237c55Ssthen struct config_strlist_head { 5920237c55Ssthen /** first in list of text items */ 6020237c55Ssthen struct config_strlist* first; 6120237c55Ssthen /** last in list of text items */ 6220237c55Ssthen struct config_strlist* last; 6320237c55Ssthen }; 6420237c55Ssthen 65933707f3Ssthen /** 66933707f3Ssthen * The configuration options. 67933707f3Ssthen * Strings are malloced. 68933707f3Ssthen */ 69933707f3Ssthen struct config_file { 70933707f3Ssthen /** verbosity level as specified in the config file */ 71933707f3Ssthen int verbosity; 72933707f3Ssthen 73933707f3Ssthen /** statistics interval (in seconds) */ 74933707f3Ssthen int stat_interval; 75933707f3Ssthen /** if false, statistics values are reset after printing them */ 76933707f3Ssthen int stat_cumulative; 77933707f3Ssthen /** if true, the statistics are kept in greater detail */ 78933707f3Ssthen int stat_extended; 798b7325afSsthen /** if true, inhibits a lot of =0 lines from the extended stats output */ 808b7325afSsthen int stat_inhibit_zero; 81933707f3Ssthen 82933707f3Ssthen /** number of threads to create */ 83933707f3Ssthen int num_threads; 84933707f3Ssthen 85933707f3Ssthen /** port on which queries are answered. */ 86933707f3Ssthen int port; 87933707f3Ssthen /** do ip4 query support. */ 88933707f3Ssthen int do_ip4; 89933707f3Ssthen /** do ip6 query support. */ 90933707f3Ssthen int do_ip6; 918b7325afSsthen /** do nat64 on queries */ 928b7325afSsthen int do_nat64; 93a3167c07Ssthen /** prefer ip4 upstream queries. */ 94a3167c07Ssthen int prefer_ip4; 9577079be7Ssthen /** prefer ip6 upstream queries. */ 9677079be7Ssthen int prefer_ip6; 97933707f3Ssthen /** do udp query support. */ 98933707f3Ssthen int do_udp; 99933707f3Ssthen /** do tcp query support. */ 100933707f3Ssthen int do_tcp; 101191f22c6Ssthen /** max number of queries on a reuse connection. */ 102191f22c6Ssthen size_t max_reuse_tcp_queries; 103191f22c6Ssthen /** timeout for REUSE entries in milliseconds. */ 104191f22c6Ssthen int tcp_reuse_timeout; 105191f22c6Ssthen /** timeout in milliseconds for TCP queries to auth servers. */ 106191f22c6Ssthen int tcp_auth_query_timeout; 107933707f3Ssthen /** tcp upstream queries (no UDP upstream queries) */ 108933707f3Ssthen int tcp_upstream; 109bdfc4d55Sflorian /** udp upstream enabled when no UDP downstream is enabled (do_udp no)*/ 110bdfc4d55Sflorian int udp_upstream_without_downstream; 11132e31f52Ssthen /** maximum segment size of tcp socket which queries are answered */ 11232e31f52Ssthen int tcp_mss; 11332e31f52Ssthen /** maximum segment size of tcp socket for outgoing queries */ 11432e31f52Ssthen int outgoing_tcp_mss; 1152308e98cSsthen /** tcp idle timeout, in msec */ 1162308e98cSsthen int tcp_idle_timeout; 1172308e98cSsthen /** do edns tcp keepalive */ 1182308e98cSsthen int do_tcp_keepalive; 1192308e98cSsthen /** tcp keepalive timeout, in msec */ 1202308e98cSsthen int tcp_keepalive_timeout; 1218b7325afSsthen /** timeout of packets sitting in the socket queue */ 1228b7325afSsthen int sock_queue_timeout; 12345872187Ssthen /** proxy protocol ports */ 12445872187Ssthen struct config_strlist* proxy_protocol_port; 125933707f3Ssthen 126933707f3Ssthen /** private key file for dnstcp-ssl service (enabled if not NULL) */ 127933707f3Ssthen char* ssl_service_key; 128933707f3Ssthen /** public key file for dnstcp-ssl service */ 129933707f3Ssthen char* ssl_service_pem; 130933707f3Ssthen /** port on which to provide ssl service */ 131933707f3Ssthen int ssl_port; 132933707f3Ssthen /** if outgoing tcp connections use SSL */ 133933707f3Ssthen int ssl_upstream; 134938a3a5eSflorian /** cert bundle for outgoing connections */ 135938a3a5eSflorian char* tls_cert_bundle; 13620237c55Ssthen /** should the system certificate store get added to the cert bundle */ 13720237c55Ssthen int tls_win_cert; 13820237c55Ssthen /** additional tls ports */ 13920237c55Ssthen struct config_strlist* tls_additional_port; 140f6b99bafSsthen /** secret key used to encrypt and decrypt TLS session ticket */ 141f6b99bafSsthen struct config_strlist_head tls_session_ticket_keys; 142f6b99bafSsthen /** TLS ciphers */ 143f6b99bafSsthen char* tls_ciphers; 144f6b99bafSsthen /** TLS chiphersuites (TLSv1.3) */ 145f6b99bafSsthen char* tls_ciphersuites; 146a3167c07Ssthen /** if SNI is to be used */ 147a3167c07Ssthen int tls_use_sni; 148933707f3Ssthen 1492c144df0Ssthen /** port on which to provide DNS over HTTPS service */ 1502c144df0Ssthen int https_port; 1512c144df0Ssthen /** endpoint for HTTP service */ 1522c144df0Ssthen char* http_endpoint; 1532c144df0Ssthen /** MAX_CONCURRENT_STREAMS HTTP/2 setting */ 1542c144df0Ssthen uint32_t http_max_streams; 1552c144df0Ssthen /** maximum size of all HTTP2 query buffers combined. */ 1562c144df0Ssthen size_t http_query_buffer_size; 1572c144df0Ssthen /** maximum size of all HTTP2 response buffers combined. */ 1582c144df0Ssthen size_t http_response_buffer_size; 1592c144df0Ssthen /** set TCP_NODELAY option for http sockets */ 1602c144df0Ssthen int http_nodelay; 161eba819a2Ssthen /** Disable TLS for http sockets downstream */ 162eba819a2Ssthen int http_notls_downstream; 1632c144df0Ssthen 164933707f3Ssthen /** outgoing port range number of ports (per thread) */ 165933707f3Ssthen int outgoing_num_ports; 166933707f3Ssthen /** number of outgoing tcp buffers per (per thread) */ 167933707f3Ssthen size_t outgoing_num_tcp; 168933707f3Ssthen /** number of incoming tcp buffers per (per thread) */ 169933707f3Ssthen size_t incoming_num_tcp; 170933707f3Ssthen /** allowed udp port numbers, array with 0 if not allowed */ 171933707f3Ssthen int* outgoing_avail_ports; 172933707f3Ssthen 173933707f3Ssthen /** EDNS buffer size to use */ 174933707f3Ssthen size_t edns_buffer_size; 175f6b99bafSsthen /** size of the stream wait buffers, max */ 176f6b99bafSsthen size_t stream_wait_size; 177933707f3Ssthen /** number of bytes buffer size for DNS messages */ 178933707f3Ssthen size_t msg_buffer_size; 179933707f3Ssthen /** size of the message cache */ 180933707f3Ssthen size_t msg_cache_size; 181933707f3Ssthen /** slabs in the message cache. */ 182933707f3Ssthen size_t msg_cache_slabs; 183933707f3Ssthen /** number of queries every thread can service */ 184933707f3Ssthen size_t num_queries_per_thread; 185933707f3Ssthen /** number of msec to wait before items can be jostled out */ 186933707f3Ssthen size_t jostle_time; 187933707f3Ssthen /** size of the rrset cache */ 188933707f3Ssthen size_t rrset_cache_size; 189933707f3Ssthen /** slabs in the rrset cache */ 190933707f3Ssthen size_t rrset_cache_slabs; 191933707f3Ssthen /** host cache ttl in seconds */ 192933707f3Ssthen int host_ttl; 193933707f3Ssthen /** number of slabs in the infra host cache */ 194933707f3Ssthen size_t infra_cache_slabs; 195933707f3Ssthen /** max number of hosts in the infra cache */ 196933707f3Ssthen size_t infra_cache_numhosts; 197d1e2768aSsthen /** min value for infra cache rtt (min retransmit timeout) */ 198b2cdf21fSsthen int infra_cache_min_rtt; 199d1e2768aSsthen /** max value for infra cache rtt (max retransmit timeout) */ 200d1e2768aSsthen int infra_cache_max_rtt; 201eba819a2Ssthen /** keep probing hosts that are down */ 202eba819a2Ssthen int infra_keep_probing; 2035d76a658Ssthen /** delay close of udp-timeouted ports, if 0 no delayclose. in msec */ 2045d76a658Ssthen int delay_close; 205eba819a2Ssthen /** udp_connect enable uses UDP connect to mitigate ICMP side channel */ 206eba819a2Ssthen int udp_connect; 207933707f3Ssthen 208933707f3Ssthen /** the target fetch policy for the iterator */ 209933707f3Ssthen char* target_fetch_policy; 2103150e5f6Ssthen /** percent*10, how many times in 1000 to pick from the fastest 2113150e5f6Ssthen * destinations */ 2123150e5f6Ssthen int fast_server_permil; 2133150e5f6Ssthen /** number of fastest server to select from */ 2143150e5f6Ssthen size_t fast_server_num; 215933707f3Ssthen 216933707f3Ssthen /** automatic interface for incoming messages. Uses ipv6 remapping, 217933707f3Ssthen * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */ 218933707f3Ssthen int if_automatic; 2190bdb4f62Ssthen /** extra ports to open if if_automatic enabled, or NULL for default */ 2200bdb4f62Ssthen char* if_automatic_ports; 221933707f3Ssthen /** SO_RCVBUF size to set on port 53 UDP socket */ 222933707f3Ssthen size_t so_rcvbuf; 223933707f3Ssthen /** SO_SNDBUF size to set on port 53 UDP socket */ 224933707f3Ssthen size_t so_sndbuf; 2255d76a658Ssthen /** SO_REUSEPORT requested on port 53 sockets */ 2265d76a658Ssthen int so_reuseport; 227a58bff56Ssthen /** IP_TRANSPARENT socket option requested on port 53 sockets */ 228a58bff56Ssthen int ip_transparent; 2292ee382b6Ssthen /** IP_FREEBIND socket option request on port 53 sockets */ 2302ee382b6Ssthen int ip_freebind; 231a3167c07Ssthen /** IP_TOS socket option requested on port 53 sockets */ 232a3167c07Ssthen int ip_dscp; 233933707f3Ssthen 234933707f3Ssthen /** number of interfaces to open. If 0 default all interfaces. */ 235933707f3Ssthen int num_ifs; 236933707f3Ssthen /** interface description strings (IP addresses) */ 237933707f3Ssthen char **ifs; 238933707f3Ssthen 239933707f3Ssthen /** number of outgoing interfaces to open. 240933707f3Ssthen * If 0 default all interfaces. */ 241933707f3Ssthen int num_out_ifs; 242933707f3Ssthen /** outgoing interface description strings (IP addresses) */ 243933707f3Ssthen char **out_ifs; 244933707f3Ssthen 245933707f3Ssthen /** the root hints */ 246933707f3Ssthen struct config_strlist* root_hints; 247933707f3Ssthen /** the stub definitions, linked list */ 248933707f3Ssthen struct config_stub* stubs; 249933707f3Ssthen /** the forward zone definitions, linked list */ 250933707f3Ssthen struct config_stub* forwards; 251bdfc4d55Sflorian /** the auth zone definitions, linked list */ 252bdfc4d55Sflorian struct config_auth* auths; 25377079be7Ssthen /** the views definitions, linked list */ 25477079be7Ssthen struct config_view* views; 255933707f3Ssthen /** list of donotquery addresses, linked list */ 256933707f3Ssthen struct config_strlist* donotqueryaddrs; 2572be9e038Ssthen #ifdef CLIENT_SUBNET 2582be9e038Ssthen /** list of servers we send edns-client-subnet option to and 2592be9e038Ssthen * accept option from, linked list */ 2602be9e038Ssthen struct config_strlist* client_subnet; 2612be9e038Ssthen /** list of zones we send edns-client-subnet option for */ 2622be9e038Ssthen struct config_strlist* client_subnet_zone; 2632be9e038Ssthen /** opcode assigned by IANA for edns0-client-subnet option */ 2642be9e038Ssthen uint16_t client_subnet_opcode; 2652be9e038Ssthen /** Do not check whitelist if incoming query contains an ECS record */ 2662be9e038Ssthen int client_subnet_always_forward; 2672be9e038Ssthen /** Subnet length we are willing to give up privacy for */ 2682be9e038Ssthen uint8_t max_client_subnet_ipv4; 2692be9e038Ssthen uint8_t max_client_subnet_ipv6; 2703150e5f6Ssthen /** Minimum subnet length we are willing to answer */ 2713150e5f6Ssthen uint8_t min_client_subnet_ipv4; 2723150e5f6Ssthen uint8_t min_client_subnet_ipv6; 2733150e5f6Ssthen /** Max number of nodes in the ECS radix tree */ 2743150e5f6Ssthen uint32_t max_ecs_tree_size_ipv4; 2753150e5f6Ssthen uint32_t max_ecs_tree_size_ipv6; 2762be9e038Ssthen #endif 277933707f3Ssthen /** list of access control entries, linked list */ 278933707f3Ssthen struct config_str2list* acls; 279933707f3Ssthen /** use default localhost donotqueryaddr entries */ 280933707f3Ssthen int donotquery_localhost; 281933707f3Ssthen 2822308e98cSsthen /** list of tcp connection limitss, linked list */ 2832308e98cSsthen struct config_str2list* tcp_connection_limits; 2842308e98cSsthen 285933707f3Ssthen /** harden against very small edns buffer sizes */ 286933707f3Ssthen int harden_short_bufsize; 287933707f3Ssthen /** harden against very large query sizes */ 288933707f3Ssthen int harden_large_queries; 289933707f3Ssthen /** harden against spoofed glue (out of zone data) */ 290933707f3Ssthen int harden_glue; 291933707f3Ssthen /** harden against receiving no DNSSEC data for trust anchor */ 292933707f3Ssthen int harden_dnssec_stripped; 293933707f3Ssthen /** harden against queries that fall under known nxdomain names */ 294933707f3Ssthen int harden_below_nxdomain; 295933707f3Ssthen /** harden the referral path, query for NS,A,AAAA and validate */ 296933707f3Ssthen int harden_referral_path; 297a58bff56Ssthen /** harden against algorithm downgrade */ 298a58bff56Ssthen int harden_algo_downgrade; 2998b7325afSsthen /** harden against unknown records in the authority section and in 3008b7325afSsthen * the additional section */ 3018b7325afSsthen int harden_unknown_additional; 302933707f3Ssthen /** use 0x20 bits in query as random ID bits */ 303933707f3Ssthen int use_caps_bits_for_id; 304a58bff56Ssthen /** 0x20 whitelist, domains that do not use capsforid */ 305a58bff56Ssthen struct config_strlist* caps_whitelist; 306933707f3Ssthen /** strip away these private addrs from answers, no DNS Rebinding */ 307933707f3Ssthen struct config_strlist* private_address; 308933707f3Ssthen /** allow domain (and subdomains) to use private address space */ 309933707f3Ssthen struct config_strlist* private_domain; 310933707f3Ssthen /** what threshold for unwanted action. */ 311933707f3Ssthen size_t unwanted_threshold; 312933707f3Ssthen /** the number of seconds maximal TTL used for RRsets and messages */ 313933707f3Ssthen int max_ttl; 314933707f3Ssthen /** the number of seconds minimum TTL used for RRsets and messages */ 315933707f3Ssthen int min_ttl; 316a58bff56Ssthen /** the number of seconds maximal negative TTL for SOA in auth */ 317a58bff56Ssthen int max_negative_ttl; 3182bdc0ed1Ssthen /** the number of seconds minimal negative TTL for SOA in auth */ 3192bdc0ed1Ssthen int min_negative_ttl; 320933707f3Ssthen /** if prefetching of messages should be performed. */ 321933707f3Ssthen int prefetch; 322933707f3Ssthen /** if prefetching of DNSKEYs should be performed. */ 323933707f3Ssthen int prefetch_key; 3243150e5f6Ssthen /** deny queries of type ANY with an empty answer */ 3253150e5f6Ssthen int deny_any; 326933707f3Ssthen 327933707f3Ssthen /** chrootdir, if not "" or chroot will be done */ 328933707f3Ssthen char* chrootdir; 329933707f3Ssthen /** username to change to, if not "". */ 330933707f3Ssthen char* username; 331933707f3Ssthen /** working directory */ 332933707f3Ssthen char* directory; 333933707f3Ssthen /** filename to log to. */ 334933707f3Ssthen char* logfile; 335933707f3Ssthen /** pidfile to write pid to. */ 336933707f3Ssthen char* pidfile; 337933707f3Ssthen 338933707f3Ssthen /** should log messages be sent to syslogd */ 339933707f3Ssthen int use_syslog; 340933707f3Ssthen /** log timestamp in ascii UTC */ 341933707f3Ssthen int log_time_ascii; 342933707f3Ssthen /** log queries with one line per query */ 343933707f3Ssthen int log_queries; 34477079be7Ssthen /** log replies with one line per reply */ 34577079be7Ssthen int log_replies; 346f6b99bafSsthen /** tag log_queries and log_replies for filtering */ 347f6b99bafSsthen int log_tag_queryreply; 3482308e98cSsthen /** log every local-zone hit **/ 3492308e98cSsthen int log_local_actions; 3502308e98cSsthen /** log servfails with a reason */ 3512308e98cSsthen int log_servfail; 35277079be7Ssthen /** log identity to report */ 35377079be7Ssthen char* log_identity; 354f46c52bfSsthen /** log dest addr for log_replies */ 355f46c52bfSsthen int log_destaddr; 356933707f3Ssthen 357933707f3Ssthen /** do not report identity (id.server, hostname.bind) */ 358933707f3Ssthen int hide_identity; 359933707f3Ssthen /** do not report version (version.server, version.bind) */ 360933707f3Ssthen int hide_version; 3612be9e038Ssthen /** do not report trustanchor (trustanchor.unbound) */ 3622be9e038Ssthen int hide_trustanchor; 363191f22c6Ssthen /** do not report the User-Agent HTTP header */ 364191f22c6Ssthen int hide_http_user_agent; 365933707f3Ssthen /** identity, hostname is returned if "". */ 366933707f3Ssthen char* identity; 367933707f3Ssthen /** version, package version returned if "". */ 368933707f3Ssthen char* version; 369191f22c6Ssthen /** User-Agent for HTTP header */ 370191f22c6Ssthen char* http_user_agent; 3719982a05dSsthen /** nsid */ 3729982a05dSsthen char *nsid_cfg_str; 3739982a05dSsthen uint8_t *nsid; 3749982a05dSsthen uint16_t nsid_len; 375933707f3Ssthen 376933707f3Ssthen /** the module configuration string */ 377933707f3Ssthen char* module_conf; 378933707f3Ssthen 379933707f3Ssthen /** files with trusted DS and DNSKEYs in zonefile format, list */ 380933707f3Ssthen struct config_strlist* trust_anchor_file_list; 381933707f3Ssthen /** list of trustanchor keys, linked list */ 382933707f3Ssthen struct config_strlist* trust_anchor_list; 383933707f3Ssthen /** files with 5011 autotrust tracked keys */ 384933707f3Ssthen struct config_strlist* auto_trust_anchor_file_list; 385933707f3Ssthen /** files with trusted DNSKEYs in named.conf format, list */ 386933707f3Ssthen struct config_strlist* trusted_keys_file_list; 387933707f3Ssthen /** insecure domain list */ 388933707f3Ssthen struct config_strlist* domain_insecure; 3892be9e038Ssthen /** send key tag query */ 3902be9e038Ssthen int trust_anchor_signaling; 39120237c55Ssthen /** enable root key sentinel */ 39220237c55Ssthen int root_key_sentinel; 393933707f3Ssthen 394933707f3Ssthen /** if not 0, this value is the validation date for RRSIGs */ 395933707f3Ssthen int32_t val_date_override; 396933707f3Ssthen /** the minimum for signature clock skew */ 397933707f3Ssthen int32_t val_sig_skew_min; 398933707f3Ssthen /** the maximum for signature clock skew */ 399933707f3Ssthen int32_t val_sig_skew_max; 400191f22c6Ssthen /** max number of query restarts, number of IPs to probe */ 401191f22c6Ssthen int32_t val_max_restart; 402933707f3Ssthen /** this value sets the number of seconds before revalidating bogus */ 403933707f3Ssthen int bogus_ttl; 404933707f3Ssthen /** should validator clean additional section for secure msgs */ 405933707f3Ssthen int val_clean_additional; 406933707f3Ssthen /** log bogus messages by the validator */ 407933707f3Ssthen int val_log_level; 408933707f3Ssthen /** squelch val_log_level to log - this is library goes to callback */ 409933707f3Ssthen int val_log_squelch; 410933707f3Ssthen /** should validator allow bogus messages to go through */ 411933707f3Ssthen int val_permissive_mode; 412938a3a5eSflorian /** use cached NSEC records to synthesise (negative) answers */ 413938a3a5eSflorian int aggressive_nsec; 414933707f3Ssthen /** ignore the CD flag in incoming queries and refuse them bogus data */ 415933707f3Ssthen int ignore_cd; 416d896b962Ssthen /** disable EDNS DO flag in outgoing requests */ 417d896b962Ssthen int disable_edns_do; 41877079be7Ssthen /** serve expired entries and prefetch them */ 41977079be7Ssthen int serve_expired; 4202308e98cSsthen /** serve expired entries until TTL after expiration */ 4212308e98cSsthen int serve_expired_ttl; 4222308e98cSsthen /** reset serve expired TTL after failed update attempt */ 4232308e98cSsthen int serve_expired_ttl_reset; 424eaf2578eSsthen /** TTL for the serve expired replies */ 425eaf2578eSsthen int serve_expired_reply_ttl; 426eaf2578eSsthen /** serve expired entries only after trying to update the entries and this 427eaf2578eSsthen * timeout (in milliseconds) is reached */ 428eaf2578eSsthen int serve_expired_client_timeout; 4290bdb4f62Ssthen /** serve EDE code 3 - Stale Answer (RFC8914) for expired entries */ 4300bdb4f62Ssthen int ede_serve_expired; 4319982a05dSsthen /** serve original TTLs rather than decrementing ones */ 4329982a05dSsthen int serve_original_ttl; 433933707f3Ssthen /** nsec3 maximum iterations per key size, string */ 434933707f3Ssthen char* val_nsec3_key_iterations; 435191f22c6Ssthen /** if zonemd failures are permitted, only logged */ 436191f22c6Ssthen int zonemd_permissive_mode; 437933707f3Ssthen /** autotrust add holddown time, in seconds */ 438933707f3Ssthen unsigned int add_holddown; 439933707f3Ssthen /** autotrust del holddown time, in seconds */ 440933707f3Ssthen unsigned int del_holddown; 441933707f3Ssthen /** autotrust keep_missing time, in seconds. 0 is forever. */ 442933707f3Ssthen unsigned int keep_missing; 443a961b961Ssthen /** permit small holddown values, allowing 5011 rollover very fast */ 444a961b961Ssthen int permit_small_holddown; 445933707f3Ssthen 446933707f3Ssthen /** size of the key cache */ 447933707f3Ssthen size_t key_cache_size; 448933707f3Ssthen /** slabs in the key cache. */ 449933707f3Ssthen size_t key_cache_slabs; 450933707f3Ssthen /** size of the neg cache */ 451933707f3Ssthen size_t neg_cache_size; 452933707f3Ssthen 453933707f3Ssthen /** local zones config */ 454933707f3Ssthen struct config_str2list* local_zones; 455933707f3Ssthen /** local zones nodefault list */ 456933707f3Ssthen struct config_strlist* local_zones_nodefault; 4578240c1b9Ssthen #ifdef USE_IPSET 4588240c1b9Ssthen /** local zones ipset list */ 4598240c1b9Ssthen struct config_strlist* local_zones_ipset; 4608240c1b9Ssthen #endif 4612be9e038Ssthen /** do not add any default local zone */ 4622be9e038Ssthen int local_zones_disable_default; 4634bfc71b0Ssthen /** local data RRs configured */ 464933707f3Ssthen struct config_strlist* local_data; 46577079be7Ssthen /** local zone override types per netblock */ 46677079be7Ssthen struct config_str3list* local_zone_overrides; 46732e31f52Ssthen /** unblock lan zones (reverse lookups for AS112 zones) */ 46898f3ca02Sbrad int unblock_lan_zones; 46932e31f52Ssthen /** insecure lan zones (don't validate AS112 zones) */ 47032e31f52Ssthen int insecure_lan_zones; 4712ee382b6Ssthen /** list of zonename, tagbitlist */ 4722ee382b6Ssthen struct config_strbytelist* local_zone_tags; 47377079be7Ssthen /** list of aclname, tagbitlist */ 47477079be7Ssthen struct config_strbytelist* acl_tags; 47577079be7Ssthen /** list of aclname, tagname, localzonetype */ 47677079be7Ssthen struct config_str3list* acl_tag_actions; 47777079be7Ssthen /** list of aclname, tagname, redirectdata */ 47877079be7Ssthen struct config_str3list* acl_tag_datas; 47977079be7Ssthen /** list of aclname, view*/ 48077079be7Ssthen struct config_str2list* acl_view; 48145872187Ssthen /** list of interface action entries, linked list */ 48245872187Ssthen struct config_str2list* interface_actions; 48345872187Ssthen /** list of interface, tagbitlist */ 48445872187Ssthen struct config_strbytelist* interface_tags; 48545872187Ssthen /** list of interface, tagname, localzonetype */ 48645872187Ssthen struct config_str3list* interface_tag_actions; 48745872187Ssthen /** list of interface, tagname, redirectdata */ 48845872187Ssthen struct config_str3list* interface_tag_datas; 48945872187Ssthen /** list of interface, view*/ 49045872187Ssthen struct config_str2list* interface_view; 4912be9e038Ssthen /** list of IP-netblock, tagbitlist */ 4922be9e038Ssthen struct config_strbytelist* respip_tags; 4932be9e038Ssthen /** list of response-driven access control entries, linked list */ 4942be9e038Ssthen struct config_str2list* respip_actions; 4952be9e038Ssthen /** RRs configured for response-driven access controls */ 4962be9e038Ssthen struct config_str2list* respip_data; 4972ee382b6Ssthen /** tag list, array with tagname[i] is malloced string */ 4982ee382b6Ssthen char** tagname; 4992ee382b6Ssthen /** number of items in the taglist */ 5002ee382b6Ssthen int num_tags; 501933707f3Ssthen 502933707f3Ssthen /** remote control section. enable toggle. */ 503933707f3Ssthen int remote_control_enable; 504933707f3Ssthen /** the interfaces the remote control should listen on */ 50520237c55Ssthen struct config_strlist_head control_ifs; 50620237c55Ssthen /** if the use-cert option is set */ 50720237c55Ssthen int control_use_cert; 508933707f3Ssthen /** port number for the control port */ 509933707f3Ssthen int control_port; 510933707f3Ssthen /** private key file for server */ 511933707f3Ssthen char* server_key_file; 512933707f3Ssthen /** certificate file for server */ 513933707f3Ssthen char* server_cert_file; 514933707f3Ssthen /** private key file for unbound-control */ 515933707f3Ssthen char* control_key_file; 516933707f3Ssthen /** certificate file for unbound-control */ 517933707f3Ssthen char* control_cert_file; 518933707f3Ssthen 519933707f3Ssthen /** Python script file */ 5208240c1b9Ssthen struct config_strlist* python_script; 521933707f3Ssthen 522a3167c07Ssthen /** Dynamic library file */ 523a3167c07Ssthen struct config_strlist* dynlib_file; 524a3167c07Ssthen 52577079be7Ssthen /** Use systemd socket activation. */ 52677079be7Ssthen int use_systemd; 52777079be7Ssthen 528933707f3Ssthen /** daemonize, i.e. fork into the background. */ 529933707f3Ssthen int do_daemonize; 530d8d14d0cSsthen 531d8d14d0cSsthen /* minimal response when positive answer */ 532d8d14d0cSsthen int minimal_responses; 533d8d14d0cSsthen 534d8d14d0cSsthen /* RRSet roundrobin */ 535d8d14d0cSsthen int rrset_roundrobin; 536229e174cSsthen 5373150e5f6Ssthen /* wait time for unknown server in msec */ 5383150e5f6Ssthen int unknown_server_time_limit; 5393150e5f6Ssthen 5402bdc0ed1Ssthen /** Wait time to drop recursion replies */ 5412bdc0ed1Ssthen int discard_timeout; 5422bdc0ed1Ssthen 5432bdc0ed1Ssthen /** Wait limit for number of replies per IP address */ 5442bdc0ed1Ssthen int wait_limit; 5452bdc0ed1Ssthen 5462bdc0ed1Ssthen /** Wait limit for number of replies per IP address with cookie */ 5472bdc0ed1Ssthen int wait_limit_cookie; 5482bdc0ed1Ssthen 5492bdc0ed1Ssthen /** wait limit per netblock */ 5502bdc0ed1Ssthen struct config_str2list* wait_limit_netblock; 5512bdc0ed1Ssthen 5522bdc0ed1Ssthen /** wait limit with cookie per netblock */ 5532bdc0ed1Ssthen struct config_str2list* wait_limit_cookie_netblock; 5542bdc0ed1Ssthen 555229e174cSsthen /* maximum UDP response size */ 556229e174cSsthen size_t max_udp_size; 55798f3ca02Sbrad 55898f3ca02Sbrad /* DNS64 prefix */ 55998f3ca02Sbrad char* dns64_prefix; 56098f3ca02Sbrad 56198f3ca02Sbrad /* Synthetize all AAAA record despite the presence of an authoritative one */ 56298f3ca02Sbrad int dns64_synthall; 5632308e98cSsthen /** ignore AAAAs for these domain names and use A record anyway */ 5642308e98cSsthen struct config_strlist* dns64_ignore_aaaa; 56598f3ca02Sbrad 5668b7325afSsthen /* NAT64 prefix; if unset defaults to dns64_prefix */ 5678b7325afSsthen char* nat64_prefix; 5688b7325afSsthen 56998f3ca02Sbrad /** true to enable dnstap support */ 57098f3ca02Sbrad int dnstap; 571a3167c07Ssthen /** using bidirectional frame streams if true */ 572a3167c07Ssthen int dnstap_bidirectional; 57398f3ca02Sbrad /** dnstap socket path */ 57498f3ca02Sbrad char* dnstap_socket_path; 575a3167c07Ssthen /** dnstap IP */ 576a3167c07Ssthen char* dnstap_ip; 577a3167c07Ssthen /** dnstap TLS enable */ 578a3167c07Ssthen int dnstap_tls; 579a3167c07Ssthen /** dnstap tls server authentication name */ 580a3167c07Ssthen char* dnstap_tls_server_name; 581a3167c07Ssthen /** dnstap server cert bundle */ 582a3167c07Ssthen char* dnstap_tls_cert_bundle; 583a3167c07Ssthen /** dnstap client key for client authentication */ 584a3167c07Ssthen char* dnstap_tls_client_key_file; 585a3167c07Ssthen /** dnstap client cert for client authentication */ 586a3167c07Ssthen char* dnstap_tls_client_cert_file; 58798f3ca02Sbrad /** true to send "identity" via dnstap */ 58898f3ca02Sbrad int dnstap_send_identity; 58998f3ca02Sbrad /** true to send "version" via dnstap */ 59098f3ca02Sbrad int dnstap_send_version; 59198f3ca02Sbrad /** dnstap "identity", hostname is used if "". */ 59298f3ca02Sbrad char* dnstap_identity; 59398f3ca02Sbrad /** dnstap "version", package version is used if "". */ 59498f3ca02Sbrad char* dnstap_version; 595*98bc733bSsthen /** dnstap sample rate */ 596*98bc733bSsthen int dnstap_sample_rate; 59798f3ca02Sbrad 59898f3ca02Sbrad /** true to log dnstap RESOLVER_QUERY message events */ 59998f3ca02Sbrad int dnstap_log_resolver_query_messages; 60098f3ca02Sbrad /** true to log dnstap RESOLVER_RESPONSE message events */ 60198f3ca02Sbrad int dnstap_log_resolver_response_messages; 60298f3ca02Sbrad /** true to log dnstap CLIENT_QUERY message events */ 60398f3ca02Sbrad int dnstap_log_client_query_messages; 60498f3ca02Sbrad /** true to log dnstap CLIENT_RESPONSE message events */ 60598f3ca02Sbrad int dnstap_log_client_response_messages; 60698f3ca02Sbrad /** true to log dnstap FORWARDER_QUERY message events */ 60798f3ca02Sbrad int dnstap_log_forwarder_query_messages; 60898f3ca02Sbrad /** true to log dnstap FORWARDER_RESPONSE message events */ 60998f3ca02Sbrad int dnstap_log_forwarder_response_messages; 610a58bff56Ssthen 6112ee382b6Ssthen /** true to disable DNSSEC lameness check in iterator */ 6122ee382b6Ssthen int disable_dnssec_lame_check; 6132ee382b6Ssthen 61477079be7Ssthen /** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */ 61577079be7Ssthen int ip_ratelimit; 6168b7325afSsthen /** ratelimit for ip addresses with a valid DNS Cookie. 0 is off, 6178b7325afSsthen * otherwise qps (unless overridden) */ 6188b7325afSsthen int ip_ratelimit_cookie; 61977079be7Ssthen /** number of slabs for ip_ratelimit cache */ 62077079be7Ssthen size_t ip_ratelimit_slabs; 62177079be7Ssthen /** memory size in bytes for ip_ratelimit cache */ 62277079be7Ssthen size_t ip_ratelimit_size; 62377079be7Ssthen /** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */ 62477079be7Ssthen int ip_ratelimit_factor; 625e21c60efSsthen /** ratelimit backoff, when on, if the limit is reached it is 626e21c60efSsthen * considered an attack and it backs off until 'demand' decreases over 627e21c60efSsthen * the RATE_WINDOW. */ 628e21c60efSsthen int ip_ratelimit_backoff; 62977079be7Ssthen 63077079be7Ssthen /** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */ 631a58bff56Ssthen int ratelimit; 632a58bff56Ssthen /** number of slabs for ratelimit cache */ 633a58bff56Ssthen size_t ratelimit_slabs; 634a58bff56Ssthen /** memory size in bytes for ratelimit cache */ 635a58bff56Ssthen size_t ratelimit_size; 636a58bff56Ssthen /** ratelimits for domain (exact match) */ 637a58bff56Ssthen struct config_str2list* ratelimit_for_domain; 638a58bff56Ssthen /** ratelimits below domain */ 639a58bff56Ssthen struct config_str2list* ratelimit_below_domain; 640a58bff56Ssthen /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */ 641a58bff56Ssthen int ratelimit_factor; 642e21c60efSsthen /** ratelimit backoff, when on, if the limit is reached it is 643e21c60efSsthen * considered an attack and it backs off until 'demand' decreases over 644e21c60efSsthen * the RATE_WINDOW. */ 645e21c60efSsthen int ratelimit_backoff; 646e21c60efSsthen 647e21c60efSsthen /** number of retries on outgoing queries */ 648e21c60efSsthen int outbound_msg_retry; 6498b7325afSsthen /** max sent queries per qstate; resets on query restarts (e.g., 6508b7325afSsthen * CNAMES) and referrals */ 6518b7325afSsthen int max_sent_count; 6528b7325afSsthen /** max number of query restarts; determines max length of CNAME chain */ 6538b7325afSsthen int max_query_restarts; 65424893edcSsthen /** minimise outgoing QNAME and hide original QTYPE if possible */ 65524893edcSsthen int qname_minimisation; 65677079be7Ssthen /** minimise QNAME in strict mode, minimise according to RFC. 65777079be7Ssthen * Do not apply fallback */ 65877079be7Ssthen int qname_minimisation_strict; 6592be9e038Ssthen /** SHM data - true if shm is enabled */ 6602be9e038Ssthen int shm_enable; 6612be9e038Ssthen /** SHM data - key for the shm */ 6622be9e038Ssthen int shm_key; 6632be9e038Ssthen 664eba819a2Ssthen /** list of EDNS client string entries, linked list */ 665eba819a2Ssthen struct config_str2list* edns_client_strings; 666eba819a2Ssthen /** EDNS opcode to use for EDNS client strings */ 667eba819a2Ssthen uint16_t edns_client_string_opcode; 6682c144df0Ssthen 6692be9e038Ssthen /** DNSCrypt */ 6702be9e038Ssthen /** true to enable dnscrypt */ 6712be9e038Ssthen int dnscrypt; 6722be9e038Ssthen /** port on which to provide dnscrypt service */ 6732be9e038Ssthen int dnscrypt_port; 6742be9e038Ssthen /** provider name 2.dnscrypt-cert.example.com */ 6752be9e038Ssthen char* dnscrypt_provider; 6762be9e038Ssthen /** dnscrypt secret keys 1.key */ 6772be9e038Ssthen struct config_strlist* dnscrypt_secret_key; 6782be9e038Ssthen /** dnscrypt provider certs 1.cert */ 6792be9e038Ssthen struct config_strlist* dnscrypt_provider_cert; 680bdfc4d55Sflorian /** dnscrypt provider certs 1.cert which have been rotated and should not be 681bdfc4d55Sflorian * advertised through DNS's providername TXT record but are required to be 682bdfc4d55Sflorian * able to handle existing traffic using the old cert. */ 683bdfc4d55Sflorian struct config_strlist* dnscrypt_provider_cert_rotated; 6847191de28Ssthen /** memory size in bytes for dnscrypt shared secrets cache */ 6857191de28Ssthen size_t dnscrypt_shared_secret_cache_size; 6867191de28Ssthen /** number of slabs for dnscrypt shared secrets cache */ 6877191de28Ssthen size_t dnscrypt_shared_secret_cache_slabs; 688bdfc4d55Sflorian /** memory size in bytes for dnscrypt nonces cache */ 689bdfc4d55Sflorian size_t dnscrypt_nonce_cache_size; 690bdfc4d55Sflorian /** number of slabs for dnscrypt nonces cache */ 691bdfc4d55Sflorian size_t dnscrypt_nonce_cache_slabs; 6929982a05dSsthen 6939982a05dSsthen /** EDNS padding according to RFC7830 and RFC8467 */ 6949982a05dSsthen /** true to enable padding of responses (default: on) */ 6959982a05dSsthen int pad_responses; 6969982a05dSsthen /** block size with which to pad encrypted responses (default: 468) */ 6979982a05dSsthen size_t pad_responses_block_size; 6989982a05dSsthen /** true to enable padding of queries (default: on) */ 6999982a05dSsthen int pad_queries; 7009982a05dSsthen /** block size with which to pad encrypted queries (default: 128) */ 7019982a05dSsthen size_t pad_queries_block_size; 7029982a05dSsthen 7032be9e038Ssthen /** IPsec module */ 7042be9e038Ssthen #ifdef USE_IPSECMOD 7052be9e038Ssthen /** false to bypass the IPsec module */ 7062be9e038Ssthen int ipsecmod_enabled; 7072be9e038Ssthen /** whitelisted domains for ipsecmod */ 7082be9e038Ssthen struct config_strlist* ipsecmod_whitelist; 7092be9e038Ssthen /** path to external hook */ 7102be9e038Ssthen char* ipsecmod_hook; 7112be9e038Ssthen /** true to proceed even with a bogus IPSECKEY */ 7122be9e038Ssthen int ipsecmod_ignore_bogus; 7132be9e038Ssthen /** max TTL for the A/AAAA records that call the hook */ 7142be9e038Ssthen int ipsecmod_max_ttl; 7152be9e038Ssthen /** false to proceed even when ipsecmod_hook fails */ 7162be9e038Ssthen int ipsecmod_strict; 7172be9e038Ssthen #endif 7187191de28Ssthen 7197191de28Ssthen /* cachedb module */ 7207191de28Ssthen #ifdef USE_CACHEDB 7217191de28Ssthen /** backend DB name */ 7227191de28Ssthen char* cachedb_backend; 7237191de28Ssthen /** secret seed for hash key calculation */ 7247191de28Ssthen char* cachedb_secret; 725d896b962Ssthen /** cachedb that does not store, but only reads from database, if on */ 726d896b962Ssthen int cachedb_no_store; 7272bdc0ed1Ssthen /** cachedb check before serving serve-expired response */ 7282bdc0ed1Ssthen int cachedb_check_when_serve_expired; 72920237c55Ssthen #ifdef USE_REDIS 73020237c55Ssthen /** redis server's IP address or host name */ 73120237c55Ssthen char* redis_server_host; 73220237c55Ssthen /** redis server's TCP port */ 73320237c55Ssthen int redis_server_port; 7348b7325afSsthen /** redis server's unix path. Or "", NULL if unused */ 7358b7325afSsthen char* redis_server_path; 7368b7325afSsthen /** redis server's AUTH password. Or "", NULL if unused */ 7378b7325afSsthen char* redis_server_password; 73820237c55Ssthen /** timeout (in ms) for communication with the redis server */ 73920237c55Ssthen int redis_timeout; 740a3167c07Ssthen /** set timeout on redis records based on DNS response ttl */ 741a3167c07Ssthen int redis_expire_records; 742d896b962Ssthen /** set the redis logical database upon connection */ 743d896b962Ssthen int redis_logical_db; 74420237c55Ssthen #endif 7457191de28Ssthen #endif 7468b7325afSsthen /** Downstream DNS Cookies */ 7478b7325afSsthen /** do answer with server cookie when request contained cookie option */ 7488b7325afSsthen int do_answer_cookie; 7498b7325afSsthen /** cookie secret */ 7508b7325afSsthen uint8_t cookie_secret[40]; 7518b7325afSsthen /** cookie secret length */ 7528b7325afSsthen size_t cookie_secret_len; 753*98bc733bSsthen /** path to cookie secret store */ 754*98bc733bSsthen char* cookie_secret_file; 7558240c1b9Ssthen 7568240c1b9Ssthen /* ipset module */ 7578240c1b9Ssthen #ifdef USE_IPSET 7588240c1b9Ssthen char* ipset_name_v4; 7598240c1b9Ssthen char* ipset_name_v6; 7608240c1b9Ssthen #endif 7610bdb4f62Ssthen /** respond with Extended DNS Errors (RFC8914) */ 7620bdb4f62Ssthen int ede; 763933707f3Ssthen }; 764933707f3Ssthen 765bdfc4d55Sflorian /** from cfg username, after daemonize setup performed */ 76647dfde74Sflorian extern uid_t cfg_uid; 767bdfc4d55Sflorian /** from cfg username, after daemonize setup performed */ 76847dfde74Sflorian extern gid_t cfg_gid; 769a961b961Ssthen /** debug and enable small timeouts */ 770a961b961Ssthen extern int autr_permit_small_holddown; 771f6b99bafSsthen /** size (in bytes) of stream wait buffers max */ 772f6b99bafSsthen extern size_t stream_wait_max; 7732c144df0Ssthen /** size (in bytes) of all total HTTP2 query buffers max */ 7742c144df0Ssthen extern size_t http2_query_buffer_max; 7752c144df0Ssthen /** size (in bytes) of all total HTTP2 response buffers max */ 7762c144df0Ssthen extern size_t http2_response_buffer_max; 77747dfde74Sflorian 778933707f3Ssthen /** 779933707f3Ssthen * Stub config options 780933707f3Ssthen */ 781933707f3Ssthen struct config_stub { 782933707f3Ssthen /** next in list */ 783933707f3Ssthen struct config_stub* next; 784933707f3Ssthen /** domain name (in text) of the stub apex domain */ 785933707f3Ssthen char* name; 786933707f3Ssthen /** list of stub nameserver hosts (domain name) */ 787933707f3Ssthen struct config_strlist* hosts; 788933707f3Ssthen /** list of stub nameserver addresses (IP address) */ 789933707f3Ssthen struct config_strlist* addrs; 790933707f3Ssthen /** if stub-prime is set */ 791933707f3Ssthen int isprime; 792d8d14d0cSsthen /** if forward-first is set (failover to without if fails) */ 793d8d14d0cSsthen int isfirst; 794e21c60efSsthen /** use tcp for queries to this stub */ 795e21c60efSsthen int tcp_upstream; 7962be9e038Ssthen /** use SSL for queries to this stub */ 79777079be7Ssthen int ssl_upstream; 7982308e98cSsthen /*** no cache */ 7992308e98cSsthen int no_cache; 80077079be7Ssthen }; 80177079be7Ssthen 80277079be7Ssthen /** 803bdfc4d55Sflorian * Auth config options 804bdfc4d55Sflorian */ 805bdfc4d55Sflorian struct config_auth { 806bdfc4d55Sflorian /** next in list */ 807bdfc4d55Sflorian struct config_auth* next; 808bdfc4d55Sflorian /** domain name (in text) of the auth apex domain */ 809bdfc4d55Sflorian char* name; 810bdfc4d55Sflorian /** list of masters */ 811bdfc4d55Sflorian struct config_strlist* masters; 812bdfc4d55Sflorian /** list of urls */ 813bdfc4d55Sflorian struct config_strlist* urls; 81420237c55Ssthen /** list of allow-notify */ 81520237c55Ssthen struct config_strlist* allow_notify; 816bdfc4d55Sflorian /** zonefile (or NULL) */ 817bdfc4d55Sflorian char* zonefile; 818bdfc4d55Sflorian /** provide downstream answers */ 819bdfc4d55Sflorian int for_downstream; 820bdfc4d55Sflorian /** provide upstream answers */ 821bdfc4d55Sflorian int for_upstream; 822938a3a5eSflorian /** fallback to recursion to authorities if zone expired and other 823938a3a5eSflorian * reasons perhaps (like, query bogus) */ 824938a3a5eSflorian int fallback_enabled; 825eaf2578eSsthen /** this zone is used to create local-zone policies */ 826eaf2578eSsthen int isrpz; 827eaf2578eSsthen /** rpz tags (or NULL) */ 828eaf2578eSsthen uint8_t* rpz_taglist; 829eaf2578eSsthen /** length of the taglist (in bytes) */ 830eaf2578eSsthen size_t rpz_taglistlen; 831eaf2578eSsthen /** Override RPZ action for this zone, regardless of zone content */ 832eaf2578eSsthen char* rpz_action_override; 833eaf2578eSsthen /** Log when this RPZ policy is applied */ 834eaf2578eSsthen int rpz_log; 835eaf2578eSsthen /** Display this name in the log when RPZ policy is applied */ 836eaf2578eSsthen char* rpz_log_name; 837eaf2578eSsthen /** Always reply with this CNAME target if the cname override action is 838eaf2578eSsthen * used */ 839eaf2578eSsthen char* rpz_cname; 840e21c60efSsthen /** signal nxdomain block with unset RA */ 841e21c60efSsthen int rpz_signal_nxdomain_ra; 842191f22c6Ssthen /** Check ZONEMD records for this zone */ 843191f22c6Ssthen int zonemd_check; 844191f22c6Ssthen /** Reject absence of ZONEMD records, zone must have one */ 845191f22c6Ssthen int zonemd_reject_absence; 846bdfc4d55Sflorian }; 847bdfc4d55Sflorian 848bdfc4d55Sflorian /** 84977079be7Ssthen * View config options 85077079be7Ssthen */ 85177079be7Ssthen struct config_view { 85277079be7Ssthen /** next in list */ 85377079be7Ssthen struct config_view* next; 85477079be7Ssthen /** view name */ 85577079be7Ssthen char* name; 85677079be7Ssthen /** local zones */ 85777079be7Ssthen struct config_str2list* local_zones; 85877079be7Ssthen /** local data RRs */ 85977079be7Ssthen struct config_strlist* local_data; 86077079be7Ssthen /** local zones nodefault list */ 86177079be7Ssthen struct config_strlist* local_zones_nodefault; 8628240c1b9Ssthen #ifdef USE_IPSET 8638240c1b9Ssthen /** local zones ipset list */ 8648240c1b9Ssthen struct config_strlist* local_zones_ipset; 8658240c1b9Ssthen #endif 86677079be7Ssthen /** Fallback to global local_zones when there is no match in the view 86777079be7Ssthen * view specific tree. 1 for yes, 0 for no */ 86877079be7Ssthen int isfirst; 8692be9e038Ssthen /** predefined actions for particular IP address responses */ 8702be9e038Ssthen struct config_str2list* respip_actions; 8712be9e038Ssthen /** data complementing the 'redirect' response IP actions */ 8722be9e038Ssthen struct config_str2list* respip_data; 873933707f3Ssthen }; 874933707f3Ssthen 875933707f3Ssthen /** 876933707f3Ssthen * List of strings for config options 877933707f3Ssthen */ 878933707f3Ssthen struct config_strlist { 879933707f3Ssthen /** next item in list */ 880933707f3Ssthen struct config_strlist* next; 881933707f3Ssthen /** config option string */ 882933707f3Ssthen char* str; 883933707f3Ssthen }; 884933707f3Ssthen 885933707f3Ssthen /** 886933707f3Ssthen * List of two strings for config options 887933707f3Ssthen */ 888933707f3Ssthen struct config_str2list { 889933707f3Ssthen /** next item in list */ 890933707f3Ssthen struct config_str2list* next; 891933707f3Ssthen /** first string */ 892933707f3Ssthen char* str; 893933707f3Ssthen /** second string */ 894933707f3Ssthen char* str2; 895933707f3Ssthen }; 896933707f3Ssthen 8972ee382b6Ssthen /** 89877079be7Ssthen * List of three strings for config options 89977079be7Ssthen */ 90077079be7Ssthen struct config_str3list { 90177079be7Ssthen /** next item in list */ 90277079be7Ssthen struct config_str3list* next; 90377079be7Ssthen /** first string */ 90477079be7Ssthen char* str; 90577079be7Ssthen /** second string */ 90677079be7Ssthen char* str2; 90777079be7Ssthen /** third string */ 90877079be7Ssthen char* str3; 90977079be7Ssthen }; 91077079be7Ssthen 91177079be7Ssthen 91277079be7Ssthen /** 9132ee382b6Ssthen * List of string, bytestring for config options 9142ee382b6Ssthen */ 9152ee382b6Ssthen struct config_strbytelist { 9162ee382b6Ssthen /** next item in list */ 9172ee382b6Ssthen struct config_strbytelist* next; 9182ee382b6Ssthen /** first string */ 9192ee382b6Ssthen char* str; 9202ee382b6Ssthen /** second bytestring */ 9212ee382b6Ssthen uint8_t* str2; 9222ee382b6Ssthen size_t str2len; 9232ee382b6Ssthen }; 9242ee382b6Ssthen 925933707f3Ssthen /** 926933707f3Ssthen * Create config file structure. Filled with default values. 927933707f3Ssthen * @return: the new structure or NULL on memory error. 928933707f3Ssthen */ 929933707f3Ssthen struct config_file* config_create(void); 930933707f3Ssthen 931933707f3Ssthen /** 932933707f3Ssthen * Create config file structure for library use. Filled with default values. 933933707f3Ssthen * @return: the new structure or NULL on memory error. 934933707f3Ssthen */ 935933707f3Ssthen struct config_file* config_create_forlib(void); 936933707f3Ssthen 937933707f3Ssthen /** 938933707f3Ssthen * Read the config file from the specified filename. 939933707f3Ssthen * @param config: where options are stored into, must be freshly created. 940933707f3Ssthen * @param filename: name of configfile. If NULL nothing is done. 941933707f3Ssthen * @param chroot: if not NULL, the chroot dir currently in use (for include). 942933707f3Ssthen * @return: false on error. In that case errno is set, ENOENT means 943933707f3Ssthen * file not found. 944933707f3Ssthen */ 945933707f3Ssthen int config_read(struct config_file* config, const char* filename, 946933707f3Ssthen const char* chroot); 947933707f3Ssthen 948933707f3Ssthen /** 949933707f3Ssthen * Destroy the config file structure. 950933707f3Ssthen * @param config: to delete. 951933707f3Ssthen */ 952933707f3Ssthen void config_delete(struct config_file* config); 953933707f3Ssthen 954933707f3Ssthen /** 955933707f3Ssthen * Apply config to global constants; this routine is called in single thread. 956933707f3Ssthen * @param config: to apply. Side effect: global constants change. 957933707f3Ssthen */ 958933707f3Ssthen void config_apply(struct config_file* config); 959933707f3Ssthen 960933707f3Ssthen /** 96147dfde74Sflorian * Find username, sets cfg_uid and cfg_gid. 962b2cdf21fSsthen * @param config: the config structure. 963b2cdf21fSsthen */ 964b2cdf21fSsthen void config_lookup_uid(struct config_file* config); 965b2cdf21fSsthen 966b2cdf21fSsthen /** 967933707f3Ssthen * Set the given keyword to the given value. 968933707f3Ssthen * @param config: where to store config 969933707f3Ssthen * @param option: option name, including the ':' character. 970933707f3Ssthen * @param value: value, this string is copied if needed, or parsed. 971933707f3Ssthen * The caller owns the value string. 972933707f3Ssthen * @return 0 on error (malloc or syntax error). 973933707f3Ssthen */ 974933707f3Ssthen int config_set_option(struct config_file* config, const char* option, 975933707f3Ssthen const char* value); 976933707f3Ssthen 977933707f3Ssthen /** 978933707f3Ssthen * Call print routine for the given option. 979933707f3Ssthen * @param cfg: config. 980933707f3Ssthen * @param opt: option name without trailing :. 981933707f3Ssthen * This is different from config_set_option. 982933707f3Ssthen * @param func: print func, called as (str, arg) for every data element. 983933707f3Ssthen * @param arg: user argument for print func. 984933707f3Ssthen * @return false if the option name is not supported (syntax error). 985933707f3Ssthen */ 986933707f3Ssthen int config_get_option(struct config_file* cfg, const char* opt, 987933707f3Ssthen void (*func)(char*,void*), void* arg); 988933707f3Ssthen 989933707f3Ssthen /** 990933707f3Ssthen * Get an option and return strlist 991933707f3Ssthen * @param cfg: config file 992933707f3Ssthen * @param opt: option name. 993933707f3Ssthen * @param list: list is returned here. malloced, caller must free it. 994933707f3Ssthen * @return 0=OK, 1=syntax error, 2=malloc failed. 995933707f3Ssthen */ 996933707f3Ssthen int config_get_option_list(struct config_file* cfg, const char* opt, 997933707f3Ssthen struct config_strlist** list); 998933707f3Ssthen 999933707f3Ssthen /** 1000933707f3Ssthen * Get an option and collate results into string 1001933707f3Ssthen * @param cfg: config file 1002933707f3Ssthen * @param opt: option name. 1003933707f3Ssthen * @param str: string. malloced, caller must free it. 1004933707f3Ssthen * @return 0=OK, 1=syntax error, 2=malloc failed. 1005933707f3Ssthen */ 1006933707f3Ssthen int config_get_option_collate(struct config_file* cfg, const char* opt, 1007933707f3Ssthen char** str); 1008933707f3Ssthen 1009933707f3Ssthen /** 1010933707f3Ssthen * function to print to a file, use as func with config_get_option. 1011933707f3Ssthen * @param line: text to print. \n appended. 1012933707f3Ssthen * @param arg: pass a FILE*, like stdout. 1013933707f3Ssthen */ 1014933707f3Ssthen void config_print_func(char* line, void* arg); 1015933707f3Ssthen 1016933707f3Ssthen /** 1017933707f3Ssthen * function to collate the text strings into a strlist_head. 1018933707f3Ssthen * @param line: text to append. 1019933707f3Ssthen * @param arg: pass a strlist_head structure. zeroed on start. 1020933707f3Ssthen */ 1021933707f3Ssthen void config_collate_func(char* line, void* arg); 1022933707f3Ssthen 1023933707f3Ssthen /** 1024933707f3Ssthen * take a strlist_head list and return a malloc string. separated with newline. 1025933707f3Ssthen * @param list: strlist first to collate. zeroes return "". 1026933707f3Ssthen * @return NULL on malloc failure. Or if malloc failure happened in strlist. 1027933707f3Ssthen */ 1028933707f3Ssthen char* config_collate_cat(struct config_strlist* list); 1029933707f3Ssthen 1030933707f3Ssthen /** 1031933707f3Ssthen * Append text at end of list. 1032933707f3Ssthen * @param list: list head. zeroed at start. 1033933707f3Ssthen * @param item: new item. malloced by caller. if NULL the insertion fails. 1034933707f3Ssthen * @return true on success. 1035452a1548Ssthen * on fail the item is free()ed. 1036933707f3Ssthen */ 1037933707f3Ssthen int cfg_strlist_append(struct config_strlist_head* list, char* item); 1038933707f3Ssthen 1039933707f3Ssthen /** 10408240c1b9Ssthen * Searches the end of a string list and appends the given text. 10418240c1b9Ssthen * @param head: pointer to strlist head variable. 10428240c1b9Ssthen * @param item: new item. malloced by caller. if NULL the insertion fails. 10438240c1b9Ssthen * @return true on success. 10448240c1b9Ssthen */ 10458240c1b9Ssthen int cfg_strlist_append_ex(struct config_strlist** head, char* item); 10468240c1b9Ssthen 10478240c1b9Ssthen /** 1048bdfc4d55Sflorian * Find string in strlist. 1049bdfc4d55Sflorian * @param head: pointer to strlist head variable. 1050bdfc4d55Sflorian * @param item: the item to search for. 1051bdfc4d55Sflorian * @return: the element in the list when found, NULL otherwise. 1052bdfc4d55Sflorian */ 1053bdfc4d55Sflorian struct config_strlist* cfg_strlist_find(struct config_strlist* head, 1054bdfc4d55Sflorian const char* item); 1055bdfc4d55Sflorian 1056bdfc4d55Sflorian /** 1057933707f3Ssthen * Insert string into strlist. 1058933707f3Ssthen * @param head: pointer to strlist head variable. 1059933707f3Ssthen * @param item: new item. malloced by caller. If NULL the insertion fails. 1060933707f3Ssthen * @return: true on success. 1061452a1548Ssthen * on fail, the item is free()d. 1062933707f3Ssthen */ 1063933707f3Ssthen int cfg_strlist_insert(struct config_strlist** head, char* item); 1064933707f3Ssthen 106577079be7Ssthen /** insert with region for allocation. */ 106677079be7Ssthen int cfg_region_strlist_insert(struct regional* region, 106777079be7Ssthen struct config_strlist** head, char* item); 106877079be7Ssthen 1069933707f3Ssthen /** 1070933707f3Ssthen * Insert string into str2list. 1071933707f3Ssthen * @param head: pointer to str2list head variable. 1072933707f3Ssthen * @param item: new item. malloced by caller. If NULL the insertion fails. 1073933707f3Ssthen * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 1074933707f3Ssthen * @return: true on success. 1075452a1548Ssthen * on fail, the item and i2 are free()d. 1076933707f3Ssthen */ 1077933707f3Ssthen int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2); 1078933707f3Ssthen 1079933707f3Ssthen /** 108077079be7Ssthen * Insert string into str3list. 108177079be7Ssthen * @param head: pointer to str3list head variable. 108277079be7Ssthen * @param item: new item. malloced by caller. If NULL the insertion fails. 108377079be7Ssthen * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 108477079be7Ssthen * @param i3: 3rd string, malloced by caller. If NULL the insertion fails. 108577079be7Ssthen * @return: true on success. 108677079be7Ssthen */ 108777079be7Ssthen int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2, 108877079be7Ssthen char* i3); 108977079be7Ssthen 109077079be7Ssthen /** 10912ee382b6Ssthen * Insert string into strbytelist. 109277079be7Ssthen * @param head: pointer to strbytelist head variable. 10932ee382b6Ssthen * @param item: new item. malloced by caller. If NULL the insertion fails. 10942ee382b6Ssthen * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 10952ee382b6Ssthen * @param i2len: length of the i2 bytestring. 10962ee382b6Ssthen * @return: true on success. 10972ee382b6Ssthen */ 10982ee382b6Ssthen int cfg_strbytelist_insert(struct config_strbytelist** head, char* item, 10992ee382b6Ssthen uint8_t* i2, size_t i2len); 11002ee382b6Ssthen 11012ee382b6Ssthen /** 110232e31f52Ssthen * Find stub in config list, also returns prevptr (for deletion). 110332e31f52Ssthen * @param pp: call routine with pointer to a pointer to the start of the list, 110432e31f52Ssthen * if the stub is found, on exit, the value contains a pointer to the 110532e31f52Ssthen * next pointer that points to the found element (or to the list start 110632e31f52Ssthen * pointer if it is the first element). 110732e31f52Ssthen * @param nm: name of stub to find. 110832e31f52Ssthen * @return: pointer to config_stub if found, or NULL if not found. 110932e31f52Ssthen */ 111032e31f52Ssthen struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm); 111132e31f52Ssthen 111232e31f52Ssthen /** 1113933707f3Ssthen * Delete items in config string list. 1114933707f3Ssthen * @param list: list. 1115933707f3Ssthen */ 1116933707f3Ssthen void config_delstrlist(struct config_strlist* list); 1117933707f3Ssthen 1118933707f3Ssthen /** 1119933707f3Ssthen * Delete items in config double string list. 1120933707f3Ssthen * @param list: list. 1121933707f3Ssthen */ 1122933707f3Ssthen void config_deldblstrlist(struct config_str2list* list); 1123933707f3Ssthen 1124933707f3Ssthen /** 112577079be7Ssthen * Delete items in config triple string list. 112677079be7Ssthen * @param list: list. 112777079be7Ssthen */ 112877079be7Ssthen void config_deltrplstrlist(struct config_str3list* list); 112977079be7Ssthen 11302c144df0Ssthen /** delete string array */ 11312c144df0Ssthen void config_del_strarray(char** array, int num); 11322c144df0Ssthen 113377079be7Ssthen /** delete stringbytelist */ 113477079be7Ssthen void config_del_strbytelist(struct config_strbytelist* list); 113577079be7Ssthen 113677079be7Ssthen /** 113732e31f52Ssthen * Delete a stub item 113832e31f52Ssthen * @param p: stub item 113932e31f52Ssthen */ 114032e31f52Ssthen void config_delstub(struct config_stub* p); 114132e31f52Ssthen 114232e31f52Ssthen /** 1143933707f3Ssthen * Delete items in config stub list. 1144933707f3Ssthen * @param list: list. 1145933707f3Ssthen */ 1146933707f3Ssthen void config_delstubs(struct config_stub* list); 1147933707f3Ssthen 1148933707f3Ssthen /** 1149bdfc4d55Sflorian * Delete an auth item 1150bdfc4d55Sflorian * @param p: auth item 1151bdfc4d55Sflorian */ 1152bdfc4d55Sflorian void config_delauth(struct config_auth* p); 1153bdfc4d55Sflorian 1154bdfc4d55Sflorian /** 1155bdfc4d55Sflorian * Delete items in config auth list. 1156bdfc4d55Sflorian * @param list: list. 1157bdfc4d55Sflorian */ 1158bdfc4d55Sflorian void config_delauths(struct config_auth* list); 1159bdfc4d55Sflorian 1160bdfc4d55Sflorian /** 116177079be7Ssthen * Delete a view item 116277079be7Ssthen * @param p: view item 116377079be7Ssthen */ 116477079be7Ssthen void config_delview(struct config_view* p); 116577079be7Ssthen 116677079be7Ssthen /** 116777079be7Ssthen * Delete items in config view list. 116877079be7Ssthen * @param list: list. 116977079be7Ssthen */ 117077079be7Ssthen void config_delviews(struct config_view* list); 117177079be7Ssthen 117220237c55Ssthen /** check if config for remote control turns on IP-address interface 117320237c55Ssthen * with certificates or a named pipe without certificates. */ 117420237c55Ssthen int options_remote_is_address(struct config_file* cfg); 117520237c55Ssthen 117677079be7Ssthen /** 1177933707f3Ssthen * Convert 14digit to time value 1178933707f3Ssthen * @param str: string of 14 digits 1179933707f3Ssthen * @return time value or 0 for error. 1180933707f3Ssthen */ 1181229e174cSsthen time_t cfg_convert_timeval(const char* str); 1182933707f3Ssthen 1183933707f3Ssthen /** 1184933707f3Ssthen * Count number of values in the string. 1185933707f3Ssthen * format ::= (sp num)+ sp 1186933707f3Ssthen * num ::= [-](0-9)+ 1187933707f3Ssthen * sp ::= (space|tab)* 1188933707f3Ssthen * 1189933707f3Ssthen * @param str: string 1190933707f3Ssthen * @return: 0 on parse error, or empty string, else 1191933707f3Ssthen * number of integer values in the string. 1192933707f3Ssthen */ 1193933707f3Ssthen int cfg_count_numbers(const char* str); 1194933707f3Ssthen 1195933707f3Ssthen /** 1196933707f3Ssthen * Convert a 'nice' memory or file size into a bytecount 1197933707f3Ssthen * From '100k' to 102400. and so on. Understands kKmMgG. 1198933707f3Ssthen * k=1024, m=1024*1024, g=1024*1024*1024. 1199933707f3Ssthen * @param str: string 1200933707f3Ssthen * @param res: result is stored here, size in bytes. 1201933707f3Ssthen * @return: true if parsed correctly, or 0 on a parse error (and an error 1202933707f3Ssthen * is logged). 1203933707f3Ssthen */ 1204933707f3Ssthen int cfg_parse_memsize(const char* str, size_t* res); 1205933707f3Ssthen 1206933707f3Ssthen /** 1207e21c60efSsthen * Parse nsid from string into binary nsid. nsid is either a hexadecimal 12089982a05dSsthen * string or an ascii string prepended with ascii_ in which case the 12099982a05dSsthen * characters after ascii_ are simply copied. 12109982a05dSsthen * @param str: the string to parse. 12119982a05dSsthen * @param nsid_len: returns length of nsid in bytes. 12129982a05dSsthen * @return malloced bytes or NULL on parse error or malloc failure. 12139982a05dSsthen */ 12149982a05dSsthen uint8_t* cfg_parse_nsid(const char* str, uint16_t* nsid_len); 12159982a05dSsthen 12169982a05dSsthen /** 12172ee382b6Ssthen * Add a tag name to the config. It is added at the end with a new ID value. 12182ee382b6Ssthen * @param cfg: the config structure. 12192ee382b6Ssthen * @param tag: string (which is copied) with the name. 12202ee382b6Ssthen * @return: false on alloc failure. 12212ee382b6Ssthen */ 12222ee382b6Ssthen int config_add_tag(struct config_file* cfg, const char* tag); 12232ee382b6Ssthen 12242ee382b6Ssthen /** 12252ee382b6Ssthen * Find tag ID in the tag list. 12262ee382b6Ssthen * @param cfg: the config structure. 12272ee382b6Ssthen * @param tag: string with tag name to search for. 12282ee382b6Ssthen * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found. 12292ee382b6Ssthen */ 12302ee382b6Ssthen int find_tag_id(struct config_file* cfg, const char* tag); 12312ee382b6Ssthen 12322ee382b6Ssthen /** 12332ee382b6Ssthen * parse taglist from string into bytestring with bitlist. 12342ee382b6Ssthen * @param cfg: the config structure (with tagnames) 12352ee382b6Ssthen * @param str: the string to parse. Parse puts 0 bytes in string. 12362ee382b6Ssthen * @param listlen: returns length of in bytes. 12372ee382b6Ssthen * @return malloced bytes with a bitlist of the tags. or NULL on parse error 12382ee382b6Ssthen * or malloc failure. 12392ee382b6Ssthen */ 12402ee382b6Ssthen uint8_t* config_parse_taglist(struct config_file* cfg, char* str, 12412ee382b6Ssthen size_t* listlen); 12422ee382b6Ssthen 12432ee382b6Ssthen /** 12442ee382b6Ssthen * convert tag bitlist to a malloced string with tag names. For debug output. 12452ee382b6Ssthen * @param cfg: the config structure (with tagnames) 12462ee382b6Ssthen * @param taglist: the tag bitlist. 12472ee382b6Ssthen * @param len: length of the tag bitlist. 12482ee382b6Ssthen * @return malloced string or NULL. 12492ee382b6Ssthen */ 12502ee382b6Ssthen char* config_taglist2str(struct config_file* cfg, uint8_t* taglist, 12512ee382b6Ssthen size_t len); 12522ee382b6Ssthen 12532ee382b6Ssthen /** 12542ee382b6Ssthen * see if two taglists intersect (have tags in common). 12552ee382b6Ssthen * @param list1: first tag bitlist. 12562ee382b6Ssthen * @param list1len: length in bytes of first list. 12572ee382b6Ssthen * @param list2: second tag bitlist. 12582ee382b6Ssthen * @param list2len: length in bytes of second list. 12592ee382b6Ssthen * @return true if there are tags in common, 0 if not. 12602ee382b6Ssthen */ 1261eaf2578eSsthen int taglist_intersect(uint8_t* list1, size_t list1len, const uint8_t* list2, 12622ee382b6Ssthen size_t list2len); 12632ee382b6Ssthen 12642ee382b6Ssthen /** 1265933707f3Ssthen * Parse local-zone directive into two strings and register it in the config. 1266933707f3Ssthen * @param cfg: to put it in. 1267933707f3Ssthen * @param val: argument strings to local-zone, "example.com nodefault". 1268933707f3Ssthen * @return: false on failure 1269933707f3Ssthen */ 1270933707f3Ssthen int cfg_parse_local_zone(struct config_file* cfg, const char* val); 1271933707f3Ssthen 1272933707f3Ssthen /** 1273933707f3Ssthen * Mark "number" or "low-high" as available or not in ports array. 1274933707f3Ssthen * @param str: string in input 1275933707f3Ssthen * @param allow: give true if this range is permitted. 1276933707f3Ssthen * @param avail: the array from cfg. 1277933707f3Ssthen * @param num: size of the array (65536). 1278933707f3Ssthen * @return: true if parsed correctly, or 0 on a parse error (and an error 1279933707f3Ssthen * is logged). 1280933707f3Ssthen */ 1281933707f3Ssthen int cfg_mark_ports(const char* str, int allow, int* avail, int num); 1282933707f3Ssthen 1283933707f3Ssthen /** 1284933707f3Ssthen * Get a condensed list of ports returned. allocated. 1285933707f3Ssthen * @param cfg: config file. 1286933707f3Ssthen * @param avail: the available ports array is returned here. 1287933707f3Ssthen * @return: number of ports in array or 0 on error. 1288933707f3Ssthen */ 1289933707f3Ssthen int cfg_condense_ports(struct config_file* cfg, int** avail); 1290933707f3Ssthen 1291933707f3Ssthen /** 1292191f22c6Ssthen * Apply system specific port range policy. 1293191f22c6Ssthen * @param cfg: config file. 1294191f22c6Ssthen * @param num: size of the array (65536). 1295191f22c6Ssthen */ 1296191f22c6Ssthen void cfg_apply_local_port_policy(struct config_file* cfg, int num); 1297191f22c6Ssthen 1298191f22c6Ssthen /** 1299933707f3Ssthen * Scan ports available 1300933707f3Ssthen * @param avail: the array from cfg. 1301933707f3Ssthen * @param num: size of the array (65536). 1302933707f3Ssthen * @return the number of ports available for use. 1303933707f3Ssthen */ 1304933707f3Ssthen int cfg_scan_ports(int* avail, int num); 1305933707f3Ssthen 1306933707f3Ssthen /** 1307933707f3Ssthen * Convert a filename to full pathname in original filesys 1308933707f3Ssthen * @param fname: the path name to convert. 1309933707f3Ssthen * Must not be null or empty. 1310933707f3Ssthen * @param cfg: config struct for chroot and chdir (if set). 1311933707f3Ssthen * @param use_chdir: if false, only chroot is applied. 1312933707f3Ssthen * @return pointer to malloced buffer which is: [chroot][chdir]fname 1313933707f3Ssthen * or NULL on malloc failure. 1314933707f3Ssthen */ 1315933707f3Ssthen char* fname_after_chroot(const char* fname, struct config_file* cfg, 1316933707f3Ssthen int use_chdir); 1317933707f3Ssthen 1318933707f3Ssthen /** 1319933707f3Ssthen * Convert a ptr shorthand into a full reverse-notation PTR record. 1320933707f3Ssthen * @param str: input string, "IP name" 1321933707f3Ssthen * @return: malloced string "reversed-ip-name PTR name" 1322933707f3Ssthen */ 1323933707f3Ssthen char* cfg_ptr_reverse(char* str); 1324933707f3Ssthen 1325933707f3Ssthen /** 1326933707f3Ssthen * Used during options parsing 1327933707f3Ssthen */ 1328933707f3Ssthen struct config_parser_state { 1329933707f3Ssthen /** name of file being parser */ 1330933707f3Ssthen char* filename; 1331933707f3Ssthen /** line number in the file, starts at 1 */ 1332933707f3Ssthen int line; 1333933707f3Ssthen /** number of errors encountered */ 1334933707f3Ssthen int errors; 1335933707f3Ssthen /** the result of parsing is stored here. */ 1336933707f3Ssthen struct config_file* cfg; 1337933707f3Ssthen /** the current chroot dir (or NULL if none) */ 1338933707f3Ssthen const char* chroot; 133945872187Ssthen /** if we are started in a toplevel, or not, after a force_toplevel */ 134045872187Ssthen int started_toplevel; 1341933707f3Ssthen }; 1342933707f3Ssthen 1343933707f3Ssthen /** global config parser object used during config parsing */ 1344933707f3Ssthen extern struct config_parser_state* cfg_parser; 134598f3ca02Sbrad /** init lex state */ 134698f3ca02Sbrad void init_cfg_parse(void); 134798f3ca02Sbrad /** lex in file */ 134898f3ca02Sbrad extern FILE* ub_c_in; 134998f3ca02Sbrad /** lex out file */ 135098f3ca02Sbrad extern FILE* ub_c_out; 135198f3ca02Sbrad /** the yacc lex generated parse function */ 135298f3ca02Sbrad int ub_c_parse(void); 135398f3ca02Sbrad /** the lexer function */ 135498f3ca02Sbrad int ub_c_lex(void); 135598f3ca02Sbrad /** wrap function */ 135698f3ca02Sbrad int ub_c_wrap(void); 1357933707f3Ssthen /** parsing helpers: print error with file and line numbers */ 1358933707f3Ssthen void ub_c_error(const char* msg); 1359933707f3Ssthen /** parsing helpers: print error with file and line numbers */ 1360933707f3Ssthen void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2); 1361933707f3Ssthen 1362d8d14d0cSsthen #ifdef UB_ON_WINDOWS 1363d8d14d0cSsthen /** 1364d8d14d0cSsthen * Obtain registry string (if it exists). 1365d8d14d0cSsthen * @param key: key string 1366d8d14d0cSsthen * @param name: name of value to fetch. 1367d8d14d0cSsthen * @return malloced string with the result or NULL if it did not 1368d8d14d0cSsthen * exist on an error (logged with log_err) was encountered. 1369d8d14d0cSsthen */ 1370d8d14d0cSsthen char* w_lookup_reg_str(const char* key, const char* name); 137124893edcSsthen 137224893edcSsthen /** Modify directory in options for module file name */ 137324893edcSsthen void w_config_adjust_directory(struct config_file* cfg); 1374d8d14d0cSsthen #endif /* UB_ON_WINDOWS */ 1375d8d14d0cSsthen 137677079be7Ssthen /** debug option for unit tests. */ 13772be9e038Ssthen extern int fake_dsa, fake_sha1; 137877079be7Ssthen 1379191f22c6Ssthen /** see if interface is https, its port number == the https port number */ 1380191f22c6Ssthen int if_is_https(const char* ifname, const char* port, int https_port); 1381191f22c6Ssthen 1382191f22c6Ssthen /** 1383191f22c6Ssthen * Return true if the config contains settings that enable https. 1384191f22c6Ssthen * @param cfg: config information. 1385191f22c6Ssthen * @return true if https ports are used for server. 1386191f22c6Ssthen */ 1387191f22c6Ssthen int cfg_has_https(struct config_file* cfg); 1388191f22c6Ssthen 138945872187Ssthen /** see if interface is PROXYv2, its port number == the proxy port number */ 139045872187Ssthen int if_is_pp2(const char* ifname, const char* port, 139145872187Ssthen struct config_strlist* proxy_protocol_port); 139245872187Ssthen 139345872187Ssthen /** see if interface is DNSCRYPT, its port number == the dnscrypt port number */ 139445872187Ssthen int if_is_dnscrypt(const char* ifname, const char* port, int dnscrypt_port); 1395191f22c6Ssthen #ifdef USE_LINUX_IP_LOCAL_PORT_RANGE 1396191f22c6Ssthen #define LINUX_IP_LOCAL_PORT_RANGE_PATH "/proc/sys/net/ipv4/ip_local_port_range" 1397191f22c6Ssthen #endif 1398191f22c6Ssthen 1399933707f3Ssthen #endif /* UTIL_CONFIG_FILE_H */ 1400