2 * libunbound/worker.c - worker thread or process that resolves
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * This file contains the worker process or thread that performs
40 * the DNS resolving and validation. The worker is called by a procedure
41 * and if in the background continues until exit, if in the foreground
42 * returns from the procedure when done.
46 #include <openssl/ssl.h>
48 #include "libunbound/libworker.h"
49 #include "libunbound/context.h"
50 #include "libunbound/unbound.h"
51 #include "libunbound/worker.h"
52 #include "libunbound/unbound-event.h"
53 #include "services/outside_network.h"
54 #include "services/mesh.h"
55 #include "services/localzone.h"
56 #include "services/cache/rrset.h"
57 #include "services/outbound_list.h"
58 #include "util/fptr_wlist.h"
59 #include "util/module.h"
60 #include "util/regional.h"
61 #include "util/random.h"
62 #include "util/config_file.h"
63 #include "util/netevent.h"
64 #include "util/storage/lookup3.h"
65 #include "util/storage/slabhash.h"
66 #include "util/net_help.h"
67 #include "util/data/dname.h"
68 #include "util/data/msgreply.h"
69 #include "util/data/msgencode.h"
70 #include "util/tube.h"
71 #include "iterator/iter_fwd.h"
72 #include "iterator/iter_hints.h"
73 #include "sldns/sbuffer.h"
74 #include "sldns/str2wire.h"
76 /** handle new query command for bg worker */
77 static void handle_newq(struct libworker* w, uint8_t* buf, uint32_t len);
79 /** delete libworker env */
81 libworker_delete_env(struct libworker* w)
84 outside_network_quit_prepare(w->back);
85 mesh_delete(w->env->mesh);
86 context_release_alloc(w->ctx, w->env->alloc,
87 !w->is_bg || w->is_bg_thread);
88 sldns_buffer_free(w->env->scratch_buffer);
89 regional_destroy(w->env->scratch);
90 forwards_delete(w->env->fwds);
91 hints_delete(w->env->hints);
92 ub_randfree(w->env->rnd);
96 SSL_CTX_free(w->sslctx);
98 outside_network_delete(w->back);
101 /** delete libworker struct */
103 libworker_delete(struct libworker* w)
106 libworker_delete_env(w);
107 comm_base_delete(w->base);
112 libworker_delete_event(struct libworker* w)
115 libworker_delete_env(w);
116 comm_base_delete_no_base(w->base);
120 /** setup fresh libworker struct */
121 static struct libworker*
122 libworker_setup(struct ub_ctx* ctx, int is_bg, struct ub_event_base* eb)
125 struct libworker* w = (struct libworker*)calloc(1, sizeof(*w));
126 struct config_file* cfg = ctx->env->cfg;
132 w->env = (struct module_env*)malloc(sizeof(*w->env));
138 w->env->alloc = context_obtain_alloc(ctx, !w->is_bg || w->is_bg_thread);
143 w->thread_num = w->env->alloc->thread_num;
144 alloc_set_id_cleanup(w->env->alloc, &libworker_alloc_cleanup, w);
145 if(!w->is_bg || w->is_bg_thread) {
146 lock_basic_lock(&ctx->cfglock);
148 w->env->scratch = regional_create_custom(cfg->msg_buffer_size);
149 w->env->scratch_buffer = sldns_buffer_new(cfg->msg_buffer_size);
150 w->env->fwds = forwards_create();
151 if(w->env->fwds && !forwards_apply_cfg(w->env->fwds, cfg)) {
152 forwards_delete(w->env->fwds);
155 w->env->hints = hints_create();
156 if(w->env->hints && !hints_apply_cfg(w->env->hints, cfg)) {
157 hints_delete(w->env->hints);
158 w->env->hints = NULL;
160 if(cfg->ssl_upstream) {
161 w->sslctx = connect_sslctx_create(NULL, NULL, NULL);
163 /* to make the setup fail after unlock */
164 hints_delete(w->env->hints);
165 w->env->hints = NULL;
168 if(!w->is_bg || w->is_bg_thread) {
169 lock_basic_unlock(&ctx->cfglock);
171 if(!w->env->scratch || !w->env->scratch_buffer || !w->env->fwds ||
176 w->env->worker = (struct worker*)w;
177 w->env->probe_timer = NULL;
178 seed = (unsigned int)time(NULL) ^ (unsigned int)getpid() ^
179 (((unsigned int)w->thread_num)<<17);
180 seed ^= (unsigned int)w->env->alloc->next_id;
181 if(!w->is_bg || w->is_bg_thread) {
182 lock_basic_lock(&ctx->cfglock);
184 if(!(w->env->rnd = ub_initstate(seed, ctx->seed_rnd))) {
185 if(!w->is_bg || w->is_bg_thread) {
186 lock_basic_unlock(&ctx->cfglock);
192 if(!w->is_bg || w->is_bg_thread) {
193 lock_basic_unlock(&ctx->cfglock);
196 /* primitive lockout for threading: if it overwrites another
197 * thread it is like wiping the cache (which is likely empty
199 /* note we are holding the ctx lock in normal threaded
200 * cases so that is solved properly, it is only for many ctx
201 * in different threads that this may clash */
202 static int done_raninit = 0;
205 hash_set_raninit((uint32_t)ub_random(w->env->rnd));
211 w->base = comm_base_create_event(eb);
212 else w->base = comm_base_create(0);
217 if(!w->is_bg || w->is_bg_thread) {
218 lock_basic_lock(&ctx->cfglock);
220 numports = cfg_condense_ports(cfg, &ports);
222 int locked = !w->is_bg || w->is_bg_thread;
225 lock_basic_unlock(&ctx->cfglock);
229 w->back = outside_network_create(w->base, cfg->msg_buffer_size,
230 (size_t)cfg->outgoing_num_ports, cfg->out_ifs,
231 cfg->num_out_ifs, cfg->do_ip4, cfg->do_ip6,
232 cfg->do_tcp?cfg->outgoing_num_tcp:0,
233 w->env->infra_cache, w->env->rnd, cfg->use_caps_bits_for_id,
234 ports, numports, cfg->unwanted_threshold,
235 cfg->outgoing_tcp_mss,
236 &libworker_alloc_cleanup, w, cfg->do_udp, w->sslctx,
237 cfg->delay_close, NULL);
238 if(!w->is_bg || w->is_bg_thread) {
239 lock_basic_unlock(&ctx->cfglock);
246 w->env->mesh = mesh_create(&ctx->mods, w->env);
251 w->env->send_query = &libworker_send_query;
252 w->env->detach_subs = &mesh_detach_subs;
253 w->env->attach_sub = &mesh_attach_sub;
254 w->env->kill_sub = &mesh_state_delete;
255 w->env->detect_cycle = &mesh_detect_cycle;
256 comm_base_timept(w->base, &w->env->now, &w->env->now_tv);
260 struct libworker* libworker_create_event(struct ub_ctx* ctx,
261 struct ub_event_base* eb)
263 return libworker_setup(ctx, 0, eb);
266 /** handle cancel command for bg worker */
268 handle_cancel(struct libworker* w, uint8_t* buf, uint32_t len)
271 if(w->is_bg_thread) {
272 lock_basic_lock(&w->ctx->cfglock);
273 q = context_deserialize_cancel(w->ctx, buf, len);
274 lock_basic_unlock(&w->ctx->cfglock);
276 q = context_deserialize_cancel(w->ctx, buf, len);
279 /* probably simply lookup failed, i.e. the message had been
280 * processed and answered before the cancel arrived */
287 /** do control command coming into bg server */
289 libworker_do_cmd(struct libworker* w, uint8_t* msg, uint32_t len)
291 switch(context_serial_getcmd(msg, len)) {
293 case UB_LIBCMD_ANSWER:
294 log_err("unknown command for bg worker %d",
295 (int)context_serial_getcmd(msg, len));
296 /* and fall through to quit */
299 comm_base_exit(w->base);
301 case UB_LIBCMD_NEWQUERY:
302 handle_newq(w, msg, len);
304 case UB_LIBCMD_CANCEL:
305 handle_cancel(w, msg, len);
310 /** handle control command coming into server */
312 libworker_handle_control_cmd(struct tube* ATTR_UNUSED(tube),
313 uint8_t* msg, size_t len, int err, void* arg)
315 struct libworker* w = (struct libworker*)arg;
319 /* it is of no use to go on, exit */
320 comm_base_exit(w->base);
323 libworker_do_cmd(w, msg, len); /* also frees the buf */
326 /** the background thread func */
328 libworker_dobg(void* arg)
332 struct libworker* w = (struct libworker*)arg;
335 log_err("libunbound bg worker init failed, nomem");
339 log_thread_set(&w->thread_num);
340 #ifdef THREADS_DISABLED
343 /* close non-used parts of the pipes */
344 tube_close_write(ctx->qq_pipe);
345 tube_close_read(ctx->rr_pipe);
347 if(!tube_setup_bg_listen(ctx->qq_pipe, w->base,
348 libworker_handle_control_cmd, w)) {
349 log_err("libunbound bg worker init failed, no bglisten");
352 if(!tube_setup_bg_write(ctx->rr_pipe, w->base)) {
353 log_err("libunbound bg worker init failed, no bgwrite");
358 comm_base_dispatch(w->base);
362 tube_remove_bg_listen(w->ctx->qq_pipe);
363 tube_remove_bg_write(w->ctx->rr_pipe);
365 (void)tube_write_msg(ctx->rr_pipe, (uint8_t*)&m,
366 (uint32_t)sizeof(m), 0);
367 #ifdef THREADS_DISABLED
368 /* close pipes from forked process before exit */
369 tube_close_read(ctx->qq_pipe);
370 tube_close_write(ctx->rr_pipe);
375 int libworker_bg(struct ub_ctx* ctx)
378 /* fork or threadcreate */
379 lock_basic_lock(&ctx->cfglock);
381 lock_basic_unlock(&ctx->cfglock);
382 w = libworker_setup(ctx, 1, NULL);
383 if(!w) return UB_NOMEM;
385 #ifdef ENABLE_LOCK_CHECKS
386 w->thread_num = 1; /* for nicer DEBUG checklocks */
388 ub_thread_create(&ctx->bg_tid, libworker_dobg, w);
390 lock_basic_unlock(&ctx->cfglock);
392 /* no fork on windows */
394 #else /* HAVE_FORK */
395 switch((ctx->bg_pid=fork())) {
397 w = libworker_setup(ctx, 1, NULL);
398 if(!w) fatal_exit("out of memory");
399 /* close non-used parts of the pipes */
400 tube_close_write(ctx->qq_pipe);
401 tube_close_read(ctx->rr_pipe);
402 (void)libworker_dobg(w);
408 /* close non-used parts, so that the worker
409 * bgprocess gets 'pipe closed' when the
410 * main process exits */
411 tube_close_read(ctx->qq_pipe);
412 tube_close_write(ctx->rr_pipe);
415 #endif /* HAVE_FORK */
420 /** get msg reply struct (in temp region) */
421 static struct reply_info*
422 parse_reply(sldns_buffer* pkt, struct regional* region, struct query_info* qi)
424 struct reply_info* rep;
425 struct msg_parse* msg;
426 if(!(msg = regional_alloc(region, sizeof(*msg)))) {
429 memset(msg, 0, sizeof(*msg));
430 sldns_buffer_set_position(pkt, 0);
431 if(parse_packet(pkt, msg, region) != 0)
433 if(!parse_create_msg(pkt, msg, NULL, qi, &rep, region)) {
439 /** insert canonname */
441 fill_canon(struct ub_result* res, uint8_t* s)
445 res->canonname = strdup(buf);
446 return res->canonname != 0;
449 /** fill data into result */
451 fill_res(struct ub_result* res, struct ub_packed_rrset_key* answer,
452 uint8_t* finalcname, struct query_info* rq, struct reply_info* rep)
455 struct packed_rrset_data* data;
459 if(!fill_canon(res, finalcname))
460 return 0; /* out of memory */
462 if(rep->rrset_count != 0)
463 res->ttl = (int)rep->ttl;
464 res->data = (char**)calloc(1, sizeof(char*));
465 res->len = (int*)calloc(1, sizeof(int));
466 return (res->data && res->len);
468 data = (struct packed_rrset_data*)answer->entry.data;
469 if(query_dname_compare(rq->qname, answer->rk.dname) != 0) {
470 if(!fill_canon(res, answer->rk.dname))
471 return 0; /* out of memory */
472 } else res->canonname = NULL;
473 res->data = (char**)calloc(data->count+1, sizeof(char*));
474 res->len = (int*)calloc(data->count+1, sizeof(int));
475 if(!res->data || !res->len)
476 return 0; /* out of memory */
477 for(i=0; i<data->count; i++) {
478 /* remove rdlength from rdata */
479 res->len[i] = (int)(data->rr_len[i] - 2);
480 res->data[i] = memdup(data->rr_data[i]+2, (size_t)res->len[i]);
482 return 0; /* out of memory */
484 /* ttl for positive answers, from CNAME and answer RRs */
485 if(data->count != 0) {
487 res->ttl = (int)data->ttl;
488 for(j=0; j<rep->an_numrrsets; j++) {
489 struct packed_rrset_data* d =
490 (struct packed_rrset_data*)rep->rrsets[j]->
492 if((int)d->ttl < res->ttl)
493 res->ttl = (int)d->ttl;
496 /* ttl for negative answers */
497 if(data->count == 0 && rep->rrset_count != 0)
498 res->ttl = (int)rep->ttl;
499 res->data[data->count] = NULL;
500 res->len[data->count] = 0;
504 /** fill result from parsed message, on error fills servfail */
506 libworker_enter_result(struct ub_result* res, sldns_buffer* buf,
507 struct regional* temp, enum sec_status msg_security)
509 struct query_info rq;
510 struct reply_info* rep;
511 res->rcode = LDNS_RCODE_SERVFAIL;
512 rep = parse_reply(buf, temp, &rq);
514 log_err("cannot parse buf");
515 return; /* error parsing buf, or out of memory */
517 if(!fill_res(res, reply_find_answer_rrset(&rq, rep),
518 reply_find_final_cname_target(&rq, rep), &rq, rep))
519 return; /* out of memory */
520 /* rcode, havedata, nxdomain, secure, bogus */
521 res->rcode = (int)FLAGS_GET_RCODE(rep->flags);
522 if(res->data && res->data[0])
524 if(res->rcode == LDNS_RCODE_NXDOMAIN)
526 if(msg_security == sec_status_secure)
528 if(msg_security == sec_status_bogus)
532 /** fillup fg results */
534 libworker_fillup_fg(struct ctx_query* q, int rcode, sldns_buffer* buf,
535 enum sec_status s, char* why_bogus)
538 q->res->why_bogus = strdup(why_bogus);
540 q->res->rcode = rcode;
545 q->res->rcode = LDNS_RCODE_SERVFAIL;
547 q->msg = memdup(sldns_buffer_begin(buf), sldns_buffer_limit(buf));
548 q->msg_len = sldns_buffer_limit(buf);
550 return; /* the error is in the rcode */
553 /* canonname and results */
555 libworker_enter_result(q->res, buf, q->w->env->scratch, s);
559 libworker_fg_done_cb(void* arg, int rcode, sldns_buffer* buf, enum sec_status s,
562 struct ctx_query* q = (struct ctx_query*)arg;
563 /* fg query is done; exit comm base */
564 comm_base_exit(q->w->base);
566 libworker_fillup_fg(q, rcode, buf, s, why_bogus);
569 /** setup qinfo and edns */
571 setup_qinfo_edns(struct libworker* w, struct ctx_query* q,
572 struct query_info* qinfo, struct edns_data* edns)
574 qinfo->qtype = (uint16_t)q->res->qtype;
575 qinfo->qclass = (uint16_t)q->res->qclass;
576 qinfo->qname = sldns_str2wire_dname(q->res->qname, &qinfo->qname_len);
580 edns->edns_present = 1;
582 edns->edns_version = 0;
583 edns->bits = EDNS_DO;
584 edns->opt_list = NULL;
585 if(sldns_buffer_capacity(w->back->udp_buff) < 65535)
586 edns->udp_size = (uint16_t)sldns_buffer_capacity(
588 else edns->udp_size = 65535;
592 int libworker_fg(struct ub_ctx* ctx, struct ctx_query* q)
594 struct libworker* w = libworker_setup(ctx, 0, NULL);
595 uint16_t qflags, qid;
596 struct query_info qinfo;
597 struct edns_data edns;
600 if(!setup_qinfo_edns(w, q, &qinfo, &edns)) {
607 /* see if there is a fixed answer */
608 sldns_buffer_write_u16_at(w->back->udp_buff, 0, qid);
609 sldns_buffer_write_u16_at(w->back->udp_buff, 2, qflags);
610 if(local_zones_answer(ctx->local_zones, &qinfo, &edns,
611 w->back->udp_buff, w->env->scratch, NULL)) {
612 regional_free_all(w->env->scratch);
613 libworker_fillup_fg(q, LDNS_RCODE_NOERROR,
614 w->back->udp_buff, sec_status_insecure, NULL);
619 /* process new query */
620 if(!mesh_new_callback(w->env->mesh, &qinfo, qflags, &edns,
621 w->back->udp_buff, qid, libworker_fg_done_cb, q)) {
628 comm_base_dispatch(w->base);
635 libworker_event_done_cb(void* arg, int rcode, sldns_buffer* buf,
636 enum sec_status s, char* why_bogus)
638 struct ctx_query* q = (struct ctx_query*)arg;
639 ub_event_callback_t cb = (ub_event_callback_t)q->cb;
640 void* cb_arg = q->cb_arg;
641 int cancelled = q->cancelled;
644 struct ub_ctx* ctx = q->w->ctx;
645 lock_basic_lock(&ctx->cfglock);
646 (void)rbtree_delete(&ctx->queries, q->node.key);
648 context_query_delete(q);
649 lock_basic_unlock(&ctx->cfglock);
654 if(s == sec_status_bogus)
656 else if(s == sec_status_secure)
658 (*cb)(cb_arg, rcode, (void*)sldns_buffer_begin(buf),
659 (int)sldns_buffer_limit(buf), sec, why_bogus);
663 int libworker_attach_mesh(struct ub_ctx* ctx, struct ctx_query* q,
666 struct libworker* w = ctx->event_worker;
667 uint16_t qflags, qid;
668 struct query_info qinfo;
669 struct edns_data edns;
672 if(!setup_qinfo_edns(w, q, &qinfo, &edns))
677 /* see if there is a fixed answer */
678 sldns_buffer_write_u16_at(w->back->udp_buff, 0, qid);
679 sldns_buffer_write_u16_at(w->back->udp_buff, 2, qflags);
680 if(local_zones_answer(ctx->local_zones, &qinfo, &edns,
681 w->back->udp_buff, w->env->scratch, NULL)) {
682 regional_free_all(w->env->scratch);
684 libworker_event_done_cb(q, LDNS_RCODE_NOERROR,
685 w->back->udp_buff, sec_status_insecure, NULL);
688 /* process new query */
690 *async_id = q->querynum;
691 if(!mesh_new_callback(w->env->mesh, &qinfo, qflags, &edns,
692 w->back->udp_buff, qid, libworker_event_done_cb, q)) {
700 /** add result to the bg worker result queue */
702 add_bg_result(struct libworker* w, struct ctx_query* q, sldns_buffer* pkt,
703 int err, char* reason)
708 /* serialize and delete unneeded q */
709 if(w->is_bg_thread) {
710 lock_basic_lock(&w->ctx->cfglock);
712 q->res->why_bogus = strdup(reason);
714 q->msg_len = sldns_buffer_remaining(pkt);
715 q->msg = memdup(sldns_buffer_begin(pkt), q->msg_len);
717 msg = context_serialize_answer(q, UB_NOMEM,
719 else msg = context_serialize_answer(q, err,
721 } else msg = context_serialize_answer(q, err, NULL, &len);
722 lock_basic_unlock(&w->ctx->cfglock);
725 q->res->why_bogus = strdup(reason);
726 msg = context_serialize_answer(q, err, pkt, &len);
727 (void)rbtree_delete(&w->ctx->queries, q->node.key);
729 context_query_delete(q);
733 log_err("out of memory for async answer");
736 if(!tube_queue_item(w->ctx->rr_pipe, msg, len)) {
737 log_err("out of memory for async answer");
743 libworker_bg_done_cb(void* arg, int rcode, sldns_buffer* buf, enum sec_status s,
746 struct ctx_query* q = (struct ctx_query*)arg;
749 if(q->w->is_bg_thread) {
751 struct ub_ctx* ctx = q->w->ctx;
752 lock_basic_lock(&ctx->cfglock);
753 (void)rbtree_delete(&ctx->queries, q->node.key);
755 context_query_delete(q);
756 lock_basic_unlock(&ctx->cfglock);
758 /* cancelled, do not give answer */
763 buf = q->w->env->scratch_buffer;
765 error_encode(buf, rcode, NULL, 0, BIT_RD, NULL);
767 add_bg_result(q->w, q, buf, UB_NOERROR, why_bogus);
771 /** handle new query command for bg worker */
773 handle_newq(struct libworker* w, uint8_t* buf, uint32_t len)
775 uint16_t qflags, qid;
776 struct query_info qinfo;
777 struct edns_data edns;
779 if(w->is_bg_thread) {
780 lock_basic_lock(&w->ctx->cfglock);
781 q = context_lookup_new_query(w->ctx, buf, len);
782 lock_basic_unlock(&w->ctx->cfglock);
784 q = context_deserialize_new_query(w->ctx, buf, len);
788 log_err("failed to deserialize newq");
791 if(!setup_qinfo_edns(w, q, &qinfo, &edns)) {
792 add_bg_result(w, q, NULL, UB_SYNTAX, NULL);
797 /* see if there is a fixed answer */
798 sldns_buffer_write_u16_at(w->back->udp_buff, 0, qid);
799 sldns_buffer_write_u16_at(w->back->udp_buff, 2, qflags);
800 if(local_zones_answer(w->ctx->local_zones, &qinfo, &edns,
801 w->back->udp_buff, w->env->scratch, NULL)) {
802 regional_free_all(w->env->scratch);
803 q->msg_security = sec_status_insecure;
804 add_bg_result(w, q, w->back->udp_buff, UB_NOERROR, NULL);
809 /* process new query */
810 if(!mesh_new_callback(w->env->mesh, &qinfo, qflags, &edns,
811 w->back->udp_buff, qid, libworker_bg_done_cb, q)) {
812 add_bg_result(w, q, NULL, UB_NOMEM, NULL);
817 void libworker_alloc_cleanup(void* arg)
819 struct libworker* w = (struct libworker*)arg;
820 slabhash_clear(&w->env->rrset_cache->table);
821 slabhash_clear(w->env->msg_cache);
824 struct outbound_entry* libworker_send_query(uint8_t* qname, size_t qnamelen,
825 uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec,
826 int want_dnssec, int nocaps, struct edns_option* opt_list,
827 struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
828 size_t zonelen, struct module_qstate* q)
830 struct libworker* w = (struct libworker*)q->env->worker;
831 struct outbound_entry* e = (struct outbound_entry*)regional_alloc(
832 q->region, sizeof(*e));
836 e->qsent = outnet_serviced_query(w->back, qname,
837 qnamelen, qtype, qclass, flags, dnssec, want_dnssec, nocaps,
838 q->env->cfg->tcp_upstream, q->env->cfg->ssl_upstream, opt_list,
839 addr, addrlen, zone, zonelen, libworker_handle_service_reply,
840 e, w->back->udp_buff);
848 libworker_handle_reply(struct comm_point* c, void* arg, int error,
849 struct comm_reply* reply_info)
851 struct module_qstate* q = (struct module_qstate*)arg;
852 struct libworker* lw = (struct libworker*)q->env->worker;
853 struct outbound_entry e;
858 mesh_report_reply(lw->env->mesh, &e, reply_info, error);
862 if(!LDNS_QR_WIRE(sldns_buffer_begin(c->buffer))
863 || LDNS_OPCODE_WIRE(sldns_buffer_begin(c->buffer)) !=
865 || LDNS_QDCOUNT(sldns_buffer_begin(c->buffer)) > 1) {
866 /* error becomes timeout for the module as if this reply
868 mesh_report_reply(lw->env->mesh, &e, reply_info,
872 mesh_report_reply(lw->env->mesh, &e, reply_info, NETEVENT_NOERROR);
877 libworker_handle_service_reply(struct comm_point* c, void* arg, int error,
878 struct comm_reply* reply_info)
880 struct outbound_entry* e = (struct outbound_entry*)arg;
881 struct libworker* lw = (struct libworker*)e->qstate->env->worker;
884 mesh_report_reply(lw->env->mesh, e, reply_info, error);
888 if(!LDNS_QR_WIRE(sldns_buffer_begin(c->buffer))
889 || LDNS_OPCODE_WIRE(sldns_buffer_begin(c->buffer)) !=
891 || LDNS_QDCOUNT(sldns_buffer_begin(c->buffer)) > 1) {
892 /* error becomes timeout for the module as if this reply
894 mesh_report_reply(lw->env->mesh, e, reply_info,
898 mesh_report_reply(lw->env->mesh, e, reply_info, NETEVENT_NOERROR);
902 /* --- fake callbacks for fptr_wlist to work --- */
903 void worker_handle_control_cmd(struct tube* ATTR_UNUSED(tube),
904 uint8_t* ATTR_UNUSED(buffer), size_t ATTR_UNUSED(len),
905 int ATTR_UNUSED(error), void* ATTR_UNUSED(arg))
910 int worker_handle_request(struct comm_point* ATTR_UNUSED(c),
911 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
912 struct comm_reply* ATTR_UNUSED(repinfo))
918 int worker_handle_reply(struct comm_point* ATTR_UNUSED(c),
919 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
920 struct comm_reply* ATTR_UNUSED(reply_info))
926 int worker_handle_service_reply(struct comm_point* ATTR_UNUSED(c),
927 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
928 struct comm_reply* ATTR_UNUSED(reply_info))
934 int remote_accept_callback(struct comm_point* ATTR_UNUSED(c),
935 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
936 struct comm_reply* ATTR_UNUSED(repinfo))
942 int remote_control_callback(struct comm_point* ATTR_UNUSED(c),
943 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
944 struct comm_reply* ATTR_UNUSED(repinfo))
950 void worker_sighandler(int ATTR_UNUSED(sig), void* ATTR_UNUSED(arg))
955 struct outbound_entry* worker_send_query(uint8_t* ATTR_UNUSED(qname),
956 size_t ATTR_UNUSED(qnamelen), uint16_t ATTR_UNUSED(qtype),
957 uint16_t ATTR_UNUSED(qclass), uint16_t ATTR_UNUSED(flags),
958 int ATTR_UNUSED(dnssec), int ATTR_UNUSED(want_dnssec),
959 int ATTR_UNUSED(nocaps), struct edns_option* ATTR_UNUSED(opt_list),
960 struct sockaddr_storage* ATTR_UNUSED(addr),
961 socklen_t ATTR_UNUSED(addrlen), uint8_t* ATTR_UNUSED(zone),
962 size_t ATTR_UNUSED(zonelen), struct module_qstate* ATTR_UNUSED(q))
969 worker_alloc_cleanup(void* ATTR_UNUSED(arg))
974 void worker_stat_timer_cb(void* ATTR_UNUSED(arg))
979 void worker_probe_timer_cb(void* ATTR_UNUSED(arg))
984 void worker_start_accept(void* ATTR_UNUSED(arg))
989 void worker_stop_accept(void* ATTR_UNUSED(arg))
994 int order_lock_cmp(const void* ATTR_UNUSED(e1), const void* ATTR_UNUSED(e2))
1001 codeline_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
1007 int replay_var_compare(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
1013 void remote_get_opt_ssl(char* ATTR_UNUSED(str), void* ATTR_UNUSED(arg))
1018 #ifdef UB_ON_WINDOWS
1020 worker_win_stop_cb(int ATTR_UNUSED(fd), short ATTR_UNUSED(ev), void*
1026 wsvc_cron_cb(void* ATTR_UNUSED(arg))
1030 #endif /* UB_ON_WINDOWS */