1ae8c6e27Sflorian /*
2ae8c6e27Sflorian  * libunbound/worker.h - prototypes for worker methods.
3ae8c6e27Sflorian  *
4ae8c6e27Sflorian  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5ae8c6e27Sflorian  *
6ae8c6e27Sflorian  * This software is open source.
7ae8c6e27Sflorian  *
8ae8c6e27Sflorian  * Redistribution and use in source and binary forms, with or without
9ae8c6e27Sflorian  * modification, are permitted provided that the following conditions
10ae8c6e27Sflorian  * are met:
11ae8c6e27Sflorian  *
12ae8c6e27Sflorian  * Redistributions of source code must retain the above copyright notice,
13ae8c6e27Sflorian  * this list of conditions and the following disclaimer.
14ae8c6e27Sflorian  *
15ae8c6e27Sflorian  * Redistributions in binary form must reproduce the above copyright notice,
16ae8c6e27Sflorian  * this list of conditions and the following disclaimer in the documentation
17ae8c6e27Sflorian  * and/or other materials provided with the distribution.
18ae8c6e27Sflorian  *
19ae8c6e27Sflorian  * Neither the name of the NLNET LABS nor the names of its contributors may
20ae8c6e27Sflorian  * be used to endorse or promote products derived from this software without
21ae8c6e27Sflorian  * specific prior written permission.
22ae8c6e27Sflorian  *
23ae8c6e27Sflorian  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24ae8c6e27Sflorian  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25ae8c6e27Sflorian  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26ae8c6e27Sflorian  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27ae8c6e27Sflorian  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28ae8c6e27Sflorian  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29ae8c6e27Sflorian  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30ae8c6e27Sflorian  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31ae8c6e27Sflorian  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32ae8c6e27Sflorian  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33ae8c6e27Sflorian  * POSSIBILITY OF SUCH DAMAGE.
34ae8c6e27Sflorian  */
35ae8c6e27Sflorian 
36ae8c6e27Sflorian /**
37ae8c6e27Sflorian  * \file
38ae8c6e27Sflorian  *
39ae8c6e27Sflorian  * This file declares the methods any worker has to implement.
40ae8c6e27Sflorian  */
41ae8c6e27Sflorian 
42ae8c6e27Sflorian #ifndef LIBUNBOUND_WORKER_H
43ae8c6e27Sflorian #define LIBUNBOUND_WORKER_H
44ae8c6e27Sflorian 
45ae8c6e27Sflorian #include "sldns/sbuffer.h"
46ae8c6e27Sflorian #include "util/data/packed_rrset.h" /* for enum sec_status */
47ae8c6e27Sflorian struct comm_reply;
48ae8c6e27Sflorian struct comm_point;
49ae8c6e27Sflorian struct module_qstate;
50ae8c6e27Sflorian struct tube;
51ae8c6e27Sflorian struct edns_option;
52ae8c6e27Sflorian struct query_info;
53ae8c6e27Sflorian 
54ae8c6e27Sflorian /**
55ae8c6e27Sflorian  * Worker service routine to send serviced queries to authoritative servers.
56ae8c6e27Sflorian  * @param qinfo: query info.
57ae8c6e27Sflorian  * @param flags: host order flags word, with opcode and CD bit.
58ae8c6e27Sflorian  * @param dnssec: if set, EDNS record will have DO bit set.
59ae8c6e27Sflorian  * @param want_dnssec: signatures needed.
60ae8c6e27Sflorian  * @param nocaps: ignore capsforid(if in config), do not perturb qname.
61*a1a7ba80Sflorian  * @param check_ratelimit: if set, will check ratelimit before sending out.
62ae8c6e27Sflorian  * @param addr: where to.
63ae8c6e27Sflorian  * @param addrlen: length of addr.
64ae8c6e27Sflorian  * @param zone: delegation point name.
65ae8c6e27Sflorian  * @param zonelen: length of zone name wireformat dname.
66*a1a7ba80Sflorian  * @param tcp_upstream: use TCP for upstream queries.
67ae8c6e27Sflorian  * @param ssl_upstream: use SSL for upstream queries.
68ae8c6e27Sflorian  * @param tls_auth_name: if ssl_upstream, use this name with TLS
69ae8c6e27Sflorian  * 	authentication.
70*a1a7ba80Sflorian  * @param q: which query state to reactivate upon return.
71*a1a7ba80Sflorian  * @param was_ratelimited: it will signal back if the query failed to pass the
72*a1a7ba80Sflorian  *	ratelimit check.
73ae8c6e27Sflorian  * @return: false on failure (memory or socket related). no query was
74ae8c6e27Sflorian  *      sent.
75ae8c6e27Sflorian  */
76ae8c6e27Sflorian struct outbound_entry* libworker_send_query(struct query_info* qinfo,
77ae8c6e27Sflorian 	uint16_t flags, int dnssec, int want_dnssec, int nocaps,
78*a1a7ba80Sflorian 	int check_ratelimit,
79ae8c6e27Sflorian 	struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
80*a1a7ba80Sflorian 	size_t zonelen, int tcp_upstream, int ssl_upstream, char* tls_auth_name,
81*a1a7ba80Sflorian 	struct module_qstate* q, int* was_ratelimited);
82ae8c6e27Sflorian 
83ae8c6e27Sflorian /** process incoming serviced query replies from the network */
84ae8c6e27Sflorian int libworker_handle_service_reply(struct comm_point* c, void* arg, int error,
85ae8c6e27Sflorian         struct comm_reply* reply_info);
86ae8c6e27Sflorian 
87ae8c6e27Sflorian /** handle control command coming into server */
88ae8c6e27Sflorian void libworker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
89ae8c6e27Sflorian 	int err, void* arg);
90ae8c6e27Sflorian 
91ae8c6e27Sflorian /** mesh callback with fg results */
92ae8c6e27Sflorian void libworker_fg_done_cb(void* arg, int rcode, sldns_buffer* buf,
93ae8c6e27Sflorian 	enum sec_status s, char* why_bogus, int was_ratelimited);
94ae8c6e27Sflorian 
95ae8c6e27Sflorian /** mesh callback with bg results */
96ae8c6e27Sflorian void libworker_bg_done_cb(void* arg, int rcode, sldns_buffer* buf,
97ae8c6e27Sflorian 	enum sec_status s, char* why_bogus, int was_ratelimited);
98ae8c6e27Sflorian 
99ae8c6e27Sflorian /** mesh callback with event results */
100ae8c6e27Sflorian void libworker_event_done_cb(void* arg, int rcode, struct sldns_buffer* buf,
101ae8c6e27Sflorian 	enum sec_status s, char* why_bogus, int was_ratelimited);
102ae8c6e27Sflorian 
103ae8c6e27Sflorian /**
104ae8c6e27Sflorian  * Worker signal handler function. User argument is the worker itself.
105ae8c6e27Sflorian  * @param sig: signal number.
106ae8c6e27Sflorian  * @param arg: the worker (main worker) that handles signals.
107ae8c6e27Sflorian  */
108ae8c6e27Sflorian void worker_sighandler(int sig, void* arg);
109ae8c6e27Sflorian 
110ae8c6e27Sflorian /**
111ae8c6e27Sflorian  * Worker service routine to send serviced queries to authoritative servers.
112ae8c6e27Sflorian  * @param qinfo: query info.
113ae8c6e27Sflorian  * @param flags: host order flags word, with opcode and CD bit.
114ae8c6e27Sflorian  * @param dnssec: if set, EDNS record will have DO bit set.
115ae8c6e27Sflorian  * @param want_dnssec: signatures needed.
116ae8c6e27Sflorian  * @param nocaps: ignore capsforid(if in config), do not perturb qname.
117*a1a7ba80Sflorian  * @param check_ratelimit: if set, will check ratelimit before sending out.
118ae8c6e27Sflorian  * @param addr: where to.
119ae8c6e27Sflorian  * @param addrlen: length of addr.
120ae8c6e27Sflorian  * @param zone: wireformat dname of the zone.
121ae8c6e27Sflorian  * @param zonelen: length of zone name.
122*a1a7ba80Sflorian  * @param tcp_upstream: use TCP for upstream queries.
123ae8c6e27Sflorian  * @param ssl_upstream: use SSL for upstream queries.
124ae8c6e27Sflorian  * @param tls_auth_name: if ssl_upstream, use this name with TLS
125ae8c6e27Sflorian  * 	authentication.
126*a1a7ba80Sflorian  * @param q: which query state to reactivate upon return.
127*a1a7ba80Sflorian  * @param was_ratelimited: it will signal back if the query failed to pass the
128*a1a7ba80Sflorian  *	ratelimit check.
129ae8c6e27Sflorian  * @return: false on failure (memory or socket related). no query was
130ae8c6e27Sflorian  *      sent.
131ae8c6e27Sflorian  */
132ae8c6e27Sflorian struct outbound_entry* worker_send_query(struct query_info* qinfo,
133ae8c6e27Sflorian 	uint16_t flags, int dnssec, int want_dnssec, int nocaps,
134*a1a7ba80Sflorian 	int check_ratelimit,
135ae8c6e27Sflorian 	struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
136*a1a7ba80Sflorian 	size_t zonelen, int tcp_upstream, int ssl_upstream, char* tls_auth_name,
137*a1a7ba80Sflorian 	struct module_qstate* q, int* was_ratelimited);
138ae8c6e27Sflorian 
139ae8c6e27Sflorian /**
140ae8c6e27Sflorian  * process control messages from the main thread. Frees the control
141ae8c6e27Sflorian  * command message.
142ae8c6e27Sflorian  * @param tube: tube control message came on.
143ae8c6e27Sflorian  * @param msg: message contents.  Is freed.
144ae8c6e27Sflorian  * @param len: length of message.
145ae8c6e27Sflorian  * @param error: if error (NETEVENT_*) happened.
146ae8c6e27Sflorian  * @param arg: user argument
147ae8c6e27Sflorian  */
148ae8c6e27Sflorian void worker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
149ae8c6e27Sflorian 	int error, void* arg);
150ae8c6e27Sflorian 
151ae8c6e27Sflorian /** handles callbacks from listening event interface */
152ae8c6e27Sflorian int worker_handle_request(struct comm_point* c, void* arg, int error,
153ae8c6e27Sflorian 	struct comm_reply* repinfo);
154ae8c6e27Sflorian 
155ae8c6e27Sflorian /** process incoming serviced query replies from the network */
156ae8c6e27Sflorian int worker_handle_service_reply(struct comm_point* c, void* arg, int error,
157ae8c6e27Sflorian 	struct comm_reply* reply_info);
158ae8c6e27Sflorian 
159ae8c6e27Sflorian /** cleanup the cache to remove all rrset IDs from it, arg is worker */
160ae8c6e27Sflorian void worker_alloc_cleanup(void* arg);
161ae8c6e27Sflorian 
162ae8c6e27Sflorian /** statistics timer callback handler */
163ae8c6e27Sflorian void worker_stat_timer_cb(void* arg);
164ae8c6e27Sflorian 
165ae8c6e27Sflorian /** probe timer callback handler */
166ae8c6e27Sflorian void worker_probe_timer_cb(void* arg);
167ae8c6e27Sflorian 
168ae8c6e27Sflorian /** start accept callback handler */
169ae8c6e27Sflorian void worker_start_accept(void* arg);
170ae8c6e27Sflorian 
171ae8c6e27Sflorian /** stop accept callback handler */
172ae8c6e27Sflorian void worker_stop_accept(void* arg);
173ae8c6e27Sflorian 
174ae8c6e27Sflorian /** handle remote control accept callbacks */
175ae8c6e27Sflorian int remote_accept_callback(struct comm_point*, void*, int, struct comm_reply*);
176ae8c6e27Sflorian 
177ae8c6e27Sflorian /** handle remote control data callbacks */
178ae8c6e27Sflorian int remote_control_callback(struct comm_point*, void*, int, struct comm_reply*);
179ae8c6e27Sflorian 
180ae8c6e27Sflorian /** routine to printout option values over SSL */
181ae8c6e27Sflorian void  remote_get_opt_ssl(char* line, void* arg);
182ae8c6e27Sflorian 
183ae8c6e27Sflorian #endif /* LIBUNBOUND_WORKER_H */
184