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 /** outgoing port range number of ports (per thread) */
135 int outgoing_num_ports;
136 /** number of outgoing tcp buffers per (per thread) */
137 size_t outgoing_num_tcp;
138 /** number of incoming tcp buffers per (per thread) */
139 size_t incoming_num_tcp;
140 /** allowed udp port numbers, array with 0 if not allowed */
141 int* outgoing_avail_ports;
143 /** EDNS buffer size to use */
144 size_t edns_buffer_size;
145 /** size of the stream wait buffers, max */
146 size_t stream_wait_size;
147 /** number of bytes buffer size for DNS messages */
148 size_t msg_buffer_size;
149 /** size of the message cache */
150 size_t msg_cache_size;
151 /** slabs in the message cache. */
152 size_t msg_cache_slabs;
153 /** number of queries every thread can service */
154 size_t num_queries_per_thread;
155 /** number of msec to wait before items can be jostled out */
157 /** size of the rrset cache */
158 size_t rrset_cache_size;
159 /** slabs in the rrset cache */
160 size_t rrset_cache_slabs;
161 /** host cache ttl in seconds */
163 /** number of slabs in the infra host cache */
164 size_t infra_cache_slabs;
165 /** max number of hosts in the infra cache */
166 size_t infra_cache_numhosts;
167 /** min value for infra cache rtt */
168 int infra_cache_min_rtt;
169 /** delay close of udp-timeouted ports, if 0 no delayclose. in msec */
172 /** the target fetch policy for the iterator */
173 char* target_fetch_policy;
174 /** percent*10, how many times in 1000 to pick from the fastest
176 int fast_server_permil;
177 /** number of fastest server to select from */
178 size_t fast_server_num;
180 /** automatic interface for incoming messages. Uses ipv6 remapping,
181 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */
183 /** SO_RCVBUF size to set on port 53 UDP socket */
185 /** SO_SNDBUF size to set on port 53 UDP socket */
187 /** SO_REUSEPORT requested on port 53 sockets */
189 /** IP_TRANSPARENT socket option requested on port 53 sockets */
191 /** IP_FREEBIND socket option request on port 53 sockets */
193 /** IP_TOS socket option requested on port 53 sockets */
196 /** number of interfaces to open. If 0 default all interfaces. */
198 /** interface description strings (IP addresses) */
201 /** number of outgoing interfaces to open.
202 * If 0 default all interfaces. */
204 /** outgoing interface description strings (IP addresses) */
207 /** the root hints */
208 struct config_strlist* root_hints;
209 /** the stub definitions, linked list */
210 struct config_stub* stubs;
211 /** the forward zone definitions, linked list */
212 struct config_stub* forwards;
213 /** the auth zone definitions, linked list */
214 struct config_auth* auths;
215 /** the views definitions, linked list */
216 struct config_view* views;
217 /** list of donotquery addresses, linked list */
218 struct config_strlist* donotqueryaddrs;
220 /** list of servers we send edns-client-subnet option to and
221 * accept option from, linked list */
222 struct config_strlist* client_subnet;
223 /** list of zones we send edns-client-subnet option for */
224 struct config_strlist* client_subnet_zone;
225 /** opcode assigned by IANA for edns0-client-subnet option */
226 uint16_t client_subnet_opcode;
227 /** Do not check whitelist if incoming query contains an ECS record */
228 int client_subnet_always_forward;
229 /** Subnet length we are willing to give up privacy for */
230 uint8_t max_client_subnet_ipv4;
231 uint8_t max_client_subnet_ipv6;
232 /** Minimum subnet length we are willing to answer */
233 uint8_t min_client_subnet_ipv4;
234 uint8_t min_client_subnet_ipv6;
235 /** Max number of nodes in the ECS radix tree */
236 uint32_t max_ecs_tree_size_ipv4;
237 uint32_t max_ecs_tree_size_ipv6;
239 /** list of access control entries, linked list */
240 struct config_str2list* acls;
241 /** use default localhost donotqueryaddr entries */
242 int donotquery_localhost;
244 /** list of tcp connection limitss, linked list */
245 struct config_str2list* tcp_connection_limits;
247 /** harden against very small edns buffer sizes */
248 int harden_short_bufsize;
249 /** harden against very large query sizes */
250 int harden_large_queries;
251 /** harden against spoofed glue (out of zone data) */
253 /** harden against receiving no DNSSEC data for trust anchor */
254 int harden_dnssec_stripped;
255 /** harden against queries that fall under known nxdomain names */
256 int harden_below_nxdomain;
257 /** harden the referral path, query for NS,A,AAAA and validate */
258 int harden_referral_path;
259 /** harden against algorithm downgrade */
260 int harden_algo_downgrade;
261 /** use 0x20 bits in query as random ID bits */
262 int use_caps_bits_for_id;
263 /** 0x20 whitelist, domains that do not use capsforid */
264 struct config_strlist* caps_whitelist;
265 /** strip away these private addrs from answers, no DNS Rebinding */
266 struct config_strlist* private_address;
267 /** allow domain (and subdomains) to use private address space */
268 struct config_strlist* private_domain;
269 /** what threshold for unwanted action. */
270 size_t unwanted_threshold;
271 /** the number of seconds maximal TTL used for RRsets and messages */
273 /** the number of seconds minimum TTL used for RRsets and messages */
275 /** the number of seconds maximal negative TTL for SOA in auth */
276 int max_negative_ttl;
277 /** if prefetching of messages should be performed. */
279 /** if prefetching of DNSKEYs should be performed. */
281 /** deny queries of type ANY with an empty answer */
284 /** chrootdir, if not "" or chroot will be done */
286 /** username to change to, if not "". */
288 /** working directory */
290 /** filename to log to. */
292 /** pidfile to write pid to. */
295 /** should log messages be sent to syslogd */
297 /** log timestamp in ascii UTC */
299 /** log queries with one line per query */
301 /** log replies with one line per reply */
303 /** tag log_queries and log_replies for filtering */
304 int log_tag_queryreply;
305 /** log every local-zone hit **/
306 int log_local_actions;
307 /** log servfails with a reason */
309 /** log identity to report */
312 /** do not report identity (id.server, hostname.bind) */
314 /** do not report version (version.server, version.bind) */
316 /** do not report trustanchor (trustanchor.unbound) */
317 int hide_trustanchor;
318 /** identity, hostname is returned if "". */
320 /** version, package version returned if "". */
323 /** the module configuration string */
326 /** files with trusted DS and DNSKEYs in zonefile format, list */
327 struct config_strlist* trust_anchor_file_list;
328 /** list of trustanchor keys, linked list */
329 struct config_strlist* trust_anchor_list;
330 /** files with 5011 autotrust tracked keys */
331 struct config_strlist* auto_trust_anchor_file_list;
332 /** files with trusted DNSKEYs in named.conf format, list */
333 struct config_strlist* trusted_keys_file_list;
334 /** DLV anchor file */
335 char* dlv_anchor_file;
336 /** DLV anchor inline */
337 struct config_strlist* dlv_anchor_list;
338 /** insecure domain list */
339 struct config_strlist* domain_insecure;
340 /** send key tag query */
341 int trust_anchor_signaling;
342 /** enable root key sentinel */
343 int root_key_sentinel;
345 /** if not 0, this value is the validation date for RRSIGs */
346 int32_t val_date_override;
347 /** the minimum for signature clock skew */
348 int32_t val_sig_skew_min;
349 /** the maximum for signature clock skew */
350 int32_t val_sig_skew_max;
351 /** this value sets the number of seconds before revalidating bogus */
353 /** should validator clean additional section for secure msgs */
354 int val_clean_additional;
355 /** log bogus messages by the validator */
357 /** squelch val_log_level to log - this is library goes to callback */
359 /** should validator allow bogus messages to go through */
360 int val_permissive_mode;
361 /** use cached NSEC records to synthesise (negative) answers */
363 /** ignore the CD flag in incoming queries and refuse them bogus data */
365 /** serve expired entries and prefetch them */
367 /** serve expired entries until TTL after expiration */
368 int serve_expired_ttl;
369 /** reset serve expired TTL after failed update attempt */
370 int serve_expired_ttl_reset;
371 /** TTL for the serve expired replies */
372 int serve_expired_reply_ttl;
373 /** serve expired entries only after trying to update the entries and this
374 * timeout (in milliseconds) is reached */
375 int serve_expired_client_timeout;
376 /** nsec3 maximum iterations per key size, string */
377 char* val_nsec3_key_iterations;
378 /** autotrust add holddown time, in seconds */
379 unsigned int add_holddown;
380 /** autotrust del holddown time, in seconds */
381 unsigned int del_holddown;
382 /** autotrust keep_missing time, in seconds. 0 is forever. */
383 unsigned int keep_missing;
384 /** permit small holddown values, allowing 5011 rollover very fast */
385 int permit_small_holddown;
387 /** size of the key cache */
388 size_t key_cache_size;
389 /** slabs in the key cache. */
390 size_t key_cache_slabs;
391 /** size of the neg cache */
392 size_t neg_cache_size;
394 /** local zones config */
395 struct config_str2list* local_zones;
396 /** local zones nodefault list */
397 struct config_strlist* local_zones_nodefault;
399 /** local zones ipset list */
400 struct config_strlist* local_zones_ipset;
402 /** do not add any default local zone */
403 int local_zones_disable_default;
404 /** local data RRs configured */
405 struct config_strlist* local_data;
406 /** local zone override types per netblock */
407 struct config_str3list* local_zone_overrides;
408 /** unblock lan zones (reverse lookups for AS112 zones) */
409 int unblock_lan_zones;
410 /** insecure lan zones (don't validate AS112 zones) */
411 int insecure_lan_zones;
412 /** list of zonename, tagbitlist */
413 struct config_strbytelist* local_zone_tags;
414 /** list of aclname, tagbitlist */
415 struct config_strbytelist* acl_tags;
416 /** list of aclname, tagname, localzonetype */
417 struct config_str3list* acl_tag_actions;
418 /** list of aclname, tagname, redirectdata */
419 struct config_str3list* acl_tag_datas;
420 /** list of aclname, view*/
421 struct config_str2list* acl_view;
422 /** list of IP-netblock, tagbitlist */
423 struct config_strbytelist* respip_tags;
424 /** list of response-driven access control entries, linked list */
425 struct config_str2list* respip_actions;
426 /** RRs configured for response-driven access controls */
427 struct config_str2list* respip_data;
428 /** tag list, array with tagname[i] is malloced string */
430 /** number of items in the taglist */
433 /** remote control section. enable toggle. */
434 int remote_control_enable;
435 /** the interfaces the remote control should listen on */
436 struct config_strlist_head control_ifs;
437 /** if the use-cert option is set */
438 int control_use_cert;
439 /** port number for the control port */
441 /** private key file for server */
442 char* server_key_file;
443 /** certificate file for server */
444 char* server_cert_file;
445 /** private key file for unbound-control */
446 char* control_key_file;
447 /** certificate file for unbound-control */
448 char* control_cert_file;
450 /** Python script file */
451 struct config_strlist* python_script;
453 /** Dynamic library file */
454 struct config_strlist* dynlib_file;
456 /** Use systemd socket activation. */
459 /** daemonize, i.e. fork into the background. */
462 /* minimal response when positive answer */
463 int minimal_responses;
465 /* RRSet roundrobin */
466 int rrset_roundrobin;
468 /* wait time for unknown server in msec */
469 int unknown_server_time_limit;
471 /* maximum UDP response size */
477 /* Synthetize all AAAA record despite the presence of an authoritative one */
479 /** ignore AAAAs for these domain names and use A record anyway */
480 struct config_strlist* dns64_ignore_aaaa;
482 /** true to enable dnstap support */
484 /** using bidirectional frame streams if true */
485 int dnstap_bidirectional;
486 /** dnstap socket path */
487 char* dnstap_socket_path;
490 /** dnstap TLS enable */
492 /** dnstap tls server authentication name */
493 char* dnstap_tls_server_name;
494 /** dnstap server cert bundle */
495 char* dnstap_tls_cert_bundle;
496 /** dnstap client key for client authentication */
497 char* dnstap_tls_client_key_file;
498 /** dnstap client cert for client authentication */
499 char* dnstap_tls_client_cert_file;
500 /** true to send "identity" via dnstap */
501 int dnstap_send_identity;
502 /** true to send "version" via dnstap */
503 int dnstap_send_version;
504 /** dnstap "identity", hostname is used if "". */
505 char* dnstap_identity;
506 /** dnstap "version", package version is used if "". */
507 char* dnstap_version;
509 /** true to log dnstap RESOLVER_QUERY message events */
510 int dnstap_log_resolver_query_messages;
511 /** true to log dnstap RESOLVER_RESPONSE message events */
512 int dnstap_log_resolver_response_messages;
513 /** true to log dnstap CLIENT_QUERY message events */
514 int dnstap_log_client_query_messages;
515 /** true to log dnstap CLIENT_RESPONSE message events */
516 int dnstap_log_client_response_messages;
517 /** true to log dnstap FORWARDER_QUERY message events */
518 int dnstap_log_forwarder_query_messages;
519 /** true to log dnstap FORWARDER_RESPONSE message events */
520 int dnstap_log_forwarder_response_messages;
522 /** true to disable DNSSEC lameness check in iterator */
523 int disable_dnssec_lame_check;
525 /** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */
527 /** number of slabs for ip_ratelimit cache */
528 size_t ip_ratelimit_slabs;
529 /** memory size in bytes for ip_ratelimit cache */
530 size_t ip_ratelimit_size;
531 /** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
532 int ip_ratelimit_factor;
534 /** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */
536 /** number of slabs for ratelimit cache */
537 size_t ratelimit_slabs;
538 /** memory size in bytes for ratelimit cache */
539 size_t ratelimit_size;
540 /** ratelimits for domain (exact match) */
541 struct config_str2list* ratelimit_for_domain;
542 /** ratelimits below domain */
543 struct config_str2list* ratelimit_below_domain;
544 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
545 int ratelimit_factor;
546 /** minimise outgoing QNAME and hide original QTYPE if possible */
547 int qname_minimisation;
548 /** minimise QNAME in strict mode, minimise according to RFC.
549 * Do not apply fallback */
550 int qname_minimisation_strict;
551 /** SHM data - true if shm is enabled */
553 /** SHM data - key for the shm */
557 /** true to enable dnscrypt */
559 /** port on which to provide dnscrypt service */
561 /** provider name 2.dnscrypt-cert.example.com */
562 char* dnscrypt_provider;
563 /** dnscrypt secret keys 1.key */
564 struct config_strlist* dnscrypt_secret_key;
565 /** dnscrypt provider certs 1.cert */
566 struct config_strlist* dnscrypt_provider_cert;
567 /** dnscrypt provider certs 1.cert which have been rotated and should not be
568 * advertised through DNS's providername TXT record but are required to be
569 * able to handle existing traffic using the old cert. */
570 struct config_strlist* dnscrypt_provider_cert_rotated;
571 /** memory size in bytes for dnscrypt shared secrets cache */
572 size_t dnscrypt_shared_secret_cache_size;
573 /** number of slabs for dnscrypt shared secrets cache */
574 size_t dnscrypt_shared_secret_cache_slabs;
575 /** memory size in bytes for dnscrypt nonces cache */
576 size_t dnscrypt_nonce_cache_size;
577 /** number of slabs for dnscrypt nonces cache */
578 size_t dnscrypt_nonce_cache_slabs;
581 /** false to bypass the IPsec module */
582 int ipsecmod_enabled;
583 /** whitelisted domains for ipsecmod */
584 struct config_strlist* ipsecmod_whitelist;
585 /** path to external hook */
587 /** true to proceed even with a bogus IPSECKEY */
588 int ipsecmod_ignore_bogus;
589 /** max TTL for the A/AAAA records that call the hook */
590 int ipsecmod_max_ttl;
591 /** false to proceed even when ipsecmod_hook fails */
597 /** backend DB name */
598 char* cachedb_backend;
599 /** secret seed for hash key calculation */
600 char* cachedb_secret;
602 /** redis server's IP address or host name */
603 char* redis_server_host;
604 /** redis server's TCP port */
605 int redis_server_port;
606 /** timeout (in ms) for communication with the redis server */
608 /** set timeout on redis records based on DNS response ttl */
609 int redis_expire_records;
620 /** from cfg username, after daemonize setup performed */
621 extern uid_t cfg_uid;
622 /** from cfg username, after daemonize setup performed */
623 extern gid_t cfg_gid;
624 /** debug and enable small timeouts */
625 extern int autr_permit_small_holddown;
626 /** size (in bytes) of stream wait buffers max */
627 extern size_t stream_wait_max;
630 * Stub config options
634 struct config_stub* next;
635 /** domain name (in text) of the stub apex domain */
637 /** list of stub nameserver hosts (domain name) */
638 struct config_strlist* hosts;
639 /** list of stub nameserver addresses (IP address) */
640 struct config_strlist* addrs;
641 /** if stub-prime is set */
643 /** if forward-first is set (failover to without if fails) */
645 /** use SSL for queries to this stub */
652 * Auth config options
656 struct config_auth* next;
657 /** domain name (in text) of the auth apex domain */
659 /** list of masters */
660 struct config_strlist* masters;
662 struct config_strlist* urls;
663 /** list of allow-notify */
664 struct config_strlist* allow_notify;
665 /** zonefile (or NULL) */
667 /** provide downstream answers */
669 /** provide upstream answers */
671 /** fallback to recursion to authorities if zone expired and other
672 * reasons perhaps (like, query bogus) */
673 int fallback_enabled;
674 /** this zone is used to create local-zone policies */
676 /** rpz tags (or NULL) */
677 uint8_t* rpz_taglist;
678 /** length of the taglist (in bytes) */
679 size_t rpz_taglistlen;
680 /** Override RPZ action for this zone, regardless of zone content */
681 char* rpz_action_override;
682 /** Log when this RPZ policy is applied */
684 /** Display this name in the log when RPZ policy is applied */
686 /** Always reply with this CNAME target if the cname override action is
692 * View config options
696 struct config_view* next;
700 struct config_str2list* local_zones;
701 /** local data RRs */
702 struct config_strlist* local_data;
703 /** local zones nodefault list */
704 struct config_strlist* local_zones_nodefault;
706 /** local zones ipset list */
707 struct config_strlist* local_zones_ipset;
709 /** Fallback to global local_zones when there is no match in the view
710 * view specific tree. 1 for yes, 0 for no */
712 /** predefined actions for particular IP address responses */
713 struct config_str2list* respip_actions;
714 /** data complementing the 'redirect' response IP actions */
715 struct config_str2list* respip_data;
719 * List of strings for config options
721 struct config_strlist {
722 /** next item in list */
723 struct config_strlist* next;
724 /** config option string */
729 * List of two strings for config options
731 struct config_str2list {
732 /** next item in list */
733 struct config_str2list* next;
741 * List of three strings for config options
743 struct config_str3list {
744 /** next item in list */
745 struct config_str3list* next;
756 * List of string, bytestring for config options
758 struct config_strbytelist {
759 /** next item in list */
760 struct config_strbytelist* next;
763 /** second bytestring */
769 * Create config file structure. Filled with default values.
770 * @return: the new structure or NULL on memory error.
772 struct config_file* config_create(void);
775 * Create config file structure for library use. Filled with default values.
776 * @return: the new structure or NULL on memory error.
778 struct config_file* config_create_forlib(void);
781 * Read the config file from the specified filename.
782 * @param config: where options are stored into, must be freshly created.
783 * @param filename: name of configfile. If NULL nothing is done.
784 * @param chroot: if not NULL, the chroot dir currently in use (for include).
785 * @return: false on error. In that case errno is set, ENOENT means
788 int config_read(struct config_file* config, const char* filename,
792 * Destroy the config file structure.
793 * @param config: to delete.
795 void config_delete(struct config_file* config);
798 * Apply config to global constants; this routine is called in single thread.
799 * @param config: to apply. Side effect: global constants change.
801 void config_apply(struct config_file* config);
804 * Find username, sets cfg_uid and cfg_gid.
805 * @param config: the config structure.
807 void config_lookup_uid(struct config_file* config);
810 * Set the given keyword to the given value.
811 * @param config: where to store config
812 * @param option: option name, including the ':' character.
813 * @param value: value, this string is copied if needed, or parsed.
814 * The caller owns the value string.
815 * @return 0 on error (malloc or syntax error).
817 int config_set_option(struct config_file* config, const char* option,
821 * Call print routine for the given option.
822 * @param cfg: config.
823 * @param opt: option name without trailing :.
824 * This is different from config_set_option.
825 * @param func: print func, called as (str, arg) for every data element.
826 * @param arg: user argument for print func.
827 * @return false if the option name is not supported (syntax error).
829 int config_get_option(struct config_file* cfg, const char* opt,
830 void (*func)(char*,void*), void* arg);
833 * Get an option and return strlist
834 * @param cfg: config file
835 * @param opt: option name.
836 * @param list: list is returned here. malloced, caller must free it.
837 * @return 0=OK, 1=syntax error, 2=malloc failed.
839 int config_get_option_list(struct config_file* cfg, const char* opt,
840 struct config_strlist** list);
843 * Get an option and collate results into string
844 * @param cfg: config file
845 * @param opt: option name.
846 * @param str: string. malloced, caller must free it.
847 * @return 0=OK, 1=syntax error, 2=malloc failed.
849 int config_get_option_collate(struct config_file* cfg, const char* opt,
853 * function to print to a file, use as func with config_get_option.
854 * @param line: text to print. \n appended.
855 * @param arg: pass a FILE*, like stdout.
857 void config_print_func(char* line, void* arg);
860 * function to collate the text strings into a strlist_head.
861 * @param line: text to append.
862 * @param arg: pass a strlist_head structure. zeroed on start.
864 void config_collate_func(char* line, void* arg);
867 * take a strlist_head list and return a malloc string. separated with newline.
868 * @param list: strlist first to collate. zeroes return "".
869 * @return NULL on malloc failure. Or if malloc failure happened in strlist.
871 char* config_collate_cat(struct config_strlist* list);
874 * Append text at end of list.
875 * @param list: list head. zeroed at start.
876 * @param item: new item. malloced by caller. if NULL the insertion fails.
877 * @return true on success.
878 * on fail the item is free()ed.
880 int cfg_strlist_append(struct config_strlist_head* list, char* item);
883 * Searches the end of a string list and appends the given text.
884 * @param head: pointer to strlist head variable.
885 * @param item: new item. malloced by caller. if NULL the insertion fails.
886 * @return true on success.
888 int cfg_strlist_append_ex(struct config_strlist** head, char* item);
891 * Find string in strlist.
892 * @param head: pointer to strlist head variable.
893 * @param item: the item to search for.
894 * @return: the element in the list when found, NULL otherwise.
896 struct config_strlist* cfg_strlist_find(struct config_strlist* head,
900 * Insert string into strlist.
901 * @param head: pointer to strlist head variable.
902 * @param item: new item. malloced by caller. If NULL the insertion fails.
903 * @return: true on success.
904 * on fail, the item is free()d.
906 int cfg_strlist_insert(struct config_strlist** head, char* item);
908 /** insert with region for allocation. */
909 int cfg_region_strlist_insert(struct regional* region,
910 struct config_strlist** head, char* item);
913 * Insert string into str2list.
914 * @param head: pointer to str2list head variable.
915 * @param item: new item. malloced by caller. If NULL the insertion fails.
916 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
917 * @return: true on success.
918 * on fail, the item and i2 are free()d.
920 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);
923 * Insert string into str3list.
924 * @param head: pointer to str3list head variable.
925 * @param item: new item. malloced by caller. If NULL the insertion fails.
926 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
927 * @param i3: 3rd string, malloced by caller. If NULL the insertion fails.
928 * @return: true on success.
930 int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2,
934 * Insert string into strbytelist.
935 * @param head: pointer to strbytelist head variable.
936 * @param item: new item. malloced by caller. If NULL the insertion fails.
937 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
938 * @param i2len: length of the i2 bytestring.
939 * @return: true on success.
941 int cfg_strbytelist_insert(struct config_strbytelist** head, char* item,
942 uint8_t* i2, size_t i2len);
945 * Find stub in config list, also returns prevptr (for deletion).
946 * @param pp: call routine with pointer to a pointer to the start of the list,
947 * if the stub is found, on exit, the value contains a pointer to the
948 * next pointer that points to the found element (or to the list start
949 * pointer if it is the first element).
950 * @param nm: name of stub to find.
951 * @return: pointer to config_stub if found, or NULL if not found.
953 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm);
956 * Delete items in config string list.
959 void config_delstrlist(struct config_strlist* list);
962 * Delete items in config double string list.
965 void config_deldblstrlist(struct config_str2list* list);
968 * Delete items in config triple string list.
971 void config_deltrplstrlist(struct config_str3list* list);
973 /** delete stringbytelist */
974 void config_del_strbytelist(struct config_strbytelist* list);
978 * @param p: stub item
980 void config_delstub(struct config_stub* p);
983 * Delete items in config stub list.
986 void config_delstubs(struct config_stub* list);
989 * Delete an auth item
990 * @param p: auth item
992 void config_delauth(struct config_auth* p);
995 * Delete items in config auth list.
998 void config_delauths(struct config_auth* list);
1001 * Delete a view item
1002 * @param p: view item
1004 void config_delview(struct config_view* p);
1007 * Delete items in config view list.
1008 * @param list: list.
1010 void config_delviews(struct config_view* list);
1012 /** check if config for remote control turns on IP-address interface
1013 * with certificates or a named pipe without certificates. */
1014 int options_remote_is_address(struct config_file* cfg);
1017 * Convert 14digit to time value
1018 * @param str: string of 14 digits
1019 * @return time value or 0 for error.
1021 time_t cfg_convert_timeval(const char* str);
1024 * Count number of values in the string.
1025 * format ::= (sp num)+ sp
1027 * sp ::= (space|tab)*
1029 * @param str: string
1030 * @return: 0 on parse error, or empty string, else
1031 * number of integer values in the string.
1033 int cfg_count_numbers(const char* str);
1036 * Convert a 'nice' memory or file size into a bytecount
1037 * From '100k' to 102400. and so on. Understands kKmMgG.
1038 * k=1024, m=1024*1024, g=1024*1024*1024.
1039 * @param str: string
1040 * @param res: result is stored here, size in bytes.
1041 * @return: true if parsed correctly, or 0 on a parse error (and an error
1044 int cfg_parse_memsize(const char* str, size_t* res);
1047 * Add a tag name to the config. It is added at the end with a new ID value.
1048 * @param cfg: the config structure.
1049 * @param tag: string (which is copied) with the name.
1050 * @return: false on alloc failure.
1052 int config_add_tag(struct config_file* cfg, const char* tag);
1055 * Find tag ID in the tag list.
1056 * @param cfg: the config structure.
1057 * @param tag: string with tag name to search for.
1058 * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found.
1060 int find_tag_id(struct config_file* cfg, const char* tag);
1063 * parse taglist from string into bytestring with bitlist.
1064 * @param cfg: the config structure (with tagnames)
1065 * @param str: the string to parse. Parse puts 0 bytes in string.
1066 * @param listlen: returns length of in bytes.
1067 * @return malloced bytes with a bitlist of the tags. or NULL on parse error
1068 * or malloc failure.
1070 uint8_t* config_parse_taglist(struct config_file* cfg, char* str,
1074 * convert tag bitlist to a malloced string with tag names. For debug output.
1075 * @param cfg: the config structure (with tagnames)
1076 * @param taglist: the tag bitlist.
1077 * @param len: length of the tag bitlist.
1078 * @return malloced string or NULL.
1080 char* config_taglist2str(struct config_file* cfg, uint8_t* taglist,
1084 * see if two taglists intersect (have tags in common).
1085 * @param list1: first tag bitlist.
1086 * @param list1len: length in bytes of first list.
1087 * @param list2: second tag bitlist.
1088 * @param list2len: length in bytes of second list.
1089 * @return true if there are tags in common, 0 if not.
1091 int taglist_intersect(uint8_t* list1, size_t list1len, const uint8_t* list2,
1095 * Parse local-zone directive into two strings and register it in the config.
1096 * @param cfg: to put it in.
1097 * @param val: argument strings to local-zone, "example.com nodefault".
1098 * @return: false on failure
1100 int cfg_parse_local_zone(struct config_file* cfg, const char* val);
1103 * Mark "number" or "low-high" as available or not in ports array.
1104 * @param str: string in input
1105 * @param allow: give true if this range is permitted.
1106 * @param avail: the array from cfg.
1107 * @param num: size of the array (65536).
1108 * @return: true if parsed correctly, or 0 on a parse error (and an error
1111 int cfg_mark_ports(const char* str, int allow, int* avail, int num);
1114 * Get a condensed list of ports returned. allocated.
1115 * @param cfg: config file.
1116 * @param avail: the available ports array is returned here.
1117 * @return: number of ports in array or 0 on error.
1119 int cfg_condense_ports(struct config_file* cfg, int** avail);
1122 * Scan ports available
1123 * @param avail: the array from cfg.
1124 * @param num: size of the array (65536).
1125 * @return the number of ports available for use.
1127 int cfg_scan_ports(int* avail, int num);
1130 * Convert a filename to full pathname in original filesys
1131 * @param fname: the path name to convert.
1132 * Must not be null or empty.
1133 * @param cfg: config struct for chroot and chdir (if set).
1134 * @param use_chdir: if false, only chroot is applied.
1135 * @return pointer to malloced buffer which is: [chroot][chdir]fname
1136 * or NULL on malloc failure.
1138 char* fname_after_chroot(const char* fname, struct config_file* cfg,
1142 * Convert a ptr shorthand into a full reverse-notation PTR record.
1143 * @param str: input string, "IP name"
1144 * @return: malloced string "reversed-ip-name PTR name"
1146 char* cfg_ptr_reverse(char* str);
1149 * Append text to the error info for validation.
1150 * @param qstate: query state.
1151 * @param str: copied into query region and appended.
1152 * Failures to allocate are logged.
1154 void errinf(struct module_qstate* qstate, const char* str);
1157 * Append text to error info: from 1.2.3.4
1158 * @param qstate: query state.
1159 * @param origin: sock list with origin of trouble.
1160 * Every element added.
1161 * If NULL: nothing is added.
1162 * if 0len element: 'from cache' is added.
1164 void errinf_origin(struct module_qstate* qstate, struct sock_list *origin);
1167 * Append text to error info: for RRset name type class
1168 * @param qstate: query state.
1169 * @param rr: rrset_key.
1171 void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr);
1174 * Append text to error info: str dname
1175 * @param qstate: query state.
1176 * @param str: explanation string
1177 * @param dname: the dname.
1179 void errinf_dname(struct module_qstate* qstate, const char* str,
1183 * Create error info in string. For validation failures.
1184 * @param qstate: query state.
1185 * @return string or NULL on malloc failure (already logged).
1186 * This string is malloced and has to be freed by caller.
1188 char* errinf_to_str_bogus(struct module_qstate* qstate);
1191 * Create error info in string. For other servfails.
1192 * @param qstate: query state.
1193 * @return string or NULL on malloc failure (already logged).
1194 * This string is malloced and has to be freed by caller.
1196 char* errinf_to_str_servfail(struct module_qstate* qstate);
1199 * Used during options parsing
1201 struct config_parser_state {
1202 /** name of file being parser */
1204 /** line number in the file, starts at 1 */
1206 /** number of errors encountered */
1208 /** the result of parsing is stored here. */
1209 struct config_file* cfg;
1210 /** the current chroot dir (or NULL if none) */
1214 /** global config parser object used during config parsing */
1215 extern struct config_parser_state* cfg_parser;
1216 /** init lex state */
1217 void init_cfg_parse(void);
1219 extern FILE* ub_c_in;
1221 extern FILE* ub_c_out;
1222 /** the yacc lex generated parse function */
1223 int ub_c_parse(void);
1224 /** the lexer function */
1226 /** wrap function */
1227 int ub_c_wrap(void);
1228 /** parsing helpers: print error with file and line numbers */
1229 void ub_c_error(const char* msg);
1230 /** parsing helpers: print error with file and line numbers */
1231 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
1233 #ifdef UB_ON_WINDOWS
1235 * Obtain registry string (if it exists).
1236 * @param key: key string
1237 * @param name: name of value to fetch.
1238 * @return malloced string with the result or NULL if it did not
1239 * exist on an error (logged with log_err) was encountered.
1241 char* w_lookup_reg_str(const char* key, const char* name);
1243 /** Modify directory in options for module file name */
1244 void w_config_adjust_directory(struct config_file* cfg);
1245 #endif /* UB_ON_WINDOWS */
1247 /** debug option for unit tests. */
1248 extern int fake_dsa, fake_sha1;
1250 #endif /* UTIL_CONFIG_FILE_H */