Data Structures | Enumerations | Functions
worker.h File Reference

This file describes the worker structure that holds a list of pending requests and handles them. More...

#include "util/netevent.h"
#include "util/locks.h"
#include "util/alloc.h"
#include "util/data/msgreply.h"
#include "util/data/msgparse.h"
#include "daemon/stats.h"
#include "util/module.h"

Data Structures

struct  worker
 Structure holding working information for unbound. More...

Enumerations

enum  worker_commands { worker_cmd_quit, worker_cmd_stats, worker_cmd_stats_noreset, worker_cmd_remote }
 worker commands More...

Functions

struct workerworker_create (struct daemon *daemon, int id, int *ports, int n)
 Create the worker structure.
int worker_init (struct worker *worker, struct config_file *cfg, struct listen_port *ports, int do_sigs)
 Initialize worker.
void worker_work (struct worker *worker)
 Make worker work.
void worker_delete (struct worker *worker)
 Delete worker.
void worker_send_cmd (struct worker *worker, enum worker_commands cmd)
 Send a command to a worker.
void worker_sighandler (int sig, void *arg)
 Worker signal handler function.
struct outbound_entryworker_send_query (uint8_t *qname, size_t qnamelen, uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec, int want_dnssec, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *zone, size_t zonelen, struct module_qstate *q)
 Worker service routine to send serviced queries to authoritative servers.
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.
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
void worker_alloc_cleanup (void *arg)
 cleanup the cache to remove all rrset IDs from it, arg is worker
void worker_stats_clear (struct worker *worker)
 Init worker stats - includes server_stats_init, outside network and mesh.
void worker_stat_timer_cb (void *arg)
 statistics timer callback handler
void worker_probe_timer_cb (void *arg)
 probe timer callback handler

Detailed Description

This file describes the worker structure that holds a list of pending requests and handles them.


Enumeration Type Documentation

worker commands

Enumerator:
worker_cmd_quit 

make the worker quit

worker_cmd_stats 

obtain statistics

worker_cmd_stats_noreset 

obtain statistics without statsclear

worker_cmd_remote 

execute remote control command


Function Documentation

struct worker* worker_create ( struct daemon daemon,
int  id,
int *  ports,
int  n 
) [read]

Create the worker structure.

Bare bones version, zeroed struct, with backpointers only. Use worker_init on it later.

Parameters:
daemon,:the daemon that this worker thread is part of.
id,:the thread number from 0.. numthreads-1.
ports,:the ports it is allowed to use, array.
n,:the number of ports.
Returns:
: the new worker or NULL on alloc failure.

References worker::numports, worker::ports, memdup(), worker::daemon, worker::thread_num, worker::cmd, tube_create(), worker::rndstate, ub_initstate(), daemon::rand, log_err(), and tube_delete().

Referenced by daemon_create_workers().

int worker_init ( struct worker worker,
struct config_file cfg,
struct listen_port ports,
int  do_sigs 
)

Initialize worker.

Allocates event base, listens to ports

Parameters:
worker,:worker to initialize, created with worker_create.
cfg,:configuration settings.
ports,:list of shared query ports.
do_sigs,:if true, worker installs signal handlers.
Returns:
: false on error.

References worker::need_to_exit, worker::base, comm_base_create(), log_err(), worker_delete(), ub_thread_sig_unblock(), worker::comsig, comm_signal_create(), worker_sighandler(), comm_signal_bind(), daemon_remote_open_accept(), worker::daemon, daemon::rc, daemon::rc_ports, wsvc_setup_worker(), worker::front, listen_create(), config_file::msg_buffer_size, config_file::incoming_num_tcp, daemon::listen_sslctx, worker_handle_request(), worker::back, outside_network_create(), config_file::outgoing_num_ports, config_file::out_ifs, config_file::num_out_ifs, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::outgoing_num_tcp, daemon::env, module_env::infra_cache, worker::rndstate, config_file::use_caps_bits_for_id, worker::ports, worker::numports, config_file::unwanted_threshold, worker_alloc_cleanup(), config_file::do_udp, tube_setup_bg_listen(), worker::cmd, worker_handle_control_cmd(), worker::stat_timer, comm_timer_create(), worker_stat_timer_cb(), worker::scratchpad, regional_create_custom(), server_stats_init(), worker::stats, alloc_init(), worker::alloc, daemon::superalloc, worker::thread_num, alloc_set_id_cleanup(), worker::env, comm_base_timept(), module_env::now, module_env::now_tv, log_set_time(), module_env::worker, module_env::send_query, worker_send_query(), module_env::alloc, module_env::rnd, module_env::scratch, module_env::mesh, mesh_create(), daemon::mods, module_env::detach_subs, mesh_detach_subs(), module_env::attach_sub, mesh_attach_sub(), module_env::kill_sub, mesh_state_delete(), module_env::detect_cycle, mesh_detect_cycle(), module_env::scratch_buffer, module_env::fwds, forwards_create(), forwards_apply_cfg(), autr_get_num_anchors(), module_env::anchors, module_env::probe_timer, worker_probe_timer_cb(), comm_timer_set(), worker_mem_report(), module_env::cfg, config_file::stat_interval, verbose(), VERB_ALGO, and worker_restart_timer().

Referenced by thread_start(), and daemon_fork().

void worker_send_cmd ( struct worker worker,
enum worker_commands  cmd 
)

Send a command to a worker.

Uses blocking writes.

Parameters:
worker,:worker to send command to.
cmd,:command to send.

References tube_write_msg(), worker::cmd, and log_err().

Referenced by daemon_stop_others(), distribute_cmd(), and server_stats_obtain().

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 verbose(), VERB_QUERY, comm_base_exit(), worker::base, worker::need_to_exit, log_err(), and log_assert.

Referenced by signal_handling_playback(), worker_init(), and fptr_whitelist_comm_signal().

struct outbound_entry* worker_send_query ( uint8_t *  qname,
size_t  qnamelen,
uint16_t  qtype,
uint16_t  qclass,
uint16_t  flags,
int  dnssec,
int  want_dnssec,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint8_t *  zone,
size_t  zonelen,
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.
want_dnssec,:signatures needed.
addr,:where to.
addrlen,:length of addr.
zone,:wireformat dname of the zone.
zonelen,:length of zone name.
q,:wich query state to reactivate upon return.
Returns:
: false on failure (memory or socket related). no query was sent.

References module_qstate::env, module_env::worker, regional_alloc(), module_qstate::region, outbound_entry::qstate, outbound_entry::qsent, outnet_serviced_query(), worker::back, module_env::cfg, config_file::tcp_upstream, config_file::ssl_upstream, worker_handle_service_reply(), outside_network::udp_buff, and outbound_entry_compare().

Referenced by worker_init(), and fptr_whitelist_modenv_send_query().

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 worker::cmd, NETEVENT_NOERROR, NETEVENT_CLOSED, comm_base_exit(), worker::base, log_info(), fatal_exit(), worker_cmd_quit, verbose(), VERB_ALGO, worker_cmd_stats, server_stats_reply(), worker_cmd_stats_noreset, worker_cmd_remote, daemon_remote_exec(), log_err(), and log_assert.

Referenced by worker_init(), and fptr_whitelist_tube_listen().

void worker_stats_clear ( struct worker worker)

Init worker stats - includes server_stats_init, outside network and mesh.

Parameters:
worker,:the worker to init

References server_stats_init(), worker::stats, worker::env, module_env::cfg, mesh_stats_clear(), module_env::mesh, worker::back, and outside_network::unwanted_replies.

Referenced by do_flush_stats(), server_stats_compile(), and worker_stat_timer_cb().