unbound: daemon/worker.h File Reference

unbound 0.1

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 "libunbound/worker.h"`
`#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"`
`#include "dnstap/dnstap.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_cmd_reload_stop , worker_cmd_reload_start , worker_cmd_reload_poll }
| worker commands More...

## Functions
struct worker * | worker_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_stats_clear (struct worker *worker)
| Init worker stats - includes server_stats_init, outside network and mesh.

## Detailed Description

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

## Enumeration Type Documentation

## ◆ worker_commands

enum worker_commands

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
worker_cmd_reload_stop | for fast-reload, perform stop
worker_cmd_reload_start | for fast-reload, start again
worker_cmd_reload_poll | for fast-reload, poll to make sure worker has released data

## Function Documentation

## ◆ worker_create()

struct worker * worker_create | ( | struct daemon * | daemon,
|  | int | id,
|  | int * | ports,
|  | int | n )

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::cmd, worker::daemon, log_err(), memdup(), worker::numports, worker::ports, daemon::rand, worker::rndstate, worker::thread_num, tube_create(), tube_delete(), and ub_initstate().

Referenced by daemon_create_workers().

## ◆ worker_init()

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 module_env::add_sub, module_env::alloc, worker::alloc, alloc_set_id_cleanup(), module_env::anchors, module_env::attach_sub, auth_xfer_pickup_initial(), module_env::auth_zones, auth_zones_pickup_zonemd_verify(), autr_get_num_anchors(), worker::back, worker::base, daemon::cfg, module_env::cfg, worker::cmd, comm_base_timept(), comm_signal_create(), comm_timer_create(), comm_timer_set(), worker::comsig, daemon::connect_dot_sslctx, worker::daemon, daemon_remote_open_accept(), config_file::delay_close, module_env::detach_subs, module_env::detect_cycle, config_file::dnstap, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::do_tcp_keepalive, config_file::do_udp, daemon::doq_table, dt_io_thread_start(), daemon::env, worker::env, worker::front, config_file::harden_large_queries, config_file::http_endpoint, config_file::http_max_streams, config_file::http_notls_downstream, config_file::incoming_num_tcp, module_env::infra_cache, config_file::ip_dscp, iterator_set_ip46_support(), module_env::kill_sub, listen_create(), daemon::listen_doh_sslctx, daemon::listen_dot_sslctx, daemon::listen_quic_sslctx, log_assert, log_err(), config_file::max_reuse_tcp_queries, module_env::mesh, mesh_add_sub(), mesh_attach_sub(), mesh_create(), mesh_detach_subs(), mesh_detect_cycle(), mesh_state_delete(), daemon::mods, config_file::msg_buffer_size, worker::need_to_exit, module_env::now, module_env::now_tv, daemon::num, config_file::num_out_ifs, worker::numports, config_file::out_ifs, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, config_file::outgoing_tcp_mss, module_env::outnet, outside_network_create(), worker::ports, pp_init(), module_env::probe_timer, daemon::rc, daemon::rc_ports, regional_create_custom(), module_env::rnd, worker::rndstate, module_env::scratch, module_env::scratch_buffer, worker::scratchpad, module_env::send_query, server_stats_init(), sldns_buffer_new(), config_file::stat_interval, worker::stat_timer, worker::stats, daemon::tcl, config_file::tcp_auth_query_timeout, config_file::tcp_idle_timeout, config_file::tcp_keepalive_timeout, config_file::tcp_reuse_timeout, worker::thread_num, config_file::tls_use_sni, tube_setup_bg_listen(), ub_thread_sig_unblock(), config_file::udp_connect, config_file::udp_upstream_without_downstream, config_file::unwanted_threshold, config_file::use_caps_bits_for_id, daemon::use_response_ip, mesh_area::use_response_ip, daemon::use_rpz, mesh_area::use_rpz, VERB_ALGO, verbose(), module_env::worker, worker_alloc_cleanup(), daemon::worker_allocs, module_env::worker_base, worker_delete(), worker_handle_request(), worker_mem_report(), worker_probe_timer_cb(), worker_restart_timer(), worker_send_query(), worker_sighandler(), worker_start_accept(), worker_stat_timer_cb(), worker_stop_accept(), and wsvc_setup_worker().

Referenced by daemon_fork(), and thread_start().

## ◆ worker_send_cmd()

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 worker::cmd, log_err(), and tube_write_msg().

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

## ◆ worker_stats_clear()

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 worker::back, module_env::cfg, worker::env, module_env::mesh, mesh_stats_clear(), outside_network::num_tcp_outgoing, outside_network::num_udp_outgoing, server_stats_init(), worker::stats, and outside_network::unwanted_replies.

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