|
unbound 0.1
|
This file contains the worker process or thread that performs the DNS resolving and validation. More...
#include "config.h"#include "libunbound/libworker.h"#include "libunbound/context.h"#include "libunbound/unbound.h"#include "libunbound/worker.h"#include "libunbound/unbound-event.h"#include "services/outside_network.h"#include "services/mesh.h"#include "services/localzone.h"#include "services/cache/rrset.h"#include "services/outbound_list.h"#include "services/authzone.h"#include "util/fptr_wlist.h"#include "util/module.h"#include "util/regional.h"#include "util/random.h"#include "util/config_file.h"#include "util/netevent.h"#include "util/proxy_protocol.h"#include "util/storage/lookup3.h"#include "util/storage/slabhash.h"#include "util/net_help.h"#include "util/data/dname.h"#include "util/data/msgreply.h"#include "util/data/msgencode.h"#include "util/tube.h"#include "sldns/sbuffer.h"#include "sldns/str2wire.h"Functions | |
| static void | handle_newq (struct libworker *w, uint8_t *buf, uint32_t len) |
| handle new query command for bg worker | |
| static void | libworker_delete_env (struct libworker *w) |
| delete libworker env | |
| static void | libworker_delete (struct libworker *w) |
| delete libworker struct | |
| void | libworker_delete_event (struct libworker *w) |
| delete worker for event-based interface. | |
| static struct libworker * | libworker_setup (struct ub_ctx *ctx, int is_bg, struct ub_event_base *eb) |
| setup fresh libworker struct | |
| struct libworker * | libworker_create_event (struct ub_ctx *ctx, struct ub_event_base *eb) |
| create worker for event-based interface. | |
| static void | handle_cancel (struct libworker *w, uint8_t *buf, uint32_t len) |
| handle cancel command for bg worker | |
| static void | libworker_do_cmd (struct libworker *w, uint8_t *msg, uint32_t len) |
| do control command coming into bg server | |
| void | libworker_handle_control_cmd (struct tube *ATTR_UNUSED(tube), uint8_t *msg, size_t len, int err, void *arg) |
| handle control command coming into server | |
| static void * | libworker_dobg (void *arg) |
| the background thread func | |
| int | libworker_bg (struct ub_ctx *ctx) |
| Create a background worker. | |
| static int | fill_canon (struct ub_result *res, uint8_t *s) |
| insert canonname | |
| static int | fill_res (struct ub_result *res, struct ub_packed_rrset_key *answer, uint8_t *finalcname, struct query_info *rq, struct reply_info *rep) |
| fill data into result | |
| void | libworker_enter_result (struct ub_result *res, sldns_buffer *buf, struct regional *temp, enum sec_status msg_security) |
| fill result from parsed message, on error fills servfail | |
| static void | libworker_fillup_fg (struct ctx_query *q, int rcode, sldns_buffer *buf, enum sec_status s, char *why_bogus, int was_ratelimited) |
| fillup fg results | |
| void | libworker_fg_done_cb (void *arg, int rcode, sldns_buffer *buf, enum sec_status s, char *why_bogus, int was_ratelimited) |
| mesh callback with fg results | |
| static int | setup_qinfo_edns (struct libworker *w, struct ctx_query *q, struct query_info *qinfo, struct edns_data *edns) |
| setup qinfo and edns | |
| int | libworker_fg (struct ub_ctx *ctx, struct ctx_query *q) |
| Create a foreground worker. | |
| void | libworker_event_done_cb (void *arg, int rcode, sldns_buffer *buf, enum sec_status s, char *why_bogus, int was_ratelimited) |
| mesh callback with event results | |
| int | libworker_attach_mesh (struct ub_ctx *ctx, struct ctx_query *q, int *async_id) |
| Attach context_query to mesh for callback in event-driven setup. | |
| static void | add_bg_result (struct libworker *w, struct ctx_query *q, sldns_buffer *pkt, int err, char *reason, int was_ratelimited) |
| add result to the bg worker result queue | |
| void | libworker_bg_done_cb (void *arg, int rcode, sldns_buffer *buf, enum sec_status s, char *why_bogus, int was_ratelimited) |
| mesh callback with bg results | |
| void | libworker_alloc_cleanup (void *arg) |
| cleanup the cache to remove all rrset IDs from it, arg is libworker | |
| struct outbound_entry * | libworker_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. | |
| 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 | worker_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)) |
| int | worker_handle_request (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(repinfo)) |
| int | worker_handle_service_reply (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(reply_info)) |
| int | remote_accept_callback (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(repinfo)) |
| int | remote_control_callback (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(repinfo)) |
| void | worker_sighandler (int ATTR_UNUSED(sig), void *ATTR_UNUSED(arg)) |
| struct outbound_entry * | worker_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)) |
| void | worker_alloc_cleanup (void *ATTR_UNUSED(arg)) |
| void | worker_stat_timer_cb (void *ATTR_UNUSED(arg)) |
| void | worker_probe_timer_cb (void *ATTR_UNUSED(arg)) |
| void | worker_start_accept (void *ATTR_UNUSED(arg)) |
| void | worker_stop_accept (void *ATTR_UNUSED(arg)) |
| 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)) |
| int | replay_var_compare (const void *ATTR_UNUSED(a), const void *ATTR_UNUSED(b)) |
| void | remote_get_opt_ssl (char *ATTR_UNUSED(str), void *ATTR_UNUSED(arg)) |
| void | fast_reload_service_cb (int ATTR_UNUSED(fd), short ATTR_UNUSED(ev), void *ATTR_UNUSED(arg)) |
| int | fast_reload_client_callback (struct comm_point *ATTR_UNUSED(c), void *ATTR_UNUSED(arg), int ATTR_UNUSED(error), struct comm_reply *ATTR_UNUSED(repinfo)) |
This file contains the worker process or thread that performs the DNS resolving and validation.
The worker is called by a procedure and if in the background continues until exit, if in the foreground returns from the procedure when done.
|
static |
handle new query command for bg worker
References add_bg_result(), module_env::auth_zones, auth_zones_downstream_answer(), libworker::back, BIT_RD, ub_ctx::cfglock, context_deserialize_new_query(), context_lookup_new_query(), libworker::ctx, libworker::env, ub_ctx::env, handle_newq(), libworker::is_bg_thread, ub_ctx::local_zones, local_zones_answer(), log_err(), module_env::mesh, mesh_new_callback(), ctx_query::msg_security, query_info::qname, regional_free_all(), module_env::scratch, sec_status_insecure, setup_qinfo_edns(), sldns_buffer_write_u16_at(), UB_NOERROR, UB_NOMEM, UB_SYNTAX, outside_network::udp_buff, ctx_query::unique_info, and ctx_query::w.
Referenced by handle_newq(), and libworker_do_cmd().
|
static |
delete libworker env
References module_env::alloc, libworker::back, context_release_alloc(), libworker::ctx, libworker::env, libworker::is_bg, libworker::is_bg_thread, libworker_delete_env(), module_env::mesh, mesh_delete(), outside_network_delete(), outside_network_quit_prepare(), regional_destroy(), module_env::rnd, module_env::scratch, module_env::scratch_buffer, libworker::shared_ports, shared_ports_delete(), sldns_buffer_free(), libworker::sslctx, and ub_randfree().
Referenced by libworker_delete(), libworker_delete_env(), and libworker_delete_event().
|
static |
delete libworker struct
References libworker::base, comm_base_delete(), libworker_delete(), and libworker_delete_env().
Referenced by libworker_delete(), libworker_dobg(), libworker_fg(), and libworker_setup().
| void libworker_delete_event | ( | struct libworker * | w | ) |
delete worker for event-based interface.
does not free the event_base.
| w | event-based worker to delete. |
References libworker::base, comm_base_delete_no_base(), libworker_delete_env(), and libworker_delete_event().
Referenced by libworker_delete_event(), ub_ctx_delete(), and ub_ctx_set_event().
|
static |
setup fresh libworker struct
References module_env::add_sub, module_env::alloc, alloc_set_id_cleanup(), module_env::attach_sub, libworker::back, libworker::base, module_env::cfg, cfg_condense_ports(), ub_ctx::cfglock, comm_base_create_event(), comm_base_timept(), connect_sslctx_create(), context_obtain_alloc(), libworker::ctx, config_file::delay_close, module_env::detach_subs, module_env::detect_cycle, config_file::do_ip4, config_file::do_ip6, config_file::do_tcp, config_file::do_udp, libworker::env, ub_ctx::env, module_env::infra_cache, config_file::ip_dscp, libworker::is_bg, libworker::is_bg_thread, module_env::kill_sub, libworker_delete(), libworker_setup(), 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(), ub_ctx::mods, config_file::msg_buffer_size, module_env::now, module_env::now_tv, 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, regional_create_custom(), module_env::rnd, module_env::scratch, module_env::scratch_buffer, ub_ctx::seed_rnd, module_env::send_query, libworker::shared_ports, shared_ports_create(), sldns_buffer_free(), sldns_buffer_new(), libworker::sslctx, config_file::tcp_auth_query_timeout, config_file::tcp_reuse_timeout, alloc_cache::thread_num, libworker::thread_num, config_file::tls_cert_bundle, config_file::tls_use_sni, config_file::tls_win_cert, ub_initstate(), ub_random(), config_file::udp_connect, config_file::udp_upstream_without_downstream, config_file::unwanted_threshold, config_file::use_caps_bits_for_id, module_env::worker, and module_env::worker_base.
Referenced by libworker_bg(), libworker_create_event(), libworker_fg(), and libworker_setup().
| struct libworker * libworker_create_event | ( | struct ub_ctx * | ctx, |
| struct ub_event_base * | eb ) |
create worker for event-based interface.
| ctx | context with config. |
| eb | event base. |
References libworker::ctx, libworker_create_event(), and libworker_setup().
Referenced by libworker_create_event(), and ub_resolve_event().
|
static |
handle cancel command for bg worker
References ctx_query::cancelled, ub_ctx::cfglock, context_deserialize_cancel(), libworker::ctx, handle_cancel(), libworker::is_bg_thread, and ctx_query::w.
Referenced by handle_cancel(), and libworker_do_cmd().
|
static |
do control command coming into bg server
References libworker::base, comm_base_exit(), context_serial_getcmd(), handle_cancel(), handle_newq(), libworker_do_cmd(), log_err(), ctx_query::msg, UB_LIBCMD_ANSWER, UB_LIBCMD_CANCEL, UB_LIBCMD_NEWQUERY, UB_LIBCMD_QUIT, and ctx_query::w.
Referenced by libworker_do_cmd(), and libworker_handle_control_cmd().
| void libworker_handle_control_cmd | ( | struct tube * | ATTR_UNUSEDtube, |
| uint8_t * | msg, | ||
| size_t | len, | ||
| int | err, | ||
| void * | arg ) |
handle control command coming into server
References libworker::base, comm_base_exit(), and libworker_do_cmd().
|
static |
the background thread func
References libworker::base, comm_base_dispatch(), libworker::ctx, libworker::is_bg_thread, libworker_delete(), libworker_dobg(), log_err(), log_thread_set(), ub_ctx::qq_pipe, ub_ctx::rr_pipe, libworker::thread_num, tube_close_read(), tube_close_write(), tube_remove_bg_listen(), tube_remove_bg_write(), tube_setup_bg_listen(), tube_setup_bg_write(), tube_write_msg(), UB_LIBCMD_QUIT, and libworker::want_quit.
Referenced by libworker_bg(), and libworker_dobg().
| int libworker_bg | ( | struct ub_ctx * | ctx | ) |
Create a background worker.
| ctx | is updated with pid/tid of the background worker. a new allocation cache is obtained from ctx. It contains the threadnumber and unique id for further (shared) cache insertions. |
References ub_ctx::bg_pid, ub_ctx::bg_tid, ub_ctx::cfglock, libworker::ctx, ub_ctx::dothread, fatal_exit(), libworker::is_bg_thread, libworker_bg(), libworker_dobg(), libworker_setup(), ub_ctx::qq_pipe, ub_ctx::rr_pipe, libworker::thread_num, ub_ctx::thread_worker, tube_close_read(), tube_close_write(), UB_FORKFAIL, UB_NOERROR, and UB_NOMEM.
Referenced by libworker_bg(), and ub_resolve_async().
|
static |
insert canonname
References ub_result::canonname, dname_str(), fill_canon(), and LDNS_MAX_DOMAINLEN.
Referenced by fill_canon(), and fill_res().
|
static |
fill data into result
References reply_info::an_numrrsets, ub_result::canonname, packed_rrset_data::count, lruhash_entry::data, ub_result::data, packed_rrset_key::dname, ub_packed_rrset_key::entry, fill_canon(), fill_res(), ub_result::len, memdup(), query_info::qname, query_dname_compare(), ub_packed_rrset_key::rk, packed_rrset_data::rr_data, packed_rrset_data::rr_len, reply_info::rrset_count, reply_info::rrsets, packed_rrset_data::ttl, reply_info::ttl, and ub_result::ttl.
Referenced by fill_res(), and libworker_enter_result().
| void libworker_enter_result | ( | struct ub_result * | res, |
| struct sldns_buffer * | buf, | ||
| struct regional * | temp, | ||
| enum sec_status | msg_security ) |
fill result from parsed message, on error fills servfail
| res | is clear at start, filled in at end. |
| buf | contains DNS message. |
| temp | temporary buffer for parse. |
| msg_security | security status of the DNS message. On error, the res may contain a different status (out of memory is not secure, not bogus). |
References ub_result::bogus, ub_result::data, fill_res(), reply_info::flags, FLAGS_GET_RCODE, ub_result::havedata, libworker_enter_result(), log_err(), ub_result::nxdomain, parse_reply_in_temp_region(), ub_result::rcode, reply_find_answer_rrset(), reply_find_final_cname_target(), sec_status_bogus, sec_status_secure, sec_status_secure_sentinel_fail, and ub_result::secure.
Referenced by libworker_enter_result(), libworker_fillup_fg(), and process_answer_detail().
|
static |
fillup fg results
References libworker::env, libworker_enter_result(), libworker_fillup_fg(), memdup(), ctx_query::msg, ctx_query::msg_len, ctx_query::msg_security, ub_result::rcode, ctx_query::res, module_env::scratch, sec_status_unchecked, sldns_buffer_begin(), sldns_buffer_limit(), ctx_query::w, ub_result::was_ratelimited, and ub_result::why_bogus.
Referenced by libworker_fg(), libworker_fg_done_cb(), and libworker_fillup_fg().
| void libworker_fg_done_cb | ( | void * | arg, |
| int | rcode, | ||
| sldns_buffer * | buf, | ||
| enum sec_status | s, | ||
| char * | why_bogus, | ||
| int | was_ratelimited ) |
mesh callback with fg results
References libworker::base, comm_base_exit(), libworker_fillup_fg(), and ctx_query::w.
|
static |
setup qinfo and edns
References libworker::back, edns_data::bits, edns_data::cookie_present, edns_data::cookie_valid, EDNS_DO, edns_data::edns_present, edns_data::edns_version, edns_data::ext_rcode, query_info::local_alias, edns_data::opt_list_in, edns_data::opt_list_inplace_cb_out, edns_data::opt_list_out, edns_data::padding_block_size, query_info::qclass, ub_result::qclass, query_info::qname, ub_result::qname, query_info::qname_len, query_info::qtype, ub_result::qtype, ctx_query::res, setup_qinfo_edns(), sldns_buffer_capacity(), sldns_str2wire_dname(), outside_network::udp_buff, edns_data::udp_size, and ctx_query::w.
Referenced by handle_newq(), libworker_attach_mesh(), libworker_fg(), and setup_qinfo_edns().
Create a foreground worker.
This worker will join the threadpool of resolver threads. It exits when the query answer has been obtained (or error). This routine blocks until the worker is finished.
| ctx | new allocation cache obtained and returned to it. |
| q | query (result is stored in here). |
References module_env::auth_zones, auth_zones_downstream_answer(), libworker::back, libworker::base, BIT_RD, comm_base_dispatch(), libworker::ctx, libworker::env, ub_ctx::env, libworker_delete(), libworker_fg(), libworker_fillup_fg(), libworker_setup(), ub_ctx::local_zones, local_zones_answer(), module_env::mesh, mesh_new_callback(), query_info::qname, regional_free_all(), module_env::scratch, sec_status_insecure, setup_qinfo_edns(), sldns_buffer_write_u16_at(), UB_INITFAIL, UB_NOERROR, UB_NOMEM, UB_SYNTAX, outside_network::udp_buff, ctx_query::unique_info, and ctx_query::w.
Referenced by libworker_fg(), and ub_resolve().
| void libworker_event_done_cb | ( | void * | arg, |
| int | rcode, | ||
| sldns_buffer * | buf, | ||
| enum sec_status | s, | ||
| char * | why_bogus, | ||
| int | was_ratelimited ) |
mesh callback with event results
References ctx_query::cancelled, ctx_query::cb, ctx_query::cb_arg, ctx_query::cb_event, ub_ctx::cfglock, context_query_delete(), libworker::ctx, rbnode_type::key, ctx_query::node, ub_ctx::num_async, ub_ctx::queries, rbtree_delete(), sec_status_bogus, sec_status_secure, sldns_buffer_begin(), sldns_buffer_limit(), and ctx_query::w.
Attach context_query to mesh for callback in event-driven setup.
| ctx | context |
| q | context query entry |
| async_id | store query num if query takes long. |
References module_env::auth_zones, auth_zones_downstream_answer(), libworker::back, BIT_RD, libworker::ctx, libworker::env, ub_ctx::env, ub_ctx::event_worker, libworker_attach_mesh(), ub_ctx::local_zones, local_zones_answer(), module_env::mesh, mesh_new_callback(), query_info::qname, ctx_query::querynum, regional_free_all(), module_env::scratch, sec_status_insecure, setup_qinfo_edns(), sldns_buffer_write_u16_at(), UB_INITFAIL, UB_NOERROR, UB_NOMEM, UB_SYNTAX, outside_network::udp_buff, ctx_query::unique_info, and ctx_query::w.
Referenced by libworker_attach_mesh(), and ub_resolve_event().
|
static |
add result to the bg worker result queue
References add_bg_result(), ub_ctx::cfglock, context_query_delete(), context_serialize_answer(), libworker::ctx, libworker::is_bg_thread, rbnode_type::key, log_err(), memdup(), ctx_query::msg, ctx_query::msg_len, ctx_query::node, ub_ctx::num_async, ub_ctx::queries, rbtree_delete(), ctx_query::res, ub_ctx::rr_pipe, sldns_buffer_begin(), sldns_buffer_remaining(), tube_queue_item(), UB_NOMEM, libworker::want_quit, ub_result::was_ratelimited, and ub_result::why_bogus.
Referenced by add_bg_result(), handle_newq(), and libworker_bg_done_cb().
| void libworker_bg_done_cb | ( | void * | arg, |
| int | rcode, | ||
| sldns_buffer * | buf, | ||
| enum sec_status | s, | ||
| char * | why_bogus, | ||
| int | was_ratelimited ) |
mesh callback with bg results
References add_bg_result(), libworker::back, BIT_RD, ctx_query::cancelled, ub_ctx::cfglock, context_query_delete(), libworker::ctx, libworker::env, error_encode(), libworker::is_bg_thread, rbnode_type::key, ctx_query::msg_security, ctx_query::node, ub_ctx::num_async, ub_ctx::queries, rbtree_delete(), module_env::scratch_buffer, UB_NOERROR, ctx_query::w, and outside_network::want_to_quit.
| void libworker_alloc_cleanup | ( | void * | arg | ) |
cleanup the cache to remove all rrset IDs from it, arg is libworker
References libworker::env, module_env::msg_cache, module_env::rrset_cache, slabhash_clear(), and rrset_cache::table.
| struct outbound_entry * libworker_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 | delegation point name. |
| zonelen | length of zone name wireformat dname. |
| 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 libworker::back, module_qstate::env, outnet_serviced_query(), outbound_entry::qsent, outbound_entry::qstate, module_qstate::region, regional_alloc(), outside_network::udp_buff, and module_env::worker.
| 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
References comm_point::buffer, libworker::env, module_qstate::env, module_env::mesh, mesh_report_reply(), NETEVENT_NOERROR, NETEVENT_TIMEOUT, outbound_entry::qstate, sldns_buffer_begin(), and module_env::worker.