unbound 0.1
config_file.c File Reference

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

#include "config.h"
#include <ctype.h>
#include <stdarg.h>
#include <errno.h>
#include <limits.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/random.h"
#include "util/rtt.h"
#include "services/cache/infra.h"
#include "sldns/wire2str.h"
#include "sldns/parseutil.h"
#include "iterator/iterator.h"
#include "iterator/iter_delegpt.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
#define S_NUMBER_NONZERO(str, var)
 put integer_nonzero into variable
#define S_UNSIGNED_OR_ZERO(str, var)
 put integer_or_zero into unsigned
#define S_SIZET_OR_ZERO(str, var)
 put integer_or_zero into size_t
#define S_SIZET_NONZERO(str, var)
 put integer_nonzero into size_t
#define S_YNO(str, var)
 put yesno into variable
#define S_MEMSIZE(str, var)
 put memsize into variable
#define S_POW2(str, var)
 put pow2 number into variable
#define S_STR(str, var)
 put string into variable
#define S_STRLIST(str, var)
 put string into strlist
#define S_STRLIST_UNIQ(str, var)
 put string into strlist if not present yet
#define S_STRLIST_APPEND(str, var)
 append string to strlist
#define O_DEC(opt, str, var)
 compare and print decimal option
#define O_UNS(opt, str, var)
 compare and print unsigned option
#define O_YNO(opt, str, var)
 compare and print yesno option
#define O_STR(opt, str, var)
 compare and print string option
#define O_IFC(opt, str, num, arr)
 compare and print array option
#define O_MEM(opt, str, var)
 compare and print memorysize option
#define O_LST(opt, name, lst)
 compare and print list option
#define O_LS2(opt, name, lst)
 compare and print list option
#define O_LS3(opt, name, lst)
 compare and print list option
#define O_LTG(opt, name, lst)
 compare and print taglist option
#define SET_AUTO_SLAB(var, name, val)

Functions

static void init_outgoing_availports (int *array, int num)
 init ports possible for use
static int init_cookie_secret (struct config_file *cfg)
 init cookie with random data
struct config_file * config_create (void)
 Create config file structure.
struct config_file * config_create_forlib (void)
 Create config file structure for library use.
static int probe_maxrto (int useful_server_top_timeout)
 Set PROBE_MAXRTO based on current RTT_MAX_TIMEOUT (USEFUL_SERVER_TOP_TIMEOUT) configuration.
int config_apply_max_rtt (int max_rtt)
 Apply the relevant changes that rely upon RTT_MAX_TIMEOUT.
int config_set_option (struct config_file *cfg, const char *opt, const char *val)
 Set the given keyword to the given value.
void config_print_func (char *line, void *arg)
 function to print to a file, use as func with config_get_option.
void config_collate_func (char *line, void *arg)
 function to collate the text strings into a strlist_head.
int config_get_option_list (struct config_file *cfg, const char *opt, struct config_strlist **list)
 Get an option and return strlist.
int config_get_option_collate (struct config_file *cfg, const char *opt, char **str)
 Get an option and collate results into string.
char * config_collate_cat (struct config_strlist *list)
 take a strlist_head list and return a malloc string.
int config_get_option (struct config_file *cfg, const char *opt, void(*func)(char *, void *), void *arg)
 Call print routine for the given option.
static void create_cfg_parser (struct config_file *cfg, char *filename, const char *chroot)
 initialize the global cfg_parser object
void config_auto_slab_values (struct config_file *cfg)
 If _slabs values are not explicitly configured, 0 value, put them in a pow2 value close to the number of threads used.
int config_read (struct config_file *cfg, const char *filename, const char *chroot)
 Read the config file from the specified filename.
struct config_stub * cfg_stub_find (struct config_stub ***pp, const char *nm)
 Find stub in config list, also returns prevptr (for deletion).
void config_delstrlist (struct config_strlist *p)
 Delete items in config string list.
void config_deldblstrlist (struct config_str2list *p)
 Delete items in config double string list.
void config_deltrplstrlist (struct config_str3list *p)
 Delete items in config triple string list.
void config_delauth (struct config_auth *p)
 Delete an auth item.
void config_delauths (struct config_auth *p)
 Delete items in config auth list.
void config_delstub (struct config_stub *p)
 Delete a stub item.
void config_delstubs (struct config_stub *p)
 Delete items in config stub list.
void config_delview (struct config_view *p)
 Delete a view item.
void config_delviews (struct config_view *p)
 Delete items in config view list.
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.
static int extract_port_from_str (const char *str, int max_port)
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.
int cfg_scan_ports (int *avail, int num)
 Scan ports available.
int cfg_condense_ports (struct config_file *cfg, int **avail)
 Get a condensed list of ports returned.
void cfg_apply_local_port_policy (struct config_file *cfg, int num)
 Apply system specific port range policy.
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.
int cfg_region_strlist_insert (struct regional *region, struct config_strlist **head, char *item)
 insert with region for allocation.
struct config_strlist * cfg_strlist_find (struct config_strlist *head, const char *item)
 Find string in strlist.
int cfg_strlist_insert (struct config_strlist **head, char *item)
 Insert string into strlist.
int cfg_strlist_append_ex (struct config_strlist **head, char *item)
 Searches the end of a string list and appends the given text.
int cfg_str2list_insert (struct config_str2list **head, char *item, char *i2)
 Insert string into str2list.
int cfg_str3list_insert (struct config_str3list **head, char *item, char *i2, char *i3)
 Insert string into str3list.
int cfg_strbytelist_insert (struct config_strbytelist **head, char *item, uint8_t *i2, size_t i2len)
 Insert string into strbytelist.
time_t cfg_convert_timeval (const char *str)
 Convert 14digit to time value.
int cfg_count_numbers (const char *s)
 Count number of values in the string.
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.
int find_tag_id (struct config_file *cfg, const char *tag)
 Find tag ID in the tag list.
int config_add_tag (struct config_file *cfg, const char *tag)
 Add a tag name to the config.
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.
uint8_t * cfg_parse_nsid (const char *str, uint16_t *nsid_len)
 Parse nsid from string into binary nsid.
char * config_taglist2str (struct config_file *cfg, uint8_t *taglist, size_t taglen)
 convert tag bitlist to a malloced string with tag names.
int taglist_intersect (uint8_t *list1, size_t list1len, const uint8_t *list2, size_t list2len)
 see if two taglists intersect (have tags in common).
void config_apply (struct config_file *config)
 Apply config to global constants; this routine is called in single thread.
void config_lookup_uid (struct config_file *cfg)
 Find username, sets cfg_uid and cfg_gid.
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.
char * fname_after_chroot (const char *fname, struct config_file *cfg, int use_chdir)
 Convert a filename to full pathname in original filesys.
static const char * next_space_pos (const char *str)
 return next space character in string
static const 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.
char * cfg_ptr_reverse (char *str)
 Convert a ptr shorthand into a full reverse-notation PTR record.
int options_remote_is_address (struct config_file *cfg)
 check if config for remote control turns on IP-address interface with certificates or a named pipe without certificates.
int if_listens_on (const char *ifname, int default_port, int port, struct config_strlist *additional_ports)
 Return true if interface will listen to specific port(s).
int if_is_ssl (const char *ifname, int default_port, int ssl_port, struct config_strlist *tls_additional_port)
 see if interface will listen on ssl; its port number == the ssl port number or any of the additional ports
int if_is_pp2 (const char *ifname, int default_port, struct config_strlist *proxy_protocol_port)
 see if interface will listen on PROXYv2; its port number == any of the proxy ports number
int if_is_https (const char *ifname, int default_port, int https_port)
 see if interface will listen on https; its port number == the https port number
int if_is_dnscrypt (const char *ifname, int default_port, int dnscrypt_port)
 see if interface will listen on DNSCRYPT; its port number == the dnscrypt port number
size_t getmem_str (char *str)
 get memory for string
int if_is_quic (const char *ifname, int default_port, int quic_port)
 see if interface will listen on quic; its port number == the quic port number
int cfg_ports_list_contains (char *ports, int p)
 See if the if_automatic_ports list contains the value.
int cfg_has_https (struct config_file *cfg)
 Return true if the config contains settings that enable https.
int cfg_has_quic (struct config_file *cfg)
 Return true if the config contains settings that enable quic.
int cfg_tls_protocols_is_valid (const char *tls_protocols)
 Check if the configured string contains supported TLS protocols.
void cfg_tls_protocols_allowed (const char *tls_protocols, int *allow12, int *allow13)
 Based on the configured TLS protocols fill which ones are allowed.
int file_get_mtime (const char *file, time_t *mtime, long *ns, int *nonexist)
 get the file mtime stat (or error, with errno and nonexist)
int cfg_local_zone_type_value_check (const char *str)
 check local-zone type for correctness
const char * cfg_local_zone_type_list (void)
 the list of local-zone types, for error printout.

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
size_t stream_wait_max = 4 * 1024 * 1024
 size (in bytes) of stream wait buffers max
size_t http2_query_buffer_max = 4 * 1024 * 1024
 size (in bytes) of all total HTTP2 query buffers max
size_t http2_response_buffer_max = 4 * 1024 * 1024
 size (in bytes) of all total HTTP2 response buffers max
struct config_parser_state * cfg_parser = 0
 global config during parsing

Detailed Description

This file contains functions for the config file.

Macro Definition Documentation

◆ IS_NUMBER_OR_ZERO

#define IS_NUMBER_OR_ZERO   if(atoi(val) == 0 && strcmp(val, "0") != 0) return 0

check that the value passed is >= 0

Referenced by config_set_option().

◆ IS_YES_OR_NO

#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

Referenced by config_set_option().

◆ 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:480

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:483

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); }

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); }

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); }

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:489

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 'nice' memory or file size into a bytecount From '100k' to 102400.
Definition config_file.c:2355

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:486

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:2193

put string into strlist

Referenced by config_set_option().

◆ S_STRLIST_UNIQ

#define S_STRLIST_UNIQ ( str,
var )
Value:
if(strcmp(opt, str)==0) \
{ if(cfg_strlist_find(cfg->var, val)) { return 0;} \
return cfg_strlist_insert(&cfg->var, strdup(val)); }
struct config_strlist * cfg_strlist_find(struct config_strlist *head, const char *item)
Find string in strlist.
Definition config_file.c:2177

put string into strlist if not present yet

Referenced by config_set_option().

◆ S_STRLIST_APPEND

#define S_STRLIST_APPEND ( str,
var )
Value:
if(strcmp(opt, str)==0) \
{ return cfg_strlist_append(&cfg->var, strdup(val)); }
int cfg_strlist_append(struct config_strlist_head *list, char *item)
Append text at end of list.
Definition config_file.c:2137

append string to 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:937
char * str
config option string
Definition config_file.h:941
struct config_strlist * next
next item in list
Definition config_file.h:939

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:947
char * str
first string
Definition config_file.h:951
char * str2
second string
Definition config_file.h:953
struct config_str2list * next
next item in list
Definition config_file.h:949

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:959
struct config_str3list * next
next item in list
Definition config_file.h:961
char * str2
second string
Definition config_file.h:965
char * str3
third string
Definition config_file.h:967
char * str
first string
Definition config_file.h:963

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); \
} \
} \
}
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:2513
List of string, bytestring for config options.
Definition config_file.h:974
char * str
first string
Definition config_file.h:978
struct config_strbytelist * next
next item in list
Definition config_file.h:976
uint8_t * str2
second bytestring
Definition config_file.h:980

compare and print taglist option

Referenced by config_get_option().

◆ SET_AUTO_SLAB

#define SET_AUTO_SLAB ( var,
name,
val )
Value:
do { \
if(cfg->var == 0) { \
cfg->var = val; \
verbose(VERB_QUERY, "setting "name": %lu", (unsigned long)val); \
} \
} while(0);
@ VERB_QUERY
3 - query level information
Definition log.h:57

Function Documentation

◆ init_outgoing_availports()

void init_outgoing_availports ( int * array,
int num )
static

init ports possible for use

References init_outgoing_availports().

Referenced by config_create(), and init_outgoing_availports().

◆ init_cookie_secret()

◆ 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::acls, config_file::add_holddown, config_file::aggressive_nsec, config_file::auths, config_file::auto_trust_anchor_file_list, config_file::bogus_ttl, config_file::caps_whitelist, config_file::chrootdir, config_create(), config_delete(), config_file::control_cert_file, config_file::control_ifs, config_file::control_key_file, config_file::control_port, config_file::control_use_cert, config_file::cookie_secret, config_file::cookie_secret_file, config_file::cookie_secret_len, config_file::del_holddown, config_file::delay_close, config_file::delegpt_max_addr, config_file::delegpt_max_ns, config_file::deny_any, config_file::directory, config_file::disable_dnssec_lame_check, config_file::disable_edns_do, config_file::discard_timeout, config_file::dns_error_reporting, 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_provider_cert_rotated, config_file::dnscrypt_secret_key, config_file::dnscrypt_shared_secret_cache_size, config_file::dnscrypt_shared_secret_cache_slabs, config_file::dnstap_bidirectional, config_file::dnstap_socket_path, config_file::dnstap_tls, config_file::do_answer_cookie, config_file::do_daemonize, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::do_tcp_keepalive, config_file::do_udp, config_file::domain_insecure, config_file::donotquery_localhost, config_file::donotqueryaddrs, config_file::dynlib_file, config_file::ede, config_file::ede_serve_expired, config_file::edns_buffer_size, config_file::edns_client_string_opcode, config_file::edns_client_strings, config_file::fast_server_num, config_file::fast_server_permil, config_strlist_head::first, config_file::forwards, config_file::harden_algo_downgrade, config_file::harden_below_nxdomain, config_file::harden_cname_follow, 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::harden_unknown_additional, config_file::harden_unverified_glue, config_file::hide_http_user_agent, config_file::hide_identity, config_file::hide_trustanchor, config_file::hide_version, config_file::host_ttl, config_file::http_endpoint, config_file::http_max_streams, config_file::http_nodelay, config_file::http_query_buffer_size, config_file::http_response_buffer_size, config_file::http_user_agent, config_file::https_port, config_file::identity, config_file::if_automatic, config_file::if_automatic_ports, config_file::ifs, config_file::ignore_cd, config_file::incoming_num_tcp, config_file::infra_cache_max_rtt, config_file::infra_cache_min_rtt, config_file::infra_cache_numhosts, config_file::infra_cache_slabs, config_file::infra_keep_probing, init_outgoing_availports(), config_file::insecure_lan_zones, config_file::ip_dscp, config_file::ip_freebind, config_file::ip_ratelimit, config_file::ip_ratelimit_backoff, config_file::ip_ratelimit_cookie, config_file::ip_ratelimit_factor, config_file::ip_ratelimit_size, config_file::ip_ratelimit_slabs, config_file::ip_transparent, config_file::iter_scrub_cname, config_file::iter_scrub_glue_count, config_file::iter_scrub_ns, config_file::iter_scrub_promiscuous, config_file::iter_scrub_rrsig, config_file::jostle_time, config_file::keep_missing, config_file::key_cache_size, config_file::key_cache_slabs, config_strlist_head::last, config_file::local_data, config_file::local_zone_overrides, config_file::local_zones, config_file::local_zones_disable_default, config_file::local_zones_nodefault, config_file::log_destaddr, config_file::log_identity, config_file::log_local_actions, config_file::log_queries, config_file::log_replies, config_file::log_servfail, config_file::log_tag_queryreply, config_file::log_thread_id, config_file::log_time_ascii, config_file::log_time_iso, config_file::logfile, config_file::max_global_quota, config_file::max_negative_ttl, config_file::max_query_restarts, config_file::max_reuse_tcp_queries, config_file::max_sent_count, config_file::max_ttl, config_file::min_negative_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::nsid_cfg_str, 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::outbound_msg_retry, config_file::outgoing_avail_ports, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, config_file::outgoing_tcp_mss, config_file::pad_queries, config_file::pad_queries_block_size, config_file::pad_responses, config_file::pad_responses_block_size, 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::quic_port, config_file::quic_size, config_file::ratelimit, config_file::ratelimit_backoff, config_file::ratelimit_below_domain, config_file::ratelimit_factor, config_file::ratelimit_for_domain, config_file::ratelimit_size, config_file::ratelimit_slabs, config_file::remote_control_enable, config_file::root_hints, config_file::root_key_sentinel, config_file::rrset_cache_size, config_file::rrset_cache_slabs, config_file::serve_expired, config_file::serve_expired_client_timeout, config_file::serve_expired_reply_ttl, config_file::serve_expired_ttl, config_file::serve_expired_ttl_reset, config_file::serve_original_ttl, 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::sock_queue_timeout, 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_inhibit_zero, config_file::stat_interval, config_file::stream_wait_size, config_file::stubs, config_file::target_fetch_policy, config_file::tcp_auth_query_timeout, config_file::tcp_connection_limits, config_file::tcp_idle_timeout, config_file::tcp_keepalive_timeout, config_file::tcp_mss, config_file::tcp_reuse_timeout, config_file::tcp_upstream, config_file::tls_cert_bundle, config_file::tls_protocols, config_file::tls_use_sni, config_file::tls_win_cert, 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_connect, 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_hash_attempts, config_file::val_log_level, config_file::val_log_squelch, config_file::val_max_restart, config_file::val_nsec3_key_iterations, config_file::val_permissive_mode, config_file::val_sig_skew_max, config_file::val_sig_skew_min, config_file::val_validation_attempts, config_file::verbosity, config_file::version, config_file::views, config_file::wait_limit, config_file::wait_limit_cookie, config_file::wait_limit_cookie_netblock, config_file::wait_limit_netblock, and config_file::zonemd_permissive_mode.

Referenced by authtest_addzone(), checkconf(), config_create(), config_create_forlib(), fr_read_config(), go(), infra_test(), print_stats_shm(), run_daemon(), service_init(), and zonemd_verify_test().

◆ config_create_forlib()

◆ probe_maxrto()

int probe_maxrto ( int useful_server_top_timeout)
static

Set PROBE_MAXRTO based on current RTT_MAX_TIMEOUT (USEFUL_SERVER_TOP_TIMEOUT) configuration.

References PROBE_MAXRTO, probe_maxrto(), and PROBE_MAXRTO_DEFAULT.

Referenced by config_apply_max_rtt(), and probe_maxrto().

◆ config_apply_max_rtt()

int config_apply_max_rtt ( int max_rtt)

Apply the relevant changes that rely upon RTT_MAX_TIMEOUT.

Apply the relevant changes that rely upon RTT_MAX_TIMEOUT; exported for unit test.

Apply the relevant changes that rely upon RTT_MAX_TIMEOUT.

References BLACKLIST_PENALTY, config_apply_max_rtt(), PROBE_MAXRTO, probe_maxrto(), and USEFUL_SERVER_TOP_TIMEOUT.

Referenced by config_apply(), config_apply_max_rtt(), config_set_option(), and infra_test().

◆ 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::aggressive_nsec, config_file::allow_proxy, 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_parse_nsid(), cfg_ptr_reverse(), cfg_strlist_insert(), cfg_tls_protocols_is_valid(), config_file::chrootdir, config_add_tag(), config_apply_max_rtt(), config_set_option(), config_file::control_cert_file, config_file::control_ifs, config_file::control_key_file, config_file::control_port, config_file::cookie_secret_file, config_file::del_holddown, config_file::delay_close, delegpt_max_addr, delegpt_max_ns, config_file::deny_any, config_file::directory, config_file::disable_dnssec_lame_check, config_file::disable_edns_do, config_file::discard_timeout, config_file::dns_error_reporting, 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_provider_cert_rotated, 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_bidirectional, config_file::dnstap_identity, config_file::dnstap_ip, 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_sample_rate, config_file::dnstap_send_identity, config_file::dnstap_send_version, config_file::dnstap_socket_path, config_file::dnstap_tls, config_file::dnstap_tls_cert_bundle, config_file::dnstap_tls_client_cert_file, config_file::dnstap_tls_client_key_file, config_file::dnstap_tls_server_name, config_file::dnstap_version, config_file::do_answer_cookie, config_file::do_daemonize, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::do_tcp_keepalive, config_file::do_udp, config_file::domain_insecure, config_file::donotquery_localhost, config_file::donotqueryaddrs, config_file::dynlib_file, config_file::ede, config_file::ede_serve_expired, config_file::edns_buffer_size, config_file::fast_server_num, config_file::fast_server_permil, config_file::harden_algo_downgrade, config_file::harden_below_nxdomain, config_file::harden_cname_follow, 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::harden_unknown_additional, config_file::harden_unverified_glue, config_file::hide_http_user_agent, config_file::hide_identity, config_file::hide_trustanchor, config_file::hide_version, config_file::host_ttl, config_file::http_endpoint, config_file::http_max_streams, config_file::http_nodelay, config_file::http_notls_downstream, config_file::http_query_buffer_size, config_file::http_response_buffer_size, config_file::http_user_agent, config_file::https_port, config_file::identity, config_file::if_automatic, config_file::if_automatic_ports, config_file::ignore_cd, config_file::incoming_num_tcp, config_file::infra_cache_max_rtt, config_file::infra_cache_min_rtt, config_file::infra_cache_numhosts, config_file::infra_cache_slabs, infra_dp_ratelimit, infra_ip_ratelimit, infra_ip_ratelimit_cookie, config_file::infra_keep_probing, config_file::insecure_lan_zones, config_file::ip_dscp, config_file::ip_freebind, config_file::ip_ratelimit, config_file::ip_ratelimit_backoff, config_file::ip_ratelimit_cookie, 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::iter_scrub_cname, config_file::iter_scrub_glue_count, config_file::iter_scrub_ns, config_file::iter_scrub_promiscuous, config_file::iter_scrub_rrsig, 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_destaddr, config_file::log_identity, config_file::log_local_actions, config_file::log_queries, config_file::log_replies, config_file::log_servfail, log_set_time_asc(), log_set_time_iso(), config_file::log_tag_queryreply, config_file::log_thread_id, config_file::log_time_ascii, config_file::log_time_iso, config_file::logfile, config_file::max_global_quota, MAX_NEG_TTL, config_file::max_negative_ttl, config_file::max_query_restarts, config_file::max_reuse_tcp_queries, config_file::max_sent_count, MAX_TTL, config_file::max_ttl, MIN_NEG_TTL, config_file::min_negative_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::nsid_cfg_str, config_file::num_out_ifs, config_file::num_queries_per_thread, config_file::out_ifs, config_file::outbound_msg_retry, config_file::outgoing_avail_ports, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, config_file::outgoing_tcp_mss, config_file::pad_queries, config_file::pad_queries_block_size, config_file::pad_responses, config_file::pad_responses_block_size, config_file::permit_small_holddown, config_file::pidfile, config_file::port, config_file::prefer_ip4, config_file::prefer_ip6, config_file::prefetch, config_file::prefetch_key, config_file::private_address, config_file::private_domain, config_file::proxy_protocol_port, config_file::python_script, config_file::qname_minimisation, config_file::qname_minimisation_strict, config_file::quic_port, config_file::quic_size, config_file::ratelimit, config_file::ratelimit_backoff, config_file::ratelimit_factor, config_file::ratelimit_size, config_file::ratelimit_slabs, config_file::remote_control_enable, config_file::root_hints, config_file::root_key_sentinel, config_file::rrset_cache_size, config_file::rrset_cache_slabs, RTT_MAX_TIMEOUT, 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_STRLIST_APPEND, S_STRLIST_UNIQ, S_UNSIGNED_OR_ZERO, S_YNO, SERVE_EXPIRED, config_file::serve_expired, config_file::serve_expired_client_timeout, SERVE_EXPIRED_REPLY_TTL, config_file::serve_expired_reply_ttl, SERVE_EXPIRED_TTL, config_file::serve_expired_ttl, SERVE_EXPIRED_TTL_RESET, config_file::serve_expired_ttl_reset, config_file::serve_original_ttl, 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::sock_queue_timeout, 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_inhibit_zero, config_file::stat_interval, config_file::stream_wait_size, config_file::target_fetch_policy, config_file::tcp_auth_query_timeout, config_file::tcp_idle_timeout, config_file::tcp_keepalive_timeout, config_file::tcp_mss, config_file::tcp_reuse_timeout, config_file::tcp_upstream, config_file::tls_additional_port, config_file::tls_cert_bundle, config_file::tls_ciphers, config_file::tls_ciphersuites, config_file::tls_protocols, config_file::tls_session_ticket_keys, config_file::tls_use_sni, config_file::tls_win_cert, 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_connect, 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_hash_attempts, config_file::val_log_level, config_file::val_log_squelch, config_file::val_max_restart, config_file::val_nsec3_key_iterations, config_file::val_permissive_mode, config_file::val_sig_skew_max, config_file::val_sig_skew_min, config_file::val_validation_attempts, verbosity, config_file::version, config_file::wait_limit, config_file::wait_limit_cookie, and config_file::zonemd_permissive_mode.

Referenced by config_set_option(), 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.

References config_print_func().

Referenced by config_print_func(), fptr_whitelist_print_func(), and print_option().

◆ 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_func(), config_collate_arg::list, and config_collate_arg::status.

Referenced by config_collate_func(), 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_get_option_list(), config_strlist_head::first, config_collate_arg::list, and config_collate_arg::status.

Referenced by config_get_option_collate(), and config_get_option_list().

◆ 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_collate(), and config_get_option_list().

Referenced by config_get_option_collate(), and 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_collate_cat(), config_strlist::next, and config_strlist::str.

Referenced by config_collate_cat(), and config_get_option_collate().

◆ config_get_option()

int config_get_option ( struct config_file * cfg,
const char * opt,
void(* func )(char *, void *),
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 config_get_option(), delegpt_max_addr, delegpt_max_ns, fptr_ok, fptr_whitelist_print_func(), 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(), config_get_option_list(), do_get_option(), and print_option().

◆ create_cfg_parser()

void create_cfg_parser ( struct config_file * cfg,
char * filename,
const char * chroot )
static

◆ config_auto_slab_values()

void config_auto_slab_values ( struct config_file * config)

If _slabs values are not explicitly configured, 0 value, put them in a pow2 value close to the number of threads used.

Starts at the current default 4. If num_threads is in between two pow2 values, 1/3 of the way stays with the lower pow2 value. Exported for unit testing.

Parameters
configwhere the _slabs values reside.

References config_parser_state::cfg, config_auto_slab_values(), log_assert, and config_file::num_threads.

Referenced by authtest_addzone(), config_auto_slab_values(), config_read(), infra_test(), run_daemon(), service_init(), and zonemd_verify_test().

◆ 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_parser_state::cfg, cfg_parser, config_parser_state::chroot, config_auto_slab_values(), config_read(), create_cfg_parser(), config_file::dnscrypt, config_file::dnscrypt_port, config_parser_state::errors, config_parser_state::filename, init_cookie_secret(), log_err(), ub_c_in, ub_c_parse(), VERB_QUERY, and verbose().

Referenced by checkconf(), config_read(), fr_read_config(), go(), print_stats_shm(), run_daemon(), service_init(), 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 cfg_stub_find(), config_stub::name, and config_stub::next.

Referenced by cfg_stub_find(), and ub_ctx_set_stub().

◆ config_delstrlist()

◆ config_deldblstrlist()

void config_deldblstrlist ( struct config_str2list * list)

◆ config_deltrplstrlist()

◆ config_delauth()

◆ config_delauths()

void config_delauths ( struct config_auth * list)

Delete items in config auth list.

Parameters
listlist.

References config_delauth(), config_delauths(), and config_auth::next.

Referenced by config_delauths(), and config_delete().

◆ config_delstub()

void config_delstub ( struct config_stub * p)

Delete a stub item.

Parameters
pstub item

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

Referenced by config_delstub(), 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(), config_delstubs(), and config_stub::next.

Referenced by config_delete(), config_delstubs(), and ub_ctx_set_fwd().

◆ config_delview()

◆ config_delviews()

void config_delviews ( struct config_view * list)

Delete items in config view list.

Parameters
listlist.

References config_delview(), config_delviews(), and config_view::next.

Referenced by config_delete(), and config_delviews().

◆ config_del_strarray()

◆ config_del_strbytelist()

◆ 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::acl_view, config_file::acls, config_file::allow_proxy, config_file::auths, config_file::auto_trust_anchor_file_list, config_file::caps_whitelist, config_file::chrootdir, config_del_strarray(), config_del_strbytelist(), config_delauths(), config_deldblstrlist(), config_delete(), config_delstrlist(), config_delstubs(), config_deltrplstrlist(), config_delviews(), config_file::control_cert_file, config_file::control_ifs, config_file::control_key_file, config_file::cookie_secret_file, config_file::directory, config_file::dns64_ignore_aaaa, config_file::dnstap_identity, config_file::dnstap_ip, config_file::dnstap_socket_path, config_file::dnstap_tls_cert_bundle, config_file::dnstap_tls_client_cert_file, config_file::dnstap_tls_client_key_file, config_file::dnstap_tls_server_name, config_file::dnstap_version, config_file::domain_insecure, config_file::donotqueryaddrs, config_file::dynlib_file, config_file::edns_client_strings, config_strlist_head::first, config_file::forwards, config_file::http_endpoint, config_file::http_user_agent, config_file::identity, config_file::if_automatic_ports, config_file::ifs, config_file::interface_actions, config_file::interface_tag_actions, config_file::interface_tag_datas, config_file::interface_tags, config_file::interface_view, config_file::local_data, config_file::local_zone_overrides, config_file::local_zone_tags, config_file::local_zones, config_file::local_zones_nodefault, log_ident_revert_to_default(), config_file::log_identity, config_file::logfile, config_file::module_conf, config_file::nsid_cfg_str, 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::proxy_protocol_port, config_file::python_script, config_file::ratelimit_below_domain, config_file::ratelimit_for_domain, config_file::respip_actions, 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::tcp_connection_limits, config_file::tls_additional_port, config_file::tls_cert_bundle, config_file::tls_ciphers, config_file::tls_ciphersuites, config_file::tls_protocols, config_file::tls_session_ticket_keys, 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, config_file::views, config_file::wait_limit_cookie_netblock, and config_file::wait_limit_netblock.

Referenced by authtest_addzone(), checkconf(), config_create(), config_delete(), fr_construct_clear(), fr_load_config(), fr_read_config(), go(), infra_test(), print_stats_shm(), run_daemon(), service_deinit(), service_init(), service_main(), ub_ctx_create(), ub_ctx_create_nopipe(), ub_ctx_delete(), and zonemd_verify_test().

◆ 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 cfg_mark_ports(), log_err(), and log_warn().

Referenced by cfg_mark_ports(), and 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.

References cfg_scan_ports().

Referenced by cfg_condense_ports(), and cfg_scan_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_condense_ports(), cfg_scan_ports(), log_assert, and config_file::outgoing_avail_ports.

Referenced by cfg_condense_ports(), and libworker_setup().

◆ cfg_apply_local_port_policy()

void cfg_apply_local_port_policy ( struct config_file * cfg,
int num )

Apply system specific port range policy.

Parameters
cfgconfig file.
numsize of the array (65536).

References cfg_apply_local_port_policy(), log_err(), and config_file::outgoing_avail_ports.

Referenced by cfg_apply_local_port_policy(), and context_finalize().

◆ ub_c_error_va_list()

void ub_c_error_va_list ( const char * fmt,
va_list args )
static

◆ ub_c_error_msg()

void ub_c_error_msg ( const char * fmt,
... )

print error with file and line number

References ub_c_error_msg(), and ub_c_error_va_list().

Referenced by ub_c_error_msg(), and ub_c_error_msg().

◆ ub_c_error()

void ub_c_error ( const char * str)

◆ ub_c_wrap()

int ub_c_wrap ( void )

wrap function

References ub_c_wrap().

Referenced by ub_c_lex(), and ub_c_wrap().

◆ 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. on fail the item is free()ed.

References cfg_strlist_append(), config_strlist_head::first, config_strlist_head::last, config_strlist::next, and config_strlist::str.

Referenced by cfg_strlist_append(), config_collate_func(), fr_output_text(), main(), and spool_txt_string().

◆ cfg_region_strlist_insert()

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

◆ cfg_strlist_find()

struct config_strlist * cfg_strlist_find ( struct config_strlist * head,
const char * item )

Find string in strlist.

Parameters
headpointer to strlist head variable.
itemthe item to search for.
Returns
: the element in the list when found, NULL otherwise.

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

Referenced by cfg_strlist_find().

◆ 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. on fail, the item is free()d.

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

Referenced by cfg_parse_local_zone(), cfg_strlist_insert(), config_set_option(), dnsc_load_local_data(), read_file_content(), setup_config(), spool_auto_file(), spool_temp_file(), 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(), ub_ctx_trustedkeys(), and zonemd_verify_test().

◆ cfg_strlist_append_ex()

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

Searches the end of a string list and appends the given text.

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

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

Referenced by cfg_strlist_append_ex().

◆ 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. on fail, the item and i2 are free()d.

References cfg_str2list_insert(), config_str2list::next, config_str2list::str, and config_str2list::str2.

Referenced by cfg_insert_respip_data(), cfg_parse_local_zone(), cfg_str2list_insert(), dnsc_load_local_data(), respip_conf_actions_test(), respip_view_conf_actions_test(), 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 cfg_str3list_insert(), config_str3list::next, config_str3list::str, config_str3list::str2, and config_str3list::str3.

Referenced by cfg_str3list_insert().

◆ 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 cfg_strbytelist_insert(), config_strbytelist::next, config_strbytelist::str, and config_strbytelist::str2.

Referenced by cfg_strbytelist_insert().

◆ 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 cfg_convert_timeval(), and sldns_mktime_from_utc().

Referenced by cfg_convert_timeval(), config_set_option(), verifytest_file(), and zonemd_verify_test().

◆ 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.

References cfg_count_numbers().

Referenced by cfg_count_numbers(), read_fetch_policy(), and val_env_parse_key_iter().

◆ isalldigit()

int isalldigit ( const char * str,
size_t l )
static

all digit number

References isalldigit().

Referenced by cfg_parse_memsize(), and isalldigit().

◆ 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 cfg_parse_memsize(), isalldigit(), and log_err().

Referenced by cfg_parse_memsize(), 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 find_tag_id(), config_file::num_tags, and config_file::tagname.

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

◆ 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 config_add_tag(), find_tag_id(), config_file::num_tags, and config_file::tagname.

Referenced by config_add_tag(), and config_set_option().

◆ cfg_set_bit()

void cfg_set_bit ( uint8_t * bitlist,
size_t len,
int id )
static

set a bit in a bit array

References cfg_set_bit(), and log_assert.

Referenced by cfg_set_bit(), and config_parse_taglist().

◆ 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(), config_parse_taglist(), find_tag_id(), log_err(), and config_file::num_tags.

Referenced by config_parse_taglist().

◆ cfg_parse_nsid()

uint8_t * cfg_parse_nsid ( const char * str,
uint16_t * nsid_len )

Parse nsid from string into binary nsid.

nsid is either a hexadecimal string or an ascii string prepended with ascii_ in which case the characters after ascii_ are simply copied.

Parameters
strthe string to parse.
nsid_lenreturns length of nsid in bytes.
Returns
malloced bytes or NULL on parse error or malloc failure.

References cfg_parse_nsid(), and sldns_hexdigit_to_int().

Referenced by cfg_parse_nsid(), and config_set_option().

◆ 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_taglist2str(), and config_file::tagname.

Referenced by config_taglist2str().

◆ taglist_intersect()

int taglist_intersect ( uint8_t * list1,
size_t list1len,
const 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.

References taglist_intersect().

Referenced by config_tag_test(), local_zones_tags_lookup(), respip_rewrite_reply(), rpz_callback_from_iterator_cname(), rpz_callback_from_iterator_module(), and taglist_intersect().

◆ 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, config_lookup_uid(), and config_file::username.

Referenced by config_lookup_uid(), and run_daemon().

◆ strlen_after_chroot()

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, config_file::directory, and strlen_after_chroot().

Referenced by fname_after_chroot(), and strlen_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, fname_after_chroot(), and strlen_after_chroot().

Referenced by check_chroot_filelist_wild(), check_chroot_string(), check_file_clobber(), file_list_contains(), file_list_contains_wild(), fname_after_chroot(), morechecks(), perform_setup(), print_option(), and setup_ctx().

◆ next_space_pos()

const char * next_space_pos ( const char * str)
static

return next space character in string

References next_space_pos().

Referenced by cfg_parse_local_zone(), cfg_ptr_reverse(), and next_space_pos().

◆ last_space_pos()

const char * last_space_pos ( const char * str)
static

return last space character in string

References last_space_pos().

Referenced by cfg_parse_local_zone(), cfg_ptr_reverse(), and last_space_pos().

◆ 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_parse_local_zone(), 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 cfg_parse_local_zone(), and 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(), cfg_ptr_reverse(), ipstrtoaddr(), last_space_pos(), log_err(), and next_space_pos().

Referenced by cfg_ptr_reverse(), and config_set_option().

◆ options_remote_is_address()

int options_remote_is_address ( struct config_file * cfg)

check if config for remote control turns on IP-address interface with certificates or a named pipe without certificates.

References config_file::control_ifs, config_strlist_head::first, options_remote_is_address(), config_file::remote_control_enable, and config_strlist::str.

Referenced by daemon_remote_create(), morechecks(), options_remote_is_address(), and setup_ctx().

◆ if_listens_on()

int if_listens_on ( const char * ifname,
int default_port,
int port,
struct config_strlist * additional_ports )

Return true if interface will listen to specific port(s).

Parameters
ifnamethe interface as configured in the configuration file.
default_portthe default port to use as the interface port if ifname does not include a port via the '@' notation.
portport to check for, if 0 it will not be checked.
additional_portsadditional configured ports, if any (nonNULL) to be checked against.
Returns
true if one of (port, additional_ports) matches the interface port.

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

Referenced by if_is_dnscrypt(), if_is_https(), if_is_pp2(), if_is_quic(), if_is_ssl(), if_listens_on(), ports_create_if(), and ub_c_error_msg().

◆ if_is_ssl()

int if_is_ssl ( const char * ifname,
int default_port,
int ssl_port,
struct config_strlist * tls_additional_port )

see if interface will listen on ssl; its port number == the ssl port number or any of the additional ports

References if_is_ssl(), and if_listens_on().

Referenced by if_is_ssl(), ports_create_if(), and ub_c_error_msg().

◆ if_is_pp2()

int if_is_pp2 ( const char * ifname,
int default_port,
struct config_strlist * proxy_protocol_port )

see if interface will listen on PROXYv2; its port number == any of the proxy ports number

References if_is_pp2(), and if_listens_on().

Referenced by if_is_pp2(), interfacechecks(), ports_create_if(), and ub_c_error_msg().

◆ if_is_https()

int if_is_https ( const char * ifname,
int default_port,
int https_port )

see if interface will listen on https; its port number == the https port number

References if_is_https(), and if_listens_on().

Referenced by cfg_has_https(), if_is_https(), interfacechecks(), ports_create_if(), and ub_c_error_msg().

◆ if_is_dnscrypt()

int if_is_dnscrypt ( const char * ifname,
int default_port,
int dnscrypt_port )

see if interface will listen on DNSCRYPT; its port number == the dnscrypt port number

References if_is_dnscrypt(), and if_listens_on().

Referenced by if_is_dnscrypt(), interfacechecks(), ports_create_if(), and ub_c_error_msg().

◆ getmem_str()

◆ if_is_quic()

int if_is_quic ( const char * ifname,
int default_port,
int quic_port )

see if interface will listen on quic; its port number == the quic port number

References if_is_quic(), and if_listens_on().

Referenced by cfg_has_quic(), if_is_quic(), interfacechecks(), ports_create_if(), and ub_c_error_msg().

◆ cfg_ports_list_contains()

int cfg_ports_list_contains ( char * ports,
int p )

See if the if_automatic_ports list contains the value.

Parameters
portsString with port numbers.
pnumber looked for.
Returns
true if found, false if not found or parse failure.

References cfg_ports_list_contains().

Referenced by cfg_has_https(), cfg_has_quic(), cfg_ports_list_contains(), config_ports_list_test(), and ub_c_error_msg().

◆ cfg_has_https()

int cfg_has_https ( struct config_file * cfg)

Return true if the config contains settings that enable https.

Parameters
cfgconfig information.
Returns
true if https ports are used for server.

References cfg_has_https(), cfg_ports_list_contains(), config_file::https_port, config_file::if_automatic_ports, if_is_https(), config_file::ifs, config_file::num_ifs, and config_file::port.

Referenced by cfg_has_https(), checkrlimits(), ct_create_sslctxs(), service_init(), and ub_c_error_msg().

◆ cfg_has_quic()

int cfg_has_quic ( struct config_file * cfg)

Return true if the config contains settings that enable quic.

Parameters
cfgconfig information.
Returns
true if quic ports are used for server.

References cfg_has_quic(), cfg_ports_list_contains(), config_file::if_automatic_ports, if_is_quic(), config_file::ifs, config_file::num_ifs, config_file::port, and config_file::quic_port.

Referenced by cfg_has_quic(), ct_create_sslctxs(), daemon_create_workers(), service_init(), and ub_c_error_msg().

◆ cfg_tls_protocols_is_valid()

int cfg_tls_protocols_is_valid ( const char * tls_protocols)

Check if the configured string contains supported TLS protocols.

Parameters
tls_protocolsString with TLS protocols.
Returns
true if all options are valid, else false.

References cfg_tls_protocols_is_valid().

Referenced by cfg_tls_protocols_is_valid(), config_set_option(), and ub_c_error_msg().

◆ cfg_tls_protocols_allowed()

void cfg_tls_protocols_allowed ( const char * tls_protocols,
int * allow12,
int * allow13 )

Based on the configured TLS protocols fill which ones are allowed.

Parameters
tls_protocolsString with TLS protocols.
allow12will be true if TLSv1.2 is configured.
allow13will be true if TLSv1.3 is configured.

References cfg_tls_protocols_allowed().

Referenced by cfg_tls_protocols_allowed(), listen_sslctx_setup(), and ub_c_error_msg().

◆ file_get_mtime()

int file_get_mtime ( const char * file,
time_t * mtime,
long * ns,
int * nonexist )

get the file mtime stat (or error, with errno and nonexist)

References file_get_mtime().

Referenced by ct_create_sslctxs(), file_get_mtime(), ssl_cert_changed(), and ub_c_error_msg().

◆ cfg_local_zone_type_value_check()

int cfg_local_zone_type_value_check ( const char * str)

check local-zone type for correctness

References cfg_local_zone_type_value_check().

Referenced by cfg_local_zone_type_value_check(), and ub_c_error_msg().

◆ cfg_local_zone_type_list()

const char * cfg_local_zone_type_list ( void )

the list of local-zone types, for error printout.

References cfg_local_zone_type_list().

Referenced by cfg_local_zone_type_list(), and ub_c_error_msg().

Variable Documentation

◆ cfg_uid

uid_t cfg_uid = (uid_t)-1

from cfg username, after daemonize setup performed

Referenced by add_open(), config_lookup_uid(), and perform_setup().

◆ cfg_gid

gid_t cfg_gid = (gid_t)-1

from cfg username, after daemonize setup performed

Referenced by add_open(), config_lookup_uid(), and perform_setup().

◆ autr_permit_small_holddown

int autr_permit_small_holddown = 0

for debug allow small timeout values for fast rollovers

debug and enable small timeouts

for debug allow small timeout values for fast rollovers

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

◆ stream_wait_max

size_t stream_wait_max = 4 * 1024 * 1024

size (in bytes) of stream wait buffers max

Referenced by config_apply(), and tcp_req_info_add_result().

◆ http2_query_buffer_max

size_t http2_query_buffer_max = 4 * 1024 * 1024

size (in bytes) of all total HTTP2 query buffers max

Referenced by config_apply().

◆ http2_response_buffer_max

size_t http2_response_buffer_max = 4 * 1024 * 1024

size (in bytes) of all total HTTP2 response buffers max

Referenced by config_apply().

◆ cfg_parser

struct config_parser_state* cfg_parser = 0

global config during parsing

global config parser object used during config parsing

global config during parsing

Referenced by config_read(), create_cfg_parser(), ub_c_error(), and ub_c_error_va_list().