unbound: util/module.c File Reference

unbound 0.1

Functions
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)
| Create error info in string.
sldns_ede_code | errinf_to_reason_bogus (struct module_qstate *qstate)
| Check the sldns_ede_code of the qstate.
char * | errinf_to_str_servfail (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_option * | edns_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

  s | the 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

  e | the 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()

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

Append text to the error info for validation.

Parameters

  qstate | query state.
  str | copied into query region and appended. Failures to allocate are logged.

Referenced by auth_zone_delegpt(), ds_response_to_ke(), errinf_dname(), errinf_origin(), errinf_reply(), errinf_rrset(), iter_operate(), prime_stub(), process_response(), processCollectClass(), processDSNSResponse(), processFinished(), processInit(), processInitRequest(), processInitRequest2(), processLastResort(), processPrimeResponse(), processQueryResponse(), processQueryTargets(), processValidate(), and validate_msg_signatures().

## ◆ errinf_origin()

void errinf_origin | ( | struct module_qstate * | qstate,
|  | struct sock_list * | origin
| ) |  |

Append text to error info: from 1.2.3.4.

Parameters

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

Create error info in string.

For validation failures.

Parameters

  qstate | query state.

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

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

Referenced by key_cache_insert(), mesh_do_callback(), mesh_send_reply(), 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.

Parameters

  qstate | query state.

Returns
  LDNS_EDE_DNSSEC_BOGUS by default, or the first explicitly set sldns_ede_code.

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

Referenced by key_cache_insert(), and mesh_send_reply().

## ◆ errinf_to_str_servfail()

char * errinf_to_str_servfail | ( | struct module_qstate * | qstate | ) |

Create error info in string.

For other servfails.

Parameters

  qstate | query state.

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

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

Referenced by mesh_query_done().

## ◆ errinf_rrset()

void errinf_rrset | ( | struct module_qstate * | qstate,
|  | struct ub_packed_rrset_key * | rr
| ) |  |

Append text to error info: for RRset name type class.

Parameters

  qstate | query state.
  rr | rrset_key.

References module_env::cfg, packed_rrset_key::dname, dname_str(), module_qstate::env, errinf(), LDNS_MAX_DOMAINLEN, config_file::log_servfail, ub_packed_rrset_key::rk, packed_rrset_key::rrset_class, sldns_wire2str_class_buf(), sldns_wire2str_type_buf(), packed_rrset_key::type, and config_file::val_log_level.

Referenced by validate_msg_signatures().

## ◆ errinf_dname()

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

Append text to error info: str dname.

Parameters

  qstate | query state.
  str | explanation string
  dname | the dname.

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

Referenced by process_dnskey_response(), process_ds_response(), process_prime_response(), processDSNSFind(), processInit(), processInitRequest(), processLastResort(), processPrimeResponse(), processQueryResponse(), and processQueryTargets().

## ◆ edns_known_options_init()

int edns_known_options_init | ( | struct module_env * | env | ) |

Initialize the edns known options by allocating the required space.

Parameters

  env | the 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

  env | the 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_code | the edns option code.
  bypass_cache_stage | whether the option interacts with the cache.
  no_aggregation | whether the option implies more specific aggregation.
  env | the 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

  cb | pointer to the callback function.
  type | inplace callback type.
  cbarg | argument for the callback function, or NULL.
  env | the module environment.
  id | module 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

  env | the module environment.
  type | inplace callback type.
  id | module 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_code | the edns option code.
  env | the 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

  list | the edns options.
  env | the 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

  list | the edns options.
  env | the 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

  level | the desired verbosity level.
  env | the 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().