2 * util/config_file.h - reads and stores the config file for unbound.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
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.
39 * This file contains functions for the config file.
42 #ifndef UTIL_CONFIG_FILE_H
43 #define UTIL_CONFIG_FILE_H
47 struct config_strlist;
48 struct config_str2list;
49 struct config_str3list;
50 struct config_strbytelist;
53 struct ub_packed_rrset_key;
56 /** List head for strlist processing, used for append operation. */
57 struct config_strlist_head {
58 /** first in list of text items */
59 struct config_strlist* first;
60 /** last in list of text items */
61 struct config_strlist* last;
65 * The configuration options.
66 * Strings are malloced.
69 /** verbosity level as specified in the config file */
72 /** statistics interval (in seconds) */
74 /** if false, statistics values are reset after printing them */
76 /** if true, the statistics are kept in greater detail */
79 /** number of threads to create */
82 /** port on which queries are answered. */
84 /** do ip4 query support. */
86 /** do ip6 query support. */
88 /** prefer ip4 upstream queries. */
90 /** prefer ip6 upstream queries. */
92 /** do udp query support. */
94 /** do tcp query support. */
96 /** tcp upstream queries (no UDP upstream queries) */
98 /** udp upstream enabled when no UDP downstream is enabled (do_udp no)*/
99 int udp_upstream_without_downstream;
100 /** maximum segment size of tcp socket which queries are answered */
102 /** maximum segment size of tcp socket for outgoing queries */
103 int outgoing_tcp_mss;
104 /** tcp idle timeout, in msec */
105 int tcp_idle_timeout;
106 /** do edns tcp keepalive */
107 int do_tcp_keepalive;
108 /** tcp keepalive timeout, in msec */
109 int tcp_keepalive_timeout;
111 /** private key file for dnstcp-ssl service (enabled if not NULL) */
112 char* ssl_service_key;
113 /** public key file for dnstcp-ssl service */
114 char* ssl_service_pem;
115 /** port on which to provide ssl service */
117 /** if outgoing tcp connections use SSL */
119 /** cert bundle for outgoing connections */
120 char* tls_cert_bundle;
121 /** should the system certificate store get added to the cert bundle */
123 /** additional tls ports */
124 struct config_strlist* tls_additional_port;
125 /** secret key used to encrypt and decrypt TLS session ticket */
126 struct config_strlist_head tls_session_ticket_keys;
129 /** TLS chiphersuites (TLSv1.3) */
130 char* tls_ciphersuites;
131 /** if SNI is to be used */
134 /** port on which to provide DNS over HTTPS service */
136 /** endpoint for HTTP service */
138 /** MAX_CONCURRENT_STREAMS HTTP/2 setting */
139 uint32_t http_max_streams;
140 /** maximum size of all HTTP2 query buffers combined. */
141 size_t http_query_buffer_size;
142 /** maximum size of all HTTP2 response buffers combined. */
143 size_t http_response_buffer_size;
144 /** set TCP_NODELAY option for http sockets */
146 /** Disable TLS for http sockets downstream */
147 int http_notls_downstream;
149 /** outgoing port range number of ports (per thread) */
150 int outgoing_num_ports;
151 /** number of outgoing tcp buffers per (per thread) */
152 size_t outgoing_num_tcp;
153 /** number of incoming tcp buffers per (per thread) */
154 size_t incoming_num_tcp;
155 /** allowed udp port numbers, array with 0 if not allowed */
156 int* outgoing_avail_ports;
158 /** EDNS buffer size to use */
159 size_t edns_buffer_size;
160 /** size of the stream wait buffers, max */
161 size_t stream_wait_size;
162 /** number of bytes buffer size for DNS messages */
163 size_t msg_buffer_size;
164 /** size of the message cache */
165 size_t msg_cache_size;
166 /** slabs in the message cache. */
167 size_t msg_cache_slabs;
168 /** number of queries every thread can service */
169 size_t num_queries_per_thread;
170 /** number of msec to wait before items can be jostled out */
172 /** size of the rrset cache */
173 size_t rrset_cache_size;
174 /** slabs in the rrset cache */
175 size_t rrset_cache_slabs;
176 /** host cache ttl in seconds */
178 /** number of slabs in the infra host cache */
179 size_t infra_cache_slabs;
180 /** max number of hosts in the infra cache */
181 size_t infra_cache_numhosts;
182 /** min value for infra cache rtt */
183 int infra_cache_min_rtt;
184 /** keep probing hosts that are down */
185 int infra_keep_probing;
186 /** delay close of udp-timeouted ports, if 0 no delayclose. in msec */
188 /** udp_connect enable uses UDP connect to mitigate ICMP side channel */
191 /** the target fetch policy for the iterator */
192 char* target_fetch_policy;
193 /** percent*10, how many times in 1000 to pick from the fastest
195 int fast_server_permil;
196 /** number of fastest server to select from */
197 size_t fast_server_num;
199 /** automatic interface for incoming messages. Uses ipv6 remapping,
200 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */
202 /** SO_RCVBUF size to set on port 53 UDP socket */
204 /** SO_SNDBUF size to set on port 53 UDP socket */
206 /** SO_REUSEPORT requested on port 53 sockets */
208 /** IP_TRANSPARENT socket option requested on port 53 sockets */
210 /** IP_FREEBIND socket option request on port 53 sockets */
212 /** IP_TOS socket option requested on port 53 sockets */
215 /** number of interfaces to open. If 0 default all interfaces. */
217 /** interface description strings (IP addresses) */
220 /** number of outgoing interfaces to open.
221 * If 0 default all interfaces. */
223 /** outgoing interface description strings (IP addresses) */
226 /** the root hints */
227 struct config_strlist* root_hints;
228 /** the stub definitions, linked list */
229 struct config_stub* stubs;
230 /** the forward zone definitions, linked list */
231 struct config_stub* forwards;
232 /** the auth zone definitions, linked list */
233 struct config_auth* auths;
234 /** the views definitions, linked list */
235 struct config_view* views;
236 /** list of donotquery addresses, linked list */
237 struct config_strlist* donotqueryaddrs;
239 /** list of servers we send edns-client-subnet option to and
240 * accept option from, linked list */
241 struct config_strlist* client_subnet;
242 /** list of zones we send edns-client-subnet option for */
243 struct config_strlist* client_subnet_zone;
244 /** opcode assigned by IANA for edns0-client-subnet option */
245 uint16_t client_subnet_opcode;
246 /** Do not check whitelist if incoming query contains an ECS record */
247 int client_subnet_always_forward;
248 /** Subnet length we are willing to give up privacy for */
249 uint8_t max_client_subnet_ipv4;
250 uint8_t max_client_subnet_ipv6;
251 /** Minimum subnet length we are willing to answer */
252 uint8_t min_client_subnet_ipv4;
253 uint8_t min_client_subnet_ipv6;
254 /** Max number of nodes in the ECS radix tree */
255 uint32_t max_ecs_tree_size_ipv4;
256 uint32_t max_ecs_tree_size_ipv6;
258 /** list of access control entries, linked list */
259 struct config_str2list* acls;
260 /** use default localhost donotqueryaddr entries */
261 int donotquery_localhost;
263 /** list of tcp connection limitss, linked list */
264 struct config_str2list* tcp_connection_limits;
266 /** harden against very small edns buffer sizes */
267 int harden_short_bufsize;
268 /** harden against very large query sizes */
269 int harden_large_queries;
270 /** harden against spoofed glue (out of zone data) */
272 /** harden against receiving no DNSSEC data for trust anchor */
273 int harden_dnssec_stripped;
274 /** harden against queries that fall under known nxdomain names */
275 int harden_below_nxdomain;
276 /** harden the referral path, query for NS,A,AAAA and validate */
277 int harden_referral_path;
278 /** harden against algorithm downgrade */
279 int harden_algo_downgrade;
280 /** use 0x20 bits in query as random ID bits */
281 int use_caps_bits_for_id;
282 /** 0x20 whitelist, domains that do not use capsforid */
283 struct config_strlist* caps_whitelist;
284 /** strip away these private addrs from answers, no DNS Rebinding */
285 struct config_strlist* private_address;
286 /** allow domain (and subdomains) to use private address space */
287 struct config_strlist* private_domain;
288 /** what threshold for unwanted action. */
289 size_t unwanted_threshold;
290 /** the number of seconds maximal TTL used for RRsets and messages */
292 /** the number of seconds minimum TTL used for RRsets and messages */
294 /** the number of seconds maximal negative TTL for SOA in auth */
295 int max_negative_ttl;
296 /** if prefetching of messages should be performed. */
298 /** if prefetching of DNSKEYs should be performed. */
300 /** deny queries of type ANY with an empty answer */
303 /** chrootdir, if not "" or chroot will be done */
305 /** username to change to, if not "". */
307 /** working directory */
309 /** filename to log to. */
311 /** pidfile to write pid to. */
314 /** should log messages be sent to syslogd */
316 /** log timestamp in ascii UTC */
318 /** log queries with one line per query */
320 /** log replies with one line per reply */
322 /** tag log_queries and log_replies for filtering */
323 int log_tag_queryreply;
324 /** log every local-zone hit **/
325 int log_local_actions;
326 /** log servfails with a reason */
328 /** log identity to report */
331 /** do not report identity (id.server, hostname.bind) */
333 /** do not report version (version.server, version.bind) */
335 /** do not report trustanchor (trustanchor.unbound) */
336 int hide_trustanchor;
337 /** identity, hostname is returned if "". */
339 /** version, package version returned if "". */
342 /** the module configuration string */
345 /** files with trusted DS and DNSKEYs in zonefile format, list */
346 struct config_strlist* trust_anchor_file_list;
347 /** list of trustanchor keys, linked list */
348 struct config_strlist* trust_anchor_list;
349 /** files with 5011 autotrust tracked keys */
350 struct config_strlist* auto_trust_anchor_file_list;
351 /** files with trusted DNSKEYs in named.conf format, list */
352 struct config_strlist* trusted_keys_file_list;
353 /** insecure domain list */
354 struct config_strlist* domain_insecure;
355 /** send key tag query */
356 int trust_anchor_signaling;
357 /** enable root key sentinel */
358 int root_key_sentinel;
360 /** if not 0, this value is the validation date for RRSIGs */
361 int32_t val_date_override;
362 /** the minimum for signature clock skew */
363 int32_t val_sig_skew_min;
364 /** the maximum for signature clock skew */
365 int32_t val_sig_skew_max;
366 /** this value sets the number of seconds before revalidating bogus */
368 /** should validator clean additional section for secure msgs */
369 int val_clean_additional;
370 /** log bogus messages by the validator */
372 /** squelch val_log_level to log - this is library goes to callback */
374 /** should validator allow bogus messages to go through */
375 int val_permissive_mode;
376 /** use cached NSEC records to synthesise (negative) answers */
378 /** ignore the CD flag in incoming queries and refuse them bogus data */
380 /** serve expired entries and prefetch them */
382 /** serve expired entries until TTL after expiration */
383 int serve_expired_ttl;
384 /** reset serve expired TTL after failed update attempt */
385 int serve_expired_ttl_reset;
386 /** TTL for the serve expired replies */
387 int serve_expired_reply_ttl;
388 /** serve expired entries only after trying to update the entries and this
389 * timeout (in milliseconds) is reached */
390 int serve_expired_client_timeout;
391 /** nsec3 maximum iterations per key size, string */
392 char* val_nsec3_key_iterations;
393 /** autotrust add holddown time, in seconds */
394 unsigned int add_holddown;
395 /** autotrust del holddown time, in seconds */
396 unsigned int del_holddown;
397 /** autotrust keep_missing time, in seconds. 0 is forever. */
398 unsigned int keep_missing;
399 /** permit small holddown values, allowing 5011 rollover very fast */
400 int permit_small_holddown;
402 /** size of the key cache */
403 size_t key_cache_size;
404 /** slabs in the key cache. */
405 size_t key_cache_slabs;
406 /** size of the neg cache */
407 size_t neg_cache_size;
409 /** local zones config */
410 struct config_str2list* local_zones;
411 /** local zones nodefault list */
412 struct config_strlist* local_zones_nodefault;
414 /** local zones ipset list */
415 struct config_strlist* local_zones_ipset;
417 /** do not add any default local zone */
418 int local_zones_disable_default;
419 /** local data RRs configured */
420 struct config_strlist* local_data;
421 /** local zone override types per netblock */
422 struct config_str3list* local_zone_overrides;
423 /** unblock lan zones (reverse lookups for AS112 zones) */
424 int unblock_lan_zones;
425 /** insecure lan zones (don't validate AS112 zones) */
426 int insecure_lan_zones;
427 /** list of zonename, tagbitlist */
428 struct config_strbytelist* local_zone_tags;
429 /** list of aclname, tagbitlist */
430 struct config_strbytelist* acl_tags;
431 /** list of aclname, tagname, localzonetype */
432 struct config_str3list* acl_tag_actions;
433 /** list of aclname, tagname, redirectdata */
434 struct config_str3list* acl_tag_datas;
435 /** list of aclname, view*/
436 struct config_str2list* acl_view;
437 /** list of IP-netblock, tagbitlist */
438 struct config_strbytelist* respip_tags;
439 /** list of response-driven access control entries, linked list */
440 struct config_str2list* respip_actions;
441 /** RRs configured for response-driven access controls */
442 struct config_str2list* respip_data;
443 /** tag list, array with tagname[i] is malloced string */
445 /** number of items in the taglist */
448 /** remote control section. enable toggle. */
449 int remote_control_enable;
450 /** the interfaces the remote control should listen on */
451 struct config_strlist_head control_ifs;
452 /** if the use-cert option is set */
453 int control_use_cert;
454 /** port number for the control port */
456 /** private key file for server */
457 char* server_key_file;
458 /** certificate file for server */
459 char* server_cert_file;
460 /** private key file for unbound-control */
461 char* control_key_file;
462 /** certificate file for unbound-control */
463 char* control_cert_file;
465 /** Python script file */
466 struct config_strlist* python_script;
468 /** Dynamic library file */
469 struct config_strlist* dynlib_file;
471 /** Use systemd socket activation. */
474 /** daemonize, i.e. fork into the background. */
477 /* minimal response when positive answer */
478 int minimal_responses;
480 /* RRSet roundrobin */
481 int rrset_roundrobin;
483 /* wait time for unknown server in msec */
484 int unknown_server_time_limit;
486 /* maximum UDP response size */
492 /* Synthetize all AAAA record despite the presence of an authoritative one */
494 /** ignore AAAAs for these domain names and use A record anyway */
495 struct config_strlist* dns64_ignore_aaaa;
497 /** true to enable dnstap support */
499 /** using bidirectional frame streams if true */
500 int dnstap_bidirectional;
501 /** dnstap socket path */
502 char* dnstap_socket_path;
505 /** dnstap TLS enable */
507 /** dnstap tls server authentication name */
508 char* dnstap_tls_server_name;
509 /** dnstap server cert bundle */
510 char* dnstap_tls_cert_bundle;
511 /** dnstap client key for client authentication */
512 char* dnstap_tls_client_key_file;
513 /** dnstap client cert for client authentication */
514 char* dnstap_tls_client_cert_file;
515 /** true to send "identity" via dnstap */
516 int dnstap_send_identity;
517 /** true to send "version" via dnstap */
518 int dnstap_send_version;
519 /** dnstap "identity", hostname is used if "". */
520 char* dnstap_identity;
521 /** dnstap "version", package version is used if "". */
522 char* dnstap_version;
524 /** true to log dnstap RESOLVER_QUERY message events */
525 int dnstap_log_resolver_query_messages;
526 /** true to log dnstap RESOLVER_RESPONSE message events */
527 int dnstap_log_resolver_response_messages;
528 /** true to log dnstap CLIENT_QUERY message events */
529 int dnstap_log_client_query_messages;
530 /** true to log dnstap CLIENT_RESPONSE message events */
531 int dnstap_log_client_response_messages;
532 /** true to log dnstap FORWARDER_QUERY message events */
533 int dnstap_log_forwarder_query_messages;
534 /** true to log dnstap FORWARDER_RESPONSE message events */
535 int dnstap_log_forwarder_response_messages;
537 /** true to disable DNSSEC lameness check in iterator */
538 int disable_dnssec_lame_check;
540 /** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */
542 /** number of slabs for ip_ratelimit cache */
543 size_t ip_ratelimit_slabs;
544 /** memory size in bytes for ip_ratelimit cache */
545 size_t ip_ratelimit_size;
546 /** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
547 int ip_ratelimit_factor;
549 /** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */
551 /** number of slabs for ratelimit cache */
552 size_t ratelimit_slabs;
553 /** memory size in bytes for ratelimit cache */
554 size_t ratelimit_size;
555 /** ratelimits for domain (exact match) */
556 struct config_str2list* ratelimit_for_domain;
557 /** ratelimits below domain */
558 struct config_str2list* ratelimit_below_domain;
559 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
560 int ratelimit_factor;
561 /** minimise outgoing QNAME and hide original QTYPE if possible */
562 int qname_minimisation;
563 /** minimise QNAME in strict mode, minimise according to RFC.
564 * Do not apply fallback */
565 int qname_minimisation_strict;
566 /** SHM data - true if shm is enabled */
568 /** SHM data - key for the shm */
571 /** list of EDNS client string entries, linked list */
572 struct config_str2list* edns_client_strings;
573 /** EDNS opcode to use for EDNS client strings */
574 uint16_t edns_client_string_opcode;
577 /** true to enable dnscrypt */
579 /** port on which to provide dnscrypt service */
581 /** provider name 2.dnscrypt-cert.example.com */
582 char* dnscrypt_provider;
583 /** dnscrypt secret keys 1.key */
584 struct config_strlist* dnscrypt_secret_key;
585 /** dnscrypt provider certs 1.cert */
586 struct config_strlist* dnscrypt_provider_cert;
587 /** dnscrypt provider certs 1.cert which have been rotated and should not be
588 * advertised through DNS's providername TXT record but are required to be
589 * able to handle existing traffic using the old cert. */
590 struct config_strlist* dnscrypt_provider_cert_rotated;
591 /** memory size in bytes for dnscrypt shared secrets cache */
592 size_t dnscrypt_shared_secret_cache_size;
593 /** number of slabs for dnscrypt shared secrets cache */
594 size_t dnscrypt_shared_secret_cache_slabs;
595 /** memory size in bytes for dnscrypt nonces cache */
596 size_t dnscrypt_nonce_cache_size;
597 /** number of slabs for dnscrypt nonces cache */
598 size_t dnscrypt_nonce_cache_slabs;
601 /** false to bypass the IPsec module */
602 int ipsecmod_enabled;
603 /** whitelisted domains for ipsecmod */
604 struct config_strlist* ipsecmod_whitelist;
605 /** path to external hook */
607 /** true to proceed even with a bogus IPSECKEY */
608 int ipsecmod_ignore_bogus;
609 /** max TTL for the A/AAAA records that call the hook */
610 int ipsecmod_max_ttl;
611 /** false to proceed even when ipsecmod_hook fails */
617 /** backend DB name */
618 char* cachedb_backend;
619 /** secret seed for hash key calculation */
620 char* cachedb_secret;
622 /** redis server's IP address or host name */
623 char* redis_server_host;
624 /** redis server's TCP port */
625 int redis_server_port;
626 /** timeout (in ms) for communication with the redis server */
628 /** set timeout on redis records based on DNS response ttl */
629 int redis_expire_records;
640 /** from cfg username, after daemonize setup performed */
641 extern uid_t cfg_uid;
642 /** from cfg username, after daemonize setup performed */
643 extern gid_t cfg_gid;
644 /** debug and enable small timeouts */
645 extern int autr_permit_small_holddown;
646 /** size (in bytes) of stream wait buffers max */
647 extern size_t stream_wait_max;
648 /** size (in bytes) of all total HTTP2 query buffers max */
649 extern size_t http2_query_buffer_max;
650 /** size (in bytes) of all total HTTP2 response buffers max */
651 extern size_t http2_response_buffer_max;
654 * Stub config options
658 struct config_stub* next;
659 /** domain name (in text) of the stub apex domain */
661 /** list of stub nameserver hosts (domain name) */
662 struct config_strlist* hosts;
663 /** list of stub nameserver addresses (IP address) */
664 struct config_strlist* addrs;
665 /** if stub-prime is set */
667 /** if forward-first is set (failover to without if fails) */
669 /** use SSL for queries to this stub */
676 * Auth config options
680 struct config_auth* next;
681 /** domain name (in text) of the auth apex domain */
683 /** list of masters */
684 struct config_strlist* masters;
686 struct config_strlist* urls;
687 /** list of allow-notify */
688 struct config_strlist* allow_notify;
689 /** zonefile (or NULL) */
691 /** provide downstream answers */
693 /** provide upstream answers */
695 /** fallback to recursion to authorities if zone expired and other
696 * reasons perhaps (like, query bogus) */
697 int fallback_enabled;
698 /** this zone is used to create local-zone policies */
700 /** rpz tags (or NULL) */
701 uint8_t* rpz_taglist;
702 /** length of the taglist (in bytes) */
703 size_t rpz_taglistlen;
704 /** Override RPZ action for this zone, regardless of zone content */
705 char* rpz_action_override;
706 /** Log when this RPZ policy is applied */
708 /** Display this name in the log when RPZ policy is applied */
710 /** Always reply with this CNAME target if the cname override action is
716 * View config options
720 struct config_view* next;
724 struct config_str2list* local_zones;
725 /** local data RRs */
726 struct config_strlist* local_data;
727 /** local zones nodefault list */
728 struct config_strlist* local_zones_nodefault;
730 /** local zones ipset list */
731 struct config_strlist* local_zones_ipset;
733 /** Fallback to global local_zones when there is no match in the view
734 * view specific tree. 1 for yes, 0 for no */
736 /** predefined actions for particular IP address responses */
737 struct config_str2list* respip_actions;
738 /** data complementing the 'redirect' response IP actions */
739 struct config_str2list* respip_data;
743 * List of strings for config options
745 struct config_strlist {
746 /** next item in list */
747 struct config_strlist* next;
748 /** config option string */
753 * List of two strings for config options
755 struct config_str2list {
756 /** next item in list */
757 struct config_str2list* next;
765 * List of three strings for config options
767 struct config_str3list {
768 /** next item in list */
769 struct config_str3list* next;
780 * List of string, bytestring for config options
782 struct config_strbytelist {
783 /** next item in list */
784 struct config_strbytelist* next;
787 /** second bytestring */
793 * Create config file structure. Filled with default values.
794 * @return: the new structure or NULL on memory error.
796 struct config_file* config_create(void);
799 * Create config file structure for library use. Filled with default values.
800 * @return: the new structure or NULL on memory error.
802 struct config_file* config_create_forlib(void);
805 * Read the config file from the specified filename.
806 * @param config: where options are stored into, must be freshly created.
807 * @param filename: name of configfile. If NULL nothing is done.
808 * @param chroot: if not NULL, the chroot dir currently in use (for include).
809 * @return: false on error. In that case errno is set, ENOENT means
812 int config_read(struct config_file* config, const char* filename,
816 * Destroy the config file structure.
817 * @param config: to delete.
819 void config_delete(struct config_file* config);
822 * Apply config to global constants; this routine is called in single thread.
823 * @param config: to apply. Side effect: global constants change.
825 void config_apply(struct config_file* config);
828 * Find username, sets cfg_uid and cfg_gid.
829 * @param config: the config structure.
831 void config_lookup_uid(struct config_file* config);
834 * Set the given keyword to the given value.
835 * @param config: where to store config
836 * @param option: option name, including the ':' character.
837 * @param value: value, this string is copied if needed, or parsed.
838 * The caller owns the value string.
839 * @return 0 on error (malloc or syntax error).
841 int config_set_option(struct config_file* config, const char* option,
845 * Call print routine for the given option.
846 * @param cfg: config.
847 * @param opt: option name without trailing :.
848 * This is different from config_set_option.
849 * @param func: print func, called as (str, arg) for every data element.
850 * @param arg: user argument for print func.
851 * @return false if the option name is not supported (syntax error).
853 int config_get_option(struct config_file* cfg, const char* opt,
854 void (*func)(char*,void*), void* arg);
857 * Get an option and return strlist
858 * @param cfg: config file
859 * @param opt: option name.
860 * @param list: list is returned here. malloced, caller must free it.
861 * @return 0=OK, 1=syntax error, 2=malloc failed.
863 int config_get_option_list(struct config_file* cfg, const char* opt,
864 struct config_strlist** list);
867 * Get an option and collate results into string
868 * @param cfg: config file
869 * @param opt: option name.
870 * @param str: string. malloced, caller must free it.
871 * @return 0=OK, 1=syntax error, 2=malloc failed.
873 int config_get_option_collate(struct config_file* cfg, const char* opt,
877 * function to print to a file, use as func with config_get_option.
878 * @param line: text to print. \n appended.
879 * @param arg: pass a FILE*, like stdout.
881 void config_print_func(char* line, void* arg);
884 * function to collate the text strings into a strlist_head.
885 * @param line: text to append.
886 * @param arg: pass a strlist_head structure. zeroed on start.
888 void config_collate_func(char* line, void* arg);
891 * take a strlist_head list and return a malloc string. separated with newline.
892 * @param list: strlist first to collate. zeroes return "".
893 * @return NULL on malloc failure. Or if malloc failure happened in strlist.
895 char* config_collate_cat(struct config_strlist* list);
898 * Append text at end of list.
899 * @param list: list head. zeroed at start.
900 * @param item: new item. malloced by caller. if NULL the insertion fails.
901 * @return true on success.
902 * on fail the item is free()ed.
904 int cfg_strlist_append(struct config_strlist_head* list, char* item);
907 * Searches the end of a string list and appends the given text.
908 * @param head: pointer to strlist head variable.
909 * @param item: new item. malloced by caller. if NULL the insertion fails.
910 * @return true on success.
912 int cfg_strlist_append_ex(struct config_strlist** head, char* item);
915 * Find string in strlist.
916 * @param head: pointer to strlist head variable.
917 * @param item: the item to search for.
918 * @return: the element in the list when found, NULL otherwise.
920 struct config_strlist* cfg_strlist_find(struct config_strlist* head,
924 * Insert string into strlist.
925 * @param head: pointer to strlist head variable.
926 * @param item: new item. malloced by caller. If NULL the insertion fails.
927 * @return: true on success.
928 * on fail, the item is free()d.
930 int cfg_strlist_insert(struct config_strlist** head, char* item);
932 /** insert with region for allocation. */
933 int cfg_region_strlist_insert(struct regional* region,
934 struct config_strlist** head, char* item);
937 * Insert string into str2list.
938 * @param head: pointer to str2list head variable.
939 * @param item: new item. malloced by caller. If NULL the insertion fails.
940 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
941 * @return: true on success.
942 * on fail, the item and i2 are free()d.
944 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);
947 * Insert string into str3list.
948 * @param head: pointer to str3list head variable.
949 * @param item: new item. malloced by caller. If NULL the insertion fails.
950 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
951 * @param i3: 3rd string, malloced by caller. If NULL the insertion fails.
952 * @return: true on success.
954 int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2,
958 * Insert string into strbytelist.
959 * @param head: pointer to strbytelist head variable.
960 * @param item: new item. malloced by caller. If NULL the insertion fails.
961 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
962 * @param i2len: length of the i2 bytestring.
963 * @return: true on success.
965 int cfg_strbytelist_insert(struct config_strbytelist** head, char* item,
966 uint8_t* i2, size_t i2len);
969 * Find stub in config list, also returns prevptr (for deletion).
970 * @param pp: call routine with pointer to a pointer to the start of the list,
971 * if the stub is found, on exit, the value contains a pointer to the
972 * next pointer that points to the found element (or to the list start
973 * pointer if it is the first element).
974 * @param nm: name of stub to find.
975 * @return: pointer to config_stub if found, or NULL if not found.
977 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm);
980 * Delete items in config string list.
983 void config_delstrlist(struct config_strlist* list);
986 * Delete items in config double string list.
989 void config_deldblstrlist(struct config_str2list* list);
992 * Delete items in config triple string list.
995 void config_deltrplstrlist(struct config_str3list* list);
997 /** delete string array */
998 void config_del_strarray(char** array, int num);
1000 /** delete stringbytelist */
1001 void config_del_strbytelist(struct config_strbytelist* list);
1004 * Delete a stub item
1005 * @param p: stub item
1007 void config_delstub(struct config_stub* p);
1010 * Delete items in config stub list.
1011 * @param list: list.
1013 void config_delstubs(struct config_stub* list);
1016 * Delete an auth item
1017 * @param p: auth item
1019 void config_delauth(struct config_auth* p);
1022 * Delete items in config auth list.
1023 * @param list: list.
1025 void config_delauths(struct config_auth* list);
1028 * Delete a view item
1029 * @param p: view item
1031 void config_delview(struct config_view* p);
1034 * Delete items in config view list.
1035 * @param list: list.
1037 void config_delviews(struct config_view* list);
1039 /** check if config for remote control turns on IP-address interface
1040 * with certificates or a named pipe without certificates. */
1041 int options_remote_is_address(struct config_file* cfg);
1044 * Convert 14digit to time value
1045 * @param str: string of 14 digits
1046 * @return time value or 0 for error.
1048 time_t cfg_convert_timeval(const char* str);
1051 * Count number of values in the string.
1052 * format ::= (sp num)+ sp
1054 * sp ::= (space|tab)*
1056 * @param str: string
1057 * @return: 0 on parse error, or empty string, else
1058 * number of integer values in the string.
1060 int cfg_count_numbers(const char* str);
1063 * Convert a 'nice' memory or file size into a bytecount
1064 * From '100k' to 102400. and so on. Understands kKmMgG.
1065 * k=1024, m=1024*1024, g=1024*1024*1024.
1066 * @param str: string
1067 * @param res: result is stored here, size in bytes.
1068 * @return: true if parsed correctly, or 0 on a parse error (and an error
1071 int cfg_parse_memsize(const char* str, size_t* res);
1074 * Add a tag name to the config. It is added at the end with a new ID value.
1075 * @param cfg: the config structure.
1076 * @param tag: string (which is copied) with the name.
1077 * @return: false on alloc failure.
1079 int config_add_tag(struct config_file* cfg, const char* tag);
1082 * Find tag ID in the tag list.
1083 * @param cfg: the config structure.
1084 * @param tag: string with tag name to search for.
1085 * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found.
1087 int find_tag_id(struct config_file* cfg, const char* tag);
1090 * parse taglist from string into bytestring with bitlist.
1091 * @param cfg: the config structure (with tagnames)
1092 * @param str: the string to parse. Parse puts 0 bytes in string.
1093 * @param listlen: returns length of in bytes.
1094 * @return malloced bytes with a bitlist of the tags. or NULL on parse error
1095 * or malloc failure.
1097 uint8_t* config_parse_taglist(struct config_file* cfg, char* str,
1101 * convert tag bitlist to a malloced string with tag names. For debug output.
1102 * @param cfg: the config structure (with tagnames)
1103 * @param taglist: the tag bitlist.
1104 * @param len: length of the tag bitlist.
1105 * @return malloced string or NULL.
1107 char* config_taglist2str(struct config_file* cfg, uint8_t* taglist,
1111 * see if two taglists intersect (have tags in common).
1112 * @param list1: first tag bitlist.
1113 * @param list1len: length in bytes of first list.
1114 * @param list2: second tag bitlist.
1115 * @param list2len: length in bytes of second list.
1116 * @return true if there are tags in common, 0 if not.
1118 int taglist_intersect(uint8_t* list1, size_t list1len, const uint8_t* list2,
1122 * Parse local-zone directive into two strings and register it in the config.
1123 * @param cfg: to put it in.
1124 * @param val: argument strings to local-zone, "example.com nodefault".
1125 * @return: false on failure
1127 int cfg_parse_local_zone(struct config_file* cfg, const char* val);
1130 * Mark "number" or "low-high" as available or not in ports array.
1131 * @param str: string in input
1132 * @param allow: give true if this range is permitted.
1133 * @param avail: the array from cfg.
1134 * @param num: size of the array (65536).
1135 * @return: true if parsed correctly, or 0 on a parse error (and an error
1138 int cfg_mark_ports(const char* str, int allow, int* avail, int num);
1141 * Get a condensed list of ports returned. allocated.
1142 * @param cfg: config file.
1143 * @param avail: the available ports array is returned here.
1144 * @return: number of ports in array or 0 on error.
1146 int cfg_condense_ports(struct config_file* cfg, int** avail);
1149 * Scan ports available
1150 * @param avail: the array from cfg.
1151 * @param num: size of the array (65536).
1152 * @return the number of ports available for use.
1154 int cfg_scan_ports(int* avail, int num);
1157 * Convert a filename to full pathname in original filesys
1158 * @param fname: the path name to convert.
1159 * Must not be null or empty.
1160 * @param cfg: config struct for chroot and chdir (if set).
1161 * @param use_chdir: if false, only chroot is applied.
1162 * @return pointer to malloced buffer which is: [chroot][chdir]fname
1163 * or NULL on malloc failure.
1165 char* fname_after_chroot(const char* fname, struct config_file* cfg,
1169 * Convert a ptr shorthand into a full reverse-notation PTR record.
1170 * @param str: input string, "IP name"
1171 * @return: malloced string "reversed-ip-name PTR name"
1173 char* cfg_ptr_reverse(char* str);
1176 * Append text to the error info for validation.
1177 * @param qstate: query state.
1178 * @param str: copied into query region and appended.
1179 * Failures to allocate are logged.
1181 void errinf(struct module_qstate* qstate, const char* str);
1184 * Append text to error info: from 1.2.3.4
1185 * @param qstate: query state.
1186 * @param origin: sock list with origin of trouble.
1187 * Every element added.
1188 * If NULL: nothing is added.
1189 * if 0len element: 'from cache' is added.
1191 void errinf_origin(struct module_qstate* qstate, struct sock_list *origin);
1194 * Append text to error info: for RRset name type class
1195 * @param qstate: query state.
1196 * @param rr: rrset_key.
1198 void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr);
1201 * Append text to error info: str dname
1202 * @param qstate: query state.
1203 * @param str: explanation string
1204 * @param dname: the dname.
1206 void errinf_dname(struct module_qstate* qstate, const char* str,
1210 * Create error info in string. For validation failures.
1211 * @param qstate: query state.
1212 * @return string or NULL on malloc failure (already logged).
1213 * This string is malloced and has to be freed by caller.
1215 char* errinf_to_str_bogus(struct module_qstate* qstate);
1218 * Create error info in string. For other servfails.
1219 * @param qstate: query state.
1220 * @return string or NULL on malloc failure (already logged).
1221 * This string is malloced and has to be freed by caller.
1223 char* errinf_to_str_servfail(struct module_qstate* qstate);
1226 * Used during options parsing
1228 struct config_parser_state {
1229 /** name of file being parser */
1231 /** line number in the file, starts at 1 */
1233 /** number of errors encountered */
1235 /** the result of parsing is stored here. */
1236 struct config_file* cfg;
1237 /** the current chroot dir (or NULL if none) */
1241 /** global config parser object used during config parsing */
1242 extern struct config_parser_state* cfg_parser;
1243 /** init lex state */
1244 void init_cfg_parse(void);
1246 extern FILE* ub_c_in;
1248 extern FILE* ub_c_out;
1249 /** the yacc lex generated parse function */
1250 int ub_c_parse(void);
1251 /** the lexer function */
1253 /** wrap function */
1254 int ub_c_wrap(void);
1255 /** parsing helpers: print error with file and line numbers */
1256 void ub_c_error(const char* msg);
1257 /** parsing helpers: print error with file and line numbers */
1258 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
1260 #ifdef UB_ON_WINDOWS
1262 * Obtain registry string (if it exists).
1263 * @param key: key string
1264 * @param name: name of value to fetch.
1265 * @return malloced string with the result or NULL if it did not
1266 * exist on an error (logged with log_err) was encountered.
1268 char* w_lookup_reg_str(const char* key, const char* name);
1270 /** Modify directory in options for module file name */
1271 void w_config_adjust_directory(struct config_file* cfg);
1272 #endif /* UB_ON_WINDOWS */
1274 /** debug option for unit tests. */
1275 extern int fake_dsa, fake_sha1;
1277 #endif /* UTIL_CONFIG_FILE_H */