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. More...
 
const char * strmodulevent (enum module_ev e)
 Debug utility: module event to string. More...
 
void errinf (struct module_qstate *qstate, const char *str)
 Append text to the error info for validation. More...
 
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. More...
 
char * errinf_to_str_bogus (struct module_qstate *qstate, struct regional *region)
 Create error info in string. More...
 
sldns_ede_code errinf_to_reason_bogus (struct module_qstate *qstate)
 Check the sldns_ede_code of the qstate->errinf. More...
 
char * errinf_to_str_servfail (struct module_qstate *qstate)
 Create error info in string. More...
 
char * errinf_to_str_misc (struct module_qstate *qstate)
 Create error info in string. More...
 
void errinf_rrset (struct module_qstate *qstate, struct ub_packed_rrset_key *rr)
 Append text to error info: for RRset name type class. More...
 
void errinf_dname (struct module_qstate *qstate, const char *str, uint8_t *dname)
 Append text to error info: str dname. More...
 
int edns_known_options_init (struct module_env *env)
 Initialize the edns known options by allocating the required space. More...
 
void edns_known_options_delete (struct module_env *env)
 Free the allocated space for the known edns options. More...
 
int edns_register_option (uint16_t opt_code, int bypass_cache_stage, int no_aggregation, struct module_env *env)
 Register a known edns option. More...
 
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. More...
 
void inplace_cb_delete (struct module_env *env, enum inplace_cb_list_type type, int id)
 Delete callback for specified type and module id. More...
 
struct edns_known_optionedns_option_is_known (uint16_t opt_code, struct module_env *env)
 Check if an edns option is known. More...
 
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. More...
 
int unique_mesh_state (struct edns_option *list, struct module_env *env)
 Check if an unique mesh state is required. More...
 
void log_edns_known_options (enum verbosity_value level, struct module_env *env)
 Log the known edns options. More...
 
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(), and val_operate().

◆ errinf()

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

Append text to the error info for validation.

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

Referenced by auth_zone_delegpt(), errinf_origin(), errinf_reply(), errinf_rrset(), iter_operate(), prime_stub(), process_response(), processCollectClass(), processFinished(), processInitRequest(), processInitRequest2(), processLastResort(), processQueryTargets(), and validate_suspend_setup_timer().

◆ 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_ds_response().

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

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

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

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

◆ errinf_rrset()

◆ errinf_dname()

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

Append text to error info: str dname.

Parameters
qstatequery state.
strexplanation string
dnamethe dname.

Referenced by process_ds_response(), processDSNSFind(), processInitRequest(), and processLastResort().

◆ 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 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 daemon_delete(), ub_ctx_create(), and ub_ctx_create_nopipe().

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

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

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

Referenced by context_finalize().