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