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