#include "config.h"
#include "util/log.h"
#include "util/net_help.h"
#include "util/random.h"
#include "daemon/worker.h"
#include "daemon/daemon.h"
#include "daemon/remote.h"
#include "daemon/acl_list.h"
#include "util/netevent.h"
#include "util/config_file.h"
#include "util/module.h"
#include "util/regional.h"
#include "util/storage/slabhash.h"
#include "services/listen_dnsport.h"
#include "services/outside_network.h"
#include "services/outbound_list.h"
#include "services/cache/rrset.h"
#include "services/cache/infra.h"
#include "services/cache/dns.h"
#include "services/mesh.h"
#include "services/localzone.h"
#include "util/data/msgparse.h"
#include "util/data/msgencode.h"
#include "util/data/dname.h"
#include "util/fptr_wlist.h"
#include "util/tube.h"
#include "iterator/iter_fwd.h"
#include <sys/types.h>
#include <netdb.h>
#include <signal.h>
Defines | |
| #define | NORMAL_UDP_SIZE 512 |
| Size of an UDP datagram. | |
Functions | |
| void | worker_mem_report (struct worker *worker, struct serviced_query *cur_serv) |
| Report on memory usage by this thread and global. | |
| void | worker_send_cmd (struct worker *worker, enum worker_commands cmd) |
| Send a command to a worker. | |
| 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 | |
| static int | worker_check_request (ldns_buffer *pkt, struct worker *worker) |
| check request sanity. | |
| 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. | |
| static enum sec_status | check_delegation_secure (struct reply_info *rep) |
| check if a delegation is secure | |
| static void | deleg_remove_nonsecure_additional (struct reply_info *rep) |
| remove nonsecure from a delegation referral additional section | |
| static int | answer_norec_from_cache (struct worker *worker, struct query_info *qinfo, uint16_t id, uint16_t flags, struct comm_reply *repinfo, struct edns_data *edns) |
| answer nonrecursive query from the cache | |
| static int | answer_from_cache (struct worker *worker, struct query_info *qinfo, struct reply_info *rep, uint16_t id, uint16_t flags, struct comm_reply *repinfo, struct edns_data *edns) |
| answer query from the cache | |
| static void | chaos_replystr (ldns_buffer *pkt, const char *str, struct edns_data *edns) |
| Fill CH class answer into buffer. | |
| static int | answer_chaos (struct worker *w, struct query_info *qinfo, struct edns_data *edns, ldns_buffer *pkt) |
| Answer CH class queries. | |
| int | worker_handle_request (struct comm_point *c, void *arg, int error, struct comm_reply *repinfo) |
| handles callbacks from listening event interface | |
| void | worker_sighandler (int sig, void *arg) |
| Worker signal handler function. | |
| static void | worker_restart_timer (struct worker *worker) |
| restart statistics timer for worker, if enabled | |
| void | worker_stat_timer_cb (void *arg) |
| statistics timer callback handler | |
| 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. | |
| 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. | |
| static int | outbound_entry_compare (void *a, void *b) |
| compare outbound entry qstates | |
| 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. | |
| 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. | |
| 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. | |
| 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) |
| 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 | libworker_handle_control_cmd (struct tube *tube, uint8_t *buffer, size_t len, int error, void *arg) |
| handle control command coming into server | |
| void | libworker_fg_done_cb (void *arg, int rcode, ldns_buffer *buf, enum sec_status s) |
| mesh callback with fg results | |
| void | libworker_bg_done_cb (void *arg, int rcode, ldns_buffer *buf, enum sec_status s) |
| mesh callback with bg results | |
| int | context_query_cmp (const void *a, const void *b) |
| compare two ctx_query elements | |
| 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 | |
| void worker_send_cmd | ( | struct worker * | worker, | |
| enum worker_commands | cmd | |||
| ) |
Send a command to a worker.
Uses blocking writes.
References worker::cmd, log_err(), and tube_write_msg().
Referenced by daemon_stop_others(), distribute_cmd(), and server_stats_obtain().
| static int worker_check_request | ( | ldns_buffer * | pkt, | |
| struct worker * | worker | |||
| ) | [static] |
check request sanity.
Returns error code, 0 OK, or -1 discard.
| pkt,: | the wire packet to examine for sanity. | |
| worker,: | parameters for checking. |
References daemon::cfg, worker::daemon, config_file::harden_large_queries, NORMAL_UDP_SIZE, VERB_QUERY, and verbose().
Referenced by worker_handle_request().
| 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.
| tube,: | tube control message came on. | |
| msg,: | message contents. Is freed. | |
| len,: | length of message. | |
| error,: | if error (NETEVENT_*) happened. | |
| arg,: | user argument |
Referenced by fptr_whitelist_tube_listen(), and worker_init().
| static void chaos_replystr | ( | ldns_buffer * | pkt, | |
| const char * | str, | |||
| struct edns_data * | edns | |||
| ) | [static] |
Fill CH class answer into buffer.
Keeps query.
| pkt,: | buffer | |
| str,: | string to put into text record (<255). | |
| edns,: | edns reply information. |
References attach_edns_record(), BIT_QR, BIT_RA, edns_data::bits, EDNS_ADVERTISED_SIZE, EDNS_ADVERTISED_VERSION, EDNS_DO, edns_data::edns_version, query_dname_len(), and edns_data::udp_size.
Referenced by answer_chaos().
| static int answer_chaos | ( | struct worker * | w, | |
| struct query_info * | qinfo, | |||
| struct edns_data * | edns, | |||
| ldns_buffer * | pkt | |||
| ) | [static] |
Answer CH class queries.
| w,: | worker | |
| qinfo,: | query info. Pointer into packet buffer. | |
| edns,: | edns info from query. | |
| pkt,: | packet buffer. |
References module_env::cfg, chaos_replystr(), worker::env, config_file::hide_identity, config_file::hide_version, config_file::identity, log_err(), query_info::qname, query_info::qtype, query_dname_compare(), and config_file::version.
Referenced by worker_handle_request().
| void worker_sighandler | ( | int | sig, | |
| void * | arg | |||
| ) |
Worker signal handler function.
User argument is the worker itself.
Referenced by fptr_whitelist_comm_signal(), signal_handling_playback(), and worker_init().
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, worker::daemon, memdup(), worker::numports, worker::ports, worker::thread_num, and tube_create().
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, comm_base_create(), comm_base_timept(), comm_signal_bind(), comm_signal_create(), comm_timer_create(), worker::comsig, worker::daemon, daemon_remote_open_accept(), module_env::detach_subs, module_env::detect_cycle, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, worker::env, daemon::env, forwards_apply_cfg(), forwards_create(), worker::front, module_env::fwds, 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, daemon::rc, daemon::rc_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, tube_setup_bg_listen(), ub_initstate(), ub_thread_sig_unblock(), config_file::unwanted_threshold, 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(), worker_stat_timer_cb(), and wsvc_setup_worker().
Referenced by daemon_fork(), and thread_start().
| 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. |
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. |
Referenced by fptr_whitelist_modenv_send_query(), and worker_init().
| void worker_stats_clear | ( | struct worker * | worker | ) |
Init worker stats - includes server_stats_init, outside network and mesh.
References worker::back, module_env::cfg, worker::env, module_env::mesh, mesh_stats_clear(), server_stats_init(), worker::stats, and outside_network::unwanted_replies.
Referenced by do_flush_stats(), server_stats_compile(), and worker_stat_timer_cb().
| 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.
| 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. |
Referenced by fptr_whitelist_modenv_send_packet(), and libworker_setup().
| 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.
| 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. |
Referenced by fptr_whitelist_modenv_send_query(), and libworker_setup().
| 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
Referenced by fptr_whitelist_rbtree_cmp(), insert_lock(), main(), and read_create().
| int codeline_cmp | ( | const void * | a, | |
| const void * | b | |||
| ) |
compare two codeline structs for rbtree from memstats test app
Referenced by fptr_whitelist_rbtree_cmp(), and main().
1.5.9