Lines Matching refs:request

29 #include <dns/request.h>
37 #define VALID_REQUEST(request) ISC_MAGIC_VALID(request, REQUEST_MAGIC)
91 #define DNS_REQUEST_F_TCP 0x0010 /*%< This request used TCP */
116 static isc_socket_t * req_getsocket(dns_request_t *request);
118 static void req_sendevent(dns_request_t *request, isc_result_t result);
119 static void req_cancel(dns_request_t *request);
120 static void req_destroy(dns_request_t *request);
252 dns_request_t *request;
259 for (request = ISC_LIST_HEAD(requestmgr->requests);
260 request != NULL;
261 request = ISC_LIST_NEXT(request, link)) {
262 dns_request_cancel(request);
419 req_send(dns_request_t *request, isc_task_t *task, isc_sockaddr_t *address) {
425 req_log(ISC_LOG_DEBUG(3), "req_send: request %p", request);
427 REQUIRE(VALID_REQUEST(request));
428 sock = req_getsocket(request);
429 isc_buffer_usedregion(request->query, &r);
435 sendevent = isc_socket_socketevent(request->mctx, sock,
437 req_senddone, request);
440 if (request->dscp == -1) {
445 sendevent->dscp = request->dscp;
448 request->flags |= DNS_REQUEST_F_SENDING;
452 request->flags &= ~DNS_REQUEST_F_SENDING;
459 dns_request_t *request;
461 request = isc_mem_get(mctx, sizeof(*request));
462 if (request == NULL)
468 request->magic = 0;
469 request->mctx = NULL;
470 request->flags = 0;
471 ISC_LINK_INIT(request, link);
472 request->query = NULL;
473 request->answer = NULL;
474 request->event = NULL;
475 request->dispatch = NULL;
476 request->dispentry = NULL;
477 request->timer = NULL;
478 request->requestmgr = NULL;
479 request->tsig = NULL;
480 request->tsigkey = NULL;
481 request->dscp = -1;
482 ISC_EVENT_INIT(&request->ctlevent, sizeof(request->ctlevent), 0, NULL,
483 DNS_EVENT_REQUESTCONTROL, do_cancel, request, NULL,
485 request->canceling = ISC_FALSE;
486 request->udpcount = 0;
488 isc_mem_attach(mctx, &request->mctx);
490 request->magic = REQUEST_MAGIC;
491 *requestp = request;
741 dns_request_t *request = NULL;
771 request = NULL;
772 result = new_request(mctx, &request);
781 request->udpcount = udpretries;
782 request->dscp = dscp;
788 NULL, NULL, task, req_timeout, request,
789 &request->timer);
793 request->event = (dns_requestevent_t *)
796 if (request->event == NULL) {
801 request->event->ev_sender = task;
802 request->event->request = request;
803 request->event->result = ISC_R_FAILURE;
818 &connected, &request->dispatch);
827 result = dns_dispatch_addresponse3(request->dispatch, dispopt,
829 request, &id, &request->dispentry,
835 dns_dispatch_detach(&request->dispatch);
841 sock = req_getsocket(request);
844 result = isc_buffer_allocate(mctx, &request->query,
849 isc_buffer_putuint16(request->query, (isc_uint16_t)r.length);
850 result = isc_buffer_copyregion(request->query, &r);
855 isc_buffer_usedregion(request->query, &r);
867 requestmgr_attach(requestmgr, &request->requestmgr);
868 request->hash = mgr_gethash(requestmgr);
869 ISC_LIST_APPEND(requestmgr->requests, request, link);
872 result = set_timer(request->timer, timeout, tcp ? 0 : udptimeout);
876 request->destaddr = *destaddr;
879 req_connected, request);
882 request->flags |= DNS_REQUEST_F_CONNECTING|DNS_REQUEST_F_TCP;
884 result = req_send(request, task, connected ? NULL : destaddr);
889 req_log(ISC_LOG_DEBUG(3), "dns_request_createraw: request %p",
890 request);
891 *requestp = request;
896 ISC_LIST_UNLINK(requestmgr->requests, request, link);
902 req_destroy(request);
976 dns_request_t *request = NULL;
1006 request = NULL;
1007 result = new_request(mctx, &request);
1016 request->udpcount = udpretries;
1017 request->dscp = dscp;
1023 NULL, NULL, task, req_timeout, request,
1024 &request->timer);
1028 request->event = (dns_requestevent_t *)
1031 if (request->event == NULL) {
1036 request->event->ev_sender = task;
1037 request->event->request = request;
1038 request->event->result = ISC_R_FAILURE;
1040 dns_tsigkey_attach(key, &request->tsigkey);
1047 dscp, &connected, &request->dispatch);
1051 result = dns_dispatch_addresponse2(request->dispatch, destaddr, task,
1052 req_response, request, &id,
1053 &request->dispentry,
1057 sock = req_getsocket(request);
1062 result = dns_message_settsigkey(message, request->tsigkey);
1066 result = req_render(message, &request->query, options, mctx);
1073 dns_dispatch_removeresponse(&request->dispentry, NULL);
1074 dns_dispatch_detach(&request->dispatch);
1083 result = dns_message_getquerytsig(message, mctx, &request->tsig);
1093 requestmgr_attach(requestmgr, &request->requestmgr);
1094 request->hash = mgr_gethash(requestmgr);
1095 ISC_LIST_APPEND(requestmgr->requests, request, link);
1098 result = set_timer(request->timer, timeout, tcp ? 0 : udptimeout);
1102 request->destaddr = *destaddr;
1105 req_connected, request);
1108 request->flags |= DNS_REQUEST_F_CONNECTING|DNS_REQUEST_F_TCP;
1110 result = req_send(request, task, connected ? NULL : destaddr);
1115 req_log(ISC_LOG_DEBUG(3), "dns_request_createvia: request %p",
1116 request);
1117 *requestp = request;
1122 ISC_LIST_UNLINK(requestmgr->requests, request, link);
1128 req_destroy(request);
1229 * If this request is no longer waiting for events,
1231 * cause the request to be destroyed.
1234 * 'request' is locked by the caller.
1237 send_if_done(dns_request_t *request, isc_result_t result) {
1238 if (request->event != NULL && !request->canceling)
1239 req_sendevent(request, result);
1247 dns_request_t *request = event->ev_arg;
1250 LOCK(&request->requestmgr->locks[request->hash]);
1251 request->canceling = ISC_FALSE;
1252 if (!DNS_REQUEST_CANCELED(request))
1253 req_cancel(request);
1254 send_if_done(request, ISC_R_CANCELED);
1255 UNLOCK(&request->requestmgr->locks[request->hash]);
1259 dns_request_cancel(dns_request_t *request) {
1260 REQUIRE(VALID_REQUEST(request));
1262 req_log(ISC_LOG_DEBUG(3), "dns_request_cancel: request %p", request);
1264 REQUIRE(VALID_REQUEST(request));
1266 LOCK(&request->requestmgr->locks[request->hash]);
1267 if (!request->canceling && !DNS_REQUEST_CANCELED(request)) {
1268 isc_event_t *ev = &request->ctlevent;
1269 isc_task_send(request->event->ev_sender, &ev);
1270 request->canceling = ISC_TRUE;
1272 UNLOCK(&request->requestmgr->locks[request->hash]);
1276 dns_request_getresponse(dns_request_t *request, dns_message_t *message,
1281 REQUIRE(VALID_REQUEST(request));
1282 REQUIRE(request->answer != NULL);
1284 req_log(ISC_LOG_DEBUG(3), "dns_request_getresponse: request %p",
1285 request);
1287 result = dns_message_setquerytsig(message, request->tsig);
1290 result = dns_message_settsigkey(message, request->tsigkey);
1293 result = dns_message_parse(message, request->answer, options);
1296 if (request->tsigkey != NULL)
1297 result = dns_tsig_verify(request->answer, message, NULL, NULL);
1302 dns_request_usedtcp(dns_request_t *request) {
1303 REQUIRE(VALID_REQUEST(request));
1305 return (ISC_TF((request->flags & DNS_REQUEST_F_TCP) != 0));
1310 dns_request_t *request;
1314 request = *requestp;
1316 req_log(ISC_LOG_DEBUG(3), "dns_request_destroy: request %p", request);
1318 LOCK(&request->requestmgr->lock);
1319 LOCK(&request->requestmgr->locks[request->hash]);
1320 ISC_LIST_UNLINK(request->requestmgr->requests, request, link);
1321 INSIST(!DNS_REQUEST_CONNECTING(request));
1322 INSIST(!DNS_REQUEST_SENDING(request));
1323 UNLOCK(&request->requestmgr->locks[request->hash]);
1324 UNLOCK(&request->requestmgr->lock);
1330 INSIST(!ISC_LINK_LINKED(request, link));
1331 INSIST(request->dispentry == NULL);
1332 INSIST(request->dispatch == NULL);
1333 INSIST(request->timer == NULL);
1335 req_destroy(request);
1341 *** Private: request.
1345 req_getsocket(dns_request_t *request) {
1349 dispattr = dns_dispatch_getattributes(request->dispatch);
1351 INSIST(request->dispentry != NULL);
1352 sock = dns_dispatch_getentrysocket(request->dispentry);
1354 sock = dns_dispatch_getsocket(request->dispatch);
1363 dns_request_t *request = event->ev_arg;
1366 REQUIRE(VALID_REQUEST(request));
1367 REQUIRE(DNS_REQUEST_CONNECTING(request));
1369 req_log(ISC_LOG_DEBUG(3), "req_connected: request %p", request);
1371 LOCK(&request->requestmgr->locks[request->hash]);
1372 request->flags &= ~DNS_REQUEST_F_CONNECTING;
1374 if (DNS_REQUEST_CANCELED(request)) {
1378 if (DNS_REQUEST_TIMEDOUT(request))
1379 send_if_done(request, ISC_R_TIMEDOUT);
1381 send_if_done(request, ISC_R_CANCELED);
1383 dns_dispatch_starttcp(request->dispatch);
1386 result = req_send(request, task, NULL);
1389 req_cancel(request);
1390 send_if_done(request, ISC_R_CANCELED);
1393 UNLOCK(&request->requestmgr->locks[request->hash]);
1400 dns_request_t *request = event->ev_arg;
1403 REQUIRE(VALID_REQUEST(request));
1404 REQUIRE(DNS_REQUEST_SENDING(request));
1406 req_log(ISC_LOG_DEBUG(3), "req_senddone: request %p", request);
1410 LOCK(&request->requestmgr->locks[request->hash]);
1411 request->flags &= ~DNS_REQUEST_F_SENDING;
1413 if (DNS_REQUEST_CANCELED(request)) {
1417 if (DNS_REQUEST_TIMEDOUT(request))
1418 send_if_done(request, ISC_R_TIMEDOUT);
1420 send_if_done(request, ISC_R_CANCELED);
1422 req_cancel(request);
1423 send_if_done(request, ISC_R_CANCELED);
1425 UNLOCK(&request->requestmgr->locks[request->hash]);
1433 dns_request_t *request = event->ev_arg;
1437 REQUIRE(VALID_REQUEST(request));
1442 req_log(ISC_LOG_DEBUG(3), "req_response: request %p: %s", request,
1445 LOCK(&request->requestmgr->locks[request->hash]);
1451 * Copy buffer to request.
1454 result = isc_buffer_allocate(request->mctx, &request->answer,
1458 result = isc_buffer_copyregion(request->answer, &r);
1460 isc_buffer_free(&request->answer);
1465 dns_dispatch_removeresponse(&request->dispentry, &devent);
1466 req_cancel(request);
1470 send_if_done(request, result);
1471 UNLOCK(&request->requestmgr->locks[request->hash]);
1476 dns_request_t *request = event->ev_arg;
1479 REQUIRE(VALID_REQUEST(request));
1481 req_log(ISC_LOG_DEBUG(3), "req_timeout: request %p", request);
1484 LOCK(&request->requestmgr->locks[request->hash]);
1486 request->udpcount-- != 0) {
1487 if (! DNS_REQUEST_SENDING(request)) {
1488 result = req_send(request, task, &request->destaddr);
1490 req_cancel(request);
1491 send_if_done(request, result);
1495 request->flags |= DNS_REQUEST_F_TIMEDOUT;
1496 req_cancel(request);
1497 send_if_done(request, ISC_R_TIMEDOUT);
1499 UNLOCK(&request->requestmgr->locks[request->hash]);
1504 req_sendevent(dns_request_t *request, isc_result_t result) {
1507 REQUIRE(VALID_REQUEST(request));
1509 req_log(ISC_LOG_DEBUG(3), "req_sendevent: request %p", request);
1514 task = request->event->ev_sender;
1515 request->event->ev_sender = request;
1516 request->event->result = result;
1517 isc_task_sendanddetach(&task, (isc_event_t **)&request->event);
1521 req_destroy(dns_request_t *request) {
1524 REQUIRE(VALID_REQUEST(request));
1526 req_log(ISC_LOG_DEBUG(3), "req_destroy: request %p", request);
1528 request->magic = 0;
1529 if (request->query != NULL)
1530 isc_buffer_free(&request->query);
1531 if (request->answer != NULL)
1532 isc_buffer_free(&request->answer);
1533 if (request->event != NULL)
1534 isc_event_free((isc_event_t **)&request->event);
1535 if (request->dispentry != NULL)
1536 dns_dispatch_removeresponse(&request->dispentry, NULL);
1537 if (request->dispatch != NULL)
1538 dns_dispatch_detach(&request->dispatch);
1539 if (request->timer != NULL)
1540 isc_timer_detach(&request->timer);
1541 if (request->tsig != NULL)
1542 isc_buffer_free(&request->tsig);
1543 if (request->tsigkey != NULL)
1544 dns_tsigkey_detach(&request->tsigkey);
1545 if (request->requestmgr != NULL)
1546 requestmgr_detach(&request->requestmgr);
1547 mctx = request->mctx;
1548 isc_mem_put(mctx, request, sizeof(*request));
1553 * Stop the current request. Must be called from the request's task.
1556 req_cancel(dns_request_t *request) {
1560 REQUIRE(VALID_REQUEST(request));
1562 req_log(ISC_LOG_DEBUG(3), "req_cancel: request %p", request);
1567 request->flags |= DNS_REQUEST_F_CANCELED;
1569 if (request->timer != NULL)
1570 isc_timer_detach(&request->timer);
1571 dispattr = dns_dispatch_getattributes(request->dispatch);
1573 if (DNS_REQUEST_CONNECTING(request) || DNS_REQUEST_SENDING(request)) {
1575 if (request->dispentry != NULL) {
1577 request->dispentry);
1580 sock = dns_dispatch_getsocket(request->dispatch);
1581 if (DNS_REQUEST_CONNECTING(request) && sock != NULL)
1583 if (DNS_REQUEST_SENDING(request) && sock != NULL)
1586 if (request->dispentry != NULL)
1587 dns_dispatch_removeresponse(&request->dispentry, NULL);
1588 dns_dispatch_detach(&request->dispatch);