2 * daemon/worker.c - worker that handles a pending list of requests.
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 LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
39 * This file implements the worker that handles callbacks on events, for
43 #include <ldns/wire2host.h>
45 #include "util/net_help.h"
46 #include "util/random.h"
47 #include "daemon/worker.h"
48 #include "daemon/daemon.h"
49 #include "daemon/remote.h"
50 #include "daemon/acl_list.h"
51 #include "util/netevent.h"
52 #include "util/config_file.h"
53 #include "util/module.h"
54 #include "util/regional.h"
55 #include "util/storage/slabhash.h"
56 #include "services/listen_dnsport.h"
57 #include "services/outside_network.h"
58 #include "services/outbound_list.h"
59 #include "services/cache/rrset.h"
60 #include "services/cache/infra.h"
61 #include "services/cache/dns.h"
62 #include "services/mesh.h"
63 #include "services/localzone.h"
64 #include "util/data/msgparse.h"
65 #include "util/data/msgencode.h"
66 #include "util/data/dname.h"
67 #include "util/fptr_wlist.h"
68 #include "util/tube.h"
69 #include "iterator/iter_fwd.h"
70 #include "iterator/iter_hints.h"
71 #include "validator/autotrust.h"
72 #include "validator/val_anchor.h"
74 #ifdef HAVE_SYS_TYPES_H
75 # include <sys/types.h>
82 #include "winrc/win_svc.h"
85 /** Size of an UDP datagram */
86 #define NORMAL_UDP_SIZE 512 /* bytes */
89 * seconds to add to prefetch leeway. This is a TTL that expires old rrsets
90 * earlier than they should in order to put the new update into the cache.
91 * This additional value is to make sure that if not all TTLs are equal in
92 * the message to be updated(and replaced), that rrsets with up to this much
93 * extra TTL are also replaced. This means that the resulting new message
94 * will have (most likely) this TTL at least, avoiding very small 'split
95 * second' TTLs due to operators choosing relative primes for TTLs (or so).
96 * Also has to be at least one to break ties (and overwrite cached entry).
98 #define PREFETCH_EXPIRY_ADD 60
100 #ifdef UNBOUND_ALLOC_STATS
101 /** measure memory leakage */
103 debug_memleak(size_t accounted, size_t heap,
104 size_t total_alloc, size_t total_free)
107 static size_t base_heap, base_accounted, base_alloc, base_free;
108 size_t base_af, cur_af, grow_af, grow_acc;
112 base_accounted = accounted;
113 base_alloc = total_alloc;
114 base_free = total_free;
116 base_af = base_alloc - base_free;
117 cur_af = total_alloc - total_free;
118 grow_af = cur_af - base_af;
119 grow_acc = accounted - base_accounted;
120 log_info("Leakage: %d leaked. growth: %u use, %u acc, %u heap",
121 (int)(grow_af - grow_acc), (unsigned)grow_af,
122 (unsigned)grow_acc, (unsigned)(heap - base_heap));
125 /** give debug heap size indication */
127 debug_total_mem(size_t calctotal)
130 extern void* unbound_start_brk;
131 extern size_t unbound_mem_alloc, unbound_mem_freed;
133 int total = cur-unbound_start_brk;
134 log_info("Total heap memory estimate: %u total-alloc: %u "
135 "total-free: %u", (unsigned)total,
136 (unsigned)unbound_mem_alloc, (unsigned)unbound_mem_freed);
137 debug_memleak(calctotal, (size_t)total,
138 unbound_mem_alloc, unbound_mem_freed);
141 #endif /* HAVE_SBRK */
143 #endif /* UNBOUND_ALLOC_STATS */
145 /** Report on memory usage by this thread and global */
147 worker_mem_report(struct worker* ATTR_UNUSED(worker),
148 struct serviced_query* ATTR_UNUSED(cur_serv))
150 #ifdef UNBOUND_ALLOC_STATS
151 /* debug func in validator module */
152 size_t total, front, back, mesh, msg, rrset, infra, ac, superac;
153 size_t me, iter, val, anch;
155 if(verbosity < VERB_ALGO)
157 front = listen_get_mem(worker->front);
158 back = outnet_get_mem(worker->back);
159 msg = slabhash_get_mem(worker->env.msg_cache);
160 rrset = slabhash_get_mem(&worker->env.rrset_cache->table);
161 infra = infra_get_mem(worker->env.infra_cache);
162 mesh = mesh_get_mem(worker->env.mesh);
163 ac = alloc_get_mem(&worker->alloc);
164 superac = alloc_get_mem(&worker->daemon->superalloc);
165 anch = anchors_get_mem(worker->env.anchors);
168 for(i=0; i<worker->env.mesh->mods.num; i++) {
169 fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh->
170 mods.mod[i]->get_mem));
171 if(strcmp(worker->env.mesh->mods.mod[i]->name, "validator")==0)
172 val += (*worker->env.mesh->mods.mod[i]->get_mem)
174 else iter += (*worker->env.mesh->mods.mod[i]->get_mem)
177 me = sizeof(*worker) + sizeof(*worker->base) + sizeof(*worker->comsig)
178 + comm_point_get_mem(worker->cmd_com)
179 + sizeof(worker->rndstate)
180 + regional_get_mem(worker->scratchpad)
181 + sizeof(*worker->env.scratch_buffer)
182 + ldns_buffer_capacity(worker->env.scratch_buffer)
183 + forwards_get_mem(worker->env.fwds)
184 + hints_get_mem(worker->env.hints);
185 if(worker->thread_num == 0)
186 me += acl_list_get_mem(worker->daemon->acl);
188 me += serviced_get_mem(cur_serv);
190 total = front+back+mesh+msg+rrset+infra+iter+val+ac+superac+me;
191 log_info("Memory conditions: %u front=%u back=%u mesh=%u msg=%u "
192 "rrset=%u infra=%u iter=%u val=%u anchors=%u "
193 "alloccache=%u globalalloccache=%u me=%u",
194 (unsigned)total, (unsigned)front, (unsigned)back,
195 (unsigned)mesh, (unsigned)msg, (unsigned)rrset,
196 (unsigned)infra, (unsigned)iter, (unsigned)val, (unsigned)anch,
197 (unsigned)ac, (unsigned)superac, (unsigned)me);
198 debug_total_mem(total);
199 #else /* no UNBOUND_ALLOC_STATS */
202 if(verbosity < VERB_QUERY)
204 for(i=0; i<worker->env.mesh->mods.num; i++) {
205 fptr_ok(fptr_whitelist_mod_get_mem(worker->env.mesh->
206 mods.mod[i]->get_mem));
207 if(strcmp(worker->env.mesh->mods.mod[i]->name, "validator")==0)
208 val += (*worker->env.mesh->mods.mod[i]->get_mem)
211 verbose(VERB_QUERY, "cache memory msg=%u rrset=%u infra=%u val=%u",
212 (unsigned)slabhash_get_mem(worker->env.msg_cache),
213 (unsigned)slabhash_get_mem(&worker->env.rrset_cache->table),
214 (unsigned)infra_get_mem(worker->env.infra_cache),
216 #endif /* UNBOUND_ALLOC_STATS */
220 worker_send_cmd(struct worker* worker, enum worker_commands cmd)
222 uint32_t c = (uint32_t)htonl(cmd);
223 if(!tube_write_msg(worker->cmd, (uint8_t*)&c, sizeof(c), 0)) {
224 log_err("worker send cmd %d failed", (int)cmd);
229 worker_handle_reply(struct comm_point* c, void* arg, int error,
230 struct comm_reply* reply_info)
232 struct module_qstate* q = (struct module_qstate*)arg;
233 struct worker* worker = q->env->worker;
234 struct outbound_entry e;
239 mesh_report_reply(worker->env.mesh, &e, reply_info, error);
240 worker_mem_report(worker, NULL);
244 if(!LDNS_QR_WIRE(ldns_buffer_begin(c->buffer))
245 || LDNS_OPCODE_WIRE(ldns_buffer_begin(c->buffer)) !=
247 || LDNS_QDCOUNT(ldns_buffer_begin(c->buffer)) > 1) {
248 /* error becomes timeout for the module as if this reply
250 mesh_report_reply(worker->env.mesh, &e, reply_info,
252 worker_mem_report(worker, NULL);
255 mesh_report_reply(worker->env.mesh, &e, reply_info, NETEVENT_NOERROR);
256 worker_mem_report(worker, NULL);
261 worker_handle_service_reply(struct comm_point* c, void* arg, int error,
262 struct comm_reply* reply_info)
264 struct outbound_entry* e = (struct outbound_entry*)arg;
265 struct worker* worker = e->qstate->env->worker;
266 struct serviced_query *sq = e->qsent;
268 verbose(VERB_ALGO, "worker svcd callback for qstate %p", e->qstate);
270 mesh_report_reply(worker->env.mesh, e, reply_info, error);
271 worker_mem_report(worker, sq);
275 if(!LDNS_QR_WIRE(ldns_buffer_begin(c->buffer))
276 || LDNS_OPCODE_WIRE(ldns_buffer_begin(c->buffer)) !=
278 || LDNS_QDCOUNT(ldns_buffer_begin(c->buffer)) > 1) {
279 /* error becomes timeout for the module as if this reply
281 verbose(VERB_ALGO, "worker: bad reply handled as timeout");
282 mesh_report_reply(worker->env.mesh, e, reply_info,
284 worker_mem_report(worker, sq);
287 mesh_report_reply(worker->env.mesh, e, reply_info, NETEVENT_NOERROR);
288 worker_mem_report(worker, sq);
292 /** check request sanity.
293 * @param pkt: the wire packet to examine for sanity.
294 * @param worker: parameters for checking.
295 * @return error code, 0 OK, or -1 discard.
298 worker_check_request(ldns_buffer* pkt, struct worker* worker)
300 if(ldns_buffer_limit(pkt) < LDNS_HEADER_SIZE) {
301 verbose(VERB_QUERY, "request too short, discarded");
304 if(ldns_buffer_limit(pkt) > NORMAL_UDP_SIZE &&
305 worker->daemon->cfg->harden_large_queries) {
306 verbose(VERB_QUERY, "request too large, discarded");
309 if(LDNS_QR_WIRE(ldns_buffer_begin(pkt))) {
310 verbose(VERB_QUERY, "request has QR bit on, discarded");
313 if(LDNS_TC_WIRE(ldns_buffer_begin(pkt))) {
314 LDNS_TC_CLR(ldns_buffer_begin(pkt));
315 verbose(VERB_QUERY, "request bad, has TC bit on");
316 return LDNS_RCODE_FORMERR;
318 if(LDNS_OPCODE_WIRE(ldns_buffer_begin(pkt)) != LDNS_PACKET_QUERY) {
319 verbose(VERB_QUERY, "request unknown opcode %d",
320 LDNS_OPCODE_WIRE(ldns_buffer_begin(pkt)));
321 return LDNS_RCODE_NOTIMPL;
323 if(LDNS_QDCOUNT(ldns_buffer_begin(pkt)) != 1) {
324 verbose(VERB_QUERY, "request wrong nr qd=%d",
325 LDNS_QDCOUNT(ldns_buffer_begin(pkt)));
326 return LDNS_RCODE_FORMERR;
328 if(LDNS_ANCOUNT(ldns_buffer_begin(pkt)) != 0) {
329 verbose(VERB_QUERY, "request wrong nr an=%d",
330 LDNS_ANCOUNT(ldns_buffer_begin(pkt)));
331 return LDNS_RCODE_FORMERR;
333 if(LDNS_NSCOUNT(ldns_buffer_begin(pkt)) != 0) {
334 verbose(VERB_QUERY, "request wrong nr ns=%d",
335 LDNS_NSCOUNT(ldns_buffer_begin(pkt)));
336 return LDNS_RCODE_FORMERR;
338 if(LDNS_ARCOUNT(ldns_buffer_begin(pkt)) > 1) {
339 verbose(VERB_QUERY, "request wrong nr ar=%d",
340 LDNS_ARCOUNT(ldns_buffer_begin(pkt)));
341 return LDNS_RCODE_FORMERR;
347 worker_handle_control_cmd(struct tube* ATTR_UNUSED(tube), uint8_t* msg,
348 size_t len, int error, void* arg)
350 struct worker* worker = (struct worker*)arg;
351 enum worker_commands cmd;
352 if(error != NETEVENT_NOERROR) {
354 if(error == NETEVENT_CLOSED)
355 comm_base_exit(worker->base);
356 else log_info("control event: %d", error);
359 if(len != sizeof(uint32_t)) {
360 fatal_exit("bad control msg length %d", (int)len);
362 cmd = ldns_read_uint32(msg);
365 case worker_cmd_quit:
366 verbose(VERB_ALGO, "got control cmd quit");
367 comm_base_exit(worker->base);
369 case worker_cmd_stats:
370 verbose(VERB_ALGO, "got control cmd stats");
371 server_stats_reply(worker, 1);
373 case worker_cmd_stats_noreset:
374 verbose(VERB_ALGO, "got control cmd stats_noreset");
375 server_stats_reply(worker, 0);
377 case worker_cmd_remote:
378 verbose(VERB_ALGO, "got control cmd remote");
379 daemon_remote_exec(worker);
382 log_err("bad command %d", (int)cmd);
387 /** check if a delegation is secure */
388 static enum sec_status
389 check_delegation_secure(struct reply_info *rep)
391 /* return smallest security status */
393 enum sec_status sec = sec_status_secure;
395 size_t num = rep->an_numrrsets + rep->ns_numrrsets;
396 /* check if answer and authority are OK */
397 for(i=0; i<num; i++) {
398 s = ((struct packed_rrset_data*)rep->rrsets[i]->entry.data)
403 /* in additional, only unchecked triggers revalidation */
404 for(i=num; i<rep->rrset_count; i++) {
405 s = ((struct packed_rrset_data*)rep->rrsets[i]->entry.data)
407 if(s == sec_status_unchecked)
413 /** remove nonsecure from a delegation referral additional section */
415 deleg_remove_nonsecure_additional(struct reply_info* rep)
417 /* we can simply edit it, since we are working in the scratch region */
421 for(i = rep->an_numrrsets+rep->ns_numrrsets; i<rep->rrset_count; i++) {
422 s = ((struct packed_rrset_data*)rep->rrsets[i]->entry.data)
424 if(s != sec_status_secure) {
425 memmove(rep->rrsets+i, rep->rrsets+i+1,
426 sizeof(struct ub_packed_rrset_key*)*
427 (rep->rrset_count - i - 1));
435 /** answer nonrecursive query from the cache */
437 answer_norec_from_cache(struct worker* worker, struct query_info* qinfo,
438 uint16_t id, uint16_t flags, struct comm_reply* repinfo,
439 struct edns_data* edns)
441 /* for a nonrecursive query return either:
442 * o an error (servfail; we try to avoid this)
443 * o a delegation (closest we have; this routine tries that)
444 * o the answer (checked by answer_from_cache)
446 * So, grab a delegation from the rrset cache.
447 * Then check if it needs validation, if so, this routine fails,
448 * so that iterator can prime and validator can verify rrsets.
450 uint16_t udpsize = edns->udp_size;
452 time_t timenow = *worker->env.now;
453 int must_validate = (!(flags&BIT_CD) || worker->env.cfg->ignore_cd)
454 && worker->env.need_to_validate;
455 struct dns_msg *msg = NULL;
458 dp = dns_cache_find_delegation(&worker->env, qinfo->qname,
459 qinfo->qname_len, qinfo->qtype, qinfo->qclass,
460 worker->scratchpad, &msg, timenow);
461 if(!dp) { /* no delegation, need to reprime */
462 regional_free_all(worker->scratchpad);
466 switch(check_delegation_secure(msg->rep)) {
467 case sec_status_unchecked:
468 /* some rrsets have not been verified yet, go and
469 * let validator do that */
470 regional_free_all(worker->scratchpad);
472 case sec_status_bogus:
473 /* some rrsets are bogus, reply servfail */
474 edns->edns_version = EDNS_ADVERTISED_VERSION;
475 edns->udp_size = EDNS_ADVERTISED_SIZE;
477 edns->bits &= EDNS_DO;
478 error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
479 &msg->qinfo, id, flags, edns);
480 regional_free_all(worker->scratchpad);
481 if(worker->stats.extended) {
482 worker->stats.ans_bogus++;
483 worker->stats.ans_rcode[LDNS_RCODE_SERVFAIL]++;
486 case sec_status_secure:
487 /* all rrsets are secure */
488 /* remove non-secure rrsets from the add. section*/
489 if(worker->env.cfg->val_clean_additional)
490 deleg_remove_nonsecure_additional(msg->rep);
493 case sec_status_indeterminate:
494 case sec_status_insecure:
501 /* return this delegation from the cache */
502 edns->edns_version = EDNS_ADVERTISED_VERSION;
503 edns->udp_size = EDNS_ADVERTISED_SIZE;
505 edns->bits &= EDNS_DO;
506 msg->rep->flags |= BIT_QR|BIT_RA;
507 if(!reply_info_answer_encode(&msg->qinfo, msg->rep, id, flags,
508 repinfo->c->buffer, 0, 1, worker->scratchpad,
509 udpsize, edns, (int)(edns->bits & EDNS_DO), secure)) {
510 error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
511 &msg->qinfo, id, flags, edns);
513 regional_free_all(worker->scratchpad);
514 if(worker->stats.extended) {
515 if(secure) worker->stats.ans_secure++;
516 server_stats_insrcode(&worker->stats, repinfo->c->buffer);
521 /** answer query from the cache */
523 answer_from_cache(struct worker* worker, struct query_info* qinfo,
524 struct reply_info* rep, uint16_t id, uint16_t flags,
525 struct comm_reply* repinfo, struct edns_data* edns)
527 time_t timenow = *worker->env.now;
528 uint16_t udpsize = edns->udp_size;
530 int must_validate = (!(flags&BIT_CD) || worker->env.cfg->ignore_cd)
531 && worker->env.need_to_validate;
532 /* see if it is possible */
533 if(rep->ttl < timenow) {
534 /* the rrsets may have been updated in the meantime.
535 * we will refetch the message format from the
536 * authoritative server
540 if(!rrset_array_lock(rep->ref, rep->rrset_count, timenow))
542 /* locked and ids and ttls are OK. */
543 /* check CNAME chain (if any) */
544 if(rep->an_numrrsets > 0 && (rep->rrsets[0]->rk.type ==
545 htons(LDNS_RR_TYPE_CNAME) || rep->rrsets[0]->rk.type ==
546 htons(LDNS_RR_TYPE_DNAME))) {
547 if(!reply_check_cname_chain(rep)) {
548 /* cname chain invalid, redo iterator steps */
549 verbose(VERB_ALGO, "Cache reply: cname chain broken");
551 rrset_array_unlock_touch(worker->env.rrset_cache,
552 worker->scratchpad, rep->ref, rep->rrset_count);
553 regional_free_all(worker->scratchpad);
557 /* check security status of the cached answer */
558 if( rep->security == sec_status_bogus && must_validate) {
560 edns->edns_version = EDNS_ADVERTISED_VERSION;
561 edns->udp_size = EDNS_ADVERTISED_SIZE;
563 edns->bits &= EDNS_DO;
564 error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
565 qinfo, id, flags, edns);
566 rrset_array_unlock_touch(worker->env.rrset_cache,
567 worker->scratchpad, rep->ref, rep->rrset_count);
568 regional_free_all(worker->scratchpad);
569 if(worker->stats.extended) {
570 worker->stats.ans_bogus ++;
571 worker->stats.ans_rcode[LDNS_RCODE_SERVFAIL] ++;
574 } else if( rep->security == sec_status_unchecked && must_validate) {
575 verbose(VERB_ALGO, "Cache reply: unchecked entry needs "
577 goto bail_out; /* need to validate cache entry first */
578 } else if(rep->security == sec_status_secure) {
579 if(reply_all_rrsets_secure(rep))
583 verbose(VERB_ALGO, "Cache reply: secure entry"
585 goto bail_out; /* rrset changed, re-verify */
591 edns->edns_version = EDNS_ADVERTISED_VERSION;
592 edns->udp_size = EDNS_ADVERTISED_SIZE;
594 edns->bits &= EDNS_DO;
595 if(!reply_info_answer_encode(qinfo, rep, id, flags,
596 repinfo->c->buffer, timenow, 1, worker->scratchpad,
597 udpsize, edns, (int)(edns->bits & EDNS_DO), secure)) {
598 error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
599 qinfo, id, flags, edns);
601 /* cannot send the reply right now, because blocking network syscall
602 * is bad while holding locks. */
603 rrset_array_unlock_touch(worker->env.rrset_cache, worker->scratchpad,
604 rep->ref, rep->rrset_count);
605 regional_free_all(worker->scratchpad);
606 if(worker->stats.extended) {
607 if(secure) worker->stats.ans_secure++;
608 server_stats_insrcode(&worker->stats, repinfo->c->buffer);
610 /* go and return this buffer to the client */
614 /** Reply to client and perform prefetch to keep cache up to date */
616 reply_and_prefetch(struct worker* worker, struct query_info* qinfo,
617 uint16_t flags, struct comm_reply* repinfo, time_t leeway)
619 /* first send answer to client to keep its latency
620 * as small as a cachereply */
621 comm_point_send_reply(repinfo);
622 server_stats_prefetch(&worker->stats, worker);
624 /* create the prefetch in the mesh as a normal lookup without
625 * client addrs waiting, which has the cache blacklisted (to bypass
626 * the cache and go to the network for the data). */
627 /* this (potentially) runs the mesh for the new query */
628 mesh_new_prefetch(worker->env.mesh, qinfo, flags, leeway +
629 PREFETCH_EXPIRY_ADD);
633 * Fill CH class answer into buffer. Keeps query.
635 * @param str: string to put into text record (<255).
636 * @param edns: edns reply information.
639 chaos_replystr(ldns_buffer* pkt, const char* str, struct edns_data* edns)
641 size_t len = strlen(str);
642 unsigned int rd = LDNS_RD_WIRE(ldns_buffer_begin(pkt));
643 unsigned int cd = LDNS_CD_WIRE(ldns_buffer_begin(pkt));
644 if(len>255) len=255; /* cap size of TXT record */
645 ldns_buffer_clear(pkt);
646 ldns_buffer_skip(pkt, (ssize_t)sizeof(uint16_t)); /* skip id */
647 ldns_buffer_write_u16(pkt, (uint16_t)(BIT_QR|BIT_RA));
648 if(rd) LDNS_RD_SET(ldns_buffer_begin(pkt));
649 if(cd) LDNS_CD_SET(ldns_buffer_begin(pkt));
650 ldns_buffer_write_u16(pkt, 1); /* qdcount */
651 ldns_buffer_write_u16(pkt, 1); /* ancount */
652 ldns_buffer_write_u16(pkt, 0); /* nscount */
653 ldns_buffer_write_u16(pkt, 0); /* arcount */
654 (void)query_dname_len(pkt); /* skip qname */
655 ldns_buffer_skip(pkt, (ssize_t)sizeof(uint16_t)); /* skip qtype */
656 ldns_buffer_skip(pkt, (ssize_t)sizeof(uint16_t)); /* skip qclass */
657 ldns_buffer_write_u16(pkt, 0xc00c); /* compr ptr to query */
658 ldns_buffer_write_u16(pkt, LDNS_RR_TYPE_TXT);
659 ldns_buffer_write_u16(pkt, LDNS_RR_CLASS_CH);
660 ldns_buffer_write_u32(pkt, 0); /* TTL */
661 ldns_buffer_write_u16(pkt, sizeof(uint8_t) + len);
662 ldns_buffer_write_u8(pkt, len);
663 ldns_buffer_write(pkt, str, len);
664 ldns_buffer_flip(pkt);
665 edns->edns_version = EDNS_ADVERTISED_VERSION;
666 edns->udp_size = EDNS_ADVERTISED_SIZE;
667 edns->bits &= EDNS_DO;
668 attach_edns_record(pkt, edns);
672 * Answer CH class queries.
674 * @param qinfo: query info. Pointer into packet buffer.
675 * @param edns: edns info from query.
676 * @param pkt: packet buffer.
677 * @return: true if a reply is to be sent.
680 answer_chaos(struct worker* w, struct query_info* qinfo,
681 struct edns_data* edns, ldns_buffer* pkt)
683 struct config_file* cfg = w->env.cfg;
684 if(qinfo->qtype != LDNS_RR_TYPE_ANY && qinfo->qtype != LDNS_RR_TYPE_TXT)
686 if(query_dname_compare(qinfo->qname,
687 (uint8_t*)"\002id\006server") == 0 ||
688 query_dname_compare(qinfo->qname,
689 (uint8_t*)"\010hostname\004bind") == 0)
691 if(cfg->hide_identity)
693 if(cfg->identity==NULL || cfg->identity[0]==0) {
694 char buf[MAXHOSTNAMELEN+1];
695 if (gethostname(buf, MAXHOSTNAMELEN) == 0) {
696 buf[MAXHOSTNAMELEN] = 0;
697 chaos_replystr(pkt, buf, edns);
699 log_err("gethostname: %s", strerror(errno));
700 chaos_replystr(pkt, "no hostname", edns);
703 else chaos_replystr(pkt, cfg->identity, edns);
706 if(query_dname_compare(qinfo->qname,
707 (uint8_t*)"\007version\006server") == 0 ||
708 query_dname_compare(qinfo->qname,
709 (uint8_t*)"\007version\004bind") == 0)
711 if(cfg->hide_version)
713 if(cfg->version==NULL || cfg->version[0]==0)
714 chaos_replystr(pkt, PACKAGE_STRING, edns);
715 else chaos_replystr(pkt, cfg->version, edns);
722 worker_handle_request(struct comm_point* c, void* arg, int error,
723 struct comm_reply* repinfo)
725 struct worker* worker = (struct worker*)arg;
728 struct lruhash_entry* e;
729 struct query_info qinfo;
730 struct edns_data edns;
733 if(error != NETEVENT_NOERROR) {
734 /* some bad tcp query DNS formats give these error calls */
735 verbose(VERB_ALGO, "handle request called with err=%d", error);
738 acl = acl_list_lookup(worker->daemon->acl, &repinfo->addr,
740 if(acl == acl_deny) {
741 comm_point_drop_reply(repinfo);
742 if(worker->stats.extended)
743 worker->stats.unwanted_queries++;
745 } else if(acl == acl_refuse) {
746 log_addr(VERB_ALGO, "refused query from",
747 &repinfo->addr, repinfo->addrlen);
748 log_buf(VERB_ALGO, "refuse", c->buffer);
749 if(worker->stats.extended)
750 worker->stats.unwanted_queries++;
751 if(worker_check_request(c->buffer, worker) == -1) {
752 comm_point_drop_reply(repinfo);
753 return 0; /* discard this */
755 ldns_buffer_set_limit(c->buffer, LDNS_HEADER_SIZE);
756 ldns_buffer_write_at(c->buffer, 4,
757 (uint8_t*)"\0\0\0\0\0\0\0\0", 8);
758 LDNS_QR_SET(ldns_buffer_begin(c->buffer));
759 LDNS_RCODE_SET(ldns_buffer_begin(c->buffer),
763 if((ret=worker_check_request(c->buffer, worker)) != 0) {
764 verbose(VERB_ALGO, "worker check request: bad query.");
765 log_addr(VERB_CLIENT,"from",&repinfo->addr, repinfo->addrlen);
767 LDNS_QR_SET(ldns_buffer_begin(c->buffer));
768 LDNS_RCODE_SET(ldns_buffer_begin(c->buffer), ret);
771 comm_point_drop_reply(repinfo);
774 worker->stats.num_queries++;
775 /* see if query is in the cache */
776 if(!query_info_parse(&qinfo, c->buffer)) {
777 verbose(VERB_ALGO, "worker parse request: formerror.");
778 log_addr(VERB_CLIENT,"from",&repinfo->addr, repinfo->addrlen);
779 ldns_buffer_rewind(c->buffer);
780 LDNS_QR_SET(ldns_buffer_begin(c->buffer));
781 LDNS_RCODE_SET(ldns_buffer_begin(c->buffer),
783 server_stats_insrcode(&worker->stats, c->buffer);
786 if(worker->env.cfg->log_queries) {
788 addr_to_str(&repinfo->addr, repinfo->addrlen, ip, sizeof(ip));
789 log_nametypeclass(0, ip, qinfo.qname, qinfo.qtype, qinfo.qclass);
791 if(qinfo.qtype == LDNS_RR_TYPE_AXFR ||
792 qinfo.qtype == LDNS_RR_TYPE_IXFR) {
793 verbose(VERB_ALGO, "worker request: refused zone transfer.");
794 log_addr(VERB_CLIENT,"from",&repinfo->addr, repinfo->addrlen);
795 ldns_buffer_rewind(c->buffer);
796 LDNS_QR_SET(ldns_buffer_begin(c->buffer));
797 LDNS_RCODE_SET(ldns_buffer_begin(c->buffer),
799 if(worker->stats.extended) {
800 worker->stats.qtype[qinfo.qtype]++;
801 server_stats_insrcode(&worker->stats, c->buffer);
805 if((ret=parse_edns_from_pkt(c->buffer, &edns)) != 0) {
806 verbose(VERB_ALGO, "worker parse edns: formerror.");
807 log_addr(VERB_CLIENT,"from",&repinfo->addr, repinfo->addrlen);
808 ldns_buffer_rewind(c->buffer);
809 LDNS_QR_SET(ldns_buffer_begin(c->buffer));
810 LDNS_RCODE_SET(ldns_buffer_begin(c->buffer), ret);
811 server_stats_insrcode(&worker->stats, c->buffer);
814 if(edns.edns_present && edns.edns_version != 0) {
815 edns.ext_rcode = (uint8_t)(EDNS_RCODE_BADVERS>>4);
816 edns.edns_version = EDNS_ADVERTISED_VERSION;
817 edns.udp_size = EDNS_ADVERTISED_SIZE;
818 edns.bits &= EDNS_DO;
819 verbose(VERB_ALGO, "query with bad edns version.");
820 log_addr(VERB_CLIENT,"from",&repinfo->addr, repinfo->addrlen);
821 error_encode(c->buffer, EDNS_RCODE_BADVERS&0xf, &qinfo,
822 *(uint16_t*)ldns_buffer_begin(c->buffer),
823 ldns_buffer_read_u16_at(c->buffer, 2), NULL);
824 attach_edns_record(c->buffer, &edns);
827 if(edns.edns_present && edns.udp_size < NORMAL_UDP_SIZE &&
828 worker->daemon->cfg->harden_short_bufsize) {
829 verbose(VERB_QUERY, "worker request: EDNS bufsize %d ignored",
831 log_addr(VERB_CLIENT,"from",&repinfo->addr, repinfo->addrlen);
832 edns.udp_size = NORMAL_UDP_SIZE;
834 if(edns.udp_size > worker->daemon->cfg->max_udp_size &&
835 c->type == comm_udp) {
837 "worker request: max UDP reply size modified"
838 " (%d to max-udp-size)", (int)edns.udp_size);
839 log_addr(VERB_CLIENT,"from",&repinfo->addr, repinfo->addrlen);
840 edns.udp_size = worker->daemon->cfg->max_udp_size;
842 if(edns.udp_size < LDNS_HEADER_SIZE) {
843 verbose(VERB_ALGO, "worker request: edns is too small.");
844 log_addr(VERB_CLIENT, "from", &repinfo->addr, repinfo->addrlen);
845 LDNS_QR_SET(ldns_buffer_begin(c->buffer));
846 LDNS_TC_SET(ldns_buffer_begin(c->buffer));
847 LDNS_RCODE_SET(ldns_buffer_begin(c->buffer),
848 LDNS_RCODE_SERVFAIL);
849 ldns_buffer_set_position(c->buffer, LDNS_HEADER_SIZE);
850 ldns_buffer_write_at(c->buffer, 4,
851 (uint8_t*)"\0\0\0\0\0\0\0\0", 8);
852 ldns_buffer_flip(c->buffer);
855 if(worker->stats.extended)
856 server_stats_insquery(&worker->stats, c, qinfo.qtype,
857 qinfo.qclass, &edns, repinfo);
858 if(c->type != comm_udp)
859 edns.udp_size = 65535; /* max size for TCP replies */
860 if(qinfo.qclass == LDNS_RR_CLASS_CH && answer_chaos(worker, &qinfo,
862 server_stats_insrcode(&worker->stats, c->buffer);
865 if(local_zones_answer(worker->daemon->local_zones, &qinfo, &edns,
866 c->buffer, worker->scratchpad)) {
867 regional_free_all(worker->scratchpad);
868 if(ldns_buffer_limit(c->buffer) == 0) {
869 comm_point_drop_reply(repinfo);
872 server_stats_insrcode(&worker->stats, c->buffer);
875 if(!(LDNS_RD_WIRE(ldns_buffer_begin(c->buffer))) &&
876 acl != acl_allow_snoop ) {
877 ldns_buffer_set_limit(c->buffer, LDNS_HEADER_SIZE);
878 ldns_buffer_write_at(c->buffer, 4,
879 (uint8_t*)"\0\0\0\0\0\0\0\0", 8);
880 LDNS_QR_SET(ldns_buffer_begin(c->buffer));
881 LDNS_RCODE_SET(ldns_buffer_begin(c->buffer),
883 ldns_buffer_flip(c->buffer);
884 server_stats_insrcode(&worker->stats, c->buffer);
885 log_addr(VERB_ALGO, "refused nonrec (cache snoop) query from",
886 &repinfo->addr, repinfo->addrlen);
889 h = query_info_hash(&qinfo);
890 if((e=slabhash_lookup(worker->env.msg_cache, h, &qinfo, 0))) {
891 /* answer from cache - we have acquired a readlock on it */
892 if(answer_from_cache(worker, &qinfo,
893 (struct reply_info*)e->data,
894 *(uint16_t*)ldns_buffer_begin(c->buffer),
895 ldns_buffer_read_u16_at(c->buffer, 2), repinfo,
897 /* prefetch it if the prefetch TTL expired */
898 if(worker->env.cfg->prefetch && *worker->env.now >=
899 ((struct reply_info*)e->data)->prefetch_ttl) {
900 time_t leeway = ((struct reply_info*)e->
901 data)->ttl - *worker->env.now;
902 lock_rw_unlock(&e->lock);
903 reply_and_prefetch(worker, &qinfo,
904 ldns_buffer_read_u16_at(c->buffer, 2),
908 lock_rw_unlock(&e->lock);
911 verbose(VERB_ALGO, "answer from the cache failed");
912 lock_rw_unlock(&e->lock);
914 if(!LDNS_RD_WIRE(ldns_buffer_begin(c->buffer))) {
915 if(answer_norec_from_cache(worker, &qinfo,
916 *(uint16_t*)ldns_buffer_begin(c->buffer),
917 ldns_buffer_read_u16_at(c->buffer, 2), repinfo,
921 verbose(VERB_ALGO, "answer norec from cache -- "
922 "need to validate or not primed");
924 ldns_buffer_rewind(c->buffer);
925 server_stats_querymiss(&worker->stats, worker);
927 if(verbosity >= VERB_CLIENT) {
928 if(c->type == comm_udp)
929 log_addr(VERB_CLIENT, "udp request from",
930 &repinfo->addr, repinfo->addrlen);
931 else log_addr(VERB_CLIENT, "tcp request from",
932 &repinfo->addr, repinfo->addrlen);
935 /* grab a work request structure for this new request */
936 mesh_new_client(worker->env.mesh, &qinfo,
937 ldns_buffer_read_u16_at(c->buffer, 2),
938 &edns, repinfo, *(uint16_t*)ldns_buffer_begin(c->buffer));
939 worker_mem_report(worker, NULL);
944 worker_sighandler(int sig, void* arg)
946 /* note that log, print, syscalls here give race conditions. */
947 /* we still print DETAIL logs, because this is extensive per message
948 * logging anyway, and the operator may then have an interest
949 * in the cause for unbound to exit */
950 struct worker* worker = (struct worker*)arg;
954 verbose(VERB_QUERY, "caught signal SIGHUP");
955 comm_base_exit(worker->base);
959 verbose(VERB_QUERY, "caught signal SIGINT");
960 worker->need_to_exit = 1;
961 comm_base_exit(worker->base);
965 verbose(VERB_QUERY, "caught signal SIGQUIT");
966 worker->need_to_exit = 1;
967 comm_base_exit(worker->base);
971 verbose(VERB_QUERY, "caught signal SIGTERM");
972 worker->need_to_exit = 1;
973 comm_base_exit(worker->base);
976 log_err("unknown signal: %d, ignored", sig);
981 /** restart statistics timer for worker, if enabled */
983 worker_restart_timer(struct worker* worker)
985 if(worker->env.cfg->stat_interval > 0) {
988 tv.tv_sec = worker->env.cfg->stat_interval;
991 comm_timer_set(worker->stat_timer, &tv);
995 void worker_stat_timer_cb(void* arg)
997 struct worker* worker = (struct worker*)arg;
998 server_stats_log(&worker->stats, worker, worker->thread_num);
999 mesh_stats(worker->env.mesh, "mesh has");
1000 worker_mem_report(worker, NULL);
1001 if(!worker->daemon->cfg->stat_cumulative) {
1002 worker_stats_clear(worker);
1004 /* start next timer */
1005 worker_restart_timer(worker);
1008 void worker_probe_timer_cb(void* arg)
1010 struct worker* worker = (struct worker*)arg;
1013 tv.tv_sec = (time_t)autr_probe_timer(&worker->env);
1017 comm_timer_set(worker->env.probe_timer, &tv);
1021 worker_create(struct daemon* daemon, int id, int* ports, int n)
1024 struct worker* worker = (struct worker*)calloc(1,
1025 sizeof(struct worker));
1028 worker->numports = n;
1029 worker->ports = (int*)memdup(ports, sizeof(int)*n);
1030 if(!worker->ports) {
1034 worker->daemon = daemon;
1035 worker->thread_num = id;
1036 if(!(worker->cmd = tube_create())) {
1037 free(worker->ports);
1041 /* create random state here to avoid locking trouble in RAND_bytes */
1042 seed = (unsigned int)time(NULL) ^ (unsigned int)getpid() ^
1043 (((unsigned int)worker->thread_num)<<17);
1044 /* shift thread_num so it does not match out pid bits */
1045 if(!(worker->rndstate = ub_initstate(seed, daemon->rand))) {
1047 log_err("could not init random numbers.");
1048 tube_delete(worker->cmd);
1049 free(worker->ports);
1058 worker_init(struct worker* worker, struct config_file *cfg,
1059 struct listen_port* ports, int do_sigs)
1061 worker->need_to_exit = 0;
1062 worker->base = comm_base_create(do_sigs);
1064 log_err("could not create event handling base");
1065 worker_delete(worker);
1068 comm_base_set_slow_accept_handlers(worker->base, &worker_stop_accept,
1069 &worker_start_accept, worker);
1072 ub_thread_sig_unblock(SIGHUP);
1074 ub_thread_sig_unblock(SIGINT);
1076 ub_thread_sig_unblock(SIGQUIT);
1078 ub_thread_sig_unblock(SIGTERM);
1079 #ifndef LIBEVENT_SIGNAL_PROBLEM
1080 worker->comsig = comm_signal_create(worker->base,
1081 worker_sighandler, worker);
1084 || !comm_signal_bind(worker->comsig, SIGHUP)
1087 || !comm_signal_bind(worker->comsig, SIGQUIT)
1089 || !comm_signal_bind(worker->comsig, SIGTERM)
1090 || !comm_signal_bind(worker->comsig, SIGINT)) {
1091 log_err("could not create signal handlers");
1092 worker_delete(worker);
1095 #endif /* LIBEVENT_SIGNAL_PROBLEM */
1096 if(!daemon_remote_open_accept(worker->daemon->rc,
1097 worker->daemon->rc_ports, worker)) {
1098 worker_delete(worker);
1101 #ifdef UB_ON_WINDOWS
1102 wsvc_setup_worker(worker);
1103 #endif /* UB_ON_WINDOWS */
1104 } else { /* !do_sigs */
1105 worker->comsig = NULL;
1107 worker->front = listen_create(worker->base, ports,
1108 cfg->msg_buffer_size, (int)cfg->incoming_num_tcp,
1109 worker->daemon->listen_sslctx, worker_handle_request, worker);
1110 if(!worker->front) {
1111 log_err("could not create listening sockets");
1112 worker_delete(worker);
1115 worker->back = outside_network_create(worker->base,
1116 cfg->msg_buffer_size, (size_t)cfg->outgoing_num_ports,
1117 cfg->out_ifs, cfg->num_out_ifs, cfg->do_ip4, cfg->do_ip6,
1118 cfg->do_tcp?cfg->outgoing_num_tcp:0,
1119 worker->daemon->env->infra_cache, worker->rndstate,
1120 cfg->use_caps_bits_for_id, worker->ports, worker->numports,
1121 cfg->unwanted_threshold, &worker_alloc_cleanup, worker,
1122 cfg->do_udp, worker->daemon->connect_sslctx);
1124 log_err("could not create outgoing sockets");
1125 worker_delete(worker);
1128 /* start listening to commands */
1129 if(!tube_setup_bg_listen(worker->cmd, worker->base,
1130 &worker_handle_control_cmd, worker)) {
1131 log_err("could not create control compt.");
1132 worker_delete(worker);
1135 worker->stat_timer = comm_timer_create(worker->base,
1136 worker_stat_timer_cb, worker);
1137 if(!worker->stat_timer) {
1138 log_err("could not create statistics timer");
1141 /* we use the msg_buffer_size as a good estimate for what the
1142 * user wants for memory usage sizes */
1143 worker->scratchpad = regional_create_custom(cfg->msg_buffer_size);
1144 if(!worker->scratchpad) {
1145 log_err("malloc failure");
1146 worker_delete(worker);
1150 server_stats_init(&worker->stats, cfg);
1151 alloc_init(&worker->alloc, &worker->daemon->superalloc,
1152 worker->thread_num);
1153 alloc_set_id_cleanup(&worker->alloc, &worker_alloc_cleanup, worker);
1154 worker->env = *worker->daemon->env;
1155 comm_base_timept(worker->base, &worker->env.now, &worker->env.now_tv);
1156 if(worker->thread_num == 0)
1157 log_set_time(worker->env.now);
1158 worker->env.worker = worker;
1159 worker->env.send_query = &worker_send_query;
1160 worker->env.alloc = &worker->alloc;
1161 worker->env.rnd = worker->rndstate;
1162 worker->env.scratch = worker->scratchpad;
1163 worker->env.mesh = mesh_create(&worker->daemon->mods, &worker->env);
1164 worker->env.detach_subs = &mesh_detach_subs;
1165 worker->env.attach_sub = &mesh_attach_sub;
1166 worker->env.kill_sub = &mesh_state_delete;
1167 worker->env.detect_cycle = &mesh_detect_cycle;
1168 worker->env.scratch_buffer = ldns_buffer_new(cfg->msg_buffer_size);
1169 if(!(worker->env.fwds = forwards_create()) ||
1170 !forwards_apply_cfg(worker->env.fwds, cfg)) {
1171 log_err("Could not set forward zones");
1172 worker_delete(worker);
1175 if(!(worker->env.hints = hints_create()) ||
1176 !hints_apply_cfg(worker->env.hints, cfg)) {
1177 log_err("Could not set root or stub hints");
1178 worker_delete(worker);
1181 /* one probe timer per process -- if we have 5011 anchors */
1182 if(autr_get_num_anchors(worker->env.anchors) > 0
1183 #ifndef THREADS_DISABLED
1184 && worker->thread_num == 0
1190 worker->env.probe_timer = comm_timer_create(worker->base,
1191 worker_probe_timer_cb, worker);
1192 if(!worker->env.probe_timer) {
1193 log_err("could not create 5011-probe timer");
1195 /* let timer fire, then it can reset itself */
1196 comm_timer_set(worker->env.probe_timer, &tv);
1199 if(!worker->env.mesh || !worker->env.scratch_buffer) {
1200 worker_delete(worker);
1203 worker_mem_report(worker, NULL);
1204 /* if statistics enabled start timer */
1205 if(worker->env.cfg->stat_interval > 0) {
1206 verbose(VERB_ALGO, "set statistics interval %d secs",
1207 worker->env.cfg->stat_interval);
1208 worker_restart_timer(worker);
1214 worker_work(struct worker* worker)
1216 comm_base_dispatch(worker->base);
1220 worker_delete(struct worker* worker)
1224 if(worker->env.mesh && verbosity >= VERB_OPS) {
1225 server_stats_log(&worker->stats, worker, worker->thread_num);
1226 mesh_stats(worker->env.mesh, "mesh has");
1227 worker_mem_report(worker, NULL);
1229 outside_network_quit_prepare(worker->back);
1230 mesh_delete(worker->env.mesh);
1231 ldns_buffer_free(worker->env.scratch_buffer);
1232 forwards_delete(worker->env.fwds);
1233 hints_delete(worker->env.hints);
1234 listen_delete(worker->front);
1235 outside_network_delete(worker->back);
1236 comm_signal_delete(worker->comsig);
1237 tube_delete(worker->cmd);
1238 comm_timer_delete(worker->stat_timer);
1239 comm_timer_delete(worker->env.probe_timer);
1240 free(worker->ports);
1241 if(worker->thread_num == 0) {
1243 #ifdef UB_ON_WINDOWS
1244 wsvc_desetup_worker(worker);
1245 #endif /* UB_ON_WINDOWS */
1247 comm_base_delete(worker->base);
1248 ub_randfree(worker->rndstate);
1249 alloc_clear(&worker->alloc);
1250 regional_destroy(worker->scratchpad);
1254 struct outbound_entry*
1255 worker_send_query(uint8_t* qname, size_t qnamelen, uint16_t qtype,
1256 uint16_t qclass, uint16_t flags, int dnssec, int want_dnssec,
1257 struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
1258 size_t zonelen, struct module_qstate* q)
1260 struct worker* worker = q->env->worker;
1261 struct outbound_entry* e = (struct outbound_entry*)regional_alloc(
1262 q->region, sizeof(*e));
1266 e->qsent = outnet_serviced_query(worker->back, qname,
1267 qnamelen, qtype, qclass, flags, dnssec, want_dnssec,
1268 q->env->cfg->tcp_upstream, q->env->cfg->ssl_upstream, addr,
1269 addrlen, zone, zonelen, worker_handle_service_reply, e,
1270 worker->back->udp_buff);
1278 worker_alloc_cleanup(void* arg)
1280 struct worker* worker = (struct worker*)arg;
1281 slabhash_clear(&worker->env.rrset_cache->table);
1282 slabhash_clear(worker->env.msg_cache);
1285 void worker_stats_clear(struct worker* worker)
1287 server_stats_init(&worker->stats, worker->env.cfg);
1288 mesh_stats_clear(worker->env.mesh);
1289 worker->back->unwanted_replies = 0;
1292 void worker_start_accept(void* arg)
1294 struct worker* worker = (struct worker*)arg;
1295 listen_start_accept(worker->front);
1296 if(worker->thread_num == 0)
1297 daemon_remote_start_accept(worker->daemon->rc);
1300 void worker_stop_accept(void* arg)
1302 struct worker* worker = (struct worker*)arg;
1303 listen_stop_accept(worker->front);
1304 if(worker->thread_num == 0)
1305 daemon_remote_stop_accept(worker->daemon->rc);
1308 /* --- fake callbacks for fptr_wlist to work --- */
1309 struct outbound_entry* libworker_send_query(uint8_t* ATTR_UNUSED(qname),
1310 size_t ATTR_UNUSED(qnamelen), uint16_t ATTR_UNUSED(qtype),
1311 uint16_t ATTR_UNUSED(qclass), uint16_t ATTR_UNUSED(flags),
1312 int ATTR_UNUSED(dnssec), int ATTR_UNUSED(want_dnssec),
1313 struct sockaddr_storage* ATTR_UNUSED(addr),
1314 socklen_t ATTR_UNUSED(addrlen), struct module_qstate* ATTR_UNUSED(q))
1320 int libworker_handle_reply(struct comm_point* ATTR_UNUSED(c),
1321 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
1322 struct comm_reply* ATTR_UNUSED(reply_info))
1328 int libworker_handle_service_reply(struct comm_point* ATTR_UNUSED(c),
1329 void* ATTR_UNUSED(arg), int ATTR_UNUSED(error),
1330 struct comm_reply* ATTR_UNUSED(reply_info))
1336 void libworker_handle_control_cmd(struct tube* ATTR_UNUSED(tube),
1337 uint8_t* ATTR_UNUSED(buffer), size_t ATTR_UNUSED(len),
1338 int ATTR_UNUSED(error), void* ATTR_UNUSED(arg))
1343 void libworker_fg_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode),
1344 ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s),
1345 char* ATTR_UNUSED(why_bogus))
1350 void libworker_bg_done_cb(void* ATTR_UNUSED(arg), int ATTR_UNUSED(rcode),
1351 ldns_buffer* ATTR_UNUSED(buf), enum sec_status ATTR_UNUSED(s),
1352 char* ATTR_UNUSED(why_bogus))
1357 int context_query_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))
1363 int order_lock_cmp(const void* ATTR_UNUSED(e1), const void* ATTR_UNUSED(e2))
1369 int codeline_cmp(const void* ATTR_UNUSED(a), const void* ATTR_UNUSED(b))