1132718Skan/*
2169689Skan * libunbound/worker.h - prototypes for worker methods.
3117395Skan *
4117395Skan * Copyright (c) 2007, NLnet Labs. All rights reserved.
5117395Skan *
6117395Skan * This software is open source.
7117395Skan *
8117395Skan * Redistribution and use in source and binary forms, with or without
9117395Skan * modification, are permitted provided that the following conditions
10117395Skan * are met:
11117395Skan *
12117395Skan * Redistributions of source code must retain the above copyright notice,
13117395Skan * this list of conditions and the following disclaimer.
14117395Skan *
15117395Skan * Redistributions in binary form must reproduce the above copyright notice,
16169689Skan * this list of conditions and the following disclaimer in the documentation
17117395Skan * and/or other materials provided with the distribution.
18132718Skan *
19117395Skan * Neither the name of the NLNET LABS nor the names of its contributors may
20117395Skan * be used to endorse or promote products derived from this software without
21132718Skan * specific prior written permission.
22132718Skan *
23132718Skan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24117395Skan * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25117395Skan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26132718Skan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27117395Skan * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28117395Skan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29117395Skan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30117395Skan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31117395Skan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32117395Skan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33132718Skan * POSSIBILITY OF SUCH DAMAGE.
34117395Skan */
35132718Skan
36117395Skan/**
37117395Skan * \file
38117395Skan *
39117395Skan * This file declares the methods any worker has to implement.
40117395Skan */
41132718Skan
42117395Skan#ifndef LIBUNBOUND_WORKER_H
43132718Skan#define LIBUNBOUND_WORKER_H
44132718Skan
45117395Skan#include "util/data/packed_rrset.h" /* for enum sec_status */
46117395Skanstruct comm_reply;
47117395Skanstruct comm_point;
48117395Skanstruct module_qstate;
49117395Skanstruct tube;
50117395Skan
51117395Skan/**
52117395Skan * Worker service routine to send serviced queries to authoritative servers.
53117395Skan * @param qname: query name. (host order)
54117395Skan * @param qnamelen: length in bytes of qname, including trailing 0.
55117395Skan * @param qtype: query type. (host order)
56117395Skan * @param qclass: query class. (host order)
57117395Skan * @param flags: host order flags word, with opcode and CD bit.
58132718Skan * @param dnssec: if set, EDNS record will have DO bit set.
59132718Skan * @param want_dnssec: signatures needed.
60132718Skan * @param addr: where to.
61132718Skan * @param addrlen: length of addr.
62117395Skan * @param zone: delegation point name.
63132718Skan * @param zonelen: length of zone name wireformat dname.
64117395Skan * @param q: wich query state to reactivate upon return.
65132718Skan * @return: false on failure (memory or socket related). no query was
66132718Skan *      sent.
67132718Skan */
68132718Skanstruct outbound_entry* libworker_send_query(uint8_t* qname, size_t qnamelen,
69117395Skan        uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec,
70169689Skan	int want_dnssec, struct sockaddr_storage* addr, socklen_t addrlen,
71169689Skan	uint8_t* zone, size_t zonelen, struct module_qstate* q);
72132718Skan
73117395Skan/** process incoming replies from the network */
74132718Skanint libworker_handle_reply(struct comm_point* c, void* arg, int error,
75132718Skan        struct comm_reply* reply_info);
76169689Skan
77169689Skan/** process incoming serviced query replies from the network */
78132718Skanint libworker_handle_service_reply(struct comm_point* c, void* arg, int error,
79132718Skan        struct comm_reply* reply_info);
80132718Skan
81132718Skan/** handle control command coming into server */
82132718Skanvoid libworker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
83117395Skan	int err, void* arg);
84117395Skan
85117395Skan/** mesh callback with fg results */
86117395Skanvoid libworker_fg_done_cb(void* arg, int rcode, ldns_buffer* buf,
87117395Skan	enum sec_status s, char* why_bogus);
88
89/** mesh callback with bg results */
90void libworker_bg_done_cb(void* arg, int rcode, ldns_buffer* buf,
91	enum sec_status s, char* why_bogus);
92
93/**
94 * Worker signal handler function. User argument is the worker itself.
95 * @param sig: signal number.
96 * @param arg: the worker (main worker) that handles signals.
97 */
98void worker_sighandler(int sig, void* arg);
99
100/**
101 * Worker service routine to send serviced queries to authoritative servers.
102 * @param qname: query name. (host order)
103 * @param qnamelen: length in bytes of qname, including trailing 0.
104 * @param qtype: query type. (host order)
105 * @param qclass: query class. (host order)
106 * @param flags: host order flags word, with opcode and CD bit.
107 * @param dnssec: if set, EDNS record will have DO bit set.
108 * @param want_dnssec: signatures needed.
109 * @param addr: where to.
110 * @param addrlen: length of addr.
111 * @param zone: wireformat dname of the zone.
112 * @param zonelen: length of zone name.
113 * @param q: wich query state to reactivate upon return.
114 * @return: false on failure (memory or socket related). no query was
115 *      sent.
116 */
117struct outbound_entry* worker_send_query(uint8_t* qname, size_t qnamelen,
118	uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec,
119	int want_dnssec, struct sockaddr_storage* addr, socklen_t addrlen,
120	uint8_t* zone, size_t zonelen, struct module_qstate* q);
121
122/**
123 * process control messages from the main thread. Frees the control
124 * command message.
125 * @param tube: tube control message came on.
126 * @param msg: message contents.  Is freed.
127 * @param len: length of message.
128 * @param error: if error (NETEVENT_*) happened.
129 * @param arg: user argument
130 */
131void worker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
132	int error, void* arg);
133
134/** handles callbacks from listening event interface */
135int worker_handle_request(struct comm_point* c, void* arg, int error,
136	struct comm_reply* repinfo);
137
138/** process incoming replies from the network */
139int worker_handle_reply(struct comm_point* c, void* arg, int error,
140	struct comm_reply* reply_info);
141
142/** process incoming serviced query replies from the network */
143int worker_handle_service_reply(struct comm_point* c, void* arg, int error,
144	struct comm_reply* reply_info);
145
146/** cleanup the cache to remove all rrset IDs from it, arg is worker */
147void worker_alloc_cleanup(void* arg);
148
149/** statistics timer callback handler */
150void worker_stat_timer_cb(void* arg);
151
152/** probe timer callback handler */
153void worker_probe_timer_cb(void* arg);
154
155/** start accept callback handler */
156void worker_start_accept(void* arg);
157
158/** stop accept callback handler */
159void worker_stop_accept(void* arg);
160
161/** handle remote control accept callbacks */
162int remote_accept_callback(struct comm_point*, void*, int, struct comm_reply*);
163
164/** handle remote control data callbacks */
165int remote_control_callback(struct comm_point*, void*, int, struct comm_reply*);
166
167/** routine to printout option values over SSL */
168void  remote_get_opt_ssl(char* line, void* arg);
169
170#endif /* LIBUNBOUND_WORKER_H */
171