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