Lines Matching refs:disp

139 	dns_dispatch_t		       *disp;
177 dns_dispatch_t *disp;
271 #define DNS_QID(disp) ((disp)->socktype == isc_sockettype_tcp) ? \
272 (disp)->qid : (disp)->mgr->qid
273 #define DISP_ARC4CTX(disp) ((disp)->socktype == isc_sockettype_udp) ? \
274 (&(disp)->arc4ctx) : (&(disp)->mgr->arc4ctx)
302 static void free_buffer(dns_dispatch_t *disp, void *buf, unsigned int len);
303 static void *allocate_udp_buffer(dns_dispatch_t *disp);
304 static inline void free_event(dns_dispatch_t *disp, dns_dispatchevent_t *ev);
305 static inline dns_dispatchevent_t *allocate_event(dns_dispatch_t *disp);
306 static void do_cancel(dns_dispatch_t *disp);
307 static dns_dispentry_t *linear_first(dns_qid_t *disp);
308 static dns_dispentry_t *linear_next(dns_qid_t *disp,
312 dns_dispatch_t *disp,
364 dispatch_log(dns_dispatch_t *disp, int level, const char *fmt, ...)
368 dispatch_log(dns_dispatch_t *disp, int level, const char *fmt, ...) {
381 level, "dispatch %p: %s", disp, msgbuf);
385 request_log(dns_dispatch_t *disp, dns_dispentry_t *resp,
390 request_log(dns_dispatch_t *disp, dns_dispentry_t *resp,
408 "dispatch %p response %p %s: %s", disp, resp,
413 "dispatch %p req/resp %p: %s", disp, resp,
646 destroy_disp_ok(dns_dispatch_t *disp)
648 if (disp->refcount != 0)
651 if (disp->recv_pending != 0)
654 if (!ISC_LIST_EMPTY(disp->activesockets))
657 if (disp->shutting_down == 0)
671 dns_dispatch_t *disp;
681 disp = event->ev_arg;
682 mgr = disp->mgr;
685 ISC_LIST_UNLINK(mgr->list, disp, link);
687 dispatch_log(disp, LVL(90),
689 disp->socket, disp->task[0]); /* XXXX */
691 if (disp->socket != NULL)
692 isc_socket_detach(&disp->socket);
693 while ((dispsocket = ISC_LIST_HEAD(disp->inactivesockets)) != NULL) {
694 ISC_LIST_UNLINK(disp->inactivesockets, dispsocket, link);
695 destroy_dispsocket(disp, &dispsocket);
697 for (i = 0; i < disp->ntasks; i++)
698 isc_task_detach(&disp->task[i]);
701 dispatch_free(&disp);
714 port_search(dns_dispatch_t *disp, in_port_t port) {
717 REQUIRE(disp->port_table != NULL);
719 portentry = ISC_LIST_HEAD(disp->port_table[port %
731 new_portentry(dns_dispatch_t *disp, in_port_t port) {
734 REQUIRE(disp->port_table != NULL);
736 portentry = isc_mempool_get(disp->portpool);
743 ISC_LIST_APPEND(disp->port_table[port % DNS_DISPATCH_PORTTABLESIZE],
753 deref_portentry(dns_dispatch_t *disp, dispportentry_t **portentryp) {
757 REQUIRE(disp->port_table != NULL);
760 qid = DNS_QID(disp);
764 ISC_LIST_UNLINK(disp->port_table[portentry->port %
767 isc_mempool_put(disp->portpool, portentry);
801 * The caller must hold the disp->lock and qid->lock.
804 get_dispsocket(dns_dispatch_t *disp, isc_sockaddr_t *dest,
810 dns_dispatchmgr_t *mgr = disp->mgr;
822 if (isc_sockaddr_pf(&disp->local) == AF_INET) {
823 nports = disp->mgr->nv4ports;
824 ports = disp->mgr->v4ports;
826 nports = disp->mgr->nv6ports;
827 ports = disp->mgr->v6ports;
832 dispsock = ISC_LIST_HEAD(disp->inactivesockets);
834 ISC_LIST_UNLINK(disp->inactivesockets, dispsock, link);
842 disp->nsockets++;
844 dispsock->disp = disp;
849 isc_task_attach(disp->task[r % disp->ntasks], &dispsock->task);
860 localaddr = disp->local;
862 port = ports[dispatch_arc4uniformrandom(DISP_ARC4CTX(disp),
870 portentry = port_search(disp, port);
876 portentry = new_portentry(disp, port);
887 dispatch_log(disp, ISC_LOG_WARNING,
910 destroy_dispsocket(disp, &dispsock);
920 destroy_dispsocket(dns_dispatch_t *disp, dispsocket_t **dispsockp) {
932 disp->nsockets--;
935 deref_portentry(disp, &dispsock->portentry);
939 qid = DNS_QID(disp);
947 isc_mempool_put(disp->mgr->spool, dispsock);
957 deactivate_dispsocket(dns_dispatch_t *disp, dispsocket_t *dispsock) {
964 ISC_LIST_UNLINK(disp->activesockets, dispsock, link);
971 deref_portentry(disp, &dispsock->portentry);
973 if (disp->nsockets > DNS_DISPATCH_POOLSOCKS)
974 destroy_dispsocket(disp, &dispsock);
978 qid = DNS_QID(disp);
985 ISC_LIST_APPEND(disp->inactivesockets, dispsock, link);
993 destroy_dispsocket(disp, &dispsock);
1025 free_buffer(dns_dispatch_t *disp, void *buf, unsigned int len) {
1029 switch (disp->socktype) {
1031 INSIST(disp->tcpbuffers > 0);
1032 disp->tcpbuffers--;
1033 isc_mem_put(disp->mgr->mctx, buf, len);
1036 LOCK(&disp->mgr->buffer_lock);
1037 INSIST(disp->mgr->buffers > 0);
1038 INSIST(len == disp->mgr->buffersize);
1039 disp->mgr->buffers--;
1040 isc_mempool_put(disp->mgr->bpool, buf);
1041 UNLOCK(&disp->mgr->buffer_lock);
1050 allocate_udp_buffer(dns_dispatch_t *disp) {
1053 LOCK(&disp->mgr->buffer_lock);
1054 temp = isc_mempool_get(disp->mgr->bpool);
1057 disp->mgr->buffers++;
1058 UNLOCK(&disp->mgr->buffer_lock);
1064 free_event(dns_dispatch_t *disp, dns_dispatchevent_t *ev) {
1065 if (disp->failsafe_ev == ev) {
1066 INSIST(disp->shutdown_out == 1);
1067 disp->shutdown_out = 0;
1072 isc_mempool_put(disp->mgr->epool, ev);
1076 allocate_event(dns_dispatch_t *disp) {
1079 ev = isc_mempool_get(disp->mgr->epool);
1095 udp_recv(ev, dispsock->disp, dispsock);
1100 dns_dispatch_t *disp = ev->ev_arg;
1104 REQUIRE(VALID_DISPATCH(disp));
1105 udp_recv(ev, disp, NULL);
1123 udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) {
1141 LOCK(&disp->lock);
1143 mgr = disp->mgr;
1146 dispatch_log(disp, LVL(90),
1148 disp->requests, disp->mgr->buffers, disp->recv_pending);
1156 INSIST(disp->recv_pending != 0);
1157 disp->recv_pending = 0;
1169 deactivate_dispsocket(disp, dispsock);
1173 if (disp->shutting_down) {
1177 free_buffer(disp, ev->region.base, ev->region.length);
1182 killit = destroy_disp_ok(disp);
1183 UNLOCK(&disp->lock);
1185 isc_task_send(disp->task[0], &disp->ctlevent);
1190 if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0) {
1204 free_buffer(disp, ev->region.base, ev->region.length);
1206 UNLOCK(&disp->lock);
1211 free_buffer(disp, ev->region.base, ev->region.length);
1214 dispatch_log(disp, ISC_LOG_ERROR,
1218 UNLOCK(&disp->lock);
1227 if (disp->mgr->blackhole != NULL &&
1228 dns_acl_match(&netaddr, NULL, disp->mgr->blackhole,
1236 dispatch_log(disp, LVL(10),
1240 free_buffer(disp, ev->region.base, ev->region.length);
1251 free_buffer(disp, ev->region.base, ev->region.length);
1252 dispatch_log(disp, LVL(10), "got garbage packet");
1256 dispatch_log(disp, LVL(92),
1266 free_buffer(disp, ev->region.base, ev->region.length);
1276 bucket = dns_hash(qid, &ev->address, id, disp->localport);
1279 resp = entry_search(qid, &ev->address, id, disp->localport,
1281 dispatch_log(disp, LVL(90),
1287 free_buffer(disp, ev->region.base, ev->region.length);
1292 dispatch_log(disp, LVL(90),
1295 free_buffer(disp, ev->region.base, ev->region.length);
1304 if (disp != resp->disp) {
1311 if (disp->socktype != resp->disp->socktype ||
1312 isc_sockaddr_getport(&disp->local) !=
1313 isc_sockaddr_getport(&resp->disp->local)) {
1314 free_buffer(disp, ev->region.base, ev->region.length);
1328 if (isc_sockaddr_pf(&resp->disp->local) == PF_INET6 &&
1329 isc_sockaddr_pf(&disp->local) != PF_INET6) {
1330 free_buffer(disp, ev->region.base, ev->region.length);
1333 isc_sockaddr_anyofpf(&a1, isc_sockaddr_pf(&resp->disp->local));
1334 isc_sockaddr_anyofpf(&a2, isc_sockaddr_pf(&disp->local));
1335 if (!isc_sockaddr_eqaddr(&a1, &resp->disp->local) &&
1336 !isc_sockaddr_eqaddr(&a2, &disp->local)) {
1337 free_buffer(disp, ev->region.base, ev->region.length);
1344 rev = allocate_event(resp->disp);
1346 free_buffer(disp, ev->region.base, ev->region.length);
1368 request_log(disp, resp, LVL(90),
1383 result = startrecv(disp, dispsock);
1391 deactivate_dispsocket(disp, dispsock);
1393 UNLOCK(&disp->lock);
1415 dns_dispatch_t *disp = ev_in->ev_arg;
1416 dns_tcpmsg_t *tcpmsg = &disp->tcpmsg;
1431 REQUIRE(VALID_DISPATCH(disp));
1433 qid = disp->qid;
1435 dispatch_log(disp, LVL(90),
1437 disp->requests, disp->tcpbuffers, disp->recv_pending);
1439 LOCK(&disp->lock);
1441 INSIST(disp->recv_pending != 0);
1442 disp->recv_pending = 0;
1444 if (disp->refcount == 0) {
1457 dispatch_log(disp, LVL(90), "shutting down on EOF");
1458 do_cancel(disp);
1469 dispatch_log(disp, level, "shutting down due to TCP "
1472 do_cancel(disp);
1483 disp->shutting_down = 1;
1484 disp->shutdown_why = tcpmsg->result;
1489 killit = destroy_disp_ok(disp);
1490 UNLOCK(&disp->lock);
1492 isc_task_send(disp->task[0], &disp->ctlevent);
1496 dispatch_log(disp, LVL(90), "result %d, length == %d, addr = %p",
1505 dispatch_log(disp, LVL(10), "got garbage packet");
1509 dispatch_log(disp, LVL(92),
1532 bucket = dns_hash(qid, &tcpmsg->address, id, disp->localport);
1534 resp = entry_search(qid, &tcpmsg->address, id, disp->localport, bucket);
1535 dispatch_log(disp, LVL(90),
1542 rev = allocate_event(disp);
1552 disp->tcpbuffers++;
1561 request_log(disp, resp, LVL(90),
1575 (void)startrecv(disp, NULL);
1577 UNLOCK(&disp->lock);
1583 * disp must be locked.
1586 startrecv(dns_dispatch_t *disp, dispsocket_t *dispsock) {
1591 if (disp->shutting_down == 1)
1594 if ((disp->attributes & DNS_DISPATCHATTR_NOLISTEN) != 0)
1597 if (disp->recv_pending != 0 && dispsock == NULL)
1600 if (disp->mgr->buffers >= disp->mgr->maxbuffers)
1603 if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0 &&
1610 socket = disp->socket;
1613 switch (disp->socktype) {
1618 region.length = disp->mgr->buffersize;
1619 region.base = allocate_udp_buffer(disp);
1627 free_buffer(disp, region.base, region.length);
1632 disp->task[0], udp_shrecv, disp);
1634 free_buffer(disp, region.base, region.length);
1635 disp->shutdown_why = res;
1636 disp->shutting_down = 1;
1637 do_cancel(disp);
1640 INSIST(disp->recv_pending == 0);
1641 disp->recv_pending = 1;
1646 res = dns_tcpmsg_readmessage(&disp->tcpmsg, disp->task[0],
1647 tcp_recv, disp);
1649 disp->shutdown_why = res;
1650 disp->shutting_down = 1;
1651 do_cancel(disp);
1654 INSIST(disp->recv_pending == 0);
1655 disp->recv_pending = 1;
2206 local_addr_match(dns_dispatch_t *disp, isc_sockaddr_t *addr) {
2210 REQUIRE(disp->socket != NULL);
2220 isc_sockaddr_getport(&disp->local) == 0 &&
2221 !portavailable(disp->mgr, disp->socket, NULL)) {
2229 if (isc_sockaddr_equal(&disp->local, addr))
2237 if (!isc_sockaddr_eqaddr(&disp->local, addr))
2239 result = isc_socket_getsockname(disp->socket, &sockaddr);
2261 dns_dispatch_t *disp;
2270 disp = ISC_LIST_HEAD(mgr->list);
2271 while (disp != NULL) {
2272 LOCK(&disp->lock);
2273 if ((disp->shutting_down == 0)
2274 && ATTRMATCH(disp->attributes, attributes, mask)
2275 && local_addr_match(disp, local))
2277 UNLOCK(&disp->lock);
2278 disp = ISC_LIST_NEXT(disp, link);
2281 if (disp == NULL) {
2286 *dispp = disp;
2383 dns_dispatch_t *disp;
2394 disp = isc_mempool_get(mgr->dpool);
2395 if (disp == NULL)
2398 disp->magic = 0;
2399 disp->mgr = mgr;
2400 disp->maxrequests = maxrequests;
2401 disp->attributes = 0;
2402 ISC_LINK_INIT(disp, link);
2403 disp->refcount = 1;
2404 disp->recv_pending = 0;
2405 memset(&disp->local, 0, sizeof(disp->local));
2406 disp->localport = 0;
2407 disp->shutting_down = 0;
2408 disp->shutdown_out = 0;
2409 disp->connected = 0;
2410 disp->tcpmsg_valid = 0;
2411 disp->shutdown_why = ISC_R_UNEXPECTED;
2412 disp->requests = 0;
2413 disp->tcpbuffers = 0;
2414 disp->qid = NULL;
2415 ISC_LIST_INIT(disp->activesockets);
2416 ISC_LIST_INIT(disp->inactivesockets);
2417 disp->nsockets = 0;
2418 dispatch_arc4init(&disp->arc4ctx, mgr->entropy, NULL);
2419 disp->port_table = NULL;
2420 disp->portpool = NULL;
2422 result = isc_mutex_init(&disp->lock);
2426 disp->failsafe_ev = allocate_event(disp);
2427 if (disp->failsafe_ev == NULL) {
2432 disp->magic = DISPATCH_MAGIC;
2434 *dispp = disp;
2441 DESTROYLOCK(&disp->lock);
2443 isc_mempool_put(mgr->dpool, disp);
2455 dns_dispatch_t *disp;
2460 disp = *dispp;
2463 mgr = disp->mgr;
2466 if (disp->tcpmsg_valid) {
2467 dns_tcpmsg_invalidate(&disp->tcpmsg);
2468 disp->tcpmsg_valid = 0;
2471 INSIST(disp->tcpbuffers == 0);
2472 INSIST(disp->requests == 0);
2473 INSIST(disp->recv_pending == 0);
2474 INSIST(ISC_LIST_EMPTY(disp->activesockets));
2475 INSIST(ISC_LIST_EMPTY(disp->inactivesockets));
2477 isc_mempool_put(mgr->epool, disp->failsafe_ev);
2478 disp->failsafe_ev = NULL;
2480 if (disp->qid != NULL)
2481 qid_destroy(mgr->mctx, &disp->qid);
2483 if (disp->port_table != NULL) {
2485 INSIST(ISC_LIST_EMPTY(disp->port_table[i]));
2486 isc_mem_put(mgr->mctx, disp->port_table,
2487 sizeof(disp->port_table[0]) *
2491 if (disp->portpool != NULL)
2492 isc_mempool_destroy(&disp->portpool);
2494 disp->mgr = NULL;
2495 DESTROYLOCK(&disp->lock);
2496 disp->magic = 0;
2497 isc_mempool_put(mgr->dpool, disp);
2508 dns_dispatch_t *disp;
2526 disp = NULL;
2527 result = dispatch_allocate(mgr, maxrequests, &disp);
2533 result = qid_allocate(mgr, buckets, increment, &disp->qid, ISC_FALSE);
2537 disp->socktype = isc_sockettype_tcp;
2538 disp->socket = NULL;
2539 isc_socket_attach(sock, &disp->socket);
2541 disp->ntasks = 1;
2542 disp->task[0] = NULL;
2543 result = isc_task_create(taskmgr, 0, &disp->task[0]);
2547 disp->ctlevent = isc_event_allocate(mgr->mctx, disp,
2549 destroy_disp, disp,
2551 if (disp->ctlevent == NULL) {
2556 isc_task_setname(disp->task[0], "tcpdispatch", disp);
2558 dns_tcpmsg_init(mgr->mctx, disp->socket, &disp->tcpmsg);
2559 disp->tcpmsg_valid = 1;
2561 disp->attributes = attributes;
2566 ISC_LIST_APPEND(mgr->list, disp, link);
2569 mgr_log(mgr, LVL(90), "created TCP dispatcher %p", disp);
2570 dispatch_log(disp, LVL(90), "created task %p", disp->task[0]);
2572 *dispp = disp;
2580 isc_task_detach(&disp->task[0]);
2582 isc_socket_detach(&disp->socket);
2584 dispatch_free(&disp);
2601 dns_dispatch_t *disp = NULL;
2629 result = dispatch_find(mgr, localaddr, attributes, mask, &disp);
2631 disp->refcount++;
2633 if (disp->maxrequests < maxrequests)
2634 disp->maxrequests = maxrequests;
2636 if ((disp->attributes & DNS_DISPATCHATTR_NOLISTEN) == 0 &&
2639 disp->attributes |= DNS_DISPATCHATTR_NOLISTEN;
2640 if (disp->recv_pending != 0)
2641 isc_socket_cancel(disp->socket, disp->task[0],
2645 UNLOCK(&disp->lock);
2648 *dispp = disp;
2658 maxrequests, attributes, &disp);
2665 *dispp = disp;
2678 get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp,
2703 nports = disp->mgr->nv4ports;
2704 ports = disp->mgr->v4ports;
2706 nports = disp->mgr->nv6ports;
2707 ports = disp->mgr->v6ports;
2716 DISP_ARC4CTX(disp),
2728 disp->localport = prt;
2792 dns_dispatch_t *disp;
2799 disp = NULL;
2800 result = dispatch_allocate(mgr, maxrequests, &disp);
2805 result = get_udpsocket(mgr, disp, sockmgr, localaddr, &sock);
2826 disp->port_table = isc_mem_get(mgr->mctx,
2827 sizeof(disp->port_table[0]) *
2829 if (disp->port_table == NULL)
2832 ISC_LIST_INIT(disp->port_table[i]);
2835 &disp->portpool);
2838 isc_mempool_setname(disp->portpool, "disp_portpool");
2839 isc_mempool_setfreemax(disp->portpool, 128);
2841 disp->socktype = isc_sockettype_udp;
2842 disp->socket = sock;
2843 disp->local = *localaddr;
2846 disp->ntasks = MAX_INTERNAL_TASKS;
2848 disp->ntasks = 1;
2849 for (i = 0; i < disp->ntasks; i++) {
2850 disp->task[i] = NULL;
2851 result = isc_task_create(taskmgr, 0, &disp->task[i]);
2854 isc_task_destroy(&disp->task[i]);
2857 isc_task_setname(disp->task[i], "udpdispatch", disp);
2860 disp->ctlevent = isc_event_allocate(mgr->mctx, disp,
2862 destroy_disp, disp,
2864 if (disp->ctlevent == NULL) {
2871 disp->attributes = attributes;
2876 ISC_LIST_APPEND(mgr->list, disp, link);
2878 mgr_log(mgr, LVL(90), "created UDP dispatcher %p", disp);
2879 dispatch_log(disp, LVL(90), "created task %p", disp->task[0]); /* XXX */
2880 if (disp->socket != NULL)
2881 dispatch_log(disp, LVL(90), "created socket %p", disp->socket);
2883 *dispp = disp;
2890 for (i = 0; i < disp->ntasks; i++)
2891 isc_task_detach(&disp->task[i]);
2893 if (disp->socket != NULL)
2894 isc_socket_detach(&disp->socket);
2896 dispatch_free(&disp);
2902 dns_dispatch_attach(dns_dispatch_t *disp, dns_dispatch_t **dispp) {
2903 REQUIRE(VALID_DISPATCH(disp));
2906 LOCK(&disp->lock);
2907 disp->refcount++;
2908 UNLOCK(&disp->lock);
2910 *dispp = disp;
2922 dns_dispatch_t *disp;
2928 disp = *dispp;
2931 LOCK(&disp->lock);
2933 INSIST(disp->refcount > 0);
2934 disp->refcount--;
2935 if (disp->refcount == 0) {
2936 if (disp->recv_pending > 0)
2937 isc_socket_cancel(disp->socket, disp->task[0],
2939 for (dispsock = ISC_LIST_HEAD(disp->activesockets);
2945 disp->shutting_down = 1;
2948 dispatch_log(disp, LVL(90), "detach: refcount %d", disp->refcount);
2950 killit = destroy_disp_ok(disp);
2951 UNLOCK(&disp->lock);
2953 isc_task_send(disp->task[0], &disp->ctlevent);
2957 dns_dispatch_addresponse2(dns_dispatch_t *disp, isc_sockaddr_t *dest,
2972 REQUIRE(VALID_DISPATCH(disp));
2977 if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0)
2980 LOCK(&disp->lock);
2982 if (disp->shutting_down == 1) {
2983 UNLOCK(&disp->lock);
2987 if (disp->requests >= disp->maxrequests) {
2988 UNLOCK(&disp->lock);
2992 if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0 &&
2993 disp->nsockets > DNS_DISPATCH_SOCKSQUOTA) {
3002 oldestsocket = ISC_LIST_HEAD(disp->activesockets);
3005 rev = allocate_event(oldestresp->disp);
3018 inc_stats(disp->mgr,
3027 ISC_LIST_UNLINK(disp->activesockets, oldestsocket, link);
3028 ISC_LIST_APPEND(disp->activesockets, oldestsocket, link);
3031 qid = DNS_QID(disp);
3034 if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0) {
3038 result = get_dispsocket(disp, dest, sockmgr, qid, &dispsocket,
3042 UNLOCK(&disp->lock);
3043 inc_stats(disp->mgr, dns_resstatscounter_dispsockfail);
3047 localport = disp->localport;
3053 id = (dns_messageid_t)dispatch_arc4random(DISP_ARC4CTX(disp));
3068 UNLOCK(&disp->lock);
3072 res = isc_mempool_get(disp->mgr->rpool);
3075 UNLOCK(&disp->lock);
3077 destroy_dispsocket(disp, &dispsocket);
3081 disp->refcount++;
3082 disp->requests++;
3085 res->disp = disp;
3102 request_log(disp, res, LVL(90),
3105 if (((disp->attributes & DNS_DISPATCHATTR_UDP) != 0) ||
3106 ((disp->attributes & DNS_DISPATCHATTR_CONNECTED) != 0)) {
3107 result = startrecv(disp, dispsocket);
3114 destroy_dispsocket(disp, &dispsocket);
3116 disp->refcount--;
3117 disp->requests--;
3119 UNLOCK(&disp->lock);
3121 isc_mempool_put(disp->mgr->rpool, res);
3127 ISC_LIST_APPEND(disp->activesockets, dispsocket, link);
3129 UNLOCK(&disp->lock);
3134 if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0)
3141 dns_dispatch_addresponse(dns_dispatch_t *disp, isc_sockaddr_t *dest,
3145 REQUIRE(VALID_DISPATCH(disp));
3146 REQUIRE((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) == 0);
3148 return (dns_dispatch_addresponse2(disp, dest, task, action, arg,
3153 dns_dispatch_starttcp(dns_dispatch_t *disp) {
3155 REQUIRE(VALID_DISPATCH(disp));
3157 dispatch_log(disp, LVL(90), "starttcp %p", disp->task[0]);
3159 LOCK(&disp->lock);
3160 disp->attributes |= DNS_DISPATCHATTR_CONNECTED;
3161 (void)startrecv(disp, NULL);
3162 UNLOCK(&disp->lock);
3170 dns_dispatch_t *disp;
3186 disp = res->disp;
3187 REQUIRE(VALID_DISPATCH(disp));
3188 mgr = disp->mgr;
3191 qid = DNS_QID(disp);
3201 LOCK(&disp->lock);
3203 INSIST(disp->requests > 0);
3204 disp->requests--;
3205 INSIST(disp->refcount > 0);
3206 disp->refcount--;
3207 if (disp->refcount == 0) {
3208 if (disp->recv_pending > 0)
3209 isc_socket_cancel(disp->socket, disp->task[0],
3211 for (dispsock = ISC_LIST_HEAD(disp->activesockets);
3217 disp->shutting_down = 1;
3245 free_buffer(disp, ev->buffer.base, ev->buffer.length);
3246 free_event(disp, ev);
3249 request_log(disp, res, LVL(90), "detaching from task %p", res->task);
3265 free_buffer(disp, ev->buffer.base, ev->buffer.length);
3266 free_event(disp, ev);
3270 isc_mempool_put(disp->mgr->rpool, res);
3271 if (disp->shutting_down == 1)
3272 do_cancel(disp);
3274 (void)startrecv(disp, NULL);
3276 killit = destroy_disp_ok(disp);
3277 UNLOCK(&disp->lock);
3279 isc_task_send(disp->task[0], &disp->ctlevent);
3283 do_cancel(dns_dispatch_t *disp) {
3288 if (disp->shutdown_out == 1)
3291 qid = DNS_QID(disp);
3312 ev = disp->failsafe_ev;
3315 ev->result = disp->shutdown_why;
3318 disp->shutdown_out = 1;
3319 request_log(disp, resp, LVL(10),
3329 dns_dispatch_getsocket(dns_dispatch_t *disp) {
3330 REQUIRE(VALID_DISPATCH(disp));
3332 return (disp->socket);
3346 dns_dispatch_getlocaladdress(dns_dispatch_t *disp, isc_sockaddr_t *addrp) {
3348 REQUIRE(VALID_DISPATCH(disp));
3351 if (disp->socktype == isc_sockettype_udp) {
3352 *addrp = disp->local;
3359 dns_dispatch_cancel(dns_dispatch_t *disp) {
3360 REQUIRE(VALID_DISPATCH(disp));
3362 LOCK(&disp->lock);
3364 if (disp->shutting_down == 1) {
3365 UNLOCK(&disp->lock);
3369 disp->shutdown_why = ISC_R_CANCELED;
3370 disp->shutting_down = 1;
3371 do_cancel(disp);
3373 UNLOCK(&disp->lock);
3379 dns_dispatch_getattributes(dns_dispatch_t *disp) {
3380 REQUIRE(VALID_DISPATCH(disp));
3383 * We don't bother locking disp here; it's the caller's responsibility
3386 return (disp->attributes);
3390 dns_dispatch_changeattributes(dns_dispatch_t *disp,
3393 REQUIRE(VALID_DISPATCH(disp));
3397 REQUIRE((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) == 0 ||
3404 LOCK(&disp->lock);
3407 if ((disp->attributes & DNS_DISPATCHATTR_NOLISTEN) != 0 &&
3409 disp->attributes &= ~DNS_DISPATCHATTR_NOLISTEN;
3410 (void)startrecv(disp, NULL);
3411 } else if ((disp->attributes & DNS_DISPATCHATTR_NOLISTEN)
3414 disp->attributes |= DNS_DISPATCHATTR_NOLISTEN;
3415 if (disp->recv_pending != 0)
3416 isc_socket_cancel(disp->socket, disp->task[0],
3421 disp->attributes &= ~mask;
3422 disp->attributes |= (attributes & mask);
3423 UNLOCK(&disp->lock);
3427 dns_dispatch_importrecv(dns_dispatch_t *disp, isc_event_t *event) {
3431 REQUIRE(VALID_DISPATCH(disp));
3432 REQUIRE((disp->attributes & DNS_DISPATCHATTR_NOLISTEN) != 0);
3437 INSIST(sevent->n <= disp->mgr->buffersize);
3439 isc_event_allocate(disp->mgr->mctx, NULL,
3441 disp, sizeof(isc_socketevent_t));
3445 buf = allocate_udp_buffer(disp);
3452 newsevent->region.length = disp->mgr->buffersize;
3460 isc_task_send(disp->task[0], ISC_EVENT_PTR(&newsevent));
3466 dns_dispatch_t *disp;
3469 disp = ISC_LIST_HEAD(mgr->list);
3470 while (disp != NULL) {
3471 isc_sockaddr_format(&disp->local, foo, sizeof(foo));
3472 printf("\tdispatch %p, addr %s\n", disp, foo);
3473 disp = ISC_LIST_NEXT(disp, link);