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
46 struct config_strlist;
47 struct config_str2list;
48 struct config_str3list;
49 struct config_strbytelist;
52 struct ub_packed_rrset_key;
56 * The configuration options.
57 * Strings are malloced.
60 /** verbosity level as specified in the config file */
63 /** statistics interval (in seconds) */
65 /** if false, statistics values are reset after printing them */
67 /** if true, the statistics are kept in greater detail */
70 /** number of threads to create */
73 /** port on which queries are answered. */
75 /** do ip4 query support. */
77 /** do ip6 query support. */
79 /** prefer ip6 upstream queries. */
81 /** do udp query support. */
83 /** do tcp query support. */
85 /** tcp upstream queries (no UDP upstream queries) */
87 /** maximum segment size of tcp socket which queries are answered */
89 /** maximum segment size of tcp socket for outgoing queries */
92 /** private key file for dnstcp-ssl service (enabled if not NULL) */
93 char* ssl_service_key;
94 /** public key file for dnstcp-ssl service */
95 char* ssl_service_pem;
96 /** port on which to provide ssl service */
98 /** if outgoing tcp connections use SSL */
101 /** outgoing port range number of ports (per thread) */
102 int outgoing_num_ports;
103 /** number of outgoing tcp buffers per (per thread) */
104 size_t outgoing_num_tcp;
105 /** number of incoming tcp buffers per (per thread) */
106 size_t incoming_num_tcp;
107 /** allowed udp port numbers, array with 0 if not allowed */
108 int* outgoing_avail_ports;
110 /** EDNS buffer size to use */
111 size_t edns_buffer_size;
112 /** number of bytes buffer size for DNS messages */
113 size_t msg_buffer_size;
114 /** size of the message cache */
115 size_t msg_cache_size;
116 /** slabs in the message cache. */
117 size_t msg_cache_slabs;
118 /** number of queries every thread can service */
119 size_t num_queries_per_thread;
120 /** number of msec to wait before items can be jostled out */
122 /** size of the rrset cache */
123 size_t rrset_cache_size;
124 /** slabs in the rrset cache */
125 size_t rrset_cache_slabs;
126 /** host cache ttl in seconds */
128 /** number of slabs in the infra host cache */
129 size_t infra_cache_slabs;
130 /** max number of hosts in the infra cache */
131 size_t infra_cache_numhosts;
132 /** min value for infra cache rtt */
133 int infra_cache_min_rtt;
134 /** delay close of udp-timeouted ports, if 0 no delayclose. in msec */
137 /** the target fetch policy for the iterator */
138 char* target_fetch_policy;
140 /** automatic interface for incoming messages. Uses ipv6 remapping,
141 * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */
143 /** SO_RCVBUF size to set on port 53 UDP socket */
145 /** SO_SNDBUF size to set on port 53 UDP socket */
147 /** SO_REUSEPORT requested on port 53 sockets */
149 /** IP_TRANSPARENT socket option requested on port 53 sockets */
151 /** IP_FREEBIND socket option request on port 53 sockets */
154 /** number of interfaces to open. If 0 default all interfaces. */
156 /** interface description strings (IP addresses) */
159 /** number of outgoing interfaces to open.
160 * If 0 default all interfaces. */
162 /** outgoing interface description strings (IP addresses) */
165 /** the root hints */
166 struct config_strlist* root_hints;
167 /** the stub definitions, linked list */
168 struct config_stub* stubs;
169 /** the forward zone definitions, linked list */
170 struct config_stub* forwards;
171 /** the views definitions, linked list */
172 struct config_view* views;
173 /** list of donotquery addresses, linked list */
174 struct config_strlist* donotqueryaddrs;
176 /** list of servers we send edns-client-subnet option to and
177 * accept option from, linked list */
178 struct config_strlist* client_subnet;
179 /** list of zones we send edns-client-subnet option for */
180 struct config_strlist* client_subnet_zone;
181 /** opcode assigned by IANA for edns0-client-subnet option */
182 uint16_t client_subnet_opcode;
183 /** Do not check whitelist if incoming query contains an ECS record */
184 int client_subnet_always_forward;
185 /** Subnet length we are willing to give up privacy for */
186 uint8_t max_client_subnet_ipv4;
187 uint8_t max_client_subnet_ipv6;
189 /** list of access control entries, linked list */
190 struct config_str2list* acls;
191 /** use default localhost donotqueryaddr entries */
192 int donotquery_localhost;
194 /** harden against very small edns buffer sizes */
195 int harden_short_bufsize;
196 /** harden against very large query sizes */
197 int harden_large_queries;
198 /** harden against spoofed glue (out of zone data) */
200 /** harden against receiving no DNSSEC data for trust anchor */
201 int harden_dnssec_stripped;
202 /** harden against queries that fall under known nxdomain names */
203 int harden_below_nxdomain;
204 /** harden the referral path, query for NS,A,AAAA and validate */
205 int harden_referral_path;
206 /** harden against algorithm downgrade */
207 int harden_algo_downgrade;
208 /** use 0x20 bits in query as random ID bits */
209 int use_caps_bits_for_id;
210 /** 0x20 whitelist, domains that do not use capsforid */
211 struct config_strlist* caps_whitelist;
212 /** strip away these private addrs from answers, no DNS Rebinding */
213 struct config_strlist* private_address;
214 /** allow domain (and subdomains) to use private address space */
215 struct config_strlist* private_domain;
216 /** what threshold for unwanted action. */
217 size_t unwanted_threshold;
218 /** the number of seconds maximal TTL used for RRsets and messages */
220 /** the number of seconds minimum TTL used for RRsets and messages */
222 /** the number of seconds maximal negative TTL for SOA in auth */
223 int max_negative_ttl;
224 /** if prefetching of messages should be performed. */
226 /** if prefetching of DNSKEYs should be performed. */
229 /** chrootdir, if not "" or chroot will be done */
231 /** username to change to, if not "". */
233 /** working directory */
235 /** filename to log to. */
237 /** pidfile to write pid to. */
240 /** should log messages be sent to syslogd */
242 /** log timestamp in ascii UTC */
244 /** log queries with one line per query */
246 /** log replies with one line per reply */
248 /** log identity to report */
251 /** do not report identity (id.server, hostname.bind) */
253 /** do not report version (version.server, version.bind) */
255 /** do not report trustanchor (trustanchor.unbound) */
256 int hide_trustanchor;
257 /** identity, hostname is returned if "". */
259 /** version, package version returned if "". */
262 /** the module configuration string */
265 /** files with trusted DS and DNSKEYs in zonefile format, list */
266 struct config_strlist* trust_anchor_file_list;
267 /** list of trustanchor keys, linked list */
268 struct config_strlist* trust_anchor_list;
269 /** files with 5011 autotrust tracked keys */
270 struct config_strlist* auto_trust_anchor_file_list;
271 /** files with trusted DNSKEYs in named.conf format, list */
272 struct config_strlist* trusted_keys_file_list;
273 /** DLV anchor file */
274 char* dlv_anchor_file;
275 /** DLV anchor inline */
276 struct config_strlist* dlv_anchor_list;
277 /** insecure domain list */
278 struct config_strlist* domain_insecure;
279 /** send key tag query */
280 int trust_anchor_signaling;
282 /** if not 0, this value is the validation date for RRSIGs */
283 int32_t val_date_override;
284 /** the minimum for signature clock skew */
285 int32_t val_sig_skew_min;
286 /** the maximum for signature clock skew */
287 int32_t val_sig_skew_max;
288 /** this value sets the number of seconds before revalidating bogus */
290 /** should validator clean additional section for secure msgs */
291 int val_clean_additional;
292 /** log bogus messages by the validator */
294 /** squelch val_log_level to log - this is library goes to callback */
296 /** should validator allow bogus messages to go through */
297 int val_permissive_mode;
298 /** ignore the CD flag in incoming queries and refuse them bogus data */
300 /** serve expired entries and prefetch them */
302 /** nsec3 maximum iterations per key size, string */
303 char* val_nsec3_key_iterations;
304 /** autotrust add holddown time, in seconds */
305 unsigned int add_holddown;
306 /** autotrust del holddown time, in seconds */
307 unsigned int del_holddown;
308 /** autotrust keep_missing time, in seconds. 0 is forever. */
309 unsigned int keep_missing;
310 /** permit small holddown values, allowing 5011 rollover very fast */
311 int permit_small_holddown;
313 /** size of the key cache */
314 size_t key_cache_size;
315 /** slabs in the key cache. */
316 size_t key_cache_slabs;
317 /** size of the neg cache */
318 size_t neg_cache_size;
320 /** local zones config */
321 struct config_str2list* local_zones;
322 /** local zones nodefault list */
323 struct config_strlist* local_zones_nodefault;
324 /** do not add any default local zone */
325 int local_zones_disable_default;
326 /** local data RRs configured */
327 struct config_strlist* local_data;
328 /** local zone override types per netblock */
329 struct config_str3list* local_zone_overrides;
330 /** unblock lan zones (reverse lookups for AS112 zones) */
331 int unblock_lan_zones;
332 /** insecure lan zones (don't validate AS112 zones) */
333 int insecure_lan_zones;
334 /** list of zonename, tagbitlist */
335 struct config_strbytelist* local_zone_tags;
336 /** list of aclname, tagbitlist */
337 struct config_strbytelist* acl_tags;
338 /** list of aclname, tagname, localzonetype */
339 struct config_str3list* acl_tag_actions;
340 /** list of aclname, tagname, redirectdata */
341 struct config_str3list* acl_tag_datas;
342 /** list of aclname, view*/
343 struct config_str2list* acl_view;
344 /** list of IP-netblock, tagbitlist */
345 struct config_strbytelist* respip_tags;
346 /** list of response-driven access control entries, linked list */
347 struct config_str2list* respip_actions;
348 /** RRs configured for response-driven access controls */
349 struct config_str2list* respip_data;
350 /** tag list, array with tagname[i] is malloced string */
352 /** number of items in the taglist */
355 /** remote control section. enable toggle. */
356 int remote_control_enable;
357 /** the interfaces the remote control should listen on */
358 struct config_strlist* control_ifs;
359 /** port number for the control port */
361 /** use certificates for remote control */
362 int remote_control_use_cert;
363 /** private key file for server */
364 char* server_key_file;
365 /** certificate file for server */
366 char* server_cert_file;
367 /** private key file for unbound-control */
368 char* control_key_file;
369 /** certificate file for unbound-control */
370 char* control_cert_file;
372 /** Python script file */
375 /** Use systemd socket activation. */
378 /** daemonize, i.e. fork into the background. */
381 /* minimal response when positive answer */
382 int minimal_responses;
384 /* RRSet roundrobin */
385 int rrset_roundrobin;
387 /* maximum UDP response size */
393 /* Synthetize all AAAA record despite the presence of an authoritative one */
396 /** true to enable dnstap support */
398 /** dnstap socket path */
399 char* dnstap_socket_path;
400 /** true to send "identity" via dnstap */
401 int dnstap_send_identity;
402 /** true to send "version" via dnstap */
403 int dnstap_send_version;
404 /** dnstap "identity", hostname is used if "". */
405 char* dnstap_identity;
406 /** dnstap "version", package version is used if "". */
407 char* dnstap_version;
409 /** true to log dnstap RESOLVER_QUERY message events */
410 int dnstap_log_resolver_query_messages;
411 /** true to log dnstap RESOLVER_RESPONSE message events */
412 int dnstap_log_resolver_response_messages;
413 /** true to log dnstap CLIENT_QUERY message events */
414 int dnstap_log_client_query_messages;
415 /** true to log dnstap CLIENT_RESPONSE message events */
416 int dnstap_log_client_response_messages;
417 /** true to log dnstap FORWARDER_QUERY message events */
418 int dnstap_log_forwarder_query_messages;
419 /** true to log dnstap FORWARDER_RESPONSE message events */
420 int dnstap_log_forwarder_response_messages;
422 /** true to disable DNSSEC lameness check in iterator */
423 int disable_dnssec_lame_check;
425 /** ratelimit for ip addresses. 0 is off, otherwise qps (unless overridden) */
427 /** number of slabs for ip_ratelimit cache */
428 size_t ip_ratelimit_slabs;
429 /** memory size in bytes for ip_ratelimit cache */
430 size_t ip_ratelimit_size;
431 /** ip_ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
432 int ip_ratelimit_factor;
434 /** ratelimit for domains. 0 is off, otherwise qps (unless overridden) */
436 /** number of slabs for ratelimit cache */
437 size_t ratelimit_slabs;
438 /** memory size in bytes for ratelimit cache */
439 size_t ratelimit_size;
440 /** ratelimits for domain (exact match) */
441 struct config_str2list* ratelimit_for_domain;
442 /** ratelimits below domain */
443 struct config_str2list* ratelimit_below_domain;
444 /** ratelimit factor, 0 blocks all, 10 allows 1/10 of traffic */
445 int ratelimit_factor;
446 /** minimise outgoing QNAME and hide original QTYPE if possible */
447 int qname_minimisation;
448 /** minimise QNAME in strict mode, minimise according to RFC.
449 * Do not apply fallback */
450 int qname_minimisation_strict;
451 /** SHM data - true if shm is enabled */
453 /** SHM data - key for the shm */
457 /** true to enable dnscrypt */
459 /** port on which to provide dnscrypt service */
461 /** provider name 2.dnscrypt-cert.example.com */
462 char* dnscrypt_provider;
463 /** dnscrypt secret keys 1.key */
464 struct config_strlist* dnscrypt_secret_key;
465 /** dnscrypt provider certs 1.cert */
466 struct config_strlist* dnscrypt_provider_cert;
470 /** false to bypass the IPsec module */
471 int ipsecmod_enabled;
472 /** whitelisted domains for ipsecmod */
473 struct config_strlist* ipsecmod_whitelist;
474 /** path to external hook */
476 /** true to proceed even with a bogus IPSECKEY */
477 int ipsecmod_ignore_bogus;
478 /** max TTL for the A/AAAA records that call the hook */
479 int ipsecmod_max_ttl;
480 /** false to proceed even when ipsecmod_hook fails */
485 /** from cfg username, after daemonise setup performed */
486 extern uid_t cfg_uid;
487 /** from cfg username, after daemonise setup performed */
488 extern gid_t cfg_gid;
489 /** debug and enable small timeouts */
490 extern int autr_permit_small_holddown;
493 * Stub config options
497 struct config_stub* next;
498 /** domain name (in text) of the stub apex domain */
500 /** list of stub nameserver hosts (domain name) */
501 struct config_strlist* hosts;
502 /** list of stub nameserver addresses (IP address) */
503 struct config_strlist* addrs;
504 /** if stub-prime is set */
506 /** if forward-first is set (failover to without if fails) */
508 /** use SSL for queries to this stub */
513 * View config options
517 struct config_view* next;
521 struct config_str2list* local_zones;
522 /** local data RRs */
523 struct config_strlist* local_data;
524 /** local zones nodefault list */
525 struct config_strlist* local_zones_nodefault;
526 /** Fallback to global local_zones when there is no match in the view
527 * view specific tree. 1 for yes, 0 for no */
529 /** predefined actions for particular IP address responses */
530 struct config_str2list* respip_actions;
531 /** data complementing the 'redirect' response IP actions */
532 struct config_str2list* respip_data;
536 * List of strings for config options
538 struct config_strlist {
539 /** next item in list */
540 struct config_strlist* next;
541 /** config option string */
546 * List of two strings for config options
548 struct config_str2list {
549 /** next item in list */
550 struct config_str2list* next;
558 * List of three strings for config options
560 struct config_str3list {
561 /** next item in list */
562 struct config_str3list* next;
573 * List of string, bytestring for config options
575 struct config_strbytelist {
576 /** next item in list */
577 struct config_strbytelist* next;
580 /** second bytestring */
585 /** List head for strlist processing, used for append operation. */
586 struct config_strlist_head {
587 /** first in list of text items */
588 struct config_strlist* first;
589 /** last in list of text items */
590 struct config_strlist* last;
594 * Create config file structure. Filled with default values.
595 * @return: the new structure or NULL on memory error.
597 struct config_file* config_create(void);
600 * Create config file structure for library use. Filled with default values.
601 * @return: the new structure or NULL on memory error.
603 struct config_file* config_create_forlib(void);
606 * Read the config file from the specified filename.
607 * @param config: where options are stored into, must be freshly created.
608 * @param filename: name of configfile. If NULL nothing is done.
609 * @param chroot: if not NULL, the chroot dir currently in use (for include).
610 * @return: false on error. In that case errno is set, ENOENT means
613 int config_read(struct config_file* config, const char* filename,
617 * Destroy the config file structure.
618 * @param config: to delete.
620 void config_delete(struct config_file* config);
623 * Apply config to global constants; this routine is called in single thread.
624 * @param config: to apply. Side effect: global constants change.
626 void config_apply(struct config_file* config);
629 * Find username, sets cfg_uid and cfg_gid.
630 * @param config: the config structure.
632 void config_lookup_uid(struct config_file* config);
635 * Set the given keyword to the given value.
636 * @param config: where to store config
637 * @param option: option name, including the ':' character.
638 * @param value: value, this string is copied if needed, or parsed.
639 * The caller owns the value string.
640 * @return 0 on error (malloc or syntax error).
642 int config_set_option(struct config_file* config, const char* option,
646 * Call print routine for the given option.
647 * @param cfg: config.
648 * @param opt: option name without trailing :.
649 * This is different from config_set_option.
650 * @param func: print func, called as (str, arg) for every data element.
651 * @param arg: user argument for print func.
652 * @return false if the option name is not supported (syntax error).
654 int config_get_option(struct config_file* cfg, const char* opt,
655 void (*func)(char*,void*), void* arg);
658 * Get an option and return strlist
659 * @param cfg: config file
660 * @param opt: option name.
661 * @param list: list is returned here. malloced, caller must free it.
662 * @return 0=OK, 1=syntax error, 2=malloc failed.
664 int config_get_option_list(struct config_file* cfg, const char* opt,
665 struct config_strlist** list);
668 * Get an option and collate results into string
669 * @param cfg: config file
670 * @param opt: option name.
671 * @param str: string. malloced, caller must free it.
672 * @return 0=OK, 1=syntax error, 2=malloc failed.
674 int config_get_option_collate(struct config_file* cfg, const char* opt,
678 * function to print to a file, use as func with config_get_option.
679 * @param line: text to print. \n appended.
680 * @param arg: pass a FILE*, like stdout.
682 void config_print_func(char* line, void* arg);
685 * function to collate the text strings into a strlist_head.
686 * @param line: text to append.
687 * @param arg: pass a strlist_head structure. zeroed on start.
689 void config_collate_func(char* line, void* arg);
692 * take a strlist_head list and return a malloc string. separated with newline.
693 * @param list: strlist first to collate. zeroes return "".
694 * @return NULL on malloc failure. Or if malloc failure happened in strlist.
696 char* config_collate_cat(struct config_strlist* list);
699 * Append text at end of list.
700 * @param list: list head. zeroed at start.
701 * @param item: new item. malloced by caller. if NULL the insertion fails.
702 * @return true on success.
704 int cfg_strlist_append(struct config_strlist_head* list, char* item);
707 * Insert string into strlist.
708 * @param head: pointer to strlist head variable.
709 * @param item: new item. malloced by caller. If NULL the insertion fails.
710 * @return: true on success.
712 int cfg_strlist_insert(struct config_strlist** head, char* item);
714 /** insert with region for allocation. */
715 int cfg_region_strlist_insert(struct regional* region,
716 struct config_strlist** head, char* item);
719 * Insert string into str2list.
720 * @param head: pointer to str2list head variable.
721 * @param item: new item. malloced by caller. If NULL the insertion fails.
722 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
723 * @return: true on success.
725 int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);
728 * Insert string into str3list.
729 * @param head: pointer to str3list head variable.
730 * @param item: new item. malloced by caller. If NULL the insertion fails.
731 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
732 * @param i3: 3rd string, malloced by caller. If NULL the insertion fails.
733 * @return: true on success.
735 int cfg_str3list_insert(struct config_str3list** head, char* item, char* i2,
739 * Insert string into strbytelist.
740 * @param head: pointer to strbytelist head variable.
741 * @param item: new item. malloced by caller. If NULL the insertion fails.
742 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
743 * @param i2len: length of the i2 bytestring.
744 * @return: true on success.
746 int cfg_strbytelist_insert(struct config_strbytelist** head, char* item,
747 uint8_t* i2, size_t i2len);
750 * Find stub in config list, also returns prevptr (for deletion).
751 * @param pp: call routine with pointer to a pointer to the start of the list,
752 * if the stub is found, on exit, the value contains a pointer to the
753 * next pointer that points to the found element (or to the list start
754 * pointer if it is the first element).
755 * @param nm: name of stub to find.
756 * @return: pointer to config_stub if found, or NULL if not found.
758 struct config_stub* cfg_stub_find(struct config_stub*** pp, const char* nm);
761 * Delete items in config string list.
764 void config_delstrlist(struct config_strlist* list);
767 * Delete items in config double string list.
770 void config_deldblstrlist(struct config_str2list* list);
773 * Delete items in config triple string list.
776 void config_deltrplstrlist(struct config_str3list* list);
778 /** delete stringbytelist */
779 void config_del_strbytelist(struct config_strbytelist* list);
783 * @param p: stub item
785 void config_delstub(struct config_stub* p);
788 * Delete items in config stub list.
791 void config_delstubs(struct config_stub* list);
795 * @param p: view item
797 void config_delview(struct config_view* p);
800 * Delete items in config view list.
803 void config_delviews(struct config_view* list);
806 * Convert 14digit to time value
807 * @param str: string of 14 digits
808 * @return time value or 0 for error.
810 time_t cfg_convert_timeval(const char* str);
813 * Count number of values in the string.
814 * format ::= (sp num)+ sp
816 * sp ::= (space|tab)*
819 * @return: 0 on parse error, or empty string, else
820 * number of integer values in the string.
822 int cfg_count_numbers(const char* str);
825 * Convert a 'nice' memory or file size into a bytecount
826 * From '100k' to 102400. and so on. Understands kKmMgG.
827 * k=1024, m=1024*1024, g=1024*1024*1024.
829 * @param res: result is stored here, size in bytes.
830 * @return: true if parsed correctly, or 0 on a parse error (and an error
833 int cfg_parse_memsize(const char* str, size_t* res);
836 * Add a tag name to the config. It is added at the end with a new ID value.
837 * @param cfg: the config structure.
838 * @param tag: string (which is copied) with the name.
839 * @return: false on alloc failure.
841 int config_add_tag(struct config_file* cfg, const char* tag);
844 * Find tag ID in the tag list.
845 * @param cfg: the config structure.
846 * @param tag: string with tag name to search for.
847 * @return: 0..(num_tags-1) with tag ID, or -1 if tagname is not found.
849 int find_tag_id(struct config_file* cfg, const char* tag);
852 * parse taglist from string into bytestring with bitlist.
853 * @param cfg: the config structure (with tagnames)
854 * @param str: the string to parse. Parse puts 0 bytes in string.
855 * @param listlen: returns length of in bytes.
856 * @return malloced bytes with a bitlist of the tags. or NULL on parse error
859 uint8_t* config_parse_taglist(struct config_file* cfg, char* str,
863 * convert tag bitlist to a malloced string with tag names. For debug output.
864 * @param cfg: the config structure (with tagnames)
865 * @param taglist: the tag bitlist.
866 * @param len: length of the tag bitlist.
867 * @return malloced string or NULL.
869 char* config_taglist2str(struct config_file* cfg, uint8_t* taglist,
873 * see if two taglists intersect (have tags in common).
874 * @param list1: first tag bitlist.
875 * @param list1len: length in bytes of first list.
876 * @param list2: second tag bitlist.
877 * @param list2len: length in bytes of second list.
878 * @return true if there are tags in common, 0 if not.
880 int taglist_intersect(uint8_t* list1, size_t list1len, uint8_t* list2,
884 * Parse local-zone directive into two strings and register it in the config.
885 * @param cfg: to put it in.
886 * @param val: argument strings to local-zone, "example.com nodefault".
887 * @return: false on failure
889 int cfg_parse_local_zone(struct config_file* cfg, const char* val);
892 * Mark "number" or "low-high" as available or not in ports array.
893 * @param str: string in input
894 * @param allow: give true if this range is permitted.
895 * @param avail: the array from cfg.
896 * @param num: size of the array (65536).
897 * @return: true if parsed correctly, or 0 on a parse error (and an error
900 int cfg_mark_ports(const char* str, int allow, int* avail, int num);
903 * Get a condensed list of ports returned. allocated.
904 * @param cfg: config file.
905 * @param avail: the available ports array is returned here.
906 * @return: number of ports in array or 0 on error.
908 int cfg_condense_ports(struct config_file* cfg, int** avail);
911 * Scan ports available
912 * @param avail: the array from cfg.
913 * @param num: size of the array (65536).
914 * @return the number of ports available for use.
916 int cfg_scan_ports(int* avail, int num);
919 * Convert a filename to full pathname in original filesys
920 * @param fname: the path name to convert.
921 * Must not be null or empty.
922 * @param cfg: config struct for chroot and chdir (if set).
923 * @param use_chdir: if false, only chroot is applied.
924 * @return pointer to malloced buffer which is: [chroot][chdir]fname
925 * or NULL on malloc failure.
927 char* fname_after_chroot(const char* fname, struct config_file* cfg,
931 * Convert a ptr shorthand into a full reverse-notation PTR record.
932 * @param str: input string, "IP name"
933 * @return: malloced string "reversed-ip-name PTR name"
935 char* cfg_ptr_reverse(char* str);
938 * Append text to the error info for validation.
939 * @param qstate: query state.
940 * @param str: copied into query region and appended.
941 * Failures to allocate are logged.
943 void errinf(struct module_qstate* qstate, const char* str);
946 * Append text to error info: from 1.2.3.4
947 * @param qstate: query state.
948 * @param origin: sock list with origin of trouble.
949 * Every element added.
950 * If NULL: nothing is added.
951 * if 0len element: 'from cache' is added.
953 void errinf_origin(struct module_qstate* qstate, struct sock_list *origin);
956 * Append text to error info: for RRset name type class
957 * @param qstate: query state.
958 * @param rr: rrset_key.
960 void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr);
963 * Append text to error info: str dname
964 * @param qstate: query state.
965 * @param str: explanation string
966 * @param dname: the dname.
968 void errinf_dname(struct module_qstate* qstate, const char* str,
972 * Create error info in string
973 * @param qstate: query state.
974 * @return string or NULL on malloc failure (already logged).
975 * This string is malloced and has to be freed by caller.
977 char* errinf_to_str(struct module_qstate* qstate);
980 * Used during options parsing
982 struct config_parser_state {
983 /** name of file being parser */
985 /** line number in the file, starts at 1 */
987 /** number of errors encountered */
989 /** the result of parsing is stored here. */
990 struct config_file* cfg;
991 /** the current chroot dir (or NULL if none) */
995 /** global config parser object used during config parsing */
996 extern struct config_parser_state* cfg_parser;
997 /** init lex state */
998 void init_cfg_parse(void);
1000 extern FILE* ub_c_in;
1002 extern FILE* ub_c_out;
1003 /** the yacc lex generated parse function */
1004 int ub_c_parse(void);
1005 /** the lexer function */
1007 /** wrap function */
1008 int ub_c_wrap(void);
1009 /** parsing helpers: print error with file and line numbers */
1010 void ub_c_error(const char* msg);
1011 /** parsing helpers: print error with file and line numbers */
1012 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
1014 #ifdef UB_ON_WINDOWS
1016 * Obtain registry string (if it exists).
1017 * @param key: key string
1018 * @param name: name of value to fetch.
1019 * @return malloced string with the result or NULL if it did not
1020 * exist on an error (logged with log_err) was encountered.
1022 char* w_lookup_reg_str(const char* key, const char* name);
1024 /** Modify directory in options for module file name */
1025 void w_config_adjust_directory(struct config_file* cfg);
1026 #endif /* UB_ON_WINDOWS */
1028 /** debug option for unit tests. */
1029 extern int fake_dsa, fake_sha1;
1031 #endif /* UTIL_CONFIG_FILE_H */