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