worker.h revision 356345
1/*
2 * libunbound/worker.h - prototypes for worker methods.
3 *
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
5 *
6 * This software is open source.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
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.
18 *
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.
22 *
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.
34 */
35
36/**
37 * \file
38 *
39 * This file declares the methods any worker has to implement.
40 */
41
42#ifndef LIBUNBOUND_WORKER_H
43#define LIBUNBOUND_WORKER_H
44
45#include "sldns/sbuffer.h"
46#include "util/data/packed_rrset.h" /* for enum sec_status */
47struct comm_reply;
48struct comm_point;
49struct module_qstate;
50struct tube;
51struct edns_option;
52struct query_info;
53
54/**
55 * Worker service routine to send serviced queries to authoritative servers.
56 * @param qinfo: query info.
57 * @param flags: host order flags word, with opcode and CD bit.
58 * @param dnssec: if set, EDNS record will have DO bit set.
59 * @param want_dnssec: signatures needed.
60 * @param nocaps: ignore capsforid(if in config), do not perturb qname.
61 * @param addr: where to.
62 * @param addrlen: length of addr.
63 * @param zone: delegation point name.
64 * @param zonelen: length of zone name wireformat dname.
65 * @param ssl_upstream: use SSL for upstream queries.
66 * @param tls_auth_name: if ssl_upstream, use this name with TLS
67 * 	authentication.
68 * @param q: wich query state to reactivate upon return.
69 * @return: false on failure (memory or socket related). no query was
70 *      sent.
71 */
72struct outbound_entry* libworker_send_query(struct query_info* qinfo,
73	uint16_t flags, int dnssec, int want_dnssec, int nocaps,
74	struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
75	size_t zonelen, int ssl_upstream, char* tls_auth_name,
76	struct module_qstate* q);
77
78/** process incoming replies from the network */
79int libworker_handle_reply(struct comm_point* c, void* arg, int error,
80        struct comm_reply* reply_info);
81
82/** process incoming serviced query replies from the network */
83int libworker_handle_service_reply(struct comm_point* c, void* arg, int error,
84        struct comm_reply* reply_info);
85
86/** handle control command coming into server */
87void libworker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
88	int err, void* arg);
89
90/** mesh callback with fg results */
91void libworker_fg_done_cb(void* arg, int rcode, sldns_buffer* buf,
92	enum sec_status s, char* why_bogus, int was_ratelimited);
93
94/** mesh callback with bg results */
95void libworker_bg_done_cb(void* arg, int rcode, sldns_buffer* buf,
96	enum sec_status s, char* why_bogus, int was_ratelimited);
97
98/** mesh callback with event results */
99void libworker_event_done_cb(void* arg, int rcode, struct sldns_buffer* buf,
100	enum sec_status s, char* why_bogus, int was_ratelimited);
101
102/**
103 * Worker signal handler function. User argument is the worker itself.
104 * @param sig: signal number.
105 * @param arg: the worker (main worker) that handles signals.
106 */
107void worker_sighandler(int sig, void* arg);
108
109/**
110 * Worker service routine to send serviced queries to authoritative servers.
111 * @param qinfo: query info.
112 * @param flags: host order flags word, with opcode and CD bit.
113 * @param dnssec: if set, EDNS record will have DO bit set.
114 * @param want_dnssec: signatures needed.
115 * @param nocaps: ignore capsforid(if in config), do not perturb qname.
116 * @param addr: where to.
117 * @param addrlen: length of addr.
118 * @param zone: wireformat dname of the zone.
119 * @param zonelen: length of zone name.
120 * @param ssl_upstream: use SSL for upstream queries.
121 * @param tls_auth_name: if ssl_upstream, use this name with TLS
122 * 	authentication.
123 * @param q: wich query state to reactivate upon return.
124 * @return: false on failure (memory or socket related). no query was
125 *      sent.
126 */
127struct outbound_entry* worker_send_query(struct query_info* qinfo,
128	uint16_t flags, int dnssec, int want_dnssec, int nocaps,
129	struct sockaddr_storage* addr, socklen_t addrlen, uint8_t* zone,
130	size_t zonelen, int ssl_upstream, char* tls_auth_name,
131	struct module_qstate* q);
132
133/**
134 * process control messages from the main thread. Frees the control
135 * command message.
136 * @param tube: tube control message came on.
137 * @param msg: message contents.  Is freed.
138 * @param len: length of message.
139 * @param error: if error (NETEVENT_*) happened.
140 * @param arg: user argument
141 */
142void worker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
143	int error, void* arg);
144
145/** handles callbacks from listening event interface */
146int worker_handle_request(struct comm_point* c, void* arg, int error,
147	struct comm_reply* repinfo);
148
149/** process incoming replies from the network */
150int worker_handle_reply(struct comm_point* c, void* arg, int error,
151	struct comm_reply* reply_info);
152
153/** process incoming serviced query replies from the network */
154int worker_handle_service_reply(struct comm_point* c, void* arg, int error,
155	struct comm_reply* reply_info);
156
157/** cleanup the cache to remove all rrset IDs from it, arg is worker */
158void worker_alloc_cleanup(void* arg);
159
160/** statistics timer callback handler */
161void worker_stat_timer_cb(void* arg);
162
163/** probe timer callback handler */
164void worker_probe_timer_cb(void* arg);
165
166/** start accept callback handler */
167void worker_start_accept(void* arg);
168
169/** stop accept callback handler */
170void worker_stop_accept(void* arg);
171
172/** handle remote control accept callbacks */
173int remote_accept_callback(struct comm_point*, void*, int, struct comm_reply*);
174
175/** handle remote control data callbacks */
176int remote_control_callback(struct comm_point*, void*, int, struct comm_reply*);
177
178/** routine to printout option values over SSL */
179void  remote_get_opt_ssl(char* line, void* arg);
180
181#endif /* LIBUNBOUND_WORKER_H */
182