This file contains functions for the config file. More...
Data Structures | |
| struct | config_file |
| The configuration options. More... | |
| struct | config_stub |
| Stub config options. More... | |
| struct | config_strlist |
| List of strings for config options. More... | |
| struct | config_str2list |
| List of two strings for config options. More... | |
| struct | config_strlist_head |
| List head for strlist processing, used for append operation. More... | |
| struct | config_parser_state |
| Used during options parsing. More... | |
Functions | |
| struct config_file * | config_create (void) |
| Create config file structure. | |
| struct config_file * | config_create_forlib (void) |
| Create config file structure for library use. | |
| int | config_read (struct config_file *config, const char *filename, const char *chroot) |
| Read the config file from the specified filename. | |
| void | config_delete (struct config_file *config) |
| Destroy the config file structure. | |
| void | config_apply (struct config_file *config) |
| Apply config to global constants; this routine is called in single thread. | |
| int | config_set_option (struct config_file *config, const char *option, const char *value) |
| Set the given keyword to the given value. | |
| int | config_get_option (struct config_file *cfg, const char *opt, void(*func)(char *, void *), void *arg) |
| Call print routine for the given option. | |
| 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. | |
| 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. | |
| char * | config_collate_cat (struct config_strlist *list) |
| take a strlist_head list and return a malloc string. | |
| int | cfg_strlist_append (struct config_strlist_head *list, char *item) |
| Append text at end of list. | |
| int | cfg_strlist_insert (struct config_strlist **head, char *item) |
| Insert string into strlist. | |
| int | cfg_str2list_insert (struct config_str2list **head, char *item, char *i2) |
| Insert string into str2list. | |
| void | config_delstrlist (struct config_strlist *list) |
| Delete items in config string list. | |
| void | config_deldblstrlist (struct config_str2list *list) |
| Delete items in config double string list. | |
| void | config_delstubs (struct config_stub *list) |
| Delete items in config stub list. | |
| uint32_t | cfg_convert_timeval (const char *str) |
| Convert 14digit to time value. | |
| int | cfg_count_numbers (const char *str) |
| Count number of values in the string. | |
| 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 | cfg_parse_local_zone (struct config_file *cfg, const char *val) |
| Parse local-zone directive into two strings and register it in the config. | |
| 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_condense_ports (struct config_file *cfg, int **avail) |
| Get a condensed list of ports returned. | |
| int | cfg_scan_ports (int *avail, int num) |
| Scan ports available. | |
| char * | fname_after_chroot (const char *fname, struct config_file *cfg, int use_chdir) |
| Convert a filename to full pathname in original filesys. | |
| char * | cfg_ptr_reverse (char *str) |
| Convert a ptr shorthand into a full reverse-notation PTR record. | |
| void | errinf (struct module_qstate *qstate, const char *str) |
| Append text to the error info for validation. | |
| void | errinf_origin (struct module_qstate *qstate, struct sock_list *origin) |
| Append text to error info: from 1.2.3.4. | |
| void | errinf_rrset (struct module_qstate *qstate, struct ub_packed_rrset_key *rr) |
| Append text to error info: for RRset name type class. | |
| void | errinf_dname (struct module_qstate *qstate, const char *str, uint8_t *dname) |
| Append text to error info: str dname. | |
| char * | errinf_to_str (struct module_qstate *qstate) |
| Create error info in string. | |
| void | ub_c_error (const char *msg) |
| parsing helpers: print error with file and line numbers | |
| void | ub_c_error_msg (const char *fmt,...) ATTR_FORMAT(printf |
| parsing helpers: print error with file and line numbers | |
Variables | |
| struct config_parser_state * | cfg_parser |
| global config parser object used during config parsing | |
This file contains functions for the config file.
| struct config_file* config_create | ( | void | ) | [read] |
Create config file structure.
Filled with default values.
References config_file::verbosity, config_file::stat_interval, config_file::stat_cumulative, config_file::stat_extended, config_file::num_threads, config_file::port, config_file::do_ip4, config_file::do_ip6, config_file::do_udp, config_file::do_tcp, config_file::tcp_upstream, config_file::ssl_service_key, config_file::ssl_service_pem, config_file::ssl_port, config_file::ssl_upstream, config_file::use_syslog, config_file::log_time_ascii, config_file::log_queries, config_file::outgoing_num_ports, config_file::num_queries_per_thread, config_file::outgoing_num_tcp, config_file::incoming_num_tcp, config_file::edns_buffer_size, config_file::msg_buffer_size, config_file::msg_cache_size, config_file::msg_cache_slabs, config_file::jostle_time, config_file::rrset_cache_size, config_file::rrset_cache_slabs, config_file::host_ttl, config_file::bogus_ttl, config_file::min_ttl, config_file::max_ttl, config_file::prefetch, config_file::prefetch_key, config_file::infra_cache_slabs, config_file::infra_cache_numhosts, config_file::outgoing_avail_ports, error_exit(), init_outgoing_availports(), config_file::username, config_file::chrootdir, config_file::directory, config_file::logfile, config_file::pidfile, config_file::target_fetch_policy, config_file::donotqueryaddrs, config_file::donotquery_localhost, config_file::root_hints, config_file::do_daemonize, config_file::if_automatic, config_file::so_rcvbuf, config_file::so_sndbuf, config_file::num_ifs, config_file::ifs, config_file::num_out_ifs, config_file::out_ifs, config_file::stubs, config_file::forwards, config_file::acls, config_file::harden_short_bufsize, config_file::harden_large_queries, config_file::harden_glue, config_file::harden_dnssec_stripped, config_file::harden_below_nxdomain, config_file::harden_referral_path, config_file::use_caps_bits_for_id, config_file::private_address, config_file::private_domain, config_file::unwanted_threshold, config_file::hide_identity, config_file::hide_version, config_file::identity, config_file::version, config_file::auto_trust_anchor_file_list, config_file::trust_anchor_file_list, config_file::trust_anchor_list, config_file::trusted_keys_file_list, config_file::dlv_anchor_file, config_file::dlv_anchor_list, config_file::domain_insecure, config_file::val_date_override, config_file::val_sig_skew_min, config_file::val_sig_skew_max, config_file::val_clean_additional, config_file::val_log_level, config_file::val_log_squelch, config_file::val_permissive_mode, config_file::ignore_cd, config_file::add_holddown, config_file::del_holddown, config_file::keep_missing, config_file::key_cache_size, config_file::key_cache_slabs, config_file::neg_cache_size, config_file::local_zones, config_file::local_zones_nodefault, config_file::local_data, config_file::python_script, config_file::remote_control_enable, config_file::control_ifs, config_file::control_port, config_file::server_key_file, config_file::server_cert_file, config_file::control_key_file, config_file::control_cert_file, config_file::module_conf, config_file::val_nsec3_key_iterations, and config_delete().
Referenced by run_daemon(), checkconf(), go(), infra_test(), config_create_forlib(), and service_init().
| struct config_file* config_create_forlib | ( | void | ) | [read] |
Create config file structure for library use.
Filled with default values.
References config_create(), config_file::chrootdir, config_file::verbosity, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, config_file::msg_cache_size, config_file::msg_cache_slabs, config_file::rrset_cache_size, config_file::rrset_cache_slabs, config_file::infra_cache_slabs, config_file::use_syslog, config_file::key_cache_size, config_file::key_cache_slabs, config_file::neg_cache_size, config_file::donotquery_localhost, config_file::val_log_level, and config_file::val_log_squelch.
Referenced by ub_ctx_create().
| int config_read | ( | struct config_file * | config, |
| const char * | filename, | ||
| const char * | chroot | ||
| ) |
Read the config file from the specified filename.
| config,: | where options are stored into, must be freshly created. |
| filename,: | name of configfile. If NULL nothing is done. |
| chroot,: | if not NULL, the chroot dir currently in use (for include). |
References log_err(), create_cfg_parser(), ub_c_in, ub_c_parse(), config_parser_state::errors, and config_parser_state::filename.
Referenced by run_daemon(), ub_ctx_config(), checkconf(), go(), and service_init().
| void config_delete | ( | struct config_file * | config | ) |
Destroy the config file structure.
| config,: | to delete. |
References config_file::username, config_file::chrootdir, config_file::directory, config_file::logfile, config_file::pidfile, config_file::target_fetch_policy, config_file::ssl_service_key, config_file::ssl_service_pem, config_file::ifs, config_file::num_ifs, config_file::out_ifs, config_file::num_out_ifs, config_delstubs(), config_file::stubs, config_file::forwards, config_delstrlist(), config_file::donotqueryaddrs, config_file::root_hints, config_file::identity, config_file::version, config_file::module_conf, config_file::outgoing_avail_ports, config_file::private_address, config_file::private_domain, config_file::auto_trust_anchor_file_list, config_file::trust_anchor_file_list, config_file::trusted_keys_file_list, config_file::trust_anchor_list, config_file::domain_insecure, config_file::dlv_anchor_file, config_file::dlv_anchor_list, config_deldblstrlist(), config_file::acls, config_file::val_nsec3_key_iterations, config_file::local_zones, config_file::local_zones_nodefault, config_file::local_data, config_file::control_ifs, config_file::server_key_file, config_file::server_cert_file, config_file::control_key_file, and config_file::control_cert_file.
Referenced by run_daemon(), ub_ctx_delete(), checkconf(), go(), infra_test(), config_create(), service_init(), service_deinit(), and service_main().
| void config_apply | ( | struct config_file * | config | ) |
Apply config to global constants; this routine is called in single thread.
| config,: | to apply. Side effect: global constants change. |
References MAX_TTL, config_file::max_ttl, MIN_TTL, config_file::min_ttl, EDNS_ADVERTISED_SIZE, config_file::edns_buffer_size, log_set_time_asc(), and config_file::log_time_ascii.
Referenced by daemon_apply_cfg(), and context_finalize().
| int config_set_option | ( | struct config_file * | config, |
| const char * | option, | ||
| const char * | value | ||
| ) |
Set the given keyword to the given value.
| config,: | where to store config |
| option,: | option name, including the ':' character. |
| value,: | value, this string is copied if needed, or parsed. The caller owns the value string. |
References S_NUMBER_OR_ZERO, verbosity, config_file::stat_interval, cfg_mark_ports(), config_file::outgoing_avail_ports, cfg_parse_local_zone(), config_file::val_date_override, cfg_convert_timeval(), cfg_ptr_reverse(), cfg_strlist_insert(), config_file::local_data, config_file::use_syslog, config_file::logfile, S_YNO, config_file::stat_extended, config_file::stat_cumulative, config_file::do_ip4, config_file::do_ip6, config_file::do_udp, config_file::do_tcp, config_file::tcp_upstream, config_file::ssl_upstream, S_STR, config_file::ssl_service_key, config_file::ssl_service_pem, S_NUMBER_NONZERO, config_file::ssl_port, config_file::if_automatic, config_file::do_daemonize, config_file::port, config_file::outgoing_num_ports, S_SIZET_OR_ZERO, config_file::outgoing_num_tcp, config_file::incoming_num_tcp, S_SIZET_NONZERO, config_file::edns_buffer_size, config_file::msg_buffer_size, S_MEMSIZE, config_file::msg_cache_size, S_POW2, config_file::msg_cache_slabs, config_file::num_queries_per_thread, config_file::jostle_time, config_file::so_rcvbuf, config_file::so_sndbuf, config_file::rrset_cache_size, config_file::rrset_cache_slabs, config_file::prefetch, config_file::prefetch_key, config_file::max_ttl, config_file::host_ttl, config_file::infra_cache_slabs, config_file::infra_cache_numhosts, config_file::chrootdir, config_file::username, config_file::directory, config_file::pidfile, config_file::hide_identity, config_file::hide_version, config_file::identity, config_file::version, S_STRLIST, config_file::root_hints, config_file::target_fetch_policy, config_file::harden_glue, config_file::harden_short_bufsize, config_file::harden_large_queries, config_file::harden_dnssec_stripped, config_file::harden_below_nxdomain, config_file::harden_referral_path, config_file::use_caps_bits_for_id, config_file::unwanted_threshold, config_file::private_address, config_file::private_domain, config_file::donotquery_localhost, config_file::donotqueryaddrs, config_file::auto_trust_anchor_file_list, config_file::trust_anchor_file_list, config_file::trust_anchor_list, config_file::trusted_keys_file_list, config_file::dlv_anchor_file, config_file::dlv_anchor_list, config_file::domain_insecure, config_file::bogus_ttl, config_file::val_clean_additional, config_file::val_log_level, config_file::val_log_squelch, config_file::log_queries, config_file::val_permissive_mode, config_file::ignore_cd, config_file::val_nsec3_key_iterations, S_UNSIGNED_OR_ZERO, config_file::add_holddown, config_file::del_holddown, config_file::keep_missing, config_file::key_cache_size, config_file::key_cache_slabs, config_file::neg_cache_size, config_file::remote_control_enable, config_file::control_ifs, config_file::control_port, config_file::server_key_file, config_file::server_cert_file, config_file::control_key_file, config_file::control_cert_file, config_file::module_conf, config_file::python_script, config_file::num_out_ifs, and config_file::out_ifs.
Referenced by do_set_option(), and ub_ctx_set_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.
| cfg,: | config. |
| opt,: | option name without trailing :. This is different from config_set_option. |
| func,: | print func, called as (str, arg) for every data element. |
| arg,: | user argument for print func. |
References fptr_ok, fptr_whitelist_print_func(), O_DEC, verbosity, O_YNO, O_IFC, O_MEM, O_UNS, O_STR, logfile, O_LST, and O_LS2.
Referenced by do_get_option(), print_option(), and 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.
| cfg,: | config file |
| opt,: | option name. |
| list,: | list is returned here. malloced, caller must free it. |
References config_get_option(), config_collate_func(), config_collate_arg::status, config_delstrlist(), config_collate_arg::list, and config_strlist_head::first.
Referenced by 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.
| cfg,: | config file |
| opt,: | option name. |
| str,: | string. malloced, caller must free it. |
References config_get_option_list(), config_collate_cat(), and config_delstrlist().
Referenced by ub_ctx_get_option().
| void config_print_func | ( | char * | line, |
| void * | arg | ||
| ) |
function to print to a file, use as func with config_get_option.
| line,: | text to print. appended. |
| arg,: | pass a FILE*, like stdout. |
Referenced by print_option(), and fptr_whitelist_print_func().
| void config_collate_func | ( | char * | line, |
| void * | arg | ||
| ) |
function to collate the text strings into a strlist_head.
| line,: | text to append. |
| arg,: | pass a strlist_head structure. zeroed on start. |
References config_collate_arg::status, cfg_strlist_append(), and config_collate_arg::list.
Referenced by config_get_option_list(), and fptr_whitelist_print_func().
| char* config_collate_cat | ( | struct config_strlist * | list | ) |
take a strlist_head list and return a malloc string.
separated with newline.
| list,: | strlist first to collate. zeroes return "". |
References config_strlist::next, and config_strlist::str.
Referenced by config_get_option_collate().
| int cfg_strlist_append | ( | struct config_strlist_head * | list, |
| char * | item | ||
| ) |
Append text at end of list.
| list,: | list head. zeroed at start. |
| item,: | new item. malloced by caller. if NULL the insertion fails. |
References config_strlist::str, config_strlist::next, config_strlist_head::last, and config_strlist_head::first.
Referenced by config_collate_func().
| int cfg_strlist_insert | ( | struct config_strlist ** | head, |
| char * | item | ||
| ) |
Insert string into strlist.
| head,: | pointer to strlist head variable. |
| item,: | new item. malloced by caller. If NULL the insertion fails. |
References config_strlist::str, and config_strlist::next.
Referenced by ub_ctx_add_ta(), ub_ctx_add_ta_file(), ub_ctx_trustedkeys(), ub_ctx_set_fwd(), ub_ctx_hosts(), read_file_content(), spool_auto_file(), setup_config(), config_set_option(), and cfg_parse_local_zone().
| int cfg_str2list_insert | ( | struct config_str2list ** | head, |
| char * | item, | ||
| char * | i2 | ||
| ) |
Insert string into str2list.
| head,: | pointer to str2list head variable. |
| item,: | new item. malloced by caller. If NULL the insertion fails. |
| i2,: | 2nd string, malloced by caller. If NULL the insertion fails. |
References config_str2list::str, config_str2list::str2, and config_str2list::next.
Referenced by cfg_parse_local_zone().
| void config_delstrlist | ( | struct config_strlist * | list | ) |
Delete items in config string list.
| list,: | list. |
References config_strlist::next, and config_strlist::str.
Referenced by lz_freeup_cfg(), replay_moment_delete(), remove_configfile(), config_get_option_list(), config_get_option_collate(), config_delstubs(), and config_delete().
| void config_deldblstrlist | ( | struct config_str2list * | list | ) |
Delete items in config double string list.
| list,: | list. |
References config_str2list::next, config_str2list::str, and config_str2list::str2.
Referenced by lz_freeup_cfg(), and config_delete().
| void config_delstubs | ( | struct config_stub * | list | ) |
Delete items in config stub list.
| list,: | list. |
References config_stub::next, config_stub::name, config_delstrlist(), config_stub::hosts, and config_stub::addrs.
Referenced by ub_ctx_set_fwd(), and config_delete().
| uint32_t cfg_convert_timeval | ( | const char * | str | ) |
Convert 14digit to time value.
| str,: | string of 14 digits |
Referenced by parse_cmdline(), verifytest_file(), and config_set_option().
| int cfg_count_numbers | ( | const char * | str | ) |
Count number of values in the string.
format ::= (sp num)+ sp num ::= [-](0-9)+ sp ::= (space|tab)*
| str,: | string |
Referenced by read_fetch_policy(), and val_apply_cfg().
| 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.
| str,: | string |
| res,: | result is stored here, size in bytes. |
References log_err(), and isalldigit().
Referenced by main(), and config_memsize_test().
| 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.
| cfg,: | to put it in. |
| val,: | argument strings to local-zone, "example.com nodefault". |
References log_err(), next_space_pos(), last_space_pos(), cfg_strlist_insert(), config_file::local_zones_nodefault, cfg_str2list_insert(), and config_file::local_zones.
Referenced by config_set_option().
| 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.
| str,: | string in input |
| allow,: | give true if this range is permitted. |
| avail,: | the array from cfg. |
| num,: | size of the array (65536). |
References log_err().
Referenced by config_set_option().
| int cfg_condense_ports | ( | struct config_file * | cfg, |
| int ** | avail | ||
| ) |
Get a condensed list of ports returned.
allocated.
| cfg,: | config file. |
| avail,: | the available ports array is returned here. |
References cfg_scan_ports(), config_file::outgoing_avail_ports, and log_assert.
Referenced by libworker_setup().
| int cfg_scan_ports | ( | int * | avail, |
| int | num | ||
| ) |
Scan ports available.
| avail,: | the array from cfg. |
| num,: | size of the array (65536). |
Referenced by cfg_condense_ports().
| char* fname_after_chroot | ( | const char * | fname, |
| struct config_file * | cfg, | ||
| int | use_chdir | ||
| ) |
Convert a filename to full pathname in original filesys.
| fname,: | the path name to convert. Must not be null or empty. |
| cfg,: | config struct for chroot and chdir (if set). |
| use_chdir,: | if false, only chroot is applied. |
References strlen_after_chroot(), config_file::chrootdir, and config_file::directory.
Referenced by daemon_remote_create(), perform_setup(), check_chroot_string(), check_chroot_filelist_wild(), morechecks(), and setup_ctx().
| char* cfg_ptr_reverse | ( | char * | str | ) |
Convert a ptr shorthand into a full reverse-notation PTR record.
| str,: | input string, "IP name" |
References log_err(), next_space_pos(), last_space_pos(), ipstrtoaddr(), and addr_is_ip6().
Referenced by config_set_option().
| void errinf | ( | struct module_qstate * | qstate, |
| const char * | str | ||
| ) |
Append text to the error info for validation.
| qstate,: | query state. |
| str,: | copied into query region and appended. Failures to allocate are logged. |
References module_qstate::env, module_env::cfg, config_file::val_log_level, regional_alloc(), module_qstate::region, log_err(), config_strlist::next, config_strlist::str, regional_strdup(), and module_qstate::errinf.
Referenced by errinf_origin(), errinf_rrset(), errinf_dname(), validate_msg_signatures(), processInit(), processFindKey(), processValidate(), primeResponseToKE(), ds_response_to_ke(), and process_dnskey_response().
| void errinf_origin | ( | struct module_qstate * | qstate, |
| struct sock_list * | origin | ||
| ) |
Append text to error info: from 1.2.3.4.
| qstate,: | query state. |
| origin,: | sock list with origin of trouble. Every element added. If NULL: nothing is added. if 0len element: 'from cache' is added. |
References module_qstate::env, module_env::cfg, config_file::val_log_level, sock_list::next, sock_list::len, addr_to_str(), sock_list::addr, and errinf().
Referenced by validate_msg_signatures(), processFindKey(), processValidate(), process_ds_response(), process_dnskey_response(), and process_prime_response().
| void errinf_rrset | ( | struct module_qstate * | qstate, |
| struct ub_packed_rrset_key * | rr | ||
| ) |
Append text to error info: for RRset name type class.
| qstate,: | query state. |
| rr,: | rrset_key. |
References module_qstate::env, module_env::cfg, config_file::val_log_level, ub_packed_rrset_key::rk, packed_rrset_key::type, packed_rrset_key::rrset_class, log_err(), dname_str(), packed_rrset_key::dname, and errinf().
Referenced by validate_msg_signatures().
| void errinf_dname | ( | struct module_qstate * | qstate, |
| const char * | str, | ||
| uint8_t * | dname | ||
| ) |
Append text to error info: str dname.
| qstate,: | query state. |
| str,: | explanation string |
| dname,: | the dname. |
References module_qstate::env, module_env::cfg, config_file::val_log_level, dname_str(), and errinf().
Referenced by processInit(), process_ds_response(), process_dnskey_response(), and process_prime_response().
| char* errinf_to_str | ( | struct module_qstate * | qstate | ) |
Create error info in string.
| qstate,: | query state. |
References module_qstate::qinfo, query_info::qtype, query_info::qclass, log_err(), dname_str(), query_info::qname, module_qstate::errinf, config_strlist::next, and config_strlist::str.
Referenced by mesh_do_callback(), key_cache_insert(), and processFinished().