request.c revision 046a9aca49bdc25bd57d75fd0dd34c021722f095
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * Copyright (C) 2000 Internet Software Consortium.
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * Permission to use, copy, modify, and distribute this software for any
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * purpose with or without fee is hereby granted, provided that the above
7de2c6e6d51f38daeb2d346f3f21dc01ccece6daEvan Hunt * copyright notice and this permission notice appear in all copies.
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
279c6ec074be17dce62dd1b2c6ed7c2cc56a7b78David Lawrence/* $Id: request.c,v 1.46 2000/12/31 05:05:34 marka Exp $ */
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein#define VALID_REQUEST(request) ((request) != NULL && \
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeintypedef ISC_LIST(dns_request_t) dns_requestlist_t;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein /* locked */
194b6a25192581bbc8ec731e32e8989042b202a4Michael Graff unsigned int hash;
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein unsigned int hash;
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington#define DNS_REQUEST_F_TIMEDOUT 0x0008 /* cancelled due to a timeout */
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington#define DNS_REQUEST_F_TCP 0x0010 /* This request used TCP */
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington (((r)->flags & DNS_REQUEST_F_CANCELED) != 0)
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrencestatic void mgr_destroy(dns_requestmgr_t *requestmgr);
ed71ea51c6ecb5d7d659b6e6a20f6b3f5c2678c6David Lawrencestatic void mgr_shutdown(dns_requestmgr_t *requestmgr);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinstatic unsigned int mgr_gethash(dns_requestmgr_t *requestmgr);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrencestatic void send_shutdown_events(dns_requestmgr_t *requestmgr);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinstatic isc_result_t req_render(dns_message_t *message, isc_buffer_t **buffer,
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrencestatic void req_senddone(isc_task_t *task, isc_event_t *event);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrencestatic void req_response(isc_task_t *task, isc_event_t *event);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrencestatic void req_timeout(isc_task_t *task, isc_event_t *event);
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austeinstatic void req_connected(isc_task_t *task, isc_event_t *event);
49a2cf8f211213712d452287ae8e121cf59e3178David Lawrencestatic void req_sendevent(dns_request_t *request, isc_result_t result);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsstatic void req_destroy(dns_request_t *request);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsstatic void req_log(int level, const char *fmt, ...);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews req_log(ISC_LOG_DEBUG(3), "dns_requestmgr_create");
cffc2e06f906dd048af4cc27d487deb157f5a082Mark Andrews REQUIRE(requestmgrp != NULL && *requestmgrp == NULL);
70e854766f5304f43e94212dc38ebaefe214148cMark Andrews REQUIRE(isc_socket_gettype(socket) == isc_sockettype_udp);
43501e6570e9081d459fb5c1a81b73c2c53c5df0Mark Andrews REQUIRE(isc_socket_gettype(socket) == isc_sockettype_udp);
2b66a51a7d72e9cc07917fb583ad528b0539d2a3Mark Andrews requestmgr = isc_mem_get(mctx, sizeof(*requestmgr));
64b92523f9333ba053f4b2860335583be455b0b3Brian Wellington isc_mem_put(mctx, requestmgr, sizeof(*requestmgr));
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley for (i = 0; i < DNS_REQUEST_NLOCKS; i++) {
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews result = isc_mutex_init(&requestmgr->locks[i]);
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews while (--i >= 0)
289ae548d52bc8f982d9823af64cafda7bd92232Mark Andrews isc_mem_put(mctx, requestmgr, sizeof(*requestmgr));
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews dns_dispatch_attach(dispatchv4, &requestmgr->dispatchv4);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews dns_dispatch_attach(dispatchv6, &requestmgr->dispatchv6);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews req_log(ISC_LOG_DEBUG(3), "dns_requestmgr_create: %p", requestmgr);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsdns_requestmgr_whenshutdown(dns_requestmgr_t *requestmgr, isc_task_t *task,
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews req_log(ISC_LOG_DEBUG(3), "dns_requestmgr_whenshutdown");
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews * We're already shutdown. Send the event.
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews ISC_LIST_APPEND(requestmgr->whenshutdown, event, ev_link);
101a7960b7989a18d873f3302b3b2415aeafb108Mark Andrewsdns_requestmgr_shutdown(dns_requestmgr_t *requestmgr) {
2b50e0d877db0d668f363d50914232f82ad8c454Mark Andrews req_log(ISC_LOG_DEBUG(3), "dns_requestmgr_shutdown: %p", requestmgr);
203596d27c225ea195e4faad4f19388c6e96ac80Bob Halley req_log(ISC_LOG_DEBUG(3), "mgr_shutdown: %p", requestmgr);
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews * Caller holds lock.
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews for (request = ISC_LIST_HEAD(requestmgr->requests);
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyrequestmgr_attach(dns_requestmgr_t *source, dns_requestmgr_t **targetp) {
e7fb847ed570dd8c1bcdacabb3d69bd81feb79aeMark Andrews * Locked by caller.
15bfd48fc5552ff1aae766021f42a250c001a098Michael Graff req_log(ISC_LOG_DEBUG(3), "requestmgr_attach: %p: eref %d iref %d",
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrewsrequestmgr_detach(dns_requestmgr_t **requestmgrp) {
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews req_log(ISC_LOG_DEBUG(3), "requestmgr_detach: %p: eref %d iref %d",
f54d0c9c6e65de367d4ef08f51d22a2fb4c56208Mark Andrews requestmgr, requestmgr->eref, requestmgr->iref);
577ca1471960830304d1d2b9bd543fa469af51c1Mark Andrews if (requestmgr->iref == 0 && requestmgr->exiting) {
577ca1471960830304d1d2b9bd543fa469af51c1Mark Andrews INSIST(ISC_LIST_HEAD(requestmgr->requests) == NULL);
281bfa2a98f1d1721538086e1b550185559f1d8bMark Andrewsdns_requestmgr_attach(dns_requestmgr_t *source, dns_requestmgr_t **targetp) {
6e9efadbea9febb0494e713e54dfea6f7ef70383Mark Andrews req_log(ISC_LOG_DEBUG(3), "dns_requestmgr_attach: %p: eref %d iref %d",
8486ce1efa5deded85415d21d5696e5a51c63357Mark Andrewsdns_requestmgr_detach(dns_requestmgr_t **requestmgrp) {
if (need_destroy)
for (i = 0; i < DNS_REQUEST_NLOCKS; i++)
static inline isc_result_t
isc_region_t r;
return (result);
unsigned int attrs;
isc_region_t r;
&blackhole);
int match;
match > 0)
if (drop) {
sizeof(netaddrstr));
return (DNS_R_BLACKHOLED);
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
if (tcp) {
goto cleanup;
goto cleanup;
attrs = 0;
goto cleanup;
case PF_INET:
case PF_INET6:
goto cleanup;
goto cleanup;
attrs = 0;
case PF_INET:
case PF_INET6:
goto cleanup;
attrmask = 0;
goto cleanup;
goto cleanup;
goto cleanup;
if (tcp)
goto cleanup;
if (tcp)
goto cleanup;
goto unlink;
goto unlink;
goto unlink;
goto unlink;
return (ISC_R_SUCCESS);
return (result);
unsigned int attrs;
&blackhole);
int match;
match > 0)
if (drop) {
sizeof(netaddrstr));
return (DNS_R_BLACKHOLED);
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
attrs = 0;
goto cleanup;
case PF_INET:
case PF_INET6:
goto cleanup;
goto cleanup;
attrs = 0;
case PF_INET:
case PF_INET6:
goto cleanup;
attrmask = 0;
goto cleanup;
goto cleanup;
goto use_tcp;
goto cleanup;
goto cleanup;
goto cleanup;
goto unlink;
goto unlink;
goto unlink;
goto unlink;
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
isc_region_t r;
return (result);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
if (tcp)
goto cleanup;
return (ISC_R_SUCCESS);
return (result);
return (ISC_R_SUCCESS);
unsigned int options)
request);
return (result);
return (result);
isc_region_t r;
goto done;
r.length);
goto done;
done: