libworker.c File Reference

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

#include "config.h"
#include "libunbound/libworker.h"
#include "libunbound/context.h"
#include "libunbound/unbound.h"
#include "services/outside_network.h"
#include "services/mesh.h"
#include "services/localzone.h"
#include "services/cache/rrset.h"
#include "services/outbound_list.h"
#include "util/module.h"
#include "util/regional.h"
#include "util/random.h"
#include "util/config_file.h"
#include "util/netevent.h"
#include "util/storage/slabhash.h"
#include "util/net_help.h"
#include "util/data/dname.h"
#include "util/data/msgreply.h"
#include "util/data/msgencode.h"
#include "util/tube.h"
#include "iterator/iter_fwd.h"

Functions

static void handle_newq (struct libworker *w, uint8_t *buf, uint32_t len)
 handle new query command for bg worker
static void libworker_delete (struct libworker *w)
 delete libworker struct
static struct libworkerlibworker_setup (struct ub_ctx *ctx, int is_bg)
 setup fresh libworker struct
static void handle_cancel (struct libworker *w, uint8_t *buf, uint32_t len)
 handle cancel command for bg worker
static void libworker_do_cmd (struct libworker *w, uint8_t *msg, uint32_t len)
 do control command coming into bg server
void libworker_handle_control_cmd (struct tube *tube, uint8_t *msg, size_t len, int err, void *arg)
 handle control command coming into server
static void * libworker_dobg (void *arg)
 the background thread func
int libworker_bg (struct ub_ctx *ctx)
 Create a background worker.
static struct reply_infoparse_reply (ldns_buffer *pkt, struct regional *region, struct query_info *qi)
 get msg reply struct (in temp region)
static int fill_canon (struct ub_result *res, uint8_t *s)
 insert canonname
static int fill_res (struct ub_result *res, struct ub_packed_rrset_key *answer, uint8_t *finalcname, struct query_info *rq)
 fill data into result
void libworker_enter_result (struct ub_result *res, ldns_buffer *buf, struct regional *temp, enum sec_status msg_security)
 fill result from parsed message, on error fills servfail
static void libworker_fillup_fg (struct ctx_query *q, int rcode, ldns_buffer *buf, enum sec_status s)
 fillup fg results
void libworker_fg_done_cb (void *arg, int rcode, ldns_buffer *buf, enum sec_status s)
 mesh callback with fg results
static int setup_qinfo_edns (struct libworker *w, struct ctx_query *q, struct query_info *qinfo, struct edns_data *edns)
 setup qinfo and edns
int libworker_fg (struct ub_ctx *ctx, struct ctx_query *q)
 Create a foreground worker.
static void add_bg_result (struct libworker *w, struct ctx_query *q, ldns_buffer *pkt, int err)
 add result to the bg worker result queue
void libworker_bg_done_cb (void *arg, int rcode, ldns_buffer *buf, enum sec_status s)
 mesh callback with bg results
void libworker_alloc_cleanup (void *arg)
 cleanup the cache to remove all rrset IDs from it, arg is libworker
int libworker_send_packet (ldns_buffer *pkt, struct sockaddr_storage *addr, socklen_t addrlen, int timeout, struct module_qstate *q, int use_tcp)
 Worker service routine to send udp messages for modules.
static int outbound_entry_compare (void *a, void *b)
 compare outbound entry qstates
struct outbound_entrylibworker_send_query (uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec, struct sockaddr_storage *addr, socklen_t addrlen, struct module_qstate *q)
 Worker service routine to send serviced queries to authoritative servers.
int libworker_handle_reply (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
 process incoming replies from the network
int libworker_handle_service_reply (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
 process incoming serviced query replies from the network
void worker_handle_control_cmd (struct tube *tube, uint8_t *buffer, size_t len, int error, void *arg)
 process control messages from the main thread.
int worker_handle_request (struct comm_point *c, void *arg, int error, struct comm_reply *repinfo)
 handles callbacks from listening event interface
int worker_handle_reply (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
 process incoming replies from the network
int worker_handle_service_reply (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info)
 process incoming serviced query replies from the network
int remote_accept_callback (struct comm_point *c, void *arg, int error, struct comm_reply *repinfo)
 handle remote control accept callbacks
int remote_control_callback (struct comm_point *c, void *arg, int error, struct comm_reply *repinfo)
 handle remote control data callbacks
void worker_sighandler (int sig, void *arg)
 Worker signal handler function.
int worker_send_packet (ldns_buffer *pkt, struct sockaddr_storage *addr, socklen_t addrlen, int timeout, struct module_qstate *q, int use_tcp)
 Worker service routine to send udp messages for modules.
struct outbound_entryworker_send_query (uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec, struct sockaddr_storage *addr, socklen_t addrlen, struct module_qstate *q)
 Worker service routine to send serviced queries to authoritative servers.
void worker_alloc_cleanup (void *arg)
 cleanup the cache to remove all rrset IDs from it, arg is worker
void worker_stat_timer_cb (void *arg)
 statistics timer callback handler
int order_lock_cmp (const void *e1, const void *e2)
 Due to module breakage by fptr wlist, these test app declarations are presented here.
int codeline_cmp (const void *a, const void *b)
 compare two codeline structs for rbtree from memstats test app


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

int libworker_bg ( struct ub_ctx ctx  ) 

Create a background worker.

Parameters:
ctx,: is 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, ub_ctx::dothread, fatal_exit(), libworker::is_bg_thread, libworker_dobg(), libworker_setup(), ub_ctx::qq_pipe, ub_ctx::rr_pipe, libworker::thread_num, tube_close_read(), tube_close_write(), UB_FORKFAIL, UB_NOERROR, and UB_NOMEM.

Referenced by ub_resolve_async().

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

fill result from parsed message, on error fills servfail

Parameters:
res,: is clear at start, filled in at end.
buf,: contains DNS message.
temp,: temporary buffer for parse.
msg_security,: security 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::bogus, ub_result::data, fill_res(), reply_info::flags, FLAGS_GET_RCODE, ub_result::havedata, log_err(), ub_result::nxdomain, parse_reply(), ub_result::rcode, reply_find_answer_rrset(), reply_find_final_cname_target(), sec_status_bogus, sec_status_secure, and ub_result::secure.

Referenced by libworker_fillup_fg(), and process_answer_detail().

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:
ctx,: new allocation cache obtained and returned to it.
q,: query (result is stored in here).
Returns:
0 if finished OK, else error.

References libworker::back, libworker::base, BIT_RD, comm_base_dispatch(), libworker::env, libworker_delete(), libworker_fg_done_cb(), libworker_fillup_fg(), libworker_setup(), ub_ctx::local_zones, local_zones_answer(), module_env::mesh, mesh_new_callback(), query_info::qname, module_env::scratch, sec_status_insecure, setup_qinfo_edns(), UB_INITFAIL, UB_NOERROR, UB_NOMEM, UB_SYNTAX, outside_network::udp_buff, and ctx_query::w.

Referenced by ub_resolve().

int libworker_send_packet ( ldns_buffer *  pkt,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
int  timeout,
struct module_qstate q,
int  use_tcp 
)

Worker service routine to send udp messages for modules.

Parameters:
pkt,: packet to send.
addr,: where to.
addrlen,: length of addr.
timeout,: seconds to wait until timeout.
q,: wich query state to reactivate upon return.
use_tcp,: true to use TCP, false for UDP.
Returns:
: false on failure (memory or socket related). no query was sent.

References libworker::back, module_qstate::env, libworker_handle_reply(), pending_tcp_query(), pending_udp_query(), and module_env::worker.

struct outbound_entry* libworker_send_query ( uint8_t *  qname,
size_t  qnamelen,
uint16_t  qtype,
uint16_t  qclass,
uint16_t  flags,
int  dnssec,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
struct module_qstate q 
) [read]

Worker service routine to send serviced queries to authoritative servers.

Parameters:
qname,: query name. (host order)
qnamelen,: length in bytes of qname, including trailing 0.
qtype,: query type. (host order)
qclass,: query class. (host order)
flags,: host order flags word, with opcode and CD bit.
dnssec,: if set, EDNS record will have DO bit set.
addr,: where to.
addrlen,: length of addr.
q,: wich query state to reactivate upon return.
Returns:
: false on failure (memory or socket related). no query was sent.

References libworker::back, module_qstate::env, libworker_handle_service_reply(), outbound_entry_compare(), outnet_serviced_query(), module_qstate::region, regional_alloc(), outside_network::udp_buff, and module_env::worker.

void worker_handle_control_cmd ( struct tube tube,
uint8_t *  msg,
size_t  len,
int  error,
void *  arg 
)

process control messages from the main thread.

Frees the control command message.

Parameters:
tube,: tube control message came on.
msg,: message contents. Is freed.
len,: length of message.
error,: if error (NETEVENT_*) happened.
arg,: user argument

References log_assert.

void worker_sighandler ( int  sig,
void *  arg 
)

Worker signal handler function.

User argument is the worker itself.

Parameters:
sig,: signal number.
arg,: the worker (main worker) that handles signals.

References log_assert.

int worker_send_packet ( ldns_buffer *  pkt,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
int  timeout,
struct module_qstate q,
int  use_tcp 
)

Worker service routine to send udp messages for modules.

Parameters:
pkt,: packet to send.
addr,: where to.
addrlen,: length of addr.
timeout,: seconds to wait until timeout.
q,: wich query state to reactivate upon return.
use_tcp,: true to use TCP, false for UDP.
Returns:
: false on failure (memory or socket related). no query was sent.

References log_assert.

struct outbound_entry* worker_send_query ( uint8_t *  qname,
size_t  qnamelen,
uint16_t  qtype,
uint16_t  qclass,
uint16_t  flags,
int  dnssec,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
struct module_qstate q 
) [read]

Worker service routine to send serviced queries to authoritative servers.

Parameters:
qname,: query name. (host order)
qnamelen,: length in bytes of qname, including trailing 0.
qtype,: query type. (host order)
qclass,: query class. (host order)
flags,: host order flags word, with opcode and CD bit.
dnssec,: if set, EDNS record will have DO bit set.
addr,: where to.
addrlen,: length of addr.
q,: wich query state to reactivate upon return.
Returns:
: false on failure (memory or socket related). no query was sent.

References log_assert.

int order_lock_cmp ( const void *  e1,
const void *  e2 
)

Due to module breakage by fptr wlist, these test app declarations are presented here.

compare two order_ids from lock-verify test app

Parameters:
e1,: first order_id
e2,: second order_id
Returns:
compare code -1, 0, +1 (like memcmp).

References log_assert.

int codeline_cmp ( const void *  a,
const void *  b 
)

compare two codeline structs for rbtree from memstats test app

Parameters:
a,: codeline
b,: codeline
Returns:
compare code -1, 0, +1 (like memcmp).

References log_assert.


Generated on Tue Oct 13 06:45:50 2009 for unbound by  doxygen 1.5.9