|
unbound 0.1
|
This file implements the worker that handles callbacks on events, for pending requests. More...
#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/authzone.h"#include "services/mesh.h"#include "services/localzone.h"#include "services/rpz.h"#include "util/data/msgparse.h"#include "util/data/msgencode.h"#include "util/data/dname.h"#include "util/fptr_wlist.h"#include "util/proxy_protocol.h"#include "util/tube.h"#include "util/edns.h"#include "util/timeval_func.h"#include "iterator/iter_fwd.h"#include "iterator/iter_hints.h"#include "iterator/iter_utils.h"#include "validator/autotrust.h"#include "validator/val_anchor.h"#include "respip/respip.h"#include "libunbound/context.h"#include "libunbound/libworker.h"#include "sldns/sbuffer.h"#include "sldns/wire2str.h"#include "util/shm_side/shm_main.h"#include "dnscrypt/dnscrypt.h"#include "dnstap/dtstream.h"#include <signal.h>Data Structures | |
| struct | check_request_result |
| Structure holding the result of the worker_check_request function. More... | |
Macros | |
| #define | ERROR_RATELIMIT 100 |
| ratelimit for error responses | |
| #define | PREFETCH_EXPIRY_ADD 60 |
| seconds to add to prefetch leeway. | |
| #define | TA_RESPONSE_MAX_TXT 16 |
| #define | TA_RESPONSE_MAX_TAGS 32 |
Functions | |
| static void | worker_mem_report (struct worker *ATTR_UNUSED(worker), struct serviced_query *ATTR_UNUSED(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_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_err_ratelimit (struct worker *worker, int err) |
| ratelimit error replies | |
| static void | query_error (sldns_buffer *pkt, int err, size_t qname_len) |
| Reply with an error. | |
| static void | worker_check_request (sldns_buffer *pkt, struct worker *worker, struct check_request_result *out) |
| check request sanity. | |
| static void | worker_send_reload_ack (struct worker *worker) |
| Send fast-reload acknowledgement to the mainthread in one byte. | |
| static void | worker_stop_and_wait (struct worker *worker) |
| stop and wait to resume the worker | |
| void | worker_handle_control_cmd (struct tube *ATTR_UNUSED(tube), uint8_t *msg, size_t len, int error, void *arg) |
| 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 | apply_respip_action (struct worker *worker, const struct query_info *qinfo, struct respip_client_info *cinfo, struct reply_info *rep, struct sockaddr_storage *addr, socklen_t addrlen, struct ub_packed_rrset_key **alias_rrset, struct reply_info **encode_repp, struct auth_zones *az, int *rpz_passthru) |
| Apply, if applicable, a response IP action to a cached answer. | |
| static int | answer_from_cache (struct worker *worker, struct query_info *qinfo, struct respip_client_info *cinfo, int *need_drop, int *is_expired_answer, int *is_secure_answer, struct ub_packed_rrset_key **alias_rrset, struct reply_info **partial_repp, struct reply_info *rep, uint16_t id, uint16_t flags, struct comm_reply *repinfo, struct edns_data *edns, int *rpz_passthru) |
| answer query from the cache. | |
| static void | reply_and_prefetch (struct worker *worker, struct query_info *qinfo, uint16_t flags, struct comm_reply *repinfo, time_t leeway, int noreply, int rpz_passthru, struct edns_option *opt_list) |
| Reply to client and perform prefetch to keep cache up to date. | |
| static void | chaos_replystr (sldns_buffer *pkt, char **str, int num, struct edns_data *edns, struct worker *worker, struct comm_reply *repinfo) |
| Fill CH class answer into buffer. | |
| static void | chaos_replyonestr (sldns_buffer *pkt, const char *str, struct edns_data *edns, struct worker *worker, struct comm_reply *repinfo) |
| Reply with one string. | |
| static void | chaos_trustanchor (sldns_buffer *pkt, struct edns_data *edns, struct worker *w, struct comm_reply *repinfo) |
| Create CH class trustanchor answer. | |
| static int | answer_chaos (struct worker *w, struct query_info *qinfo, struct edns_data *edns, struct comm_reply *repinfo, sldns_buffer *pkt) |
| Answer CH class queries. | |
| static void | answer_notify (struct worker *w, struct query_info *qinfo, struct edns_data *edns, sldns_buffer *pkt, struct sockaddr_storage *addr, socklen_t addrlen) |
| Answer notify queries. | |
| static int | deny_refuse (struct comm_point *c, enum acl_access acl, enum acl_access deny, enum acl_access refuse, struct worker *worker, struct comm_reply *repinfo, struct acl_addr *acladdr, int ede, struct check_request_result *check_result) |
| static int | deny_refuse_all (struct comm_point *c, enum acl_access *acl, struct worker *worker, struct comm_reply *repinfo, struct acl_addr **acladdr, int ede, int check_proxy, struct check_request_result *check_result) |
| static int | deny_refuse_non_local (struct comm_point *c, enum acl_access acl, struct worker *worker, struct comm_reply *repinfo, struct acl_addr *acladdr, int ede, struct check_request_result *check_result) |
| static int | check_ip_ratelimit (struct worker *worker, struct sockaddr_storage *addr, socklen_t addrlen, int has_cookie, sldns_buffer *pkt) |
| 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 | |
| void | worker_probe_timer_cb (void *arg) |
| probe timer callback handler | |
| struct worker * | worker_create (struct daemon *daemon, int id) |
| 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. | |
| struct outbound_entry * | worker_send_query (struct query_info *qinfo, uint16_t flags, int dnssec, int want_dnssec, int nocaps, int check_ratelimit, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t *zone, size_t zonelen, int tcp_upstream, int ssl_upstream, char *tls_auth_name, struct module_qstate *q, int *was_ratelimited, int *ratelimit_incremented) |
| 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. | |
| void | worker_start_accept (void *arg) |
| start accept callback handler | |
| void | worker_stop_accept (void *arg) |
| stop accept callback handler | |
| struct outbound_entry * | libworker_send_query (struct query_info *ATTR_UNUSED(qinfo), uint16_t ATTR_UNUSED(flags), int ATTR_UNUSED(dnssec), int ATTR_UNUSED(want_dnssec), int ATTR_UNUSED(nocaps), int ATTR_UNUSED(check_ratelimit), struct sockaddr_storage *ATTR_UNUSED(addr), socklen_t ATTR_UNUSED(addrlen), uint8_t *ATTR_UNUSED(zone), size_t ATTR_UNUSED(zonelen), int ATTR_UNUSED(tcp_upstream), int ATTR_UNUSED(ssl_upstream), char *ATTR_UNUSED(tls_auth_name), struct module_qstate *ATTR_UNUSED(q), int *ATTR_UNUSED(was_ratelimited), int *ATTR_UNUSED(ratelimit_incremented)) |
| int | libworker_handle_service_reply (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(reply_info)) |
| void | libworker_handle_control_cmd (struct tube *ATTR_UNUSED(tube), uint8_t *ATTR_UNUSED(buffer), size_t ATTR_UNUSED(len), int ATTR_UNUSED(error), void *ATTR_UNUSED(arg)) |
| void | libworker_fg_done_cb (void *ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), sldns_buffer *ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s), char *ATTR_UNUSED(why_bogus), int ATTR_UNUSED(was_ratelimited)) |
| void | libworker_bg_done_cb (void *ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), sldns_buffer *ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s), char *ATTR_UNUSED(why_bogus), int ATTR_UNUSED(was_ratelimited)) |
| void | libworker_event_done_cb (void *ATTR_UNUSED(arg), int ATTR_UNUSED(rcode), sldns_buffer *ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s), char *ATTR_UNUSED(why_bogus), int ATTR_UNUSED(was_ratelimited)) |
| void | libworker_alloc_cleanup (void *ATTR_UNUSED(arg)) |
| int | context_query_cmp (const void *ATTR_UNUSED(a), const void *ATTR_UNUSED(b)) |
| int | order_lock_cmp (const void *ATTR_UNUSED(e1), const void *ATTR_UNUSED(e2)) |
| int | codeline_cmp (const void *ATTR_UNUSED(a), const void *ATTR_UNUSED(b)) |
This file implements the worker that handles callbacks on events, for pending requests.
| #define ERROR_RATELIMIT 100 |
ratelimit for error responses
Referenced by worker_err_ratelimit().
| #define PREFETCH_EXPIRY_ADD 60 |
seconds to add to prefetch leeway.
This is a TTL that expires old rrsets earlier than they should in order to put the new update into the cache. This additional value is to make sure that if not all TTLs are equal in the message to be updated(and replaced), that rrsets with up to this much extra TTL are also replaced. This means that the resulting new message will have (most likely) this TTL at least, avoiding very small 'split second' TTLs due to operators choosing relative primes for TTLs (or so). Also has to be at least one to break ties (and overwrite cached entry).
Referenced by reply_and_prefetch().
|
static |
Report on memory usage by this thread and global.
References daemon::acl, acl_list_get_mem(), worker::alloc, alloc_get_mem(), module_env::anchors, anchors_get_mem(), worker::back, worker::base, worker::cmd_com, worker::comsig, worker::daemon, daemon::env, worker::env, forwards_get_mem(), fptr_ok, fptr_whitelist_mod_get_mem(), worker::front, module_env::fwds, module_func_block::get_mem, module_env::hints, hints_get_mem(), module_env::infra_cache, infra_get_mem(), listen_get_mem(), log_info(), module_env::mesh, mesh_get_mem(), module_stack::mod, mesh_area::mods, module_env::msg_cache, module_func_block::name, module_stack::num, outnet_get_mem(), regional_get_mem(), worker::rndstate, module_env::rrset_cache, module_env::scratch_buffer, worker::scratchpad, serviced_get_mem(), slabhash_get_mem(), sldns_buffer_capacity(), daemon::superalloc, rrset_cache::table, worker::thread_num, unbound_mem_alloc, unbound_mem_freed, VERB_ALGO, VERB_QUERY, verbose(), verbosity, and worker_mem_report().
Referenced by worker_delete(), worker_handle_request(), worker_handle_service_reply(), worker_init(), worker_mem_report(), and worker_stat_timer_cb().
| void worker_send_cmd | ( | struct worker * | worker, |
| enum worker_commands | cmd ) |
Send a command to a worker.
Uses blocking writes.
| worker | worker to send command to. |
| cmd | command to send. |
References worker::cmd, log_err(), tube_write_msg(), and worker_send_cmd().
Referenced by daemon_stop_others(), distribute_cmd(), fr_main_perform_reload_nopause_poll(), fr_main_perform_reload_stop(), server_stats_obtain(), and worker_send_cmd().
| 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
References comm_point::buffer, module_qstate::env, worker::env, module_env::mesh, mesh_report_reply(), NETEVENT_NOERROR, NETEVENT_TIMEOUT, outbound_entry::qsent, outbound_entry::qstate, sldns_buffer_begin(), sldns_buffer_limit(), VERB_ALGO, verbose(), module_env::worker, worker_handle_service_reply(), and worker_mem_report().
Referenced by fptr_whitelist_serviced_query(), worker_handle_control_cmd(), worker_handle_service_reply(), and worker_send_query().
|
static |
ratelimit error replies
| worker | the worker struct with ratelimit counter |
| err | error code that would be wanted. |
References worker::env, worker::err_limit_count, worker::err_limit_time, ERROR_RATELIMIT, module_env::now, and worker_err_ratelimit().
Referenced by worker_check_request(), worker_err_ratelimit(), and worker_handle_request().
|
static |
Reply with an error.
This reply includes the qname if it has been parsed. For error ratelimiting, the err ratelimit routine should be checked beforehand. The reply is without EDNS, and copies RD and sets QR flag.
| pkt | the packet buffer from the comm point. |
| err | the error code that would be wanted. |
| qname_len | 0 if not parsed, and the qname length in packet. |
References LDNS_MAX_DOMAINLEN, query_error(), sldns_buffer_begin(), sldns_buffer_flip(), sldns_buffer_read_u16_at(), sldns_buffer_set_position(), and sldns_buffer_write_u16_at().
Referenced by query_error(), and worker_handle_request().
|
static |
check request sanity.
| pkt | the wire packet to examine for sanity. |
| worker | parameters for checking. |
| out | struct to update with the result. |
References daemon::cfg, worker::daemon, config_file::harden_large_queries, NORMAL_UDP_SIZE, sldns_buffer_begin(), sldns_buffer_limit(), VERB_QUERY, verbose(), worker_check_request(), and worker_err_ratelimit().
Referenced by worker_check_request(), and worker_handle_request().
|
static |
Send fast-reload acknowledgement to the mainthread in one byte.
This signals that this worker has received the previous command. The worker is waiting if that is after a reload_stop command. Or the worker has briefly processed the event itself, and in doing so released data pointers to old config, after a reload_poll command.
References fast_reload_thread::commreload, worker::daemon, daemon::fast_reload_thread, log_err(), sock_strerror(), worker::thread_num, and worker_send_reload_ack().
Referenced by worker_send_reload_ack(), and worker_stop_and_wait().
|
static |
stop and wait to resume the worker
References worker::base, worker::cmd, comm_base_exit(), worker::daemon, worker::env, daemon::fast_reload_drop_mesh, fast_reload_worker_pickup_changes(), log_err(), module_env::mesh, mesh_delete_all(), tube_read_msg(), VERB_ALGO, verbose(), worker_cmd_quit, worker_cmd_reload_start, worker_send_reload_ack(), and worker_stop_and_wait().
Referenced by worker_stop_and_wait().
|
static |
check if a delegation is secure
References reply_info::an_numrrsets, check_delegation_secure(), lruhash_entry::data, ub_packed_rrset_key::entry, reply_info::ns_numrrsets, reply_info::rrset_count, reply_info::rrsets, sec_status_secure, sec_status_unchecked, and packed_rrset_data::security.
Referenced by answer_norec_from_cache(), and check_delegation_secure().
|
static |
remove nonsecure from a delegation referral additional section
References reply_info::an_numrrsets, reply_info::ar_numrrsets, lruhash_entry::data, deleg_remove_nonsecure_additional(), ub_packed_rrset_key::entry, reply_info::ns_numrrsets, reply_info::rrset_count, reply_info::rrsets, sec_status_secure, and packed_rrset_data::security.
Referenced by answer_norec_from_cache(), and deleg_remove_nonsecure_additional().
|
static |
answer nonrecursive query from the cache
References ub_server_stats::ans_bogus, ub_server_stats::ans_rcode, ub_server_stats::ans_secure, answer_norec_from_cache(), BIT_CD, BIT_QR, BIT_RA, edns_data::bits, comm_point::buffer, comm_reply::c, module_env::cfg, check_delegation_secure(), deleg_remove_nonsecure_additional(), config_file::disable_edns_do, dns_cache_find_delegation(), config_file::ede, EDNS_ADVERTISED_SIZE, EDNS_ADVERTISED_VERSION, EDNS_DO, edns_opt_list_append_ede(), edns_data::edns_present, edns_data::edns_version, worker::env, error_encode(), edns_data::ext_rcode, ub_server_stats::extended, reply_info::flags, config_file::ignore_cd, inplace_cb_reply_cache_call(), inplace_cb_reply_servfail_call(), query_info::local_alias, module_env::need_to_validate, module_env::now, module_env::now_tv, edns_data::opt_list_inplace_cb_out, edns_data::opt_list_out, query_info::qclass, dns_msg::qinfo, query_info::qname, query_info::qname_len, query_info::qtype, reply_info::reason_bogus, reply_info::reason_bogus_str, dns_msg::rep, reply_info_answer_encode(), worker::scratchpad, sec_status_bogus, sec_status_indeterminate, sec_status_insecure, sec_status_secure, sec_status_secure_sentinel_fail, sec_status_unchecked, server_stats_insrcode(), worker::stats, edns_data::udp_size, and config_file::val_clean_additional.
Referenced by answer_norec_from_cache(), and worker_handle_request().
|
static |
Apply, if applicable, a response IP action to a cached answer.
If the answer is rewritten as a result of an action, '*encode_repp' will point to the reply info containing the modified answer. '*encode_repp' will be intact otherwise. It returns 1 on success, 0 otherwise.
References apply_respip_action(), worker::env, ub_server_stats::extended, LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, LDNS_RR_TYPE_ANY, query_info::local_alias, query_info::qclass, query_info::qname, query_info::qtype, respip_always_deny, respip_deny, respip_inform_deny, respip_inform_print(), respip_none, respip_rewrite_reply(), module_env::respip_set, ub_server_stats::rpz_action, worker::scratchpad, worker::stats, and module_env::views.
Referenced by answer_from_cache(), apply_respip_action(), and mesh_serve_expired_callback().
|
static |
answer query from the cache.
Normally, the answer message will be built in repinfo->c->buffer; if the answer is supposed to be suppressed or the answer is supposed to be an incomplete CNAME chain, the buffer is explicitly cleared to signal the caller as such. In the latter case *partial_rep will point to the incomplete reply, and this function is (possibly) supposed to be called again with that *partial_rep value to complete the chain. In addition, if the query should be completely dropped, '*need_drop' will be set to 1.
References reply_info::an_numrrsets, ub_server_stats::ans_bogus, ub_server_stats::ans_rcode, answer_from_cache(), apply_respip_action(), module_env::auth_zones, BIT_CD, edns_data::bits, comm_point::buffer, comm_reply::c, module_env::cfg, comm_reply::client_addr, comm_reply::client_addrlen, worker::daemon, config_file::disable_edns_do, config_file::ede, config_file::ede_serve_expired, EDNS_ADVERTISED_SIZE, EDNS_ADVERTISED_VERSION, EDNS_DO, EDNS_OPT_LIST_APPEND_EDE, edns_opt_list_append_ede(), edns_data::edns_present, edns_data::edns_version, worker::env, error_encode(), edns_data::ext_rcode, ub_server_stats::extended, reply_info::flags, config_file::ignore_cd, inplace_cb_reply_cache_call(), inplace_cb_reply_servfail_call(), LDNS_RR_TYPE_CNAME, LDNS_RR_TYPE_DNAME, module_env::need_to_validate, module_env::now, module_env::now_tv, edns_data::opt_list_inplace_cb_out, edns_data::opt_list_out, reply_info::reason_bogus, reply_info::reason_bogus_str, reply_info::ref, reply_an_ns_rrsets_secure(), reply_check_cname_chain(), reply_info_answer_encode(), reply_info_can_answer_expired(), reply_info_copy(), respip_merge_cname(), module_env::respip_set, ub_packed_rrset_key::rk, rrset_array_lock(), rrset_array_unlock_touch(), module_env::rrset_cache, reply_info::rrset_count, reply_info::rrsets, worker::scratchpad, sec_status_bogus, sec_status_secure, sec_status_secure_sentinel_fail, sec_status_unchecked, reply_info::security, config_file::serve_expired, config_file::serve_expired_client_timeout, reply_info::serve_expired_norec_ttl, worker::stats, reply_info::ttl, TTL_IS_EXPIRED, packed_rrset_key::type, edns_data::udp_size, daemon::use_response_ip, daemon::use_rpz, VERB_ALGO, verbose(), and module_env::views.
Referenced by answer_from_cache(), and worker_handle_request().
|
static |
Reply to client and perform prefetch to keep cache up to date.
References comm_point::buffer, comm_reply::c, comm_reply::client_addr, comm_point_send_reply(), worker::env, reply_info::flags, module_env::mesh, mesh_new_prefetch(), mesh_area::mods, modstack_find(), PREFETCH_EXPIRY_ADD, reply_and_prefetch(), server_stats_prefetch(), sldns_buffer_copy(), tcp_req_info::spool_buffer, worker::stats, and comm_point::tcp_req_info.
Referenced by reply_and_prefetch(), and worker_handle_request().
|
static |
Fill CH class answer into buffer.
Keeps query.
| pkt | buffer |
| str | string to put into text record (<255). array of strings, every string becomes a text record. |
| num | number of strings in array. |
| edns | edns reply information. |
| worker | worker with scratch region. |
| repinfo | reply information for a communication point. |
References attach_edns_record(), BIT_QR, BIT_RA, edns_data::bits, calc_edns_field_size(), chaos_replystr(), EDNS_ADVERTISED_SIZE, EDNS_ADVERTISED_VERSION, EDNS_DO, edns_data::edns_version, worker::env, edns_data::ext_rcode, inplace_cb_reply_local_call(), LDNS_RR_CLASS_CH, LDNS_RR_TYPE_TXT, module_env::now_tv, edns_data::opt_list_inplace_cb_out, query_dname_len(), worker::scratchpad, sldns_buffer_begin(), sldns_buffer_capacity(), sldns_buffer_clear(), sldns_buffer_flip(), sldns_buffer_limit(), sldns_buffer_position(), sldns_buffer_skip(), sldns_buffer_write(), sldns_buffer_write_u16(), sldns_buffer_write_u16_at(), sldns_buffer_write_u32(), sldns_buffer_write_u8(), and edns_data::udp_size.
Referenced by chaos_replyonestr(), chaos_replystr(), and chaos_trustanchor().
|
static |
Reply with one string.
References chaos_replyonestr(), and chaos_replystr().
Referenced by answer_chaos(), and chaos_replyonestr().
|
static |
Create CH class trustanchor answer.
| pkt | buffer |
| edns | edns reply information. |
| w | worker with scratch region. |
| repinfo | reply information for a communication point. |
References anchor_list_keytags(), module_env::anchors, chaos_replystr(), chaos_trustanchor(), worker::env, trust_anchor::lock, val_anchors::lock, trust_anchor::name, trust_anchor::namelen, module_env::need_to_validate, RBTREE_FOR, regional_alloc(), regional_free_all(), worker::scratchpad, sldns_wire2str_dname_buf(), and val_anchors::tree.
Referenced by answer_chaos(), and chaos_trustanchor().
|
static |
Answer CH class queries.
| w | worker |
| qinfo | query info. Pointer into packet buffer. |
| edns | edns info from query. |
| repinfo | reply information for a communication point. |
| pkt | packet buffer. |
References answer_chaos(), module_env::cfg, chaos_replyonestr(), chaos_trustanchor(), worker::env, config_file::hide_identity, config_file::hide_trustanchor, config_file::hide_version, config_file::identity, LDNS_RR_TYPE_ANY, LDNS_RR_TYPE_TXT, log_err(), query_info::qname, query_info::qtype, query_dname_compare(), and config_file::version.
Referenced by answer_chaos(), and worker_handle_request().
|
static |
Answer notify queries.
These are notifies for authoritative zones, the reply is an ack that the notify has been received. We need to check access permission here.
| w | worker |
| qinfo | query info. Pointer into packet buffer. |
| edns | edns info from query. |
| addr | client address. |
| addrlen | client address length. |
| pkt | packet buffer. |
References answer_notify(), auth_zone_parse_notify_serial(), module_env::auth_zones, auth_zones_notify(), edns_data::bits, dname_str(), EDNS_ADVERTISED_SIZE, EDNS_ADVERTISED_VERSION, EDNS_DO, edns_data::edns_version, worker::env, error_encode(), edns_data::ext_rcode, LDNS_MAX_DOMAINLEN, log_addr(), query_info::qclass, query_info::qname, query_info::qname_len, sldns_buffer_begin(), sldns_buffer_read_u16_at(), edns_data::udp_size, VERB_DETAIL, and verbosity.
Referenced by answer_notify(), and worker_handle_request().
| int worker_handle_request | ( | struct comm_point * | c, |
| void * | arg, | ||
| int | error, | ||
| struct comm_reply * | repinfo ) |
handles callbacks from listening event interface
References sldns_struct_rr_descriptor::_name, acl_allow_cookie, acl_allow_setrd, acl_allow_snoop, acl_deny_non_local, acl_refuse_non_local, unbound_socket::addr, addr_to_str(), unbound_socket::addrlen, ub_server_stats::ans_expired, ub_server_stats::ans_secure, answer_chaos(), answer_from_cache(), answer_norec_from_cache(), answer_notify(), module_env::auth_zones, auth_zones_downstream_answer(), BIT_TC, comm_point::buffer, comm_reply::c, daemon::cfg, module_env::cfg, comm_reply::client_addr, comm_reply::client_addrlen, comm_point_drop_reply(), edns_data::cookie_present, daemon::cookie_secrets, edns_data::cookie_valid, worker::daemon, lruhash_entry::data, packed_rrset_key::dname, dname_str(), dnsc_handle_curved_request(), config_file::do_answer_cookie, config_file::ede, EDNS_ADVERTISED_SIZE, EDNS_ADVERTISED_VERSION, edns_bypass_cache_stage(), EDNS_OPT_LIST_APPEND_EDE, edns_data::edns_present, EDNS_RCODE_BADVERS, edns_data::edns_version, worker::env, error_encode(), ub_server_stats::extended, extended_error_encode(), get_cname_target(), config_file::harden_short_bufsize, LDNS_EXT_RCODE_BADCOOKIE, LDNS_MAX_DOMAINLEN, LDNS_RR_CLASS_CH, LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, LDNS_RR_TYPE_ANY, LDNS_RR_TYPE_MAILA, LDNS_RR_TYPE_MAILB, LDNS_RR_TYPE_OPT, LDNS_RR_TYPE_TXT, query_info::local_alias, local_alias_shallow_copy_qname(), daemon::local_zones, local_zones_answer(), lruhash_entry::lock, log_addr(), config_file::log_destaddr, log_err(), config_file::log_queries, log_query_in(), config_file::log_replies, log_reply_info(), ub_server_stats::max_query_time_us, comm_reply::max_udp_size, module_env::mesh, mesh_new_client(), module_env::msg_cache, NETEVENT_DONE, NETEVENT_NOERROR, NORMAL_UDP_SIZE, module_env::now, module_env::now_tv, ub_server_stats::num_queries, ub_server_stats::num_queries_ip_ratelimited, ub_server_stats::num_queries_timed_out, ub_server_stats::num_query_dnscrypt_cert, ub_server_stats::num_query_dnscrypt_cleartext, ub_server_stats::num_query_dnscrypt_crypted, ub_server_stats::num_query_dnscrypt_crypted_malformed, config_file::num_tags, edns_data::opt_list_in, edns_data::opt_list_inplace_cb_out, edns_data::opt_list_out, parse_edns_from_query_pkt(), config_file::prefetch, reply_info::prefetch_ttl, query_info::qclass, query_info::qname, query_info::qname_len, query_info::qtype, ub_server_stats::qtype, query_error(), query_info_hash(), query_info_parse(), comm_point::recv_tv, regional_free_all(), comm_reply::remote_addr, comm_reply::remote_addrlen, reply_and_prefetch(), ub_packed_rrset_key::rk, rpz_callback_from_worker_request(), local_rrset::rrset, worker::scratchpad, config_file::serve_expired, reply_info::serve_expired_norec_ttl, server_stats_downstream_cookie(), server_stats_insquery(), server_stats_insrcode(), server_stats_querymiss(), slabhash_lookup(), sldns_buffer_begin(), sldns_buffer_capacity(), sldns_buffer_copy(), sldns_buffer_limit(), sldns_buffer_read_u16_at(), sldns_buffer_rewind(), sldns_rr_descript(), config_file::sock_queue_timeout, comm_point::socket, comm_point::ssl, worker::stats, acl_addr::tag_actions, acl_addr::tag_actions_size, acl_addr::tag_datas, acl_addr::tag_datas_size, acl_addr::taglen, acl_addr::taglist, config_file::tagname, timeval_subtract(), reply_info::ttl, TTL_IS_EXPIRED, comm_point::type, edns_data::udp_size, daemon::use_response_ip, daemon::use_rpz, VERB_ALGO, VERB_CLIENT, VERB_QUERY, verbose(), verbosity, worker_check_request(), worker_err_ratelimit(), worker_handle_request(), and worker_mem_report().
Referenced by fptr_whitelist_comm_point(), worker_handle_control_cmd(), worker_handle_request(), and worker_init().
| void worker_sighandler | ( | int | sig, |
| void * | arg ) |
Worker signal handler function.
User argument is the worker itself.
| sig | signal number. |
| arg | the worker (main worker) that handles signals. |
References worker::base, comm_base_exit(), worker::need_to_exit, and worker_sighandler().
Referenced by fptr_whitelist_comm_signal(), libworker_handle_control_cmd(), signal_handling_playback(), worker_init(), and worker_sighandler().
|
static |
restart statistics timer for worker, if enabled
References module_env::cfg, comm_timer_set(), worker::daemon, worker::env, log_err(), config_file::stat_interval, daemon::stat_time_offset, daemon::stat_time_specific, worker::stat_timer, timeval_subtract(), and worker_restart_timer().
Referenced by worker_init(), worker_restart_timer(), and worker_stat_timer_cb().
| void worker_stat_timer_cb | ( | void * | arg | ) |
statistics timer callback handler
References daemon::cfg, worker::daemon, worker::env, module_env::mesh, mesh_stats(), server_stats_log(), config_file::shm_enable, config_file::stat_cumulative, worker::stats, worker::thread_num, worker_mem_report(), worker_restart_timer(), worker_stat_timer_cb(), and worker_stats_clear().
Referenced by fptr_whitelist_comm_timer(), worker_handle_control_cmd(), worker_init(), and worker_stat_timer_cb().
| void worker_probe_timer_cb | ( | void * | arg | ) |
probe timer callback handler
References autr_probe_timer(), comm_timer_set(), worker::env, module_env::probe_timer, and worker_probe_timer_cb().
Referenced by fptr_whitelist_comm_timer(), worker_handle_control_cmd(), worker_init(), and worker_probe_timer_cb().
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. |
References worker::cmd, worker::daemon, log_err(), daemon::rand, worker::rndstate, worker::thread_num, tube_create(), tube_delete(), ub_initstate(), and worker_create().
Referenced by daemon_create_workers(), and worker_create().
| 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::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, fatal_exit(), 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, 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(), 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(), daemon::shared_ports, 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_init(), 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(), thread_start(), and worker_init().
| void worker_work | ( | struct worker * | worker | ) |
Make worker work.
References worker::base, comm_base_dispatch(), and worker_work().
Referenced by daemon_fork(), thread_start(), and worker_work().
| void worker_delete | ( | struct worker * | worker | ) |
Delete worker.
References worker::back, worker::base, daemon::cfg, worker::cmd, comm_base_delete(), comm_signal_delete(), comm_timer_delete(), worker::comsig, worker::daemon, config_file::dnstap, dt_io_thread_stop(), worker::env, worker::front, listen_delete(), log_thread_set(), module_env::mesh, mesh_delete(), mesh_stats(), outside_network_delete(), outside_network_quit_prepare(), module_env::probe_timer, regional_destroy(), worker::rndstate, module_env::scratch, module_env::scratch_buffer, worker::scratchpad, server_stats_log(), sldns_buffer_free(), worker::stat_timer, worker::stats, worker::thread_num, tube_delete(), ub_randfree(), VERB_OPS, verbosity, worker_delete(), worker_mem_report(), and wsvc_desetup_worker().
Referenced by daemon_cleanup(), worker_delete(), and worker_init().
| struct outbound_entry * worker_send_query | ( | struct query_info * | qinfo, |
| uint16_t | flags, | ||
| int | dnssec, | ||
| int | want_dnssec, | ||
| int | nocaps, | ||
| int | check_ratelimit, | ||
| struct sockaddr_storage * | addr, | ||
| socklen_t | addrlen, | ||
| uint8_t * | zone, | ||
| size_t | zonelen, | ||
| int | tcp_upstream, | ||
| int | ssl_upstream, | ||
| char * | tls_auth_name, | ||
| struct module_qstate * | q, | ||
| int * | was_ratelimited, | ||
| int * | ratelimit_incremented ) |
Worker service routine to send serviced queries to authoritative servers.
| qinfo | query info. |
| flags | host order flags word, with opcode and CD bit. |
| dnssec | if set, EDNS record will have DO bit set. |
| want_dnssec | signatures needed. |
| nocaps | ignore capsforid(if in config), do not perturb qname. |
| check_ratelimit | if set, will check ratelimit before sending out. |
| addr | where to. |
| addrlen | length of addr. |
| zone | wireformat dname of the zone. |
| zonelen | length of zone name. |
| tcp_upstream | use TCP for upstream queries. |
| ssl_upstream | use SSL for upstream queries. |
| tls_auth_name | if ssl_upstream, use this name with TLS authentication. |
| q | which query state to reactivate upon return. |
| was_ratelimited | it will signal back if the query failed to pass the ratelimit check. |
| ratelimit_incremented | set to true if the ratelimit counter was increased. |
References worker::back, module_qstate::env, outnet_serviced_query(), outbound_entry::qsent, outbound_entry::qstate, module_qstate::region, regional_alloc(), outside_network::udp_buff, module_env::worker, worker_handle_service_reply(), and worker_send_query().
Referenced by fptr_whitelist_modenv_send_query(), libworker_handle_control_cmd(), worker_init(), and worker_send_query().
| void worker_alloc_cleanup | ( | void * | arg | ) |
cleanup the cache to remove all rrset IDs from it, arg is worker
References worker::env, module_env::msg_cache, module_env::rrset_cache, slabhash_clear(), rrset_cache::table, and worker_alloc_cleanup().
Referenced by fptr_whitelist_alloc_cleanup(), worker_alloc_cleanup(), worker_handle_control_cmd(), and worker_init().
| void worker_stats_clear | ( | struct worker * | worker | ) |
Init worker stats - includes server_stats_init, outside network and mesh.
| 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, outside_network::unwanted_replies, and worker_stats_clear().
Referenced by do_flush_stats(), server_stats_compile(), worker_stat_timer_cb(), and worker_stats_clear().
| void worker_start_accept | ( | void * | arg | ) |
start accept callback handler
References worker::daemon, daemon_remote_start_accept(), worker::front, listen_start_accept(), daemon::rc, worker::thread_num, and worker_start_accept().
Referenced by fptr_whitelist_start_accept(), worker_handle_control_cmd(), worker_init(), and worker_start_accept().
| void worker_stop_accept | ( | void * | arg | ) |
stop accept callback handler
References worker::daemon, daemon_remote_stop_accept(), worker::front, listen_stop_accept(), daemon::rc, worker::thread_num, and worker_stop_accept().
Referenced by fptr_whitelist_stop_accept(), worker_handle_control_cmd(), worker_init(), and worker_stop_accept().