worker.h revision 266114
1295484Semaste/*
2295484Semaste * libunbound/worker.h - prototypes for worker methods.
3295484Semaste *
4295484Semaste * Copyright (c) 2007, NLnet Labs. All rights reserved.
5295484Semaste *
6295484Semaste * This software is open source.
7295484Semaste *
8295484Semaste * Redistribution and use in source and binary forms, with or without
9295484Semaste * modification, are permitted provided that the following conditions
10295484Semaste * are met:
11295484Semaste *
12295484Semaste * Redistributions of source code must retain the above copyright notice,
13295484Semaste * this list of conditions and the following disclaimer.
14295484Semaste *
15295484Semaste * Redistributions in binary form must reproduce the above copyright notice,
16295484Semaste * this list of conditions and the following disclaimer in the documentation
17295484Semaste * and/or other materials provided with the distribution.
18295484Semaste *
19295484Semaste * Neither the name of the NLNET LABS nor the names of its contributors may
20295484Semaste * be used to endorse or promote products derived from this software without
21295484Semaste * specific prior written permission.
22295484Semaste *
23295484Semaste * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24295484Semaste * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25295484Semaste * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26295484Semaste * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27295484Semaste * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28295484Semaste * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29295484Semaste * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30295484Semaste * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31295484Semaste * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32295484Semaste * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33295484Semaste * POSSIBILITY OF SUCH DAMAGE.
34295484Semaste */
35295484Semaste
36295484Semaste/**
37295484Semaste * \file
38295484Semaste *
39295484Semaste * This file declares the methods any worker has to implement.
40295484Semaste */
41295484Semaste
42295484Semaste#ifndef LIBUNBOUND_WORKER_H
43295484Semaste#define LIBUNBOUND_WORKER_H
44295484Semaste
45295484Semaste#include "ldns/sbuffer.h"
46295484Semaste#include "util/data/packed_rrset.h" /* for enum sec_status */
47295484Semastestruct comm_reply;
48295484Semastestruct comm_point;
49295484Semastestruct module_qstate;
50295484Semastestruct tube;
51295484Semaste
52295484Semaste/**
53295484Semaste * Worker service routine to send serviced queries to authoritative servers.
54295484Semaste * @param qname: query name. (host order)
55295484Semaste * @param qnamelen: length in bytes of qname, including trailing 0.
56295484Semaste * @param qtype: query type. (host order)
57295484Semaste * @param qclass: query class. (host order)
58295484Semaste * @param flags: host order flags word, with opcode and CD bit.
59295484Semaste * @param dnssec: if set, EDNS record will have DO bit set.
60295484Semaste * @param want_dnssec: signatures needed.
61295484Semaste * @param addr: where to.
62295484Semaste * @param addrlen: length of addr.
63295484Semaste * @param zone: delegation point name.
64295484Semaste * @param zonelen: length of zone name wireformat dname.
65295484Semaste * @param q: wich query state to reactivate upon return.
66295484Semaste * @return: false on failure (memory or socket related). no query was
67295484Semaste *      sent.
68295484Semaste */
69295484Semastestruct outbound_entry* libworker_send_query(uint8_t* qname, size_t qnamelen,
70295484Semaste        uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec,
71295484Semaste	int want_dnssec, struct sockaddr_storage* addr, socklen_t addrlen,
72295484Semaste	uint8_t* zone, size_t zonelen, struct module_qstate* q);
73295484Semaste
74295484Semaste/** process incoming replies from the network */
75295484Semasteint libworker_handle_reply(struct comm_point* c, void* arg, int error,
76295484Semaste        struct comm_reply* reply_info);
77295484Semaste
78295484Semaste/** process incoming serviced query replies from the network */
79295484Semasteint libworker_handle_service_reply(struct comm_point* c, void* arg, int error,
80295484Semaste        struct comm_reply* reply_info);
81295484Semaste
82295484Semaste/** handle control command coming into server */
83295484Semastevoid libworker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
84295484Semaste	int err, void* arg);
85295484Semaste
86295484Semaste/** mesh callback with fg results */
87295484Semastevoid libworker_fg_done_cb(void* arg, int rcode, sldns_buffer* buf,
88295484Semaste	enum sec_status s, char* why_bogus);
89295484Semaste
90295484Semaste/** mesh callback with bg results */
91295484Semastevoid libworker_bg_done_cb(void* arg, int rcode, sldns_buffer* buf,
92295484Semaste	enum sec_status s, char* why_bogus);
93295484Semaste
94295484Semaste/**
95295484Semaste * Worker signal handler function. User argument is the worker itself.
96295484Semaste * @param sig: signal number.
97295484Semaste * @param arg: the worker (main worker) that handles signals.
98295484Semaste */
99295484Semastevoid worker_sighandler(int sig, void* arg);
100295484Semaste
101295484Semaste/**
102295484Semaste * Worker service routine to send serviced queries to authoritative servers.
103295484Semaste * @param qname: query name. (host order)
104295484Semaste * @param qnamelen: length in bytes of qname, including trailing 0.
105295484Semaste * @param qtype: query type. (host order)
106295484Semaste * @param qclass: query class. (host order)
107295484Semaste * @param flags: host order flags word, with opcode and CD bit.
108295484Semaste * @param dnssec: if set, EDNS record will have DO bit set.
109295484Semaste * @param want_dnssec: signatures needed.
110295484Semaste * @param addr: where to.
111295484Semaste * @param addrlen: length of addr.
112295484Semaste * @param zone: wireformat dname of the zone.
113295484Semaste * @param zonelen: length of zone name.
114295484Semaste * @param q: wich query state to reactivate upon return.
115295484Semaste * @return: false on failure (memory or socket related). no query was
116295484Semaste *      sent.
117295484Semaste */
118295484Semastestruct outbound_entry* worker_send_query(uint8_t* qname, size_t qnamelen,
119295484Semaste	uint16_t qtype, uint16_t qclass, uint16_t flags, int dnssec,
120295484Semaste	int want_dnssec, struct sockaddr_storage* addr, socklen_t addrlen,
121295484Semaste	uint8_t* zone, size_t zonelen, struct module_qstate* q);
122295484Semaste
123295484Semaste/**
124295484Semaste * process control messages from the main thread. Frees the control
125295484Semaste * command message.
126295484Semaste * @param tube: tube control message came on.
127295484Semaste * @param msg: message contents.  Is freed.
128295484Semaste * @param len: length of message.
129295484Semaste * @param error: if error (NETEVENT_*) happened.
130295484Semaste * @param arg: user argument
131295484Semaste */
132295484Semastevoid worker_handle_control_cmd(struct tube* tube, uint8_t* msg, size_t len,
133295484Semaste	int error, void* arg);
134295484Semaste
135295484Semaste/** handles callbacks from listening event interface */
136295484Semasteint worker_handle_request(struct comm_point* c, void* arg, int error,
137295484Semaste	struct comm_reply* repinfo);
138295484Semaste
139295484Semaste/** process incoming replies from the network */
140295484Semasteint worker_handle_reply(struct comm_point* c, void* arg, int error,
141295484Semaste	struct comm_reply* reply_info);
142295484Semaste
143295484Semaste/** process incoming serviced query replies from the network */
144295484Semasteint worker_handle_service_reply(struct comm_point* c, void* arg, int error,
145295484Semaste	struct comm_reply* reply_info);
146295484Semaste
147295484Semaste/** cleanup the cache to remove all rrset IDs from it, arg is worker */
148295484Semastevoid worker_alloc_cleanup(void* arg);
149295484Semaste
150295484Semaste/** statistics timer callback handler */
151295484Semastevoid worker_stat_timer_cb(void* arg);
152295484Semaste
153295484Semaste/** probe timer callback handler */
154295484Semastevoid worker_probe_timer_cb(void* arg);
155295484Semaste
156295484Semaste/** start accept callback handler */
157295484Semastevoid worker_start_accept(void* arg);
158295484Semaste
159295484Semaste/** stop accept callback handler */
160295484Semastevoid worker_stop_accept(void* arg);
161295484Semaste
162295484Semaste/** handle remote control accept callbacks */
163295484Semasteint remote_accept_callback(struct comm_point*, void*, int, struct comm_reply*);
164295484Semaste
165295484Semaste/** handle remote control data callbacks */
166295484Semasteint remote_control_callback(struct comm_point*, void*, int, struct comm_reply*);
167295484Semaste
168295484Semaste/** routine to printout option values over SSL */
169295484Semastevoid  remote_get_opt_ssl(char* line, void* arg);
170295484Semaste
171295484Semaste#endif /* LIBUNBOUND_WORKER_H */
172295484Semaste