2 * Copyright (C) 2004-2007, 2009, 2010 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: request.h,v 1.31 2010-03-04 23:50:34 tbox Exp $ */
21 #define DNS_REQUEST_H 1
27 /*! \file dns/request.h
30 * The request module provides simple request/response services useful for
31 * sending SOA queries, DNS Notify messages, and dynamic update requests.
34 *\li The module ensures appropriate synchronization of data structures it
35 * creates and manipulates.
41 *\li No anticipated impact.
45 #include <isc/event.h>
47 #include <dns/types.h>
49 #define DNS_REQUESTOPT_TCP 0x00000001U
50 #define DNS_REQUESTOPT_CASE 0x00000002U
52 typedef struct dns_requestevent {
53 ISC_EVENT_COMMON(struct dns_requestevent);
55 dns_request_t *request;
61 dns_requestmgr_create(isc_mem_t *mctx, isc_timermgr_t *timermgr,
62 isc_socketmgr_t *socketmgr, isc_taskmgr_t *taskmgr,
63 dns_dispatchmgr_t *dispatchmgr,
64 dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6,
65 dns_requestmgr_t **requestmgrp);
67 * Create a request manager.
71 *\li 'mctx' is a valid memory context.
73 *\li 'timermgr' is a valid timer manager.
75 *\li 'socketmgr' is a valid socket manager.
77 *\li 'taskmgr' is a valid task manager.
79 *\li 'dispatchv4' is a valid dispatcher with an IPv4 UDP socket, or is NULL.
81 *\li 'dispatchv6' is a valid dispatcher with an IPv6 UDP socket, or is NULL.
83 *\li requestmgrp != NULL && *requestmgrp == NULL
87 *\li On success, *requestmgrp is a valid request manager.
93 *\li Any other result indicates failure.
97 dns_requestmgr_whenshutdown(dns_requestmgr_t *requestmgr, isc_task_t *task,
98 isc_event_t **eventp);
100 * Send '*eventp' to 'task' when 'requestmgr' has completed shutdown.
104 *\li It is not safe to detach the last reference to 'requestmgr' until
105 * shutdown is complete.
109 *\li 'requestmgr' is a valid request manager.
111 *\li 'task' is a valid task.
113 *\li *eventp is a valid event.
117 *\li *eventp == NULL.
121 dns_requestmgr_shutdown(dns_requestmgr_t *requestmgr);
123 * Start the shutdown process for 'requestmgr'.
127 *\li This call has no effect if the request manager is already shutting
132 *\li 'requestmgr' is a valid requestmgr.
136 dns_requestmgr_attach(dns_requestmgr_t *source, dns_requestmgr_t **targetp);
138 * Attach to the request manager. dns_requestmgr_shutdown() must not
139 * have been called on 'source' prior to calling dns_requestmgr_attach().
143 *\li 'source' is a valid requestmgr.
145 *\li 'targetp' to be non NULL and '*targetp' to be NULL.
149 dns_requestmgr_detach(dns_requestmgr_t **requestmgrp);
151 * Detach from the given requestmgr. If this is the final detach
152 * requestmgr will be destroyed. dns_requestmgr_shutdown() must
153 * be called before the final detach.
157 *\li '*requestmgrp' is a valid requestmgr.
160 *\li '*requestmgrp' is NULL.
164 dns_request_create(dns_requestmgr_t *requestmgr, dns_message_t *message,
165 isc_sockaddr_t *address, unsigned int options,
167 unsigned int timeout, isc_task_t *task,
168 isc_taskaction_t action, void *arg,
169 dns_request_t **requestp);
171 * Create and send a request.
175 *\li 'message' will be rendered and sent to 'address'. If the
176 * #DNS_REQUESTOPT_TCP option is set, TCP will be used. The request
177 * will timeout after 'timeout' seconds.
179 *\li If the #DNS_REQUESTOPT_CASE option is set, use case sensitive
182 *\li When the request completes, successfully, due to a timeout, or
183 * because it was canceled, a completion event will be sent to 'task'.
187 *\li 'message' is a valid DNS message.
189 *\li 'address' is a valid sockaddr.
193 *\li 'task' is a valid task.
195 *\li requestp != NULL && *requestp == NULL
198 /*% See dns_request_createvia3() */
200 dns_request_createvia(dns_requestmgr_t *requestmgr, dns_message_t *message,
201 isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
202 unsigned int options, dns_tsigkey_t *key,
203 unsigned int timeout, isc_task_t *task,
204 isc_taskaction_t action, void *arg,
205 dns_request_t **requestp);
207 /*% See dns_request_createvia3() */
209 dns_request_createvia2(dns_requestmgr_t *requestmgr, dns_message_t *message,
210 isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
211 unsigned int options, dns_tsigkey_t *key,
212 unsigned int timeout, unsigned int udptimeout,
213 isc_task_t *task, isc_taskaction_t action, void *arg,
214 dns_request_t **requestp);
217 dns_request_createvia3(dns_requestmgr_t *requestmgr, dns_message_t *message,
218 isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
219 unsigned int options, dns_tsigkey_t *key,
220 unsigned int timeout, unsigned int udptimeout,
221 unsigned int udpretries, isc_task_t *task,
222 isc_taskaction_t action, void *arg,
223 dns_request_t **requestp);
225 * Create and send a request.
229 *\li 'message' will be rendered and sent to 'address'. If the
230 * #DNS_REQUESTOPT_TCP option is set, TCP will be used. The request
231 * will timeout after 'timeout' seconds. UDP requests will be resent
232 * at 'udptimeout' intervals if non-zero or 'udpretries' is non-zero.
234 *\li If the #DNS_REQUESTOPT_CASE option is set, use case sensitive
237 *\li When the request completes, successfully, due to a timeout, or
238 * because it was canceled, a completion event will be sent to 'task'.
242 *\li 'message' is a valid DNS message.
244 *\li 'dstaddr' is a valid sockaddr.
246 *\li 'srcaddr' is a valid sockaddr or NULL.
248 *\li 'srcaddr' and 'dstaddr' are the same protocol family.
252 *\li 'task' is a valid task.
254 *\li requestp != NULL && *requestp == NULL
257 /*% See dns_request_createraw3() */
259 dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
260 isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
261 unsigned int options, unsigned int timeout,
262 isc_task_t *task, isc_taskaction_t action, void *arg,
263 dns_request_t **requestp);
265 /*% See dns_request_createraw3() */
267 dns_request_createraw2(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
268 isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
269 unsigned int options, unsigned int timeout,
270 unsigned int udptimeout, isc_task_t *task,
271 isc_taskaction_t action, void *arg,
272 dns_request_t **requestp);
275 dns_request_createraw3(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf,
276 isc_sockaddr_t *srcaddr, isc_sockaddr_t *destaddr,
277 unsigned int options, unsigned int timeout,
278 unsigned int udptimeout, unsigned int udpretries,
279 isc_task_t *task, isc_taskaction_t action, void *arg,
280 dns_request_t **requestp);
282 * \brief Create and send a request.
286 *\li 'msgbuf' will be sent to 'destaddr' after setting the id. If the
287 * #DNS_REQUESTOPT_TCP option is set, TCP will be used. The request
288 * will timeout after 'timeout' seconds. UDP requests will be resent
289 * at 'udptimeout' intervals if non-zero or if 'udpretries' is not zero.
291 *\li When the request completes, successfully, due to a timeout, or
292 * because it was canceled, a completion event will be sent to 'task'.
296 *\li 'msgbuf' is a valid DNS message in compressed wire format.
298 *\li 'destaddr' is a valid sockaddr.
300 *\li 'srcaddr' is a valid sockaddr or NULL.
302 *\li 'srcaddr' and 'dstaddr' are the same protocol family.
306 *\li 'task' is a valid task.
308 *\li requestp != NULL && *requestp == NULL
312 dns_request_cancel(dns_request_t *request);
318 *\li 'request' is a valid request.
322 *\li If the completion event for 'request' has not yet been sent, it
323 * will be sent, and the result code will be ISC_R_CANCELED.
327 dns_request_getresponse(dns_request_t *request, dns_message_t *message,
328 unsigned int options);
330 * Get the response to 'request' by filling in 'message'.
332 * 'options' is passed to dns_message_parse(). See dns_message_parse()
337 *\li 'request' is a valid request for which the caller has received the
340 *\li The result code of the completion event was #ISC_R_SUCCESS.
346 *\li Any result that dns_message_parse() can return.
350 dns_request_usedtcp(dns_request_t *request);
352 * Return whether this query used TCP or not. Setting #DNS_REQUESTOPT_TCP
353 * in the call to dns_request_create() will cause the function to return
354 * #ISC_TRUE, otherwise the result is based on the query message size.
357 *\li 'request' is a valid request.
360 *\li ISC_TRUE if TCP was used.
361 *\li ISC_FALSE if UDP was used.
365 dns_request_destroy(dns_request_t **requestp);
371 *\li 'request' is a valid request for which the caller has received the
376 *\li *requestp == NULL
381 #endif /* DNS_REQUEST_H */