#include "config.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"
Data Structures | |
struct | worker |
Structure holding working information for unbound. More... | |
Enumerations | |
enum | worker_commands { worker_cmd_quit } |
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, ldns_buffer *buffer, enum worker_commands cmd) |
Send a command to a worker. | |
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_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) |
Worker service routine to send serviced queries to authoritative servers. | |
int | worker_handle_control_cmd (struct comm_point *c, void *arg, int error, struct comm_reply *reply_info) |
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_stat_timer_cb (void *arg) |
statistics timer callback handler |
enum worker_commands |
Create the worker structure.
Bare bones version, zeroed struct, with backpointers only. Use worker_init on it later.
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. |
References worker::cmd_recv_fd, worker::cmd_send_fd, worker::daemon, fd_set_nonblock(), log_err(), memdup(), worker::numports, worker::ports, and worker::thread_num.
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
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. |
References module_env::alloc, worker::alloc, alloc_init(), alloc_set_id_cleanup(), module_env::attach_sub, worker::back, worker::base, module_env::cfg, worker::cmd_com, worker::cmd_recv_fd, comm_base_create(), comm_base_timept(), comm_point_create_local(), comm_signal_bind(), comm_signal_create(), comm_timer_create(), worker::comsig, worker::daemon, module_env::detach_subs, module_env::detect_cycle, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, worker::env, daemon::env, worker::front, config_file::incoming_num_tcp, module_env::infra_cache, module_env::kill_sub, listen_create(), log_err(), log_set_time(), module_env::mesh, 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, config_file::num_out_ifs, config_file::num_queries_per_thread, worker::numports, config_file::out_ifs, config_file::outgoing_num_ports, config_file::outgoing_num_tcp, outside_network_create(), worker::ports, regional_create_custom(), worker::request_size, module_env::rnd, worker::rndstate, module_env::scratch, module_env::scratch_buffer, worker::scratchpad, module_env::send_packet, module_env::send_query, server_stats_init(), config_file::stat_interval, worker::stat_timer, worker::stats, daemon::superalloc, worker::thread_num, ub_initstate(), ub_thread_sig_unblock(), config_file::use_caps_bits_for_id, VERB_ALGO, verbose(), module_env::worker, worker_alloc_cleanup(), worker_delete(), worker_handle_control_cmd(), worker_handle_request(), worker_mem_report(), worker_restart_timer(), worker_send_packet(), worker_send_query(), worker_sighandler(), and worker_stat_timer_cb().
Referenced by daemon_fork(), and thread_start().
void worker_send_cmd | ( | struct worker * | worker, | |
ldns_buffer * | buffer, | |||
enum worker_commands | cmd | |||
) |
Send a command to a worker.
Uses blocking writes.
worker,: | worker to send command to. | |
buffer,: | an empty buffer to use. | |
cmd,: | command to send. |
References worker::cmd_send_fd, log_err(), and write_socket().
Referenced by daemon_stop_others().
void worker_sighandler | ( | int | sig, | |
void * | arg | |||
) |
Worker signal handler function.
User argument is the worker itself.
References worker::base, comm_base_exit(), log_assert, log_err(), worker::need_to_exit, VERB_QUERY, and verbose().
Referenced by fptr_whitelist_comm_signal(), signal_handling_playback(), and worker_init().
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.
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. |
References worker::back, module_qstate::env, log_assert, pending_tcp_query(), pending_udp_query(), module_env::worker, and worker_handle_reply().
Referenced by fptr_whitelist_modenv_send_packet(), and worker_init().
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.
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. |
References worker::back, module_qstate::env, log_assert, outbound_entry_compare(), outnet_serviced_query(), outbound_entry::qsent, outbound_entry::qstate, module_qstate::region, regional_alloc(), outside_network::udp_buff, module_env::worker, and worker_handle_service_reply().
Referenced by fptr_whitelist_modenv_send_query(), and worker_init().
int worker_handle_control_cmd | ( | struct comm_point * | c, | |
void * | arg, | |||
int | error, | |||
struct comm_reply * | reply_info | |||
) |
process control messages from the main thread.
c,: | comm point to read from. | |
arg,: | worker. | |
error,: | error status of comm point. | |
reply_info,: | not used. |
References worker::base, comm_point::buffer, comm_base_exit(), fatal_exit(), log_assert, log_err(), log_info(), NETEVENT_CLOSED, NETEVENT_NOERROR, VERB_ALGO, verbose(), and worker_cmd_quit.
Referenced by fptr_whitelist_comm_point(), and worker_init().