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