xref: /openbsd-src/usr.sbin/unbound/libunbound/worker.h (revision e21c60efe88ccf825a55e871fba3e7017d017ae8)
198f3ca02Sbrad /*
298f3ca02Sbrad  * libunbound/worker.h - prototypes for worker methods.
398f3ca02Sbrad  *
498f3ca02Sbrad  * Copyright (c) 2007, NLnet Labs. All rights reserved.
598f3ca02Sbrad  *
698f3ca02Sbrad  * This software is open source.
798f3ca02Sbrad  *
898f3ca02Sbrad  * Redistribution and use in source and binary forms, with or without
998f3ca02Sbrad  * modification, are permitted provided that the following conditions
1098f3ca02Sbrad  * are met:
1198f3ca02Sbrad  *
1298f3ca02Sbrad  * Redistributions of source code must retain the above copyright notice,
1398f3ca02Sbrad  * this list of conditions and the following disclaimer.
1498f3ca02Sbrad  *
1598f3ca02Sbrad  * Redistributions in binary form must reproduce the above copyright notice,
1698f3ca02Sbrad  * this list of conditions and the following disclaimer in the documentation
1798f3ca02Sbrad  * and/or other materials provided with the distribution.
1898f3ca02Sbrad  *
1998f3ca02Sbrad  * Neither the name of the NLNET LABS nor the names of its contributors may
2098f3ca02Sbrad  * be used to endorse or promote products derived from this software without
2198f3ca02Sbrad  * specific prior written permission.
2298f3ca02Sbrad  *
2398f3ca02Sbrad  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2498f3ca02Sbrad  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2598f3ca02Sbrad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2698f3ca02Sbrad  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
2798f3ca02Sbrad  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2898f3ca02Sbrad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2998f3ca02Sbrad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3098f3ca02Sbrad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3198f3ca02Sbrad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3298f3ca02Sbrad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3398f3ca02Sbrad  * POSSIBILITY OF SUCH DAMAGE.
3498f3ca02Sbrad  */
3598f3ca02Sbrad 
3698f3ca02Sbrad /**
3798f3ca02Sbrad  * \file
3898f3ca02Sbrad  *
3998f3ca02Sbrad  * This file declares the methods any worker has to implement.
4098f3ca02Sbrad  */
4198f3ca02Sbrad 
4298f3ca02Sbrad #ifndef LIBUNBOUND_WORKER_H
4398f3ca02Sbrad #define LIBUNBOUND_WORKER_H
4498f3ca02Sbrad 
45fdfb4ba6Ssthen #include "sldns/sbuffer.h"
4698f3ca02Sbrad #include "util/data/packed_rrset.h" /* for enum sec_status */
4798f3ca02Sbrad struct comm_reply;
4898f3ca02Sbrad struct comm_point;
4998f3ca02Sbrad struct module_qstate;
5098f3ca02Sbrad struct tube;
512ee382b6Ssthen struct edns_option;
5277079be7Ssthen struct query_info;
5398f3ca02Sbrad 
5498f3ca02Sbrad /**
5598f3ca02Sbrad  * Worker service routine to send serviced queries to authoritative servers.
5677079be7Ssthen  * @param qinfo: query info.
5798f3ca02Sbrad  * @param flags: host order flags word, with opcode and CD bit.
5898f3ca02Sbrad  * @param dnssec: if set, EDNS record will have DO bit set.
5998f3ca02Sbrad  * @param want_dnssec: signatures needed.
6098f3ca02Sbrad  * @param nocaps: ignore capsforid(if in config), do not perturb qname.
61*e21c60efSsthen  * @param check_ratelimit: if set, will check ratelimit before sending out.
6298f3ca02Sbrad  * @param addr: where to.
6398f3ca02Sbrad  * @param addrlen: length of addr.
6498f3ca02Sbrad  * @param zone: delegation point name.
6598f3ca02Sbrad  * @param zonelen: length of zone name wireformat dname.
66*e21c60efSsthen  * @param tcp_upstream: use TCP for upstream queries.
6777079be7Ssthen  * @param ssl_upstream: use SSL for upstream queries.
6820237c55Ssthen  * @param tls_auth_name: if ssl_upstream, use this name with TLS
6920237c55Ssthen  * 	authentication.
70*e21c60efSsthen  * @param q: which query state to reactivate upon return.
71*e21c60efSsthen  * @param was_ratelimited: it will signal back if the query failed to pass the
72*e21c60efSsthen  *	ratelimit check.
7398f3ca02Sbrad  * @return: false on failure (memory or socket related). no query was
7498f3ca02Sbrad  *      sent.
7598f3ca02Sbrad  */
7677079be7Ssthen struct outbound_entry* libworker_send_query(struct query_info* qinfo,
7777079be7Ssthen 	uint16_t flags, int dnssec, int want_dnssec, int nocaps,
78*e21c60efSsthen 	int check_ratelimit,
792ee382b6Ssthen 	struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
80*e21c60efSsthen 	size_t zonelen, int tcp_upstream, int ssl_upstream, char* tls_auth_name,
81*e21c60efSsthen 	struct module_qstate* q, int* was_ratelimited);
8298f3ca02Sbrad 
8398f3ca02Sbrad /** process incoming serviced query replies from the network */
8498f3ca02Sbrad int libworker_handle_service_reply(struct comm_point* c, void* arg, int error,
8598f3ca02Sbrad         struct comm_reply* reply_info);
8698f3ca02Sbrad 
8798f3ca02Sbrad /** handle control command coming into server */
8898f3ca02Sbrad void libworker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
8998f3ca02Sbrad 	int err, void* arg);
9098f3ca02Sbrad 
9198f3ca02Sbrad /** mesh callback with fg results */
9298f3ca02Sbrad void libworker_fg_done_cb(void* arg, int rcode, sldns_buffer* buf,
932308e98cSsthen 	enum sec_status s, char* why_bogus, int was_ratelimited);
9498f3ca02Sbrad 
9598f3ca02Sbrad /** mesh callback with bg results */
9698f3ca02Sbrad void libworker_bg_done_cb(void* arg, int rcode, sldns_buffer* buf,
972308e98cSsthen 	enum sec_status s, char* why_bogus, int was_ratelimited);
9898f3ca02Sbrad 
9998f3ca02Sbrad /** mesh callback with event results */
10098f3ca02Sbrad void libworker_event_done_cb(void* arg, int rcode, struct sldns_buffer* buf,
1012308e98cSsthen 	enum sec_status s, char* why_bogus, int was_ratelimited);
10298f3ca02Sbrad 
10398f3ca02Sbrad /**
10498f3ca02Sbrad  * Worker signal handler function. User argument is the worker itself.
10598f3ca02Sbrad  * @param sig: signal number.
10698f3ca02Sbrad  * @param arg: the worker (main worker) that handles signals.
10798f3ca02Sbrad  */
10898f3ca02Sbrad void worker_sighandler(int sig, void* arg);
10998f3ca02Sbrad 
11098f3ca02Sbrad /**
11198f3ca02Sbrad  * Worker service routine to send serviced queries to authoritative servers.
11277079be7Ssthen  * @param qinfo: query info.
11398f3ca02Sbrad  * @param flags: host order flags word, with opcode and CD bit.
11498f3ca02Sbrad  * @param dnssec: if set, EDNS record will have DO bit set.
11598f3ca02Sbrad  * @param want_dnssec: signatures needed.
11698f3ca02Sbrad  * @param nocaps: ignore capsforid(if in config), do not perturb qname.
117*e21c60efSsthen  * @param check_ratelimit: if set, will check ratelimit before sending out.
11898f3ca02Sbrad  * @param addr: where to.
11998f3ca02Sbrad  * @param addrlen: length of addr.
12098f3ca02Sbrad  * @param zone: wireformat dname of the zone.
12198f3ca02Sbrad  * @param zonelen: length of zone name.
122*e21c60efSsthen  * @param tcp_upstream: use TCP for upstream queries.
12377079be7Ssthen  * @param ssl_upstream: use SSL for upstream queries.
12420237c55Ssthen  * @param tls_auth_name: if ssl_upstream, use this name with TLS
12520237c55Ssthen  * 	authentication.
126*e21c60efSsthen  * @param q: which query state to reactivate upon return.
127*e21c60efSsthen  * @param was_ratelimited: it will signal back if the query failed to pass the
128*e21c60efSsthen  *	ratelimit check.
12998f3ca02Sbrad  * @return: false on failure (memory or socket related). no query was
13098f3ca02Sbrad  *      sent.
13198f3ca02Sbrad  */
13277079be7Ssthen struct outbound_entry* worker_send_query(struct query_info* qinfo,
13377079be7Ssthen 	uint16_t flags, int dnssec, int want_dnssec, int nocaps,
134*e21c60efSsthen 	int check_ratelimit,
1352ee382b6Ssthen 	struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
136*e21c60efSsthen 	size_t zonelen, int tcp_upstream, int ssl_upstream, char* tls_auth_name,
137*e21c60efSsthen 	struct module_qstate* q, int* was_ratelimited);
13898f3ca02Sbrad 
13998f3ca02Sbrad /**
14098f3ca02Sbrad  * process control messages from the main thread. Frees the control
14198f3ca02Sbrad  * command message.
14298f3ca02Sbrad  * @param tube: tube control message came on.
14398f3ca02Sbrad  * @param msg: message contents.  Is freed.
14498f3ca02Sbrad  * @param len: length of message.
14598f3ca02Sbrad  * @param error: if error (NETEVENT_*) happened.
14698f3ca02Sbrad  * @param arg: user argument
14798f3ca02Sbrad  */
14898f3ca02Sbrad void worker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
14998f3ca02Sbrad 	int error, void* arg);
15098f3ca02Sbrad 
15198f3ca02Sbrad /** handles callbacks from listening event interface */
15298f3ca02Sbrad int worker_handle_request(struct comm_point* c, void* arg, int error,
15398f3ca02Sbrad 	struct comm_reply* repinfo);
15498f3ca02Sbrad 
15598f3ca02Sbrad /** process incoming serviced query replies from the network */
15698f3ca02Sbrad int worker_handle_service_reply(struct comm_point* c, void* arg, int error,
15798f3ca02Sbrad 	struct comm_reply* reply_info);
15898f3ca02Sbrad 
15998f3ca02Sbrad /** cleanup the cache to remove all rrset IDs from it, arg is worker */
16098f3ca02Sbrad void worker_alloc_cleanup(void* arg);
16198f3ca02Sbrad 
16298f3ca02Sbrad /** statistics timer callback handler */
16398f3ca02Sbrad void worker_stat_timer_cb(void* arg);
16498f3ca02Sbrad 
16598f3ca02Sbrad /** probe timer callback handler */
16698f3ca02Sbrad void worker_probe_timer_cb(void* arg);
16798f3ca02Sbrad 
16898f3ca02Sbrad /** start accept callback handler */
16998f3ca02Sbrad void worker_start_accept(void* arg);
17098f3ca02Sbrad 
17198f3ca02Sbrad /** stop accept callback handler */
17298f3ca02Sbrad void worker_stop_accept(void* arg);
17398f3ca02Sbrad 
17498f3ca02Sbrad /** handle remote control accept callbacks */
17598f3ca02Sbrad int remote_accept_callback(struct comm_point*, void*, int, struct comm_reply*);
17698f3ca02Sbrad 
17798f3ca02Sbrad /** handle remote control data callbacks */
17898f3ca02Sbrad int remote_control_callback(struct comm_point*, void*, int, struct comm_reply*);
17998f3ca02Sbrad 
18098f3ca02Sbrad /** routine to printout option values over SSL */
18198f3ca02Sbrad void  remote_get_opt_ssl(char* line, void* arg);
18298f3ca02Sbrad 
18398f3ca02Sbrad #endif /* LIBUNBOUND_WORKER_H */
184