Data Structures | Macros | Functions | Variables
config_file.c File Reference

This file contains functions for the config file. More...

#include "config.h"
#include <ctype.h>
#include <stdarg.h>
#include "util/log.h"
#include "util/configyyrename.h"
#include "util/config_file.h"
#include "util/configparser.h"
#include "util/net_help.h"
#include "util/data/msgparse.h"
#include "util/module.h"
#include "util/regional.h"
#include "util/fptr_wlist.h"
#include "util/data/dname.h"
#include "util/rtt.h"
#include "services/cache/infra.h"
#include "sldns/wire2str.h"
#include "sldns/parseutil.h"
#include "util/iana_ports.inc"

Data Structures

struct  config_collate_arg
 collate func arg More...
 

Macros

#define IS_NUMBER_OR_ZERO   if(atoi(val) == 0 && strcmp(val, "0") != 0) return 0
 check that the value passed is >= 0
 
#define IS_NONZERO_NUMBER   if(atoi(val) == 0) return 0
 check that the value passed is > 0
 
#define IS_POW2_NUMBER   if(atoi(val) == 0 || !is_pow2((size_t)atoi(val))) return 0
 check that the value passed is not 0 and a power of 2
 
#define IS_YES_OR_NO   if(strcmp(val, "yes") != 0 && strcmp(val, "no") != 0) return 0
 check that the value passed is yes or no
 
#define S_NUMBER_OR_ZERO(str, var)
 put integer_or_zero into variable More...
 
#define S_NUMBER_NONZERO(str, var)
 put integer_nonzero into variable More...
 
#define S_UNSIGNED_OR_ZERO(str, var)
 put integer_or_zero into unsigned More...
 
#define S_SIZET_OR_ZERO(str, var)
 put integer_or_zero into size_t More...
 
#define S_SIZET_NONZERO(str, var)
 put integer_nonzero into size_t More...
 
#define S_YNO(str, var)
 put yesno into variable More...
 
#define S_MEMSIZE(str, var)
 put memsize into variable More...
 
#define S_POW2(str, var)
 put pow2 number into variable More...
 
#define S_STR(str, var)
 put string into variable More...
 
#define S_STRLIST(str, var)
 put string into strlist More...
 
#define O_DEC(opt, str, var)
 compare and print decimal option More...
 
#define O_UNS(opt, str, var)
 compare and print unsigned option More...
 
#define O_YNO(opt, str, var)
 compare and print yesno option More...
 
#define O_STR(opt, str, var)
 compare and print string option More...
 
#define O_IFC(opt, str, num, arr)
 compare and print array option More...
 
#define O_MEM(opt, str, var)
 compare and print memorysize option More...
 
#define O_LST(opt, name, lst)
 compare and print list option More...
 
#define O_LS2(opt, name, lst)
 compare and print list option More...
 
#define O_LS3(opt, name, lst)
 compare and print list option More...
 
#define O_LTG(opt, name, lst)
 compare and print taglist option More...
 

Functions

static void init_outgoing_availports (int *array, int num)
 init ports possible for use
 
struct config_fileconfig_create (void)
 Create config file structure. More...
 
struct config_fileconfig_create_forlib (void)
 Create config file structure for library use. More...
 
int config_set_option (struct config_file *cfg, const char *opt, const char *val)
 Set the given keyword to the given value. More...
 
void config_print_func (char *line, void *arg)
 function to print to a file, use as func with config_get_option. More...
 
void config_collate_func (char *line, void *arg)
 function to collate the text strings into a strlist_head. More...
 
int config_get_option_list (struct config_file *cfg, const char *opt, struct config_strlist **list)
 Get an option and return strlist. More...
 
int config_get_option_collate (struct config_file *cfg, const char *opt, char **str)
 Get an option and collate results into string. More...
 
char * config_collate_cat (struct config_strlist *list)
 take a strlist_head list and return a malloc string. More...
 
int config_get_option (struct config_file *cfg, const char *opt, void(*func)(char *, void *), void *arg)
 Call print routine for the given option. More...
 
static void create_cfg_parser (struct config_file *cfg, char *filename, const char *chroot)
 initialize the global cfg_parser object
 
int config_read (struct config_file *cfg, const char *filename, const char *chroot)
 Read the config file from the specified filename. More...
 
struct config_stubcfg_stub_find (struct config_stub ***pp, const char *nm)
 Find stub in config list, also returns prevptr (for deletion). More...
 
void config_delstrlist (struct config_strlist *p)
 Delete items in config string list. More...
 
void config_deldblstrlist (struct config_str2list *p)
 Delete items in config double string list. More...
 
void config_deltrplstrlist (struct config_str3list *p)
 Delete items in config triple string list. More...
 
void config_delstub (struct config_stub *p)
 Delete a stub item. More...
 
void config_delstubs (struct config_stub *p)
 Delete items in config stub list. More...
 
void config_delview (struct config_view *p)
 Delete a view item. More...
 
void config_delviews (struct config_view *p)
 Delete items in config view list. More...
 
static void config_del_strarray (char **array, int num)
 delete string array
 
void config_del_strbytelist (struct config_strbytelist *p)
 delete stringbytelist
 
void config_delete (struct config_file *cfg)
 Destroy the config file structure. More...
 
int cfg_mark_ports (const char *str, int allow, int *avail, int num)
 Mark "number" or "low-high" as available or not in ports array. More...
 
int cfg_scan_ports (int *avail, int num)
 Scan ports available. More...
 
int cfg_condense_ports (struct config_file *cfg, int **avail)
 Get a condensed list of ports returned. More...
 
static void ub_c_error_va_list (const char *fmt, va_list args)
 print error with file and line number
 
void ub_c_error_msg (const char *fmt,...)
 print error with file and line number
 
void ub_c_error (const char *str)
 parsing helpers: print error with file and line numbers
 
int ub_c_wrap (void)
 wrap function
 
int cfg_strlist_append (struct config_strlist_head *list, char *item)
 Append text at end of list. More...
 
int cfg_region_strlist_insert (struct regional *region, struct config_strlist **head, char *item)
 insert with region for allocation. More...
 
int cfg_strlist_insert (struct config_strlist **head, char *item)
 Insert string into strlist. More...
 
int cfg_str2list_insert (struct config_str2list **head, char *item, char *i2)
 Insert string into str2list. More...
 
int cfg_str3list_insert (struct config_str3list **head, char *item, char *i2, char *i3)
 Insert string into str3list. More...
 
int cfg_strbytelist_insert (struct config_strbytelist **head, char *item, uint8_t *i2, size_t i2len)
 Insert string into strbytelist. More...
 
time_t cfg_convert_timeval (const char *str)
 Convert 14digit to time value. More...
 
int cfg_count_numbers (const char *s)
 Count number of values in the string. More...
 
static int isalldigit (const char *str, size_t l)
 all digit number
 
int cfg_parse_memsize (const char *str, size_t *res)
 Convert a 'nice' memory or file size into a bytecount From '100k' to 102400. More...
 
int find_tag_id (struct config_file *cfg, const char *tag)
 Find tag ID in the tag list. More...
 
int config_add_tag (struct config_file *cfg, const char *tag)
 Add a tag name to the config. More...
 
static void cfg_set_bit (uint8_t *bitlist, size_t len, int id)
 set a bit in a bit array
 
uint8_t * config_parse_taglist (struct config_file *cfg, char *str, size_t *listlen)
 parse taglist from string into bytestring with bitlist. More...
 
char * config_taglist2str (struct config_file *cfg, uint8_t *taglist, size_t taglen)
 convert tag bitlist to a malloced string with tag names. More...
 
int taglist_intersect (uint8_t *list1, size_t list1len, uint8_t *list2, size_t list2len)
 see if two taglists intersect (have tags in common). More...
 
void config_apply (struct config_file *config)
 Apply config to global constants; this routine is called in single thread. More...
 
void config_lookup_uid (struct config_file *cfg)
 Find username, sets cfg_uid and cfg_gid. More...
 
static size_t strlen_after_chroot (const char *fname, struct config_file *cfg, int use_chdir)
 Calculate string length of full pathname in original filesys. More...
 
char * fname_after_chroot (const char *fname, struct config_file *cfg, int use_chdir)
 Convert a filename to full pathname in original filesys. More...
 
static char * next_space_pos (const char *str)
 return next space character in string
 
static char * last_space_pos (const char *str)
 return last space character in string
 
int cfg_parse_local_zone (struct config_file *cfg, const char *val)
 Parse local-zone directive into two strings and register it in the config. More...
 
char * cfg_ptr_reverse (char *str)
 Convert a ptr shorthand into a full reverse-notation PTR record. More...
 
void errinf (struct module_qstate *qstate, const char *str)
 Append text to the error info for validation. More...
 
void errinf_origin (struct module_qstate *qstate, struct sock_list *origin)
 Append text to error info: from 1.2.3.4. More...
 
char * errinf_to_str (struct module_qstate *qstate)
 Create error info in string. More...
 
void errinf_rrset (struct module_qstate *qstate, struct ub_packed_rrset_key *rr)
 Append text to error info: for RRset name type class. More...
 
void errinf_dname (struct module_qstate *qstate, const char *str, uint8_t *dname)
 Append text to error info: str dname. More...
 

Variables

uid_t cfg_uid = (uid_t)-1
 from cfg username, after daemonize setup performed
 
gid_t cfg_gid = (gid_t)-1
 from cfg username, after daemonize setup performed
 
int autr_permit_small_holddown = 0
 for debug allow small timeout values for fast rollovers More...
 
struct config_parser_statecfg_parser = 0
 global config during parsing More...
 

Detailed Description

This file contains functions for the config file.

Macro Definition Documentation

◆ S_NUMBER_OR_ZERO

#define S_NUMBER_OR_ZERO (   str,
  var 
)
Value:
if(strcmp(opt, str) == 0) \
{ IS_NUMBER_OR_ZERO; cfg->var = atoi(val); }
#define IS_NUMBER_OR_ZERO
check that the value passed is >= 0
Definition: config_file.c:336

put integer_or_zero into variable

Referenced by config_set_option().

◆ S_NUMBER_NONZERO

#define S_NUMBER_NONZERO (   str,
  var 
)
Value:
if(strcmp(opt, str) == 0) \
{ IS_NONZERO_NUMBER; cfg->var = atoi(val); }
#define IS_NONZERO_NUMBER
check that the value passed is > 0
Definition: config_file.c:339

put integer_nonzero into variable

Referenced by config_set_option().

◆ S_UNSIGNED_OR_ZERO

#define S_UNSIGNED_OR_ZERO (   str,
  var 
)
Value:
if(strcmp(opt, str) == 0) \
{ IS_NUMBER_OR_ZERO; cfg->var = (unsigned)atoi(val); }
#define IS_NUMBER_OR_ZERO
check that the value passed is >= 0
Definition: config_file.c:336

put integer_or_zero into unsigned

Referenced by config_set_option().

◆ S_SIZET_OR_ZERO

#define S_SIZET_OR_ZERO (   str,
  var 
)
Value:
if(strcmp(opt, str) == 0) \
{ IS_NUMBER_OR_ZERO; cfg->var = (size_t)atoi(val); }
#define IS_NUMBER_OR_ZERO
check that the value passed is >= 0
Definition: config_file.c:336

put integer_or_zero into size_t

Referenced by config_set_option().

◆ S_SIZET_NONZERO

#define S_SIZET_NONZERO (   str,
  var 
)
Value:
if(strcmp(opt, str) == 0) \
{ IS_NONZERO_NUMBER; cfg->var = (size_t)atoi(val); }
#define IS_NONZERO_NUMBER
check that the value passed is > 0
Definition: config_file.c:339

put integer_nonzero into size_t

Referenced by config_set_option().

◆ S_YNO

#define S_YNO (   str,
  var 
)
Value:
if(strcmp(opt, str) == 0) \
{ IS_YES_OR_NO; cfg->var = (strcmp(val, "yes") == 0); }
#define IS_YES_OR_NO
check that the value passed is yes or no
Definition: config_file.c:345

put yesno into variable

Referenced by config_set_option().

◆ S_MEMSIZE

#define S_MEMSIZE (   str,
  var 
)
Value:
if(strcmp(opt, str)==0) \
{ return cfg_parse_memsize(val, &cfg->var); }
int cfg_parse_memsize(const char *str, size_t *res)
Convert a &#39;nice&#39; memory or file size into a bytecount From &#39;100k&#39; to 102400.
Definition: config_file.c:1589

put memsize into variable

Referenced by config_set_option().

◆ S_POW2

#define S_POW2 (   str,
  var 
)
Value:
if(strcmp(opt, str)==0) \
{ IS_POW2_NUMBER; cfg->var = (size_t)atoi(val); }
#define IS_POW2_NUMBER
check that the value passed is not 0 and a power of 2
Definition: config_file.c:342

put pow2 number into variable

Referenced by config_set_option().

◆ S_STR

#define S_STR (   str,
  var 
)
Value:
if(strcmp(opt, str)==0) \
{ free(cfg->var); return (cfg->var = strdup(val)) != NULL; }

put string into variable

Referenced by config_set_option().

◆ S_STRLIST

#define S_STRLIST (   str,
  var 
)
Value:
if(strcmp(opt, str)==0) \
{ return cfg_strlist_insert(&cfg->var, strdup(val)); }
int cfg_strlist_insert(struct config_strlist **head, char *item)
Insert string into strlist.
Definition: config_file.c:1462

put string into strlist

Referenced by config_set_option().

◆ O_DEC

#define O_DEC (   opt,
  str,
  var 
)
Value:
if(strcmp(opt, str)==0) \
{snprintf(buf, len, "%d", (int)cfg->var); \
func(buf, arg);}

compare and print decimal option

Referenced by config_get_option().

◆ O_UNS

#define O_UNS (   opt,
  str,
  var 
)
Value:
if(strcmp(opt, str)==0) \
{snprintf(buf, len, "%u", (unsigned)cfg->var); \
func(buf, arg);}

compare and print unsigned option

Referenced by config_get_option().

◆ O_YNO

#define O_YNO (   opt,
  str,
  var 
)
Value:
if(strcmp(opt, str)==0) \
{func(cfg->var?"yes":"no", arg);}

compare and print yesno option

Referenced by config_get_option().

◆ O_STR

#define O_STR (   opt,
  str,
  var 
)
Value:
if(strcmp(opt, str)==0) \
{func(cfg->var?cfg->var:"", arg);}

compare and print string option

Referenced by config_get_option().

◆ O_IFC

#define O_IFC (   opt,
  str,
  num,
  arr 
)
Value:
if(strcmp(opt, str)==0) \
{int i; for(i=0; i<cfg->num; i++) func(cfg->arr[i], arg);}

compare and print array option

Referenced by config_get_option().

◆ O_MEM

#define O_MEM (   opt,
  str,
  var 
)
Value:
if(strcmp(opt, str)==0) { \
if(cfg->var > 1024*1024*1024) { \
size_t f=cfg->var/(size_t)1000000, b=cfg->var%(size_t)1000000; \
snprintf(buf, len, "%u%6.6u", (unsigned)f, (unsigned)b); \
} else snprintf(buf, len, "%u", (unsigned)cfg->var); \
func(buf, arg);}

compare and print memorysize option

Referenced by config_get_option().

◆ O_LST

#define O_LST (   opt,
  name,
  lst 
)
Value:
if(strcmp(opt, name)==0) { \
struct config_strlist* p = cfg->lst; \
for(p = cfg->lst; p; p = p->next) \
func(p->str, arg); \
}
List of strings for config options.
Definition: config_file.h:555

compare and print list option

Referenced by config_get_option().

◆ O_LS2

#define O_LS2 (   opt,
  name,
  lst 
)
Value:
if(strcmp(opt, name)==0) { \
struct config_str2list* p = cfg->lst; \
for(p = cfg->lst; p; p = p->next) { \
snprintf(buf, len, "%s %s", p->str, p->str2); \
func(buf, arg); \
} \
}
List of two strings for config options.
Definition: config_file.h:565

compare and print list option

Referenced by config_get_option().

◆ O_LS3

#define O_LS3 (   opt,
  name,
  lst 
)
Value:
if(strcmp(opt, name)==0) { \
struct config_str3list* p = cfg->lst; \
for(p = cfg->lst; p; p = p->next) { \
snprintf(buf, len, "%s %s %s", p->str, p->str2, p->str3); \
func(buf, arg); \
} \
}
List of three strings for config options.
Definition: config_file.h:577

compare and print list option

Referenced by config_get_option().

◆ O_LTG

#define O_LTG (   opt,
  name,
  lst 
)
Value:
if(strcmp(opt, name)==0) { \
char* tmpstr = NULL; \
struct config_strbytelist *p = cfg->lst; \
for(p = cfg->lst; p; p = p->next) {\
tmpstr = config_taglist2str(cfg, p->str2, p->str2len); \
if(tmpstr) {\
snprintf(buf, len, "%s %s", p->str, tmpstr); \
func(buf, arg); \
free(tmpstr); \
} \
} \
}
List of string, bytestring for config options.
Definition: config_file.h:592
char * config_taglist2str(struct config_file *cfg, uint8_t *taglist, size_t taglen)
convert tag bitlist to a malloced string with tag names.
Definition: config_file.c:1715

compare and print taglist option

Referenced by config_get_option().

Function Documentation

◆ config_create()

struct config_file* config_create ( void  )

Create config file structure.

Filled with default values.

Returns
: the new structure or NULL on memory error.

References config_file::bogus_ttl, config_file::chrootdir, config_file::delay_close, config_file::directory, config_file::do_daemonize, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::do_udp, config_file::donotquery_localhost, config_file::donotqueryaddrs, config_file::edns_buffer_size, config_file::forwards, config_file::host_ttl, config_file::if_automatic, config_file::ifs, config_file::incoming_num_tcp, config_file::infra_cache_min_rtt, config_file::infra_cache_numhosts, config_file::infra_cache_slabs, init_outgoing_availports(), config_file::ip_freebind, config_file::ip_transparent, config_file::jostle_time, config_file::log_identity, config_file::log_queries, config_file::log_replies, config_file::log_time_ascii, config_file::logfile, config_file::max_negative_ttl, config_file::max_ttl, config_file::min_ttl, config_file::msg_buffer_size, config_file::msg_cache_size, config_file::msg_cache_slabs, config_file::num_ifs, config_file::num_out_ifs, config_file::num_queries_per_thread, config_file::num_threads, config_file::out_ifs, config_file::outgoing_avail_ports, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, config_file::outgoing_tcp_mss, config_file::pidfile, config_file::port, config_file::prefetch, config_file::prefetch_key, config_file::root_hints, config_file::rrset_cache_size, config_file::rrset_cache_slabs, config_file::so_rcvbuf, config_file::so_reuseport, config_file::so_sndbuf, config_file::ssl_port, config_file::ssl_service_key, config_file::ssl_service_pem, config_file::ssl_upstream, config_file::stat_cumulative, config_file::stat_extended, config_file::stat_interval, config_file::stubs, config_file::target_fetch_policy, config_file::tcp_mss, config_file::tcp_upstream, config_file::udp_upstream_without_downstream, config_file::use_syslog, config_file::use_systemd, config_file::username, and config_file::verbosity.

Referenced by checkconf(), config_create_forlib(), go(), infra_test(), and print_stats_shm().

◆ config_create_forlib()

struct config_file* config_create_forlib ( void  )

◆ config_set_option()

int config_set_option ( struct config_file config,
const char *  option,
const char *  value 
)

Set the given keyword to the given value.

Parameters
configwhere to store config
optionoption name, including the ':' character.
valuevalue, this string is copied if needed, or parsed. The caller owns the value string.
Returns
0 on error (malloc or syntax error).

References config_file::add_holddown, config_file::auto_trust_anchor_file_list, autr_permit_small_holddown, config_file::bogus_ttl, config_file::caps_whitelist, cfg_convert_timeval(), cfg_mark_ports(), cfg_parse_local_zone(), cfg_ptr_reverse(), cfg_strlist_insert(), config_file::chrootdir, config_add_tag(), config_file::control_cert_file, config_file::control_ifs, config_file::control_key_file, config_file::control_port, config_file::del_holddown, config_file::delay_close, config_file::directory, config_file::disable_dnssec_lame_check, config_file::dlv_anchor_file, config_file::dlv_anchor_list, config_file::dnscrypt, config_file::dnscrypt_nonce_cache_size, config_file::dnscrypt_nonce_cache_slabs, config_file::dnscrypt_port, config_file::dnscrypt_provider, config_file::dnscrypt_provider_cert, config_file::dnscrypt_secret_key, config_file::dnscrypt_shared_secret_cache_size, config_file::dnscrypt_shared_secret_cache_slabs, config_file::dnstap, config_file::dnstap_identity, config_file::dnstap_log_client_query_messages, config_file::dnstap_log_client_response_messages, config_file::dnstap_log_forwarder_query_messages, config_file::dnstap_log_forwarder_response_messages, config_file::dnstap_log_resolver_query_messages, config_file::dnstap_log_resolver_response_messages, config_file::dnstap_send_identity, config_file::dnstap_send_version, config_file::dnstap_socket_path, config_file::dnstap_version, config_file::do_daemonize, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::do_udp, config_file::domain_insecure, config_file::donotquery_localhost, config_file::donotqueryaddrs, config_file::edns_buffer_size, config_file::harden_algo_downgrade, config_file::harden_below_nxdomain, config_file::harden_dnssec_stripped, config_file::harden_glue, config_file::harden_large_queries, config_file::harden_referral_path, config_file::harden_short_bufsize, config_file::hide_identity, config_file::hide_trustanchor, config_file::hide_version, config_file::host_ttl, config_file::identity, config_file::if_automatic, config_file::ignore_cd, config_file::incoming_num_tcp, config_file::infra_cache_min_rtt, config_file::infra_cache_numhosts, config_file::infra_cache_slabs, infra_dp_ratelimit, infra_ip_ratelimit, config_file::insecure_lan_zones, config_file::ip_freebind, config_file::ip_ratelimit, config_file::ip_ratelimit_factor, config_file::ip_ratelimit_size, config_file::ip_ratelimit_slabs, config_file::ip_transparent, IS_NUMBER_OR_ZERO, IS_YES_OR_NO, config_file::jostle_time, config_file::keep_missing, config_file::key_cache_size, config_file::key_cache_slabs, config_file::local_data, config_file::log_identity, config_file::log_queries, config_file::log_replies, log_set_time_asc(), config_file::log_time_ascii, config_file::logfile, MAX_NEG_TTL, config_file::max_negative_ttl, MAX_TTL, config_file::max_ttl, MIN_TTL, config_file::min_ttl, config_file::module_conf, config_file::msg_buffer_size, config_file::msg_cache_size, config_file::msg_cache_slabs, config_file::neg_cache_size, config_file::num_out_ifs, config_file::num_queries_per_thread, config_file::out_ifs, config_file::outgoing_avail_ports, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, config_file::outgoing_tcp_mss, config_file::permit_small_holddown, config_file::pidfile, config_file::port, config_file::prefetch, config_file::prefetch_key, config_file::private_address, config_file::private_domain, config_file::python_script, config_file::qname_minimisation, config_file::qname_minimisation_strict, config_file::ratelimit, config_file::ratelimit_factor, config_file::ratelimit_size, config_file::ratelimit_slabs, config_file::remote_control_enable, config_file::root_hints, config_file::rrset_cache_size, config_file::rrset_cache_slabs, RTT_MIN_TIMEOUT, S_MEMSIZE, S_NUMBER_NONZERO, S_NUMBER_OR_ZERO, S_POW2, S_SIZET_NONZERO, S_SIZET_OR_ZERO, S_STR, S_STRLIST, S_UNSIGNED_OR_ZERO, S_YNO, config_file::serve_expired, config_file::server_cert_file, config_file::server_key_file, config_file::shm_enable, config_file::shm_key, config_file::so_rcvbuf, config_file::so_reuseport, config_file::so_sndbuf, config_file::ssl_port, config_file::ssl_service_key, config_file::ssl_service_pem, config_file::ssl_upstream, config_file::stat_cumulative, config_file::stat_extended, config_file::stat_interval, config_file::target_fetch_policy, config_file::tcp_mss, config_file::tcp_upstream, config_file::trust_anchor_file_list, config_file::trust_anchor_list, config_file::trust_anchor_signaling, config_file::trusted_keys_file_list, config_file::udp_upstream_without_downstream, config_file::unblock_lan_zones, config_file::unwanted_threshold, config_file::use_caps_bits_for_id, config_file::use_syslog, config_file::use_systemd, config_file::username, config_file::val_clean_additional, config_file::val_date_override, config_file::val_log_level, config_file::val_log_squelch, config_file::val_nsec3_key_iterations, config_file::val_permissive_mode, config_file::val_sig_skew_max, config_file::val_sig_skew_min, verbosity, and config_file::version.

Referenced by do_set_option(), and ub_ctx_set_option().

◆ config_print_func()

void config_print_func ( char *  line,
void *  arg 
)

function to print to a file, use as func with config_get_option.

Parameters
linetext to print.
appended.
argpass a FILE*, like stdout.

Referenced by fptr_whitelist_print_func().

◆ config_collate_func()

void config_collate_func ( char *  line,
void *  arg 
)

function to collate the text strings into a strlist_head.

Parameters
linetext to append.
argpass a strlist_head structure. zeroed on start.

References cfg_strlist_append(), config_collate_arg::list, and config_collate_arg::status.

Referenced by config_get_option_list(), and fptr_whitelist_print_func().

◆ config_get_option_list()

int config_get_option_list ( struct config_file cfg,
const char *  opt,
struct config_strlist **  list 
)

Get an option and return strlist.

Parameters
cfgconfig file
optoption name.
listlist is returned here. malloced, caller must free it.
Returns
0=OK, 1=syntax error, 2=malloc failed.

References config_collate_func(), config_delstrlist(), config_get_option(), config_strlist_head::first, config_collate_arg::list, and config_collate_arg::status.

Referenced by config_get_option_collate().

◆ config_get_option_collate()

int config_get_option_collate ( struct config_file cfg,
const char *  opt,
char **  str 
)

Get an option and collate results into string.

Parameters
cfgconfig file
optoption name.
strstring. malloced, caller must free it.
Returns
0=OK, 1=syntax error, 2=malloc failed.

References config_collate_cat(), config_delstrlist(), config_get_option_list(), and config_collate_arg::list.

Referenced by ub_ctx_get_option().

◆ config_collate_cat()

char* config_collate_cat ( struct config_strlist list)

take a strlist_head list and return a malloc string.

separated with newline.

Parameters
liststrlist first to collate. zeroes return "".
Returns
NULL on malloc failure. Or if malloc failure happened in strlist.

References config_strlist::next, and config_strlist::str.

Referenced by config_get_option_collate().

◆ config_get_option()

int config_get_option ( struct config_file cfg,
const char *  opt,
void(*)(char *, void *)  func,
void *  arg 
)

Call print routine for the given option.

Parameters
cfgconfig.
optoption name without trailing :. This is different from config_set_option.
funcprint func, called as (str, arg) for every data element.
arguser argument for print func.
Returns
false if the option name is not supported (syntax error).

References fptr_ok, fptr_whitelist_print_func(), logfile, O_DEC, O_IFC, O_LS2, O_LS3, O_LST, O_LTG, O_MEM, O_STR, O_UNS, O_YNO, and verbosity.

Referenced by config_get_option_list(), and do_get_option().

◆ config_read()

int config_read ( struct config_file config,
const char *  filename,
const char *  chroot 
)

Read the config file from the specified filename.

Parameters
configwhere options are stored into, must be freshly created.
filenamename of configfile. If NULL nothing is done.
chrootif not NULL, the chroot dir currently in use (for include).
Returns
: false on error. In that case errno is set, ENOENT means file not found.

References config_read(), create_cfg_parser(), config_file::dnscrypt, config_file::dnscrypt_port, config_parser_state::errors, log_err(), ub_c_in, ub_c_parse(), VERB_QUERY, and verbose().

Referenced by config_read(), and ub_ctx_config().

◆ cfg_stub_find()

struct config_stub* cfg_stub_find ( struct config_stub ***  pp,
const char *  nm 
)

Find stub in config list, also returns prevptr (for deletion).

Parameters
ppcall routine with pointer to a pointer to the start of the list, if the stub is found, on exit, the value contains a pointer to the next pointer that points to the found element (or to the list start pointer if it is the first element).
nmname of stub to find.
Returns
: pointer to config_stub if found, or NULL if not found.

References config_stub::name, and config_stub::next.

Referenced by ub_ctx_set_stub().

◆ config_delstrlist()

void config_delstrlist ( struct config_strlist list)

◆ config_deldblstrlist()

void config_deldblstrlist ( struct config_str2list list)

Delete items in config double string list.

Parameters
listlist.

References config_str2list::next, config_str2list::str, and config_str2list::str2.

Referenced by config_delete(), config_delview(), and lz_freeup_cfg().

◆ config_deltrplstrlist()

void config_deltrplstrlist ( struct config_str3list list)

Delete items in config triple string list.

Parameters
listlist.

References config_str3list::next, config_str3list::str, config_str3list::str2, and config_str3list::str3.

Referenced by config_delete(), read_acl_tag_actions(), and read_acl_tag_datas().

◆ config_delstub()

void config_delstub ( struct config_stub p)

Delete a stub item.

Parameters
pstub item

References config_stub::addrs, config_delstrlist(), config_stub::hosts, and config_stub::name.

Referenced by config_delstubs(), and ub_ctx_set_stub().

◆ config_delstubs()

void config_delstubs ( struct config_stub list)

Delete items in config stub list.

Parameters
listlist.

References config_delstub(), and config_stub::next.

Referenced by config_delete(), and ub_ctx_set_fwd().

◆ config_delview()

void config_delview ( struct config_view p)

◆ config_delviews()

void config_delviews ( struct config_view list)

Delete items in config view list.

Parameters
listlist.

References config_delview(), and config_view::next.

Referenced by config_delete().

◆ config_delete()

void config_delete ( struct config_file config)

Destroy the config file structure.

Parameters
configto delete.

References config_file::acl_tag_actions, config_file::acl_tag_datas, config_file::acl_tags, config_file::acls, config_file::auto_trust_anchor_file_list, config_file::caps_whitelist, config_file::chrootdir, config_del_strarray(), config_del_strbytelist(), config_deldblstrlist(), config_delstrlist(), config_delstubs(), config_deltrplstrlist(), config_delviews(), config_file::control_cert_file, config_file::control_ifs, config_file::control_key_file, config_file::directory, config_file::dlv_anchor_file, config_file::dlv_anchor_list, config_file::dnstap_identity, config_file::dnstap_socket_path, config_file::dnstap_version, config_file::domain_insecure, config_file::donotqueryaddrs, config_file::forwards, config_file::identity, config_file::ifs, config_file::local_data, config_file::local_zone_overrides, config_file::local_zone_tags, config_file::local_zones, config_file::local_zones_nodefault, config_file::log_identity, config_file::logfile, config_file::module_conf, config_file::num_ifs, config_file::num_out_ifs, config_file::num_tags, config_file::out_ifs, config_file::outgoing_avail_ports, config_file::pidfile, config_file::private_address, config_file::private_domain, config_file::python_script, config_file::ratelimit_below_domain, config_file::ratelimit_for_domain, config_file::respip_tags, config_file::root_hints, config_file::server_cert_file, config_file::server_key_file, config_file::ssl_service_key, config_file::ssl_service_pem, config_file::stubs, config_file::tagname, config_file::target_fetch_policy, config_file::trust_anchor_file_list, config_file::trust_anchor_list, config_file::trusted_keys_file_list, config_file::username, config_file::val_nsec3_key_iterations, config_file::version, and config_file::views.

Referenced by service_deinit(), ub_ctx_create(), ub_ctx_create_nopipe(), and ub_ctx_delete().

◆ cfg_mark_ports()

int cfg_mark_ports ( const char *  str,
int  allow,
int *  avail,
int  num 
)

Mark "number" or "low-high" as available or not in ports array.

Parameters
strstring in input
allowgive true if this range is permitted.
availthe array from cfg.
numsize of the array (65536).
Returns
: true if parsed correctly, or 0 on a parse error (and an error is logged).

References log_err(), and config_strbytelist::str.

Referenced by config_set_option().

◆ cfg_scan_ports()

int cfg_scan_ports ( int *  avail,
int  num 
)

Scan ports available.

Parameters
availthe array from cfg.
numsize of the array (65536).
Returns
the number of ports available for use.

Referenced by cfg_condense_ports().

◆ cfg_condense_ports()

int cfg_condense_ports ( struct config_file cfg,
int **  avail 
)

Get a condensed list of ports returned.

allocated.

Parameters
cfgconfig file.
availthe available ports array is returned here.
Returns
: number of ports in array or 0 on error.

References cfg_scan_ports(), log_assert, and config_file::outgoing_avail_ports.

◆ cfg_strlist_append()

int cfg_strlist_append ( struct config_strlist_head list,
char *  item 
)

Append text at end of list.

Parameters
listlist head. zeroed at start.
itemnew item. malloced by caller. if NULL the insertion fails.
Returns
true on success.

References config_strlist_head::first, config_strlist_head::last, config_strlist::next, and config_strlist::str.

Referenced by config_collate_func().

◆ cfg_region_strlist_insert()

int cfg_region_strlist_insert ( struct regional region,
struct config_strlist **  head,
char *  item 
)

insert with region for allocation.

References config_strlist::next, regional_alloc_zero(), and config_strlist::str.

Referenced by acl_list_tag_data_cfg().

◆ cfg_strlist_insert()

int cfg_strlist_insert ( struct config_strlist **  head,
char *  item 
)

Insert string into strlist.

Parameters
headpointer to strlist head variable.
itemnew item. malloced by caller. If NULL the insertion fails.
Returns
: true on success.

References config_strlist::next, and config_strlist::str.

Referenced by cfg_parse_local_zone(), config_set_option(), dnsc_load_local_data(), ub_ctx_add_ta(), ub_ctx_add_ta_autr(), ub_ctx_add_ta_file(), ub_ctx_hosts(), ub_ctx_set_fwd(), ub_ctx_set_stub(), and ub_ctx_trustedkeys().

◆ cfg_str2list_insert()

int cfg_str2list_insert ( struct config_str2list **  head,
char *  item,
char *  i2 
)

Insert string into str2list.

Parameters
headpointer to str2list head variable.
itemnew item. malloced by caller. If NULL the insertion fails.
i22nd string, malloced by caller. If NULL the insertion fails.
Returns
: true on success.

References config_str2list::next, config_str2list::str, and config_str2list::str2.

Referenced by cfg_parse_local_zone(), dnsc_load_local_data(), and views_apply_cfg().

◆ cfg_str3list_insert()

int cfg_str3list_insert ( struct config_str3list **  head,
char *  item,
char *  i2,
char *  i3 
)

Insert string into str3list.

Parameters
headpointer to str3list head variable.
itemnew item. malloced by caller. If NULL the insertion fails.
i22nd string, malloced by caller. If NULL the insertion fails.
i33rd string, malloced by caller. If NULL the insertion fails.
Returns
: true on success.

References config_str3list::next, config_str3list::str, config_str3list::str2, and config_str3list::str3.

◆ cfg_strbytelist_insert()

int cfg_strbytelist_insert ( struct config_strbytelist **  head,
char *  item,
uint8_t *  i2,
size_t  i2len 
)

Insert string into strbytelist.

Parameters
headpointer to strbytelist head variable.
itemnew item. malloced by caller. If NULL the insertion fails.
i22nd string, malloced by caller. If NULL the insertion fails.
i2lenlength of the i2 bytestring.
Returns
: true on success.

References config_strbytelist::next, config_strbytelist::str, and config_strbytelist::str2.

◆ cfg_convert_timeval()

time_t cfg_convert_timeval ( const char *  str)

Convert 14digit to time value.

Parameters
strstring of 14 digits
Returns
time value or 0 for error.

References sldns_mktime_from_utc().

Referenced by config_set_option().

◆ cfg_count_numbers()

int cfg_count_numbers ( const char *  str)

Count number of values in the string.

format ::= (sp num)+ sp num ::= [-](0-9)+ sp ::= (space|tab)*

Parameters
strstring
Returns
: 0 on parse error, or empty string, else number of integer values in the string.

Referenced by read_fetch_policy(), and val_apply_cfg().

◆ cfg_parse_memsize()

int cfg_parse_memsize ( const char *  str,
size_t *  res 
)

Convert a 'nice' memory or file size into a bytecount From '100k' to 102400.

and so on. Understands kKmMgG. k=1024, m=1024*1024, g=1024*1024*1024.

Parameters
strstring
resresult is stored here, size in bytes.
Returns
: true if parsed correctly, or 0 on a parse error (and an error is logged).

References isalldigit(), and log_err().

Referenced by config_memsize_test(), and main().

◆ find_tag_id()

int find_tag_id ( struct config_file cfg,
const char *  tag 
)

Find tag ID in the tag list.

Parameters
cfgthe config structure.
tagstring with tag name to search for.
Returns
: 0..(num_tags-1) with tag ID, or -1 if tagname is not found.

References config_file::num_tags, and config_file::tagname.

Referenced by acl_list_tag_action_cfg(), acl_list_tag_data_cfg(), config_add_tag(), and config_parse_taglist().

◆ config_add_tag()

int config_add_tag ( struct config_file cfg,
const char *  tag 
)

Add a tag name to the config.

It is added at the end with a new ID value.

Parameters
cfgthe config structure.
tagstring (which is copied) with the name.
Returns
: false on alloc failure.

References find_tag_id(), config_file::num_tags, and config_file::tagname.

Referenced by config_set_option().

◆ config_parse_taglist()

uint8_t* config_parse_taglist ( struct config_file cfg,
char *  str,
size_t *  listlen 
)

parse taglist from string into bytestring with bitlist.

Parameters
cfgthe config structure (with tagnames)
strthe string to parse. Parse puts 0 bytes in string.
listlenreturns length of in bytes.
Returns
malloced bytes with a bitlist of the tags. or NULL on parse error or malloc failure.

References cfg_set_bit(), find_tag_id(), log_err(), and config_file::num_tags.

◆ config_taglist2str()

char* config_taglist2str ( struct config_file cfg,
uint8_t *  taglist,
size_t  len 
)

convert tag bitlist to a malloced string with tag names.

For debug output.

Parameters
cfgthe config structure (with tagnames)
taglistthe tag bitlist.
lenlength of the tag bitlist.
Returns
malloced string or NULL.

References config_file::tagname.

◆ taglist_intersect()

int taglist_intersect ( uint8_t *  list1,
size_t  list1len,
uint8_t *  list2,
size_t  list2len 
)

see if two taglists intersect (have tags in common).

Parameters
list1first tag bitlist.
list1lenlength in bytes of first list.
list2second tag bitlist.
list2lenlength in bytes of second list.
Returns
true if there are tags in common, 0 if not.

Referenced by config_tag_test(), and local_zones_tags_lookup().

◆ config_apply()

void config_apply ( struct config_file config)

◆ config_lookup_uid()

void config_lookup_uid ( struct config_file config)

Find username, sets cfg_uid and cfg_gid.

Parameters
configthe config structure.

References cfg_gid, cfg_uid, and config_file::username.

◆ strlen_after_chroot()

static size_t strlen_after_chroot ( const char *  fname,
struct config_file cfg,
int  use_chdir 
)
static

Calculate string length of full pathname in original filesys.

Parameters
fnamethe path name to convert. Must not be null or empty.
cfgconfig struct for chroot and chdir (if set).
use_chdirif false, only chroot is applied.
Returns
length of string. remember to allocate one more for 0 at end in mallocs.

References config_file::chrootdir, and config_file::directory.

Referenced by fname_after_chroot().

◆ fname_after_chroot()

char* fname_after_chroot ( const char *  fname,
struct config_file cfg,
int  use_chdir 
)

Convert a filename to full pathname in original filesys.

Parameters
fnamethe path name to convert. Must not be null or empty.
cfgconfig struct for chroot and chdir (if set).
use_chdirif false, only chroot is applied.
Returns
pointer to malloced buffer which is: [chroot][chdir]fname or NULL on malloc failure.

References config_file::chrootdir, config_file::directory, and strlen_after_chroot().

Referenced by check_chroot_filelist_wild(), check_chroot_string(), print_option(), and setup_ctx().

◆ cfg_parse_local_zone()

int cfg_parse_local_zone ( struct config_file cfg,
const char *  val 
)

Parse local-zone directive into two strings and register it in the config.

Parameters
cfgto put it in.
valargument strings to local-zone, "example.com nodefault".
Returns
: false on failure

References cfg_str2list_insert(), cfg_strlist_insert(), last_space_pos(), config_file::local_zones, config_file::local_zones_nodefault, log_err(), and next_space_pos().

Referenced by config_set_option().

◆ cfg_ptr_reverse()

char* cfg_ptr_reverse ( char *  str)

Convert a ptr shorthand into a full reverse-notation PTR record.

Parameters
strinput string, "IP name"
Returns
: malloced string "reversed-ip-name PTR name"

References addr_is_ip6(), config_file::directory, ipstrtoaddr(), last_space_pos(), log_err(), memdup(), and next_space_pos().

Referenced by config_set_option().

◆ errinf()

void errinf ( struct module_qstate qstate,
const char *  str 
)

Append text to the error info for validation.

Parameters
qstatequery state.
strcopied into query region and appended. Failures to allocate are logged.

References module_env::cfg, module_qstate::env, module_qstate::errinf, log_err(), config_strlist::next, module_qstate::region, regional_alloc(), regional_strdup(), config_strlist::str, and config_file::val_log_level.

Referenced by errinf_dname(), errinf_origin(), errinf_rrset(), and validate_msg_signatures().

◆ errinf_origin()

void errinf_origin ( struct module_qstate qstate,
struct sock_list origin 
)

Append text to error info: from 1.2.3.4.

Parameters
qstatequery state.
originsock list with origin of trouble. Every element added. If NULL: nothing is added. if 0len element: 'from cache' is added.

References sock_list::addr, addr_to_str(), module_env::cfg, module_qstate::env, errinf(), sock_list::len, sock_list::next, and config_file::val_log_level.

Referenced by process_ds_response(), and validate_msg_signatures().

◆ errinf_to_str()

char* errinf_to_str ( struct module_qstate qstate)

Create error info in string.

Parameters
qstatequery state.
Returns
string or NULL on malloc failure (already logged). This string is malloced and has to be freed by caller.

References dname_str(), module_qstate::errinf, LDNS_MAX_DOMAINLEN, log_err(), config_strlist::next, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qtype, sldns_wire2str_class_buf(), sldns_wire2str_type_buf(), and config_strlist::str.

Referenced by key_cache_insert(), and processFinished().

◆ errinf_rrset()

void errinf_rrset ( struct module_qstate qstate,
struct ub_packed_rrset_key rr 
)

◆ errinf_dname()

void errinf_dname ( struct module_qstate qstate,
const char *  str,
uint8_t *  dname 
)

Append text to error info: str dname.

Parameters
qstatequery state.
strexplanation string
dnamethe dname.

References module_env::cfg, dname_str(), module_qstate::env, errinf(), LDNS_MAX_DOMAINLEN, and config_file::val_log_level.

Referenced by process_ds_response().

Variable Documentation

◆ autr_permit_small_holddown

int autr_permit_small_holddown = 0

for debug allow small timeout values for fast rollovers

debug and enable small timeouts

Referenced by autr_probe_timer(), calc_next_probe(), config_apply(), config_set_option(), and set_tp_times().

◆ cfg_parser

struct config_parser_state* cfg_parser = 0

global config during parsing

global config parser object used during config parsing