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 /** dnstap sample rate */ 596 int dnstap_sample_rate; 597 598 /** true to log dnstap RESOLVER_QUERY message events */ 599 int dnstap_log_resolver_query_messages; 600 /** true to log dnstap RESOLVER_RESPONSE message events */ 601 int dnstap_log_resolver_response_messages; 602 /** true to log dnstap CLIENT_QUERY message events */ 603 int dnstap_log_client_query_messages; 604 /** true to log dnstap CLIENT_RESPONSE message events */ 605 int dnstap_log_client_response_messages; 606 /** true to log dnstap FORWARDER_QUERY message events */ 607 int dnstap_log_forwarder_query_messages; 608 /** true to log dnstap FORWARDER_RESPONSE message events */ 609 int dnstap_log_forwarder_response_messages; 610 611 /** true to disable DNSSEC lameness check in iterator */ 612 int disable_dnssec_lame_check; 613 614 /** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */ 615 int ip_ratelimit; 616 /** ratelimit for ip addresses with a valid DNS Cookie. 0 is off, 617 * otherwise qps (unless overridden) */ 618 int ip_ratelimit_cookie; 619 /** number of slabs for ip_ratelimit cache */ 620 size_t ip_ratelimit_slabs; 621 /** memory size in bytes for ip_ratelimit cache */ 622 size_t ip_ratelimit_size; 623 /** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */ 624 int ip_ratelimit_factor; 625 /** ratelimit backoff, when on, if the limit is reached it is 626 * considered an attack and it backs off until 'demand' decreases over 627 * the RATE_WINDOW. */ 628 int ip_ratelimit_backoff; 629 630 /** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */ 631 int ratelimit; 632 /** number of slabs for ratelimit cache */ 633 size_t ratelimit_slabs; 634 /** memory size in bytes for ratelimit cache */ 635 size_t ratelimit_size; 636 /** ratelimits for domain (exact match) */ 637 struct config_str2list* ratelimit_for_domain; 638 /** ratelimits below domain */ 639 struct config_str2list* ratelimit_below_domain; 640 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */ 641 int ratelimit_factor; 642 /** ratelimit backoff, when on, if the limit is reached it is 643 * considered an attack and it backs off until 'demand' decreases over 644 * the RATE_WINDOW. */ 645 int ratelimit_backoff; 646 647 /** number of retries on outgoing queries */ 648 int outbound_msg_retry; 649 /** max sent queries per qstate; resets on query restarts (e.g., 650 * CNAMES) and referrals */ 651 int max_sent_count; 652 /** max number of query restarts; determines max length of CNAME chain */ 653 int max_query_restarts; 654 /** minimise outgoing QNAME and hide original QTYPE if possible */ 655 int qname_minimisation; 656 /** minimise QNAME in strict mode, minimise according to RFC. 657 * Do not apply fallback */ 658 int qname_minimisation_strict; 659 /** SHM data - true if shm is enabled */ 660 int shm_enable; 661 /** SHM data - key for the shm */ 662 int shm_key; 663 664 /** list of EDNS client string entries, linked list */ 665 struct config_str2list* edns_client_strings; 666 /** EDNS opcode to use for EDNS client strings */ 667 uint16_t edns_client_string_opcode; 668 669 /** DNSCrypt */ 670 /** true to enable dnscrypt */ 671 int dnscrypt; 672 /** port on which to provide dnscrypt service */ 673 int dnscrypt_port; 674 /** provider name 2.dnscrypt-cert.example.com */ 675 char* dnscrypt_provider; 676 /** dnscrypt secret keys 1.key */ 677 struct config_strlist* dnscrypt_secret_key; 678 /** dnscrypt provider certs 1.cert */ 679 struct config_strlist* dnscrypt_provider_cert; 680 /** dnscrypt provider certs 1.cert which have been rotated and should not be 681 * advertised through DNS's providername TXT record but are required to be 682 * able to handle existing traffic using the old cert. */ 683 struct config_strlist* dnscrypt_provider_cert_rotated; 684 /** memory size in bytes for dnscrypt shared secrets cache */ 685 size_t dnscrypt_shared_secret_cache_size; 686 /** number of slabs for dnscrypt shared secrets cache */ 687 size_t dnscrypt_shared_secret_cache_slabs; 688 /** memory size in bytes for dnscrypt nonces cache */ 689 size_t dnscrypt_nonce_cache_size; 690 /** number of slabs for dnscrypt nonces cache */ 691 size_t dnscrypt_nonce_cache_slabs; 692 693 /** EDNS padding according to RFC7830 and RFC8467 */ 694 /** true to enable padding of responses (default: on) */ 695 int pad_responses; 696 /** block size with which to pad encrypted responses (default: 468) */ 697 size_t pad_responses_block_size; 698 /** true to enable padding of queries (default: on) */ 699 int pad_queries; 700 /** block size with which to pad encrypted queries (default: 128) */ 701 size_t pad_queries_block_size; 702 703 /** IPsec module */ 704 #ifdef USE_IPSECMOD 705 /** false to bypass the IPsec module */ 706 int ipsecmod_enabled; 707 /** whitelisted domains for ipsecmod */ 708 struct config_strlist* ipsecmod_whitelist; 709 /** path to external hook */ 710 char* ipsecmod_hook; 711 /** true to proceed even with a bogus IPSECKEY */ 712 int ipsecmod_ignore_bogus; 713 /** max TTL for the A/AAAA records that call the hook */ 714 int ipsecmod_max_ttl; 715 /** false to proceed even when ipsecmod_hook fails */ 716 int ipsecmod_strict; 717 #endif 718 719 /* cachedb module */ 720 #ifdef USE_CACHEDB 721 /** backend DB name */ 722 char* cachedb_backend; 723 /** secret seed for hash key calculation */ 724 char* cachedb_secret; 725 /** cachedb that does not store, but only reads from database, if on */ 726 int cachedb_no_store; 727 /** cachedb check before serving serve-expired response */ 728 int cachedb_check_when_serve_expired; 729 #ifdef USE_REDIS 730 /** redis server's IP address or host name */ 731 char* redis_server_host; 732 /** redis server's TCP port */ 733 int redis_server_port; 734 /** redis server's unix path. Or "", NULL if unused */ 735 char* redis_server_path; 736 /** redis server's AUTH password. Or "", NULL if unused */ 737 char* redis_server_password; 738 /** timeout (in ms) for communication with the redis server */ 739 int redis_timeout; 740 /** set timeout on redis records based on DNS response ttl */ 741 int redis_expire_records; 742 /** set the redis logical database upon connection */ 743 int redis_logical_db; 744 #endif 745 #endif 746 /** Downstream DNS Cookies */ 747 /** do answer with server cookie when request contained cookie option */ 748 int do_answer_cookie; 749 /** cookie secret */ 750 uint8_t cookie_secret[40]; 751 /** cookie secret length */ 752 size_t cookie_secret_len; 753 /** path to cookie secret store */ 754 char* cookie_secret_file; 755 756 /* ipset module */ 757 #ifdef USE_IPSET 758 char* ipset_name_v4; 759 char* ipset_name_v6; 760 #endif 761 /** respond with Extended DNS Errors (RFC8914) */ 762 int ede; 763 }; 764 765 /** from cfg username, after daemonize setup performed */ 766 extern uid_t cfg_uid; 767 /** from cfg username, after daemonize setup performed */ 768 extern gid_t cfg_gid; 769 /** debug and enable small timeouts */ 770 extern int autr_permit_small_holddown; 771 /** size (in bytes) of stream wait buffers max */ 772 extern size_t stream_wait_max; 773 /** size (in bytes) of all total HTTP2 query buffers max */ 774 extern size_t http2_query_buffer_max; 775 /** size (in bytes) of all total HTTP2 response buffers max */ 776 extern size_t http2_response_buffer_max; 777 778 /** 779 * Stub config options 780 */ 781 struct config_stub { 782 /** next in list */ 783 struct config_stub* next; 784 /** domain name (in text) of the stub apex domain */ 785 char* name; 786 /** list of stub nameserver hosts (domain name) */ 787 struct config_strlist* hosts; 788 /** list of stub nameserver addresses (IP address) */ 789 struct config_strlist* addrs; 790 /** if stub-prime is set */ 791 int isprime; 792 /** if forward-first is set (failover to without if fails) */ 793 int isfirst; 794 /** use tcp for queries to this stub */ 795 int tcp_upstream; 796 /** use SSL for queries to this stub */ 797 int ssl_upstream; 798 /*** no cache */ 799 int no_cache; 800 }; 801 802 /** 803 * Auth config options 804 */ 805 struct config_auth { 806 /** next in list */ 807 struct config_auth* next; 808 /** domain name (in text) of the auth apex domain */ 809 char* name; 810 /** list of masters */ 811 struct config_strlist* masters; 812 /** list of urls */ 813 struct config_strlist* urls; 814 /** list of allow-notify */ 815 struct config_strlist* allow_notify; 816 /** zonefile (or NULL) */ 817 char* zonefile; 818 /** provide downstream answers */ 819 int for_downstream; 820 /** provide upstream answers */ 821 int for_upstream; 822 /** fallback to recursion to authorities if zone expired and other 823 * reasons perhaps (like, query bogus) */ 824 int fallback_enabled; 825 /** this zone is used to create local-zone policies */ 826 int isrpz; 827 /** rpz tags (or NULL) */ 828 uint8_t* rpz_taglist; 829 /** length of the taglist (in bytes) */ 830 size_t rpz_taglistlen; 831 /** Override RPZ action for this zone, regardless of zone content */ 832 char* rpz_action_override; 833 /** Log when this RPZ policy is applied */ 834 int rpz_log; 835 /** Display this name in the log when RPZ policy is applied */ 836 char* rpz_log_name; 837 /** Always reply with this CNAME target if the cname override action is 838 * used */ 839 char* rpz_cname; 840 /** signal nxdomain block with unset RA */ 841 int rpz_signal_nxdomain_ra; 842 /** Check ZONEMD records for this zone */ 843 int zonemd_check; 844 /** Reject absence of ZONEMD records, zone must have one */ 845 int zonemd_reject_absence; 846 }; 847 848 /** 849 * View config options 850 */ 851 struct config_view { 852 /** next in list */ 853 struct config_view* next; 854 /** view name */ 855 char* name; 856 /** local zones */ 857 struct config_str2list* local_zones; 858 /** local data RRs */ 859 struct config_strlist* local_data; 860 /** local zones nodefault list */ 861 struct config_strlist* local_zones_nodefault; 862 #ifdef USE_IPSET 863 /** local zones ipset list */ 864 struct config_strlist* local_zones_ipset; 865 #endif 866 /** Fallback to global local_zones when there is no match in the view 867 * view specific tree. 1 for yes, 0 for no */ 868 int isfirst; 869 /** predefined actions for particular IP address responses */ 870 struct config_str2list* respip_actions; 871 /** data complementing the 'redirect' response IP actions */ 872 struct config_str2list* respip_data; 873 }; 874 875 /** 876 * List of strings for config options 877 */ 878 struct config_strlist { 879 /** next item in list */ 880 struct config_strlist* next; 881 /** config option string */ 882 char* str; 883 }; 884 885 /** 886 * List of two strings for config options 887 */ 888 struct config_str2list { 889 /** next item in list */ 890 struct config_str2list* next; 891 /** first string */ 892 char* str; 893 /** second string */ 894 char* str2; 895 }; 896 897 /** 898 * List of three strings for config options 899 */ 900 struct config_str3list { 901 /** next item in list */ 902 struct config_str3list* next; 903 /** first string */ 904 char* str; 905 /** second string */ 906 char* str2; 907 /** third string */ 908 char* str3; 909 }; 910 911 912 /** 913 * List of string, bytestring for config options 914 */ 915 struct config_strbytelist { 916 /** next item in list */ 917 struct config_strbytelist* next; 918 /** first string */ 919 char* str; 920 /** second bytestring */ 921 uint8_t* str2; 922 size_t str2len; 923 }; 924 925 /** 926 * Create config file structure. Filled with default values. 927 * @return: the new structure or NULL on memory error. 928 */ 929 struct config_file* config_create(void); 930 931 /** 932 * Create config file structure for library use. Filled with default values. 933 * @return: the new structure or NULL on memory error. 934 */ 935 struct config_file* config_create_forlib(void); 936 937 /** 938 * Read the config file from the specified filename. 939 * @param config: where options are stored into, must be freshly created. 940 * @param filename: name of configfile. If NULL nothing is done. 941 * @param chroot: if not NULL, the chroot dir currently in use (for include). 942 * @return: false on error. In that case errno is set, ENOENT means 943 * file not found. 944 */ 945 int config_read(struct config_file* config, const char* filename, 946 const char* chroot); 947 948 /** 949 * Destroy the config file structure. 950 * @param config: to delete. 951 */ 952 void config_delete(struct config_file* config); 953 954 /** 955 * Apply config to global constants; this routine is called in single thread. 956 * @param config: to apply. Side effect: global constants change. 957 */ 958 void config_apply(struct config_file* config); 959 960 /** 961 * Find username, sets cfg_uid and cfg_gid. 962 * @param config: the config structure. 963 */ 964 void config_lookup_uid(struct config_file* config); 965 966 /** 967 * Set the given keyword to the given value. 968 * @param config: where to store config 969 * @param option: option name, including the ':' character. 970 * @param value: value, this string is copied if needed, or parsed. 971 * The caller owns the value string. 972 * @return 0 on error (malloc or syntax error). 973 */ 974 int config_set_option(struct config_file* config, const char* option, 975 const char* value); 976 977 /** 978 * Call print routine for the given option. 979 * @param cfg: config. 980 * @param opt: option name without trailing :. 981 * This is different from config_set_option. 982 * @param func: print func, called as (str, arg) for every data element. 983 * @param arg: user argument for print func. 984 * @return false if the option name is not supported (syntax error). 985 */ 986 int config_get_option(struct config_file* cfg, const char* opt, 987 void (*func)(char*,void*), void* arg); 988 989 /** 990 * Get an option and return strlist 991 * @param cfg: config file 992 * @param opt: option name. 993 * @param list: list is returned here. malloced, caller must free it. 994 * @return 0=OK, 1=syntax error, 2=malloc failed. 995 */ 996 int config_get_option_list(struct config_file* cfg, const char* opt, 997 struct config_strlist** list); 998 999 /** 1000 * Get an option and collate results into string 1001 * @param cfg: config file 1002 * @param opt: option name. 1003 * @param str: string. malloced, caller must free it. 1004 * @return 0=OK, 1=syntax error, 2=malloc failed. 1005 */ 1006 int config_get_option_collate(struct config_file* cfg, const char* opt, 1007 char** str); 1008 1009 /** 1010 * function to print to a file, use as func with config_get_option. 1011 * @param line: text to print. \n appended. 1012 * @param arg: pass a FILE*, like stdout. 1013 */ 1014 void config_print_func(char* line, void* arg); 1015 1016 /** 1017 * function to collate the text strings into a strlist_head. 1018 * @param line: text to append. 1019 * @param arg: pass a strlist_head structure. zeroed on start. 1020 */ 1021 void config_collate_func(char* line, void* arg); 1022 1023 /** 1024 * take a strlist_head list and return a malloc string. separated with newline. 1025 * @param list: strlist first to collate. zeroes return "". 1026 * @return NULL on malloc failure. Or if malloc failure happened in strlist. 1027 */ 1028 char* config_collate_cat(struct config_strlist* list); 1029 1030 /** 1031 * Append text at end of list. 1032 * @param list: list head. zeroed at start. 1033 * @param item: new item. malloced by caller. if NULL the insertion fails. 1034 * @return true on success. 1035 * on fail the item is free()ed. 1036 */ 1037 int cfg_strlist_append(struct config_strlist_head* list, char* item); 1038 1039 /** 1040 * Searches the end of a string list and appends the given text. 1041 * @param head: pointer to strlist head variable. 1042 * @param item: new item. malloced by caller. if NULL the insertion fails. 1043 * @return true on success. 1044 */ 1045 int cfg_strlist_append_ex(struct config_strlist** head, char* item); 1046 1047 /** 1048 * Find string in strlist. 1049 * @param head: pointer to strlist head variable. 1050 * @param item: the item to search for. 1051 * @return: the element in the list when found, NULL otherwise. 1052 */ 1053 struct config_strlist* cfg_strlist_find(struct config_strlist* head, 1054 const char* item); 1055 1056 /** 1057 * Insert string into strlist. 1058 * @param head: pointer to strlist head variable. 1059 * @param item: new item. malloced by caller. If NULL the insertion fails. 1060 * @return: true on success. 1061 * on fail, the item is free()d. 1062 */ 1063 int cfg_strlist_insert(struct config_strlist** head, char* item); 1064 1065 /** insert with region for allocation. */ 1066 int cfg_region_strlist_insert(struct regional* region, 1067 struct config_strlist** head, char* item); 1068 1069 /** 1070 * Insert string into str2list. 1071 * @param head: pointer to str2list head variable. 1072 * @param item: new item. malloced by caller. If NULL the insertion fails. 1073 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 1074 * @return: true on success. 1075 * on fail, the item and i2 are free()d. 1076 */ 1077 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2); 1078 1079 /** 1080 * Insert string into str3list. 1081 * @param head: pointer to str3list head variable. 1082 * @param item: new item. malloced by caller. If NULL the insertion fails. 1083 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 1084 * @param i3: 3rd string, malloced by caller. If NULL the insertion fails. 1085 * @return: true on success. 1086 */ 1087 int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2, 1088 char* i3); 1089 1090 /** 1091 * Insert string into strbytelist. 1092 * @param head: pointer to strbytelist head variable. 1093 * @param item: new item. malloced by caller. If NULL the insertion fails. 1094 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails. 1095 * @param i2len: length of the i2 bytestring. 1096 * @return: true on success. 1097 */ 1098 int cfg_strbytelist_insert(struct config_strbytelist** head, char* item, 1099 uint8_t* i2, size_t i2len); 1100 1101 /** 1102 * Find stub in config list, also returns prevptr (for deletion). 1103 * @param pp: call routine with pointer to a pointer to the start of the list, 1104 * if the stub is found, on exit, the value contains a pointer to the 1105 * next pointer that points to the found element (or to the list start 1106 * pointer if it is the first element). 1107 * @param nm: name of stub to find. 1108 * @return: pointer to config_stub if found, or NULL if not found. 1109 */ 1110 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm); 1111 1112 /** 1113 * Delete items in config string list. 1114 * @param list: list. 1115 */ 1116 void config_delstrlist(struct config_strlist* list); 1117 1118 /** 1119 * Delete items in config double string list. 1120 * @param list: list. 1121 */ 1122 void config_deldblstrlist(struct config_str2list* list); 1123 1124 /** 1125 * Delete items in config triple string list. 1126 * @param list: list. 1127 */ 1128 void config_deltrplstrlist(struct config_str3list* list); 1129 1130 /** delete string array */ 1131 void config_del_strarray(char** array, int num); 1132 1133 /** delete stringbytelist */ 1134 void config_del_strbytelist(struct config_strbytelist* list); 1135 1136 /** 1137 * Delete a stub item 1138 * @param p: stub item 1139 */ 1140 void config_delstub(struct config_stub* p); 1141 1142 /** 1143 * Delete items in config stub list. 1144 * @param list: list. 1145 */ 1146 void config_delstubs(struct config_stub* list); 1147 1148 /** 1149 * Delete an auth item 1150 * @param p: auth item 1151 */ 1152 void config_delauth(struct config_auth* p); 1153 1154 /** 1155 * Delete items in config auth list. 1156 * @param list: list. 1157 */ 1158 void config_delauths(struct config_auth* list); 1159 1160 /** 1161 * Delete a view item 1162 * @param p: view item 1163 */ 1164 void config_delview(struct config_view* p); 1165 1166 /** 1167 * Delete items in config view list. 1168 * @param list: list. 1169 */ 1170 void config_delviews(struct config_view* list); 1171 1172 /** check if config for remote control turns on IP-address interface 1173 * with certificates or a named pipe without certificates. */ 1174 int options_remote_is_address(struct config_file* cfg); 1175 1176 /** 1177 * Convert 14digit to time value 1178 * @param str: string of 14 digits 1179 * @return time value or 0 for error. 1180 */ 1181 time_t cfg_convert_timeval(const char* str); 1182 1183 /** 1184 * Count number of values in the string. 1185 * format ::= (sp num)+ sp 1186 * num ::= [-](0-9)+ 1187 * sp ::= (space|tab)* 1188 * 1189 * @param str: string 1190 * @return: 0 on parse error, or empty string, else 1191 * number of integer values in the string. 1192 */ 1193 int cfg_count_numbers(const char* str); 1194 1195 /** 1196 * Convert a 'nice' memory or file size into a bytecount 1197 * From '100k' to 102400. and so on. Understands kKmMgG. 1198 * k=1024, m=1024*1024, g=1024*1024*1024. 1199 * @param str: string 1200 * @param res: result is stored here, size in bytes. 1201 * @return: true if parsed correctly, or 0 on a parse error (and an error 1202 * is logged). 1203 */ 1204 int cfg_parse_memsize(const char* str, size_t* res); 1205 1206 /** 1207 * Parse nsid from string into binary nsid. nsid is either a hexadecimal 1208 * string or an ascii string prepended with ascii_ in which case the 1209 * characters after ascii_ are simply copied. 1210 * @param str: the string to parse. 1211 * @param nsid_len: returns length of nsid in bytes. 1212 * @return malloced bytes or NULL on parse error or malloc failure. 1213 */ 1214 uint8_t* cfg_parse_nsid(const char* str, uint16_t* nsid_len); 1215 1216 /** 1217 * Add a tag name to the config. It is added at the end with a new ID value. 1218 * @param cfg: the config structure. 1219 * @param tag: string (which is copied) with the name. 1220 * @return: false on alloc failure. 1221 */ 1222 int config_add_tag(struct config_file* cfg, const char* tag); 1223 1224 /** 1225 * Find tag ID in the tag list. 1226 * @param cfg: the config structure. 1227 * @param tag: string with tag name to search for. 1228 * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found. 1229 */ 1230 int find_tag_id(struct config_file* cfg, const char* tag); 1231 1232 /** 1233 * parse taglist from string into bytestring with bitlist. 1234 * @param cfg: the config structure (with tagnames) 1235 * @param str: the string to parse. Parse puts 0 bytes in string. 1236 * @param listlen: returns length of in bytes. 1237 * @return malloced bytes with a bitlist of the tags. or NULL on parse error 1238 * or malloc failure. 1239 */ 1240 uint8_t* config_parse_taglist(struct config_file* cfg, char* str, 1241 size_t* listlen); 1242 1243 /** 1244 * convert tag bitlist to a malloced string with tag names. For debug output. 1245 * @param cfg: the config structure (with tagnames) 1246 * @param taglist: the tag bitlist. 1247 * @param len: length of the tag bitlist. 1248 * @return malloced string or NULL. 1249 */ 1250 char* config_taglist2str(struct config_file* cfg, uint8_t* taglist, 1251 size_t len); 1252 1253 /** 1254 * see if two taglists intersect (have tags in common). 1255 * @param list1: first tag bitlist. 1256 * @param list1len: length in bytes of first list. 1257 * @param list2: second tag bitlist. 1258 * @param list2len: length in bytes of second list. 1259 * @return true if there are tags in common, 0 if not. 1260 */ 1261 int taglist_intersect(uint8_t* list1, size_t list1len, const uint8_t* list2, 1262 size_t list2len); 1263 1264 /** 1265 * Parse local-zone directive into two strings and register it in the config. 1266 * @param cfg: to put it in. 1267 * @param val: argument strings to local-zone, "example.com nodefault". 1268 * @return: false on failure 1269 */ 1270 int cfg_parse_local_zone(struct config_file* cfg, const char* val); 1271 1272 /** 1273 * Mark "number" or "low-high" as available or not in ports array. 1274 * @param str: string in input 1275 * @param allow: give true if this range is permitted. 1276 * @param avail: the array from cfg. 1277 * @param num: size of the array (65536). 1278 * @return: true if parsed correctly, or 0 on a parse error (and an error 1279 * is logged). 1280 */ 1281 int cfg_mark_ports(const char* str, int allow, int* avail, int num); 1282 1283 /** 1284 * Get a condensed list of ports returned. allocated. 1285 * @param cfg: config file. 1286 * @param avail: the available ports array is returned here. 1287 * @return: number of ports in array or 0 on error. 1288 */ 1289 int cfg_condense_ports(struct config_file* cfg, int** avail); 1290 1291 /** 1292 * Apply system specific port range policy. 1293 * @param cfg: config file. 1294 * @param num: size of the array (65536). 1295 */ 1296 void cfg_apply_local_port_policy(struct config_file* cfg, int num); 1297 1298 /** 1299 * Scan ports available 1300 * @param avail: the array from cfg. 1301 * @param num: size of the array (65536). 1302 * @return the number of ports available for use. 1303 */ 1304 int cfg_scan_ports(int* avail, int num); 1305 1306 /** 1307 * Convert a filename to full pathname in original filesys 1308 * @param fname: the path name to convert. 1309 * Must not be null or empty. 1310 * @param cfg: config struct for chroot and chdir (if set). 1311 * @param use_chdir: if false, only chroot is applied. 1312 * @return pointer to malloced buffer which is: [chroot][chdir]fname 1313 * or NULL on malloc failure. 1314 */ 1315 char* fname_after_chroot(const char* fname, struct config_file* cfg, 1316 int use_chdir); 1317 1318 /** 1319 * Convert a ptr shorthand into a full reverse-notation PTR record. 1320 * @param str: input string, "IP name" 1321 * @return: malloced string "reversed-ip-name PTR name" 1322 */ 1323 char* cfg_ptr_reverse(char* str); 1324 1325 /** 1326 * Used during options parsing 1327 */ 1328 struct config_parser_state { 1329 /** name of file being parser */ 1330 char* filename; 1331 /** line number in the file, starts at 1 */ 1332 int line; 1333 /** number of errors encountered */ 1334 int errors; 1335 /** the result of parsing is stored here. */ 1336 struct config_file* cfg; 1337 /** the current chroot dir (or NULL if none) */ 1338 const char* chroot; 1339 /** if we are started in a toplevel, or not, after a force_toplevel */ 1340 int started_toplevel; 1341 }; 1342 1343 /** global config parser object used during config parsing */ 1344 extern struct config_parser_state* cfg_parser; 1345 /** init lex state */ 1346 void init_cfg_parse(void); 1347 /** lex in file */ 1348 extern FILE* ub_c_in; 1349 /** lex out file */ 1350 extern FILE* ub_c_out; 1351 /** the yacc lex generated parse function */ 1352 int ub_c_parse(void); 1353 /** the lexer function */ 1354 int ub_c_lex(void); 1355 /** wrap function */ 1356 int ub_c_wrap(void); 1357 /** parsing helpers: print error with file and line numbers */ 1358 void ub_c_error(const char* msg); 1359 /** parsing helpers: print error with file and line numbers */ 1360 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2); 1361 1362 #ifdef UB_ON_WINDOWS 1363 /** 1364 * Obtain registry string (if it exists). 1365 * @param key: key string 1366 * @param name: name of value to fetch. 1367 * @return malloced string with the result or NULL if it did not 1368 * exist on an error (logged with log_err) was encountered. 1369 */ 1370 char* w_lookup_reg_str(const char* key, const char* name); 1371 1372 /** Modify directory in options for module file name */ 1373 void w_config_adjust_directory(struct config_file* cfg); 1374 #endif /* UB_ON_WINDOWS */ 1375 1376 /** debug option for unit tests. */ 1377 extern int fake_dsa, fake_sha1; 1378 1379 /** see if interface is https, its port number == the https port number */ 1380 int if_is_https(const char* ifname, const char* port, int https_port); 1381 1382 /** 1383 * Return true if the config contains settings that enable https. 1384 * @param cfg: config information. 1385 * @return true if https ports are used for server. 1386 */ 1387 int cfg_has_https(struct config_file* cfg); 1388 1389 /** see if interface is PROXYv2, its port number == the proxy port number */ 1390 int if_is_pp2(const char* ifname, const char* port, 1391 struct config_strlist* proxy_protocol_port); 1392 1393 /** see if interface is DNSCRYPT, its port number == the dnscrypt port number */ 1394 int if_is_dnscrypt(const char* ifname, const char* port, int dnscrypt_port); 1395 #ifdef USE_LINUX_IP_LOCAL_PORT_RANGE 1396 #define LINUX_IP_LOCAL_PORT_RANGE_PATH "/proc/sys/net/ipv4/ip_local_port_range" 1397 #endif 1398 1399 #endif /* UTIL_CONFIG_FILE_H */ 1400