libworker.h File Reference

This file contains the worker process or thread that performs the DNS resolving and validation. More...

Data Structures

struct  libworker
 The library-worker status structure Internal to the worker. More...
 

Functions

int libworker_bg (struct ub_ctx *ctx)
 Create a background worker. More...
 
int libworker_fg (struct ub_ctx *ctx, struct ctx_query *q)
 Create a foreground worker. More...
 
struct libworkerlibworker_create_event (struct ub_ctx *ctx, struct ub_event_base *eb)
 create worker for event-based interface. More...
 
int libworker_attach_mesh (struct ub_ctx *ctx, struct ctx_query *q, int *async_id)
 Attach context_query to mesh for callback in event-driven setup. More...
 
void libworker_delete_event (struct libworker *w)
 delete worker for event-based interface. More...
 
void libworker_alloc_cleanup (void *arg)
 cleanup the cache to remove all rrset IDs from it, arg is libworker
 
void libworker_enter_result (struct ub_result *res, struct sldns_buffer *buf, struct regional *temp, enum sec_status msg_security)
 fill result from parsed message, on error fills servfail More...
 

Detailed Description

This file contains the worker process or thread that performs the DNS resolving and validation.

The worker is called by a procedure and if in the background continues until exit, if in the foreground returns from the procedure when done.

Function Documentation

◆ libworker_bg()

int libworker_bg ( struct ub_ctx ctx)

Create a background worker.

Parameters
ctxis updated with pid/tid of the background worker. a new allocation cache is obtained from ctx. It contains the threadnumber and unique id for further (shared) cache insertions.
Returns
0 if OK, else error. Further communication is done via the pipes in ctx.

References ub_ctx::bg_pid, ub_ctx::bg_tid, ub_ctx::cfglock, libworker::ctx, ub_ctx::dothread, libworker::is_bg_thread, libworker_dobg(), libworker_setup(), libworker::thread_num, ub_ctx::thread_worker, UB_FORKFAIL, and UB_NOMEM.

Referenced by ub_resolve_async().

◆ libworker_fg()

int libworker_fg ( struct ub_ctx ctx,
struct ctx_query q 
)

Create a foreground worker.

This worker will join the threadpool of resolver threads. It exits when the query answer has been obtained (or error). This routine blocks until the worker is finished.

Parameters
ctxnew allocation cache obtained and returned to it.
qquery (result is stored in here).
Returns
0 if finished OK, else error.

References libworker::back, BIT_RD, libworker::ctx, libworker::env, libworker_delete(), libworker_fillup_fg(), libworker_setup(), ub_ctx::local_zones, local_zones_answer(), regional_free_all(), module_env::scratch, setup_qinfo_edns(), sldns_buffer_write_u16_at(), UB_INITFAIL, UB_SYNTAX, outside_network::udp_buff, and ctx_query::w.

Referenced by ub_resolve().

◆ libworker_create_event()

struct libworker* libworker_create_event ( struct ub_ctx ctx,
struct ub_event_base eb 
)

create worker for event-based interface.

Parameters
ctxcontext with config.
ebevent base.
Returns
new worker or NULL.

References libworker::ctx, and libworker_setup().

◆ libworker_attach_mesh()

int libworker_attach_mesh ( struct ub_ctx ctx,
struct ctx_query q,
int *  async_id 
)

Attach context_query to mesh for callback in event-driven setup.

Parameters
ctxcontext
qcontext query entry
async_idstore query num if query takes long.
Returns
0 if finished OK, else error.

References libworker::back, BIT_RD, libworker::ctx, libworker::env, ub_ctx::event_worker, libworker_event_done_cb(), ub_ctx::local_zones, local_zones_answer(), query_info::qname, regional_free_all(), module_env::scratch, setup_qinfo_edns(), sldns_buffer_write_u16_at(), UB_INITFAIL, UB_SYNTAX, outside_network::udp_buff, and ctx_query::w.

◆ libworker_delete_event()

void libworker_delete_event ( struct libworker w)

delete worker for event-based interface.

does not free the event_base.

Parameters
wevent-based worker to delete.

References libworker::base, comm_base_delete_no_base(), and libworker_delete_env().

Referenced by ub_ctx_set_event().

◆ libworker_enter_result()

void libworker_enter_result ( struct ub_result res,
struct sldns_buffer buf,
struct regional temp,
enum sec_status  msg_security 
)

fill result from parsed message, on error fills servfail

Parameters
resis clear at start, filled in at end.
bufcontains DNS message.
temptemporary buffer for parse.
msg_securitysecurity status of the DNS message. On error, the res may contain a different status (out of memory is not secure, not bogus).

References ub_result::rcode.