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