module.c File Reference

Implementation of module.h. More...

#include "config.h"
#include "util/module.h"
#include "sldns/wire2str.h"
#include "util/config_file.h"
#include "util/regional.h"
#include "util/data/dname.h"
#include "util/net_help.h"

Functions

const char * strextstate (enum module_ext_state s)
 Debug utility: module external qstate to string.
 
const char * strmodulevent (enum module_ev e)
 Debug utility: module event to string.
 
void errinf (struct module_qstate *qstate, const char *str)
 Append text to the error info for validation.
 
void errinf_ede (struct module_qstate *qstate, const char *str, sldns_ede_code reason_bogus)
 
void errinf_origin (struct module_qstate *qstate, struct sock_list *origin)
 Append text to error info: from 1.2.3.4.
 
char * errinf_to_str_bogus (struct module_qstate *qstate, struct regional *region)
 Create error info in string.
 
sldns_ede_code errinf_to_reason_bogus (struct module_qstate *qstate)
 Check the sldns_ede_code of the qstate->errinf.
 
char * errinf_to_str_servfail (struct module_qstate *qstate)
 Create error info in string.
 
char * errinf_to_str_misc (struct module_qstate *qstate)
 Create error info in string.
 
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.
 
int edns_known_options_init (struct module_env *env)
 Initialize the edns known options by allocating the required space.
 
void edns_known_options_delete (struct module_env *env)
 Free the allocated space for the known edns options.
 
int edns_register_option (uint16_t opt_code, int bypass_cache_stage, int no_aggregation, struct module_env *env)
 Register a known edns option.
 
int inplace_cb_register (void *cb, enum inplace_cb_list_type type, void *cbarg, struct module_env *env, int id)
 Register an inplace callback function.
 
void inplace_cb_delete (struct module_env *env, enum inplace_cb_list_type type, int id)
 Delete callback for specified type and module id.
 
struct edns_known_optionedns_option_is_known (uint16_t opt_code, struct module_env *env)
 Check if an edns option is known.
 
int edns_bypass_cache_stage (struct edns_option *list, struct module_env *env)
 Check if an edns option needs to bypass the reply from cache stage.
 
int unique_mesh_state (struct edns_option *list, struct module_env *env)
 Check if an unique mesh state is required.
 
void log_edns_known_options (enum verbosity_value level, struct module_env *env)
 Log the known edns options.
 
void copy_state_to_super (struct module_qstate *qstate, int ATTR_UNUSED(id), struct module_qstate *super)
 

Detailed Description

Implementation of module.h.

Function Documentation

◆ strextstate()

const char * strextstate ( enum module_ext_state  s)

Debug utility: module external qstate to string.

Parameters
sthe state value.
Returns
descriptive string.

References module_error, module_finished, module_restart_next, module_state_initial, module_wait_module, module_wait_reply, and module_wait_subquery.

Referenced by dns64_operate(), get_mesh_status(), ipset_operate(), iter_operate(), mesh_run(), and val_operate().

◆ strmodulevent()

const char * strmodulevent ( enum module_ev  e)

Debug utility: module event to string.

Parameters
ethe module event value.
Returns
descriptive string.

References module_event_capsfail, module_event_error, module_event_moddone, module_event_new, module_event_noreply, module_event_pass, and module_event_reply.

Referenced by dns64_operate(), ipset_operate(), iter_operate(), pymod::setTTL(), pymod_thread::setTTL(), and val_operate().

◆ errinf()

◆ errinf_origin()

void errinf_origin ( struct module_qstate qstate,
struct sock_list origin 
)

Append text to error info: from 1.2.3.4.

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

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

Referenced by process_dnskey_response(), process_ds_response(), process_prime_response(), processFindKey(), processValidate(), and validate_msg_signatures().

◆ errinf_to_str_bogus()

char * errinf_to_str_bogus ( struct module_qstate qstate,
struct regional region 
)

Create error info in string.

For validation failures.

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

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

Referenced by mesh_do_callback(), and processFinished().

◆ errinf_to_reason_bogus()

sldns_ede_code errinf_to_reason_bogus ( struct module_qstate qstate)

Check the sldns_ede_code of the qstate->errinf.

Parameters
qstatequery state.
Returns
the latest explicitly set sldns_ede_code or LDNS_EDE_NONE.

References module_qstate::errinf, errinf_strlist::next, and errinf_strlist::reason_bogus.

Referenced by processFinished().

◆ errinf_to_str_servfail()

char * errinf_to_str_servfail ( struct module_qstate qstate)

Create error info in string.

For other servfails.

Parameters
qstatequery state.
Returns
string or NULL on malloc failure (already logged).

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

Referenced by mesh_query_done().

◆ errinf_to_str_misc()

char * errinf_to_str_misc ( struct module_qstate qstate)

Create error info in string.

For misc failures that are not servfail.

Parameters
qstatequery state.
Returns
string or NULL on malloc failure (already logged).

References module_qstate::errinf, log_err(), errinf_strlist::next, module_qstate::region, regional_strdup(), and errinf_strlist::str.

Referenced by ds_response_to_ke(), primeResponseToKE(), process_dnskey_response(), and processFinished().

◆ errinf_rrset()

◆ errinf_dname()

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

◆ edns_known_options_init()

int edns_known_options_init ( struct module_env env)

Initialize the edns known options by allocating the required space.

Parameters
envthe module environment.
Returns
false on failure (no memory).

References module_env::edns_known_options, and MAX_KNOWN_EDNS_OPTS.

Referenced by check_mod(), daemon_init(), and ub_ctx_create_nopipe().

◆ edns_known_options_delete()

void edns_known_options_delete ( struct module_env env)

Free the allocated space for the known edns options.

Parameters
envthe module environment.

References module_env::edns_known_options.

Referenced by check_mod(), daemon_delete(), daemon_init(), ub_ctx_create(), ub_ctx_create_nopipe(), and ub_ctx_delete().

◆ edns_register_option()

int edns_register_option ( uint16_t  opt_code,
int  bypass_cache_stage,
int  no_aggregation,
struct module_env env 
)

Register a known edns option.

Overwrite the flags if it is already registered. Used before creating workers to register known edns options.

Parameters
opt_codethe edns option code.
bypass_cache_stagewhether the option interacts with the cache.
no_aggregationwhether the option implies more specific aggregation.
envthe module environment.
Returns
true on success, false on failure (registering more options than allowed or trying to register after the environment is copied to the threads.)

Checking if we are full first is faster but it does not provide the option to change the flags when the array is full. It only impacts unbound initialization, leave it for now.

References edns_known_option::bypass_cache_stage, module_env::edns_known_options, log_err(), MAX_KNOWN_EDNS_OPTS, edns_known_option::no_aggregation, edns_known_option::opt_code, and module_env::worker.

◆ inplace_cb_register()

int inplace_cb_register ( void *  cb,
enum inplace_cb_list_type  type,
void *  cbarg,
struct module_env env,
int  id 
)

Register an inplace callback function.

Parameters
cbpointer to the callback function.
typeinplace callback type.
cbargargument for the callback function, or NULL.
envthe module environment.
idmodule id.
Returns
true on success, false on failure (out of memory or trying to register after the environment is copied to the threads.)

References inplace_cb::cb, inplace_cb::id, log_err(), and module_env::worker.

◆ inplace_cb_delete()

void inplace_cb_delete ( struct module_env env,
enum inplace_cb_list_type  type,
int  id 
)

Delete callback for specified type and module id.

Parameters
envthe module environment.
typeinplace callback type.
idmodule id.

References inplace_cb::id, and inplace_cb::next.

Referenced by pythonmod_deinit().

◆ edns_option_is_known()

struct edns_known_option * edns_option_is_known ( uint16_t  opt_code,
struct module_env env 
)

Check if an edns option is known.

Parameters
opt_codethe edns option code.
envthe module environment.
Returns
pointer to registered option if the edns option is known, NULL otherwise.

References module_env::edns_known_options, and edns_known_option::opt_code.

◆ edns_bypass_cache_stage()

int edns_bypass_cache_stage ( struct edns_option list,
struct module_env env 
)

Check if an edns option needs to bypass the reply from cache stage.

Parameters
listthe edns options.
envthe module environment.
Returns
true if an edns option needs to bypass the cache stage, false otherwise.

References edns_known_option::bypass_cache_stage, module_env::edns_known_options, edns_option::next, edns_option::opt_code, and edns_known_option::opt_code.

Referenced by worker_handle_request().

◆ unique_mesh_state()

int unique_mesh_state ( struct edns_option list,
struct module_env env 
)

Check if an unique mesh state is required.

Might be triggered by EDNS option or set for the complete env.

Parameters
listthe edns options.
envthe module environment.
Returns
true if an edns option needs a unique mesh state, false otherwise.

References module_env::edns_known_options, edns_option::next, edns_known_option::no_aggregation, edns_option::opt_code, and edns_known_option::opt_code.

Referenced by mesh_new_callback(), and mesh_new_client().

◆ log_edns_known_options()

void log_edns_known_options ( enum verbosity_value  level,
struct module_env env 
)

Log the known edns options.

Parameters
levelthe desired verbosity level.
envthe module environment.

References edns_known_option::bypass_cache_stage, module_env::edns_known_options, edns_known_option::no_aggregation, edns_known_option::opt_code, sldns_wire2str_edns_option_code_print(), verbose(), and verbosity.

Referenced by context_finalize(), and daemon_setup_modules().