Functions
mesh.c File Reference

This file contains functions to assist in dealing with a mesh of query states. More...

#include "config.h"
#include "services/mesh.h"
#include "services/outbound_list.h"
#include "services/cache/dns.h"
#include "util/log.h"
#include "util/net_help.h"
#include "util/module.h"
#include "util/regional.h"
#include "util/data/msgencode.h"
#include "util/timehist.h"
#include "util/fptr_wlist.h"
#include "util/alloc.h"
#include "util/config_file.h"
#include "sldns/sbuffer.h"
#include "sldns/wire2str.h"
#include "services/localzone.h"
#include "util/data/dname.h"
#include "respip/respip.h"

Functions

static void timeval_subtract (struct timeval *d, const struct timeval *end, const struct timeval *start)
 subtract timers and the values do not overflow or become negative
 
static void timeval_add (struct timeval *d, const struct timeval *add)
 add timers and the values do not overflow or become negative
 
static void timeval_divide (struct timeval *avg, const struct timeval *sum, size_t d)
 divide sum of timers to get average
 
static int timeval_smaller (const struct timeval *x, const struct timeval *y)
 histogram compare of time values
 
static int client_info_compare (const struct respip_client_info *ci_a, const struct respip_client_info *ci_b)
 
int mesh_state_compare (const void *ap, const void *bp)
 compare two mesh_states
 
int mesh_state_ref_compare (const void *ap, const void *bp)
 compare two mesh references
 
struct mesh_areamesh_create (struct module_stack *stack, struct module_env *env)
 Allocate mesh, to empty. More...
 
static void mesh_delete_helper (rbnode_type *n)
 help mesh delete delete mesh states
 
void mesh_delete (struct mesh_area *mesh)
 Delete mesh, and all query states and replies in it. More...
 
void mesh_delete_all (struct mesh_area *mesh)
 Delete all mesh states from the mesh. More...
 
int mesh_make_new_space (struct mesh_area *mesh, sldns_buffer *qbuf)
 Make space for another recursion state for a reply in the mesh. More...
 
void mesh_new_client (struct mesh_area *mesh, struct query_info *qinfo, struct respip_client_info *cinfo, uint16_t qflags, struct edns_data *edns, struct comm_reply *rep, uint16_t qid)
 New query incoming from clients. More...
 
int mesh_new_callback (struct mesh_area *mesh, struct query_info *qinfo, uint16_t qflags, struct edns_data *edns, sldns_buffer *buf, uint16_t qid, mesh_cb_func_type cb, void *cb_arg)
 New query with callback. More...
 
void mesh_new_prefetch (struct mesh_area *mesh, struct query_info *qinfo, uint16_t qflags, time_t leeway)
 New prefetch message. More...
 
void mesh_report_reply (struct mesh_area *mesh, struct outbound_entry *e, struct comm_reply *reply, int what)
 Handle new event from the wire. More...
 
struct mesh_statemesh_state_create (struct module_env *env, struct query_info *qinfo, struct respip_client_info *cinfo, uint16_t qflags, int prime, int valrec)
 Create and initialize a new mesh state and its query state Does not put the mesh state into rbtrees and so on. More...
 
int mesh_state_is_unique (struct mesh_state *mstate)
 Check if the mesh state is unique. More...
 
void mesh_state_make_unique (struct mesh_state *mstate)
 Make a mesh state unique. More...
 
void mesh_state_cleanup (struct mesh_state *mstate)
 Cleanup a mesh state and its query state. More...
 
void mesh_state_delete (struct module_qstate *qstate)
 Delete mesh state, cleanup and also rbtrees and so on. More...
 
static int find_in_subsub (struct mesh_state *m, struct mesh_state *tofind, size_t *c)
 helper recursive rbtree find routine
 
static int mesh_detect_cycle_found (struct module_qstate *qstate, struct mesh_state *dep_m)
 find cycle for already looked up mesh_state
 
void mesh_detach_subs (struct module_qstate *qstate)
 Detach-subqueries. More...
 
int mesh_add_sub (struct module_qstate *qstate, struct query_info *qinfo, uint16_t qflags, int prime, int valrec, struct module_qstate **newq, struct mesh_state **sub)
 Add detached query. More...
 
int mesh_attach_sub (struct module_qstate *qstate, struct query_info *qinfo, uint16_t qflags, int prime, int valrec, struct module_qstate **newq)
 Attach subquery. More...
 
int mesh_state_attachment (struct mesh_state *super, struct mesh_state *sub)
 Setup attachment super/sub relation between super and sub mesh state. More...
 
static void mesh_do_callback (struct mesh_state *m, int rcode, struct reply_info *rep, struct mesh_cb *r)
 callback results to mesh cb entry More...
 
static void mesh_send_reply (struct mesh_state *m, int rcode, struct reply_info *rep, struct mesh_reply *r, struct mesh_reply *prev)
 Send reply to mesh reply entry. More...
 
void mesh_query_done (struct mesh_state *mstate)
 Query state is done, send messages to reply entries. More...
 
void mesh_walk_supers (struct mesh_area *mesh, struct mesh_state *mstate)
 Call inform_super for the super query states that are interested in the results from this query state. More...
 
struct mesh_statemesh_area_find (struct mesh_area *mesh, struct respip_client_info *cinfo, struct query_info *qinfo, uint16_t qflags, int prime, int valrec)
 Find a mesh state in the mesh area. More...
 
int mesh_state_add_cb (struct mesh_state *s, struct edns_data *edns, sldns_buffer *buf, mesh_cb_func_type cb, void *cb_arg, uint16_t qid, uint16_t qflags)
 Create new callback structure and attach it to a mesh state. More...
 
int mesh_state_add_reply (struct mesh_state *s, struct edns_data *edns, struct comm_reply *rep, uint16_t qid, uint16_t qflags, const struct query_info *qinfo)
 Create new reply structure and attach it to a mesh state. More...
 
static int mesh_continue (struct mesh_area *mesh, struct mesh_state *mstate, enum module_ext_state s, enum module_ev *ev)
 Continue processing the mesh state at another module. More...
 
void mesh_run (struct mesh_area *mesh, struct mesh_state *mstate, enum module_ev ev, struct outbound_entry *e)
 Run the mesh. More...
 
void mesh_log_list (struct mesh_area *mesh)
 Print all the states in the mesh to the log. More...
 
void mesh_stats (struct mesh_area *mesh, const char *str)
 Print some stats about the mesh to the log. More...
 
void mesh_stats_clear (struct mesh_area *mesh)
 Clear the stats that the mesh keeps (number of queries serviced) More...
 
size_t mesh_get_mem (struct mesh_area *mesh)
 Calculate memory size in use by mesh and all queries inside it. More...
 
int mesh_detect_cycle (struct module_qstate *qstate, struct query_info *qinfo, uint16_t flags, int prime, int valrec)
 Find cycle; see if the given mesh is in the targets sub, or sub-sub, ... More...
 
void mesh_list_insert (struct mesh_state *m, struct mesh_state **fp, struct mesh_state **lp)
 Insert mesh state into a double linked list. More...
 
void mesh_list_remove (struct mesh_state *m, struct mesh_state **fp, struct mesh_state **lp)
 Remove mesh state from a double linked list. More...
 

Detailed Description

This file contains functions to assist in dealing with a mesh of query states.

This mesh is supposed to be thread-specific. It consists of query states (per qname, qtype, qclass) and connections between query states and the super and subquery states, and replies to send back to clients.

Function Documentation

◆ mesh_create()

struct mesh_area* mesh_create ( struct module_stack stack,
struct module_env env 
)

◆ mesh_delete()

void mesh_delete ( struct mesh_area mesh)

Delete mesh, and all query states and replies in it.

Parameters
meshthe mesh to delete.

References mesh_area::all, rbtree_type::count, mesh_area::histogram, mesh_delete_helper(), mesh_area::qbuf_bak, rbtree_type::root, sldns_buffer_free(), and timehist_delete().

Referenced by libworker_delete_env(), and worker_delete().

◆ mesh_delete_all()

void mesh_delete_all ( struct mesh_area mesh)

◆ mesh_make_new_space()

int mesh_make_new_space ( struct mesh_area mesh,
struct sldns_buffer qbuf 
)

Make space for another recursion state for a reply in the mesh.

Parameters
meshmesh area
qbufquery buffer to save if recursion is invoked to make space. This buffer is necessary, because the following sequence in calls can result in an overwrite of the incoming query: delete_other_mesh_query - iter_clean - serviced_delete - waiting udp query is sent - on error callback - callback sends SERVFAIL reply over the same network channel, and shared UDP buffer is overwritten. You can pass NULL if there is no buffer that must be backed up.
Returns
false if no space is available.

References rbtree_type::count, mesh_area::env, mesh_area::jostle_first, mesh_area::jostle_max, log_nametypeclass(), mesh_area::max_reply_states, module_env::now_tv, mesh_area::num_reply_states, mesh_area::qbuf_bak, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qtype, mesh_state::reply_list, module_qstate::return_msg, module_qstate::return_rcode, mesh_state::s, sldns_buffer_copy(), mesh_reply::start_time, mesh_state::super_set, timeval_smaller(), timeval_subtract(), VERB_ALGO, and verbose().

Referenced by mesh_new_client(), and mesh_new_prefetch().

◆ mesh_new_client()

void mesh_new_client ( struct mesh_area mesh,
struct query_info qinfo,
struct respip_client_info cinfo,
uint16_t  qflags,
struct edns_data edns,
struct comm_reply rep,
uint16_t  qid 
)

New query incoming from clients.

Create new query state if needed, and add mesh_reply to it. Returns error to client on malloc failures. Will run the mesh area queries to process if a new query state is created.

Parameters
meshthe mesh.
qinfoquery from client.
cinfoadditional information associated with the query client. 'cinfo' itself is ephemeral but data pointed to by its members can be assumed to be valid and unchanged until the query processing is completed.
qflagsflags from client query.
ednsedns data from client query.
repwhere to reply to.
qidquery id to reply with.

References BIT_CD, BIT_RD, comm_point::buffer, comm_reply::c, comm_point_drop_reply(), mesh_area::env, inplace_cb_reply_servfail_call(), log_err(), mesh_area::max_reply_states, mesh_area_find(), mesh_make_new_space(), mesh_state_create(), mesh_area::num_reply_addrs, edns_data::opt_list, mesh_state::s, mesh_area::stats_dropped, mesh_state::unique, unique_mesh_state(), VERB_ALGO, and verbose().

◆ mesh_new_callback()

int mesh_new_callback ( struct mesh_area mesh,
struct query_info qinfo,
uint16_t  qflags,
struct edns_data edns,
struct sldns_buffer buf,
uint16_t  qid,
mesh_cb_func_type  cb,
void *  cb_arg 
)

New query with callback.

Create new query state if needed, and add mesh_cb to it. Will run the mesh area queries to process if a new query state is created.

Parameters
meshthe mesh.
qinfoquery from client.
qflagsflags from client query.
ednsedns data from client query.
bufbuffer for reply contents.
qidquery id to reply with.
cbcallback function.
cb_argcallback user arg.
Returns
0 on error.

References mesh_area::all, BIT_CD, BIT_RD, mesh_state::cb_list, rbtree_type::count, edns_opt_copy_region(), module_qstate::edns_opts_front_in, mesh_area::env, log_assert, mesh_area_find(), mesh_run(), mesh_state_add_cb(), mesh_state_create(), mesh_state_delete(), mesh_state_make_unique(), module_event_new, mesh_state::node, mesh_area::num_detached_states, mesh_area::num_reply_addrs, mesh_area::num_reply_states, edns_data::opt_list, rbtree_insert(), module_qstate::region, mesh_state::reply_list, mesh_state::s, mesh_state::super_set, mesh_state::unique, and unique_mesh_state().

Referenced by handle_newq().

◆ mesh_new_prefetch()

void mesh_new_prefetch ( struct mesh_area mesh,
struct query_info qinfo,
uint16_t  qflags,
time_t  leeway 
)

◆ mesh_report_reply()

void mesh_report_reply ( struct mesh_area mesh,
struct outbound_entry e,
struct comm_reply reply,
int  what 
)

Handle new event from the wire.

A serviced query has returned. The query state will be made runnable, and the mesh_area will process query states until processing is complete.

Parameters
meshthe query mesh.
eoutbound entry, with query state to run and reply pointer.
replythe comm point reply info.
whatNETEVENT_* error code (if not 0, what is wrong, TIMEOUT).

References module_qstate::mesh_info, mesh_run(), module_event_capsfail, module_event_noreply, module_event_reply, NETEVENT_CAPSFAIL, NETEVENT_NOERROR, outbound_entry::qstate, and module_qstate::reply.

Referenced by libworker_handle_reply(), libworker_handle_service_reply(), worker_handle_reply(), and worker_handle_service_reply().

◆ mesh_state_create()

struct mesh_state* mesh_state_create ( struct module_env env,
struct query_info qinfo,
struct respip_client_info cinfo,
uint16_t  qflags,
int  prime,
int  valrec 
)

Create and initialize a new mesh state and its query state Does not put the mesh state into rbtrees and so on.

Parameters
envmodule environment to set.
qinfoquery info that the mesh is for.
cinfocontrol info for the query client (can be NULL).
qflagsflags for query (RD / CD flag).
primeif true, it is a priming query, set is_priming on mesh state.
valrecif true, it is a validation recursion query, and sets is_valrec on the mesh state.
Returns
: new mesh state or NULL on allocation error.

References module_env::alloc, alloc_reg_obtain(), alloc_reg_release(), BIT_CD, BIT_RD, module_qstate::client_info, module_qstate::curmod, module_qstate::is_priming, module_qstate::is_valrec, rbnode_type::key, query_info::local_alias, mesh_state_ref_compare(), mesh_state::node, mesh_state::num_activated, query_info::qclass, module_qstate::qinfo, query_info::qname, query_info::qname_len, query_info::qtype, module_qstate::query_flags, rbtree_init(), RBTREE_NULL, module_qstate::region, regional_alloc(), regional_alloc_init(), mesh_state::replies_sent, module_qstate::reply, mesh_state::reply_list, module_qstate::return_msg, module_qstate::return_rcode, mesh_state::run_node, mesh_state::s, mesh_state::sub_set, mesh_state::super_set, and mesh_state::unique.

Referenced by mesh_add_sub(), mesh_new_callback(), mesh_new_client(), and mesh_new_prefetch().

◆ mesh_state_is_unique()

int mesh_state_is_unique ( struct mesh_state mstate)

Check if the mesh state is unique.

A unique mesh state uses it's unique member to point to itself, else NULL.

Parameters
mstatemesh state to check.
Returns
true if the mesh state is unique, false otherwise.

References mesh_state::unique.

Referenced by mesh_detect_cycle().

◆ mesh_state_make_unique()

void mesh_state_make_unique ( struct mesh_state mstate)

Make a mesh state unique.

A unique mesh state uses it's unique member to point to itself.

Parameters
mstatemesh state to check.

References mesh_state::unique.

Referenced by mesh_new_callback().

◆ mesh_state_cleanup()

void mesh_state_cleanup ( struct mesh_state mstate)

Cleanup a mesh state and its query state.

Does not do rbtree or reference cleanup.

Parameters
mstatemesh state to cleanup. Its pointer may no longer be used afterwards. Cleanup rbtrees before calling this function.

References mesh_cb::cb, mesh_cb::cb_arg, mesh_state::cb_list, comm_point_drop_reply(), module_qstate::env, fptr_ok, fptr_whitelist_mesh_cb(), module_env::mesh, mesh_reply::next, mesh_cb::next, mesh_area::num_reply_addrs, mesh_reply::query_reply, mesh_state::replies_sent, mesh_state::reply_list, and mesh_state::s.

Referenced by mesh_state_delete().

◆ mesh_state_delete()

void mesh_state_delete ( struct module_qstate qstate)

◆ mesh_detach_subs()

void mesh_detach_subs ( struct module_qstate qstate)

◆ mesh_add_sub()

int mesh_add_sub ( struct module_qstate qstate,
struct query_info qinfo,
uint16_t  qflags,
int  prime,
int  valrec,
struct module_qstate **  newq,
struct mesh_state **  sub 
)

Add detached query.

Creates it if it does not exist already. Does not make super/sub references. Performs a cycle detection - for double check - and fails if there is one. Updates stat items in mesh_area structure. Pass if it is priming query or not. return: o if error (malloc) happened. o need to initialise the new state (module init; it is a new state). so that the next run of the query with this module is successful. o no init needed, attachment successful. o added subquery, created if it did not exist already.

Parameters
qstatethe state to find mesh state, and that wants to receive the results from the new subquery.
qinfowhat to query for (copied).
qflagswhat flags to use (RD / CD flag or not).
primeif it is a (stub) priming query.
valrecif it is a validation recursion query (lookup of key, DS).
newqIf the new subquery needs initialisation, it is returned, otherwise NULL is returned.
subThe added mesh state, created if it did not exist already.
Returns
: false on error, true if success (and init may be needed).

References mesh_area::all, module_qstate::env, log_assert, log_err(), module_env::mesh, mesh_area_find(), mesh_detect_cycle_found(), mesh_state_create(), mesh_area::num_detached_states, rbtree_insert(), mesh_area::run, VERB_ALGO, and verbose().

Referenced by fptr_whitelist_modenv_add_sub(), and mesh_attach_sub().

◆ mesh_attach_sub()

int mesh_attach_sub ( struct module_qstate qstate,
struct query_info qinfo,
uint16_t  qflags,
int  prime,
int  valrec,
struct module_qstate **  newq 
)

Attach subquery.

Creates it if it does not exist already. Keeps sub and super references correct. Performs a cycle detection - for double check - and fails if there is one. Also fails if the sub-sub-references become too large. Updates stat items in mesh_area structure. Pass if it is priming query or not. return: o if error (malloc) happened. o need to initialise the new state (module init; it is a new state). so that the next run of the query with this module is successful. o no init needed, attachment successful.

Parameters
qstatethe state to find mesh state, and that wants to receive the results from the new subquery.
qinfowhat to query for (copied).
qflagswhat flags to use (RD / CD flag or not).
primeif it is a (stub) priming query.
valrecif it is a validation recursion query (lookup of key, DS).
newqIf the new subquery needs initialisation, it is returned, otherwise NULL is returned.
Returns
: false on error, true if success (and init may be needed).

References mesh_state::cb_list, rbtree_type::count, module_qstate::env, log_assert, module_env::mesh, mesh_add_sub(), module_qstate::mesh_info, mesh_state_attachment(), mesh_area::num_detached_states, mesh_state::reply_list, and mesh_state::super_set.

Referenced by fptr_whitelist_modenv_attach_sub().

◆ mesh_state_attachment()

int mesh_state_attachment ( struct mesh_state super,
struct mesh_state sub 
)

Setup attachment super/sub relation between super and sub mesh state.

The relation must not be present when calling the function. Does not update stat items in mesh_area.

Parameters
supersuper state.
subsub state.
Returns
: 0 on alloc error.

References rbnode_type::key, log_assert, log_err(), mesh_state_ref::node, rbtree_insert(), module_qstate::region, regional_alloc(), mesh_state::s, mesh_state_ref::s, mesh_state::sub_set, and mesh_state::super_set.

Referenced by mesh_attach_sub().

◆ mesh_do_callback()

static void mesh_do_callback ( struct mesh_state m,
int  rcode,
struct reply_info rep,
struct mesh_cb r 
)
static

callback results to mesh cb entry

Parameters
mmesh state to send it for.
rcodeif not 0, error code.
repreply to send (or NULL if rcode is set).
rcallback entry

References sec_status_secure, and reply_info::security.

Referenced by mesh_query_done().

◆ mesh_send_reply()

static void mesh_send_reply ( struct mesh_state m,
int  rcode,
struct reply_info rep,
struct mesh_reply r,
struct mesh_reply prev 
)
static

Send reply to mesh reply entry.

Parameters
mmesh state to send it for.
rcodeif not 0, error code.
repreply to send (or NULL if rcode is set).
rreply entry
prevprevious reply, already has its answer encoded in buffer.

References BIT_CD, module_env::cfg, mesh_reply::edns, module_qstate::env, config_file::ignore_cd, module_env::need_to_validate, mesh_reply::qflags, mesh_state::s, sec_status_bogus, and reply_info::security.

Referenced by mesh_query_done().

◆ mesh_query_done()

void mesh_query_done ( struct mesh_state mstate)

Query state is done, send messages to reply entries.

Encode messages using reply entry values and the querystate (with original qinfo), using given reply_info. Pass errcode != 0 if an error reply is needed. If no reply entries, nothing is done. Must be called before a module can module_finished or return module_error. The module must handle the super query states itself as well.

Parameters
mstatemesh state that is done. return_rcode and return_msg are used for replies. return_rcode: if not 0 (NOERROR) an error is sent back (and return_msg is ignored). return_msg: reply to encode and send back to clients.

References mesh_state::cb_list, comm_point_drop_reply(), module_qstate::is_drop, mesh_reply::local_alias, mesh_do_callback(), mesh_send_reply(), mesh_reply::next, mesh_cb::next, query_info::qclass, module_qstate::qinfo, mesh_reply::qname, query_info::qtype, mesh_reply::query_reply, dns_msg::rep, mesh_state::replies_sent, mesh_state::reply_list, module_qstate::respip_action_info, respip_inform_print(), module_qstate::return_msg, module_qstate::return_rcode, and mesh_state::s.

◆ mesh_walk_supers()

void mesh_walk_supers ( struct mesh_area mesh,
struct mesh_state mstate 
)

Call inform_super for the super query states that are interested in the results from this query state.

These can then be changed for error or results. Called when a module is module_finished or returns module_error. The super query states become runnable with event module_event_pass, it calls the current module for the super with the inform_super event.

Parameters
meshmesh area to add newly runnable modules to.
mstatethe state that has results, used to find mesh state.

References module_qstate::curmod, fptr_ok, fptr_whitelist_mod_inform_super(), module_func_block::inform_super, module_stack::mod, mesh_area::mods, RBTREE_FOR, rbtree_insert(), mesh_area::run, mesh_state::run_node, mesh_state::s, mesh_state_ref::s, and mesh_state::super_set.

◆ mesh_area_find()

struct mesh_state* mesh_area_find ( struct mesh_area mesh,
struct respip_client_info cinfo,
struct query_info qinfo,
uint16_t  qflags,
int  prime,
int  valrec 
)

Find a mesh state in the mesh area.

Pass relevant flags.

Parameters
meshthe mesh area to look in.
cinfoif non-NULL client specific info that may affect IP-based actions that apply to the query result.
qinfowhat query
qflagsif RD / CD bit is set or not.
primeif it is a priming query.
valrecif it is a validation-recursion query.
Returns
: mesh state or NULL if not found.

References mesh_area::all, module_qstate::client_info, module_qstate::is_priming, module_qstate::is_valrec, rbnode_type::key, mesh_state::node, module_qstate::qinfo, module_qstate::query_flags, rbtree_search(), mesh_state::s, and mesh_state::unique.

Referenced by mesh_add_sub(), mesh_detect_cycle(), mesh_new_callback(), mesh_new_client(), and mesh_new_prefetch().

◆ mesh_state_add_cb()

int mesh_state_add_cb ( struct mesh_state s,
struct edns_data edns,
struct sldns_buffer buf,
mesh_cb_func_type  cb,
void *  cb_arg,
uint16_t  qid,
uint16_t  qflags 
)

Create new callback structure and attach it to a mesh state.

Does not update stat items in mesh area.

Parameters
sthe mesh state.
ednsedns data for reply (bufsize).
bufbuffer for reply
cbcallback to call with results.
cb_argcallback user arg.
qidID of reply.
qflagsoriginal query flags.
Returns
: 0 on alloc error.

References mesh_cb::buf, mesh_cb::cb, mesh_cb::cb_arg, mesh_state::cb_list, mesh_cb::edns, edns_opt_copy_region(), fptr_whitelist_mesh_cb(), log_assert, mesh_cb::next, edns_data::opt_list, mesh_cb::qflags, mesh_cb::qid, module_qstate::region, regional_alloc(), and mesh_state::s.

Referenced by mesh_new_callback().

◆ mesh_state_add_reply()

int mesh_state_add_reply ( struct mesh_state s,
struct edns_data edns,
struct comm_reply rep,
uint16_t  qid,
uint16_t  qflags,
const struct query_info qinfo 
)

◆ mesh_continue()

static int mesh_continue ( struct mesh_area mesh,
struct mesh_state mstate,
enum module_ext_state  s,
enum module_ev ev 
)
static

Continue processing the mesh state at another module.

Handles module to modules tranfer of control. Handles module finished.

Parameters
meshthe mesh area.
mstatecurrently active mesh state. Deleted if finished, calls _done and _supers to send replies to clients and inform other mesh states. This in turn may create additional runnable mesh states.
sstate at which the current module exited.
evthe event sent to the module. returned is the event to send to the next module.
Returns
true if continue processing at the new module. false if not continued processing is needed.

References module_func_block::clear, rbtree_type::count, module_qstate::curmod, fptr_ok, fptr_whitelist_mod_clear(), log_err(), log_query_info(), MESH_MAX_ACTIVATION, module_qstate::minfo, module_stack::mod, mesh_area::mods, module_error, module_event_pass, module_restart_next, module_wait_module, module_wait_subquery, module_stack::num, mesh_state::num_activated, module_qstate::qinfo, module_qstate::return_rcode, mesh_state::s, mesh_state::sub_set, and VERB_QUERY.

Referenced by mesh_run().

◆ mesh_run()

void mesh_run ( struct mesh_area mesh,
struct mesh_state mstate,
enum module_ev  ev,
struct outbound_entry e 
)

Run the mesh.

Run all runnable mesh states. Which can create new runnable mesh states. Until completion. Automatically called by mesh_report_reply and mesh_new_client as needed.

Parameters
meshmesh area.
mstatefirst mesh state to run.
evevent the mstate. Others get event_pass.
eif a reply, its outbound entry.

References rbtree_type::count, module_qstate::curmod, module_qstate::env, module_qstate::ext_state, fptr_ok, fptr_whitelist_mod_operate(), rbnode_type::key, mesh_continue(), mesh_log_list(), mesh_stats(), module_stack::mod, mesh_area::mods, module_event_pass, module_func_block::name, module_func_block::operate, rbtree_delete(), regional_free_all(), module_qstate::reply, rbtree_type::root, mesh_area::run, mesh_state::s, module_env::scratch, strextstate(), VERB_ALGO, verbose(), and verbosity.

Referenced by mesh_new_callback(), mesh_new_prefetch(), and mesh_report_reply().

◆ mesh_log_list()

void mesh_log_list ( struct mesh_area mesh)

◆ mesh_stats()

void mesh_stats ( struct mesh_area mesh,
const char *  str 
)

◆ mesh_stats_clear()

void mesh_stats_clear ( struct mesh_area mesh)

◆ mesh_get_mem()

size_t mesh_get_mem ( struct mesh_area mesh)

Calculate memory size in use by mesh and all queries inside it.

Parameters
meshthe mesh to examine.
Returns
size in bytes.

References mesh_area::histogram, timehist::num, and mesh_state::s.

◆ mesh_detect_cycle()

int mesh_detect_cycle ( struct module_qstate qstate,
struct query_info qinfo,
uint16_t  flags,
int  prime,
int  valrec 
)

Find cycle; see if the given mesh is in the targets sub, or sub-sub, ...

trees. If the sub-sub structure is too large, it returns 'a cycle'=2.

Parameters
qstategiven mesh querystate.
qinfoquery info for dependency.
flagsquery flags of dependency.
primeif dependency is a priming query or not.
valrecif it is a validation recursion query (lookup of key, DS).
Returns
true if the name,type,class exists and the given qstate mesh exists as a dependency of that name. Thus if qstate becomes dependent on name,type,class then a cycle is created, this is return value 1. Too large to search is value 2 (also true).

References module_qstate::env, module_env::mesh, mesh_area_find(), mesh_detect_cycle_found(), module_qstate::mesh_info, and mesh_state_is_unique().

Referenced by fptr_whitelist_modenv_detect_cycle().

◆ mesh_list_insert()

void mesh_list_insert ( struct mesh_state m,
struct mesh_state **  fp,
struct mesh_state **  lp 
)

Insert mesh state into a double linked list.

Inserted at end.

Parameters
mmesh state.
fppointer to the first-elem-pointer of the list.
lppointer to the last-elem-pointer of the list.

References mesh_state::next, and mesh_state::prev.

Referenced by mesh_new_prefetch().

◆ mesh_list_remove()

void mesh_list_remove ( struct mesh_state m,
struct mesh_state **  fp,
struct mesh_state **  lp 
)

Remove mesh state from a double linked list.

Remove from any position.

Parameters
mmesh state.
fppointer to the first-elem-pointer of the list.
lppointer to the last-elem-pointer of the list.

References mesh_state::next, and mesh_state::prev.

Referenced by mesh_state_delete().