Lines Matching defs:mgr

199 	dns_dispatchmgr_t      *mgr;		/*%< dispatch manager */
218 /*% Locked by mgr->lock. */
261 (disp)->qid : (disp)->mgr->qid
263 ((disp)->rngctx) : ((disp)->mgr->rngctx)
272 #define PORTBUFLOCK(mgr) if ((mgr)->qid != NULL) LOCK(&((mgr)->qid->lock))
273 #define PORTBUFUNLOCK(mgr) if ((mgr)->qid != NULL) UNLOCK((&(mgr)->qid->lock))
300 static isc_result_t get_udpsocket(dns_dispatchmgr_t *mgr,
306 static isc_result_t dispatch_createudp(dns_dispatchmgr_t *mgr,
314 static isc_boolean_t destroy_mgr_ok(dns_dispatchmgr_t *mgr);
316 static isc_result_t qid_allocate(dns_dispatchmgr_t *mgr, unsigned int buckets,
320 static isc_result_t open_socket(isc_socketmgr_t *mgr, isc_sockaddr_t *local,
323 static isc_boolean_t portavailable(dns_dispatchmgr_t *mgr, isc_socket_t *sock,
329 mgr_log(dns_dispatchmgr_t *mgr, int level, const char *fmt, ...)
333 mgr_log(dns_dispatchmgr_t *mgr, int level, const char *fmt, ...) {
346 level, "dispatchmgr %p: %s", mgr, msgbuf);
350 inc_stats(dns_dispatchmgr_t *mgr, isc_statscounter_t counter) {
351 if (mgr->stats != NULL)
352 isc_stats_increment(mgr->stats, counter);
356 dec_stats(dns_dispatchmgr_t *mgr, isc_statscounter_t counter) {
357 if (mgr->stats != NULL)
358 isc_stats_decrement(mgr->stats, counter);
509 dns_dispatchmgr_t *mgr;
519 mgr = disp->mgr;
521 LOCK(&mgr->lock);
522 ISC_LIST_UNLINK(mgr->list, disp, link);
545 killmgr = destroy_mgr_ok(mgr);
546 UNLOCK(&mgr->lock);
548 destroy_mgr(&mgr);
663 dns_dispatchmgr_t *mgr = disp->mgr;
677 nports = disp->mgr->nv4ports;
678 ports = disp->mgr->v4ports;
680 nports = disp->mgr->nv6ports;
681 ports = disp->mgr->v6ports;
692 dispsock = isc_mempool_get(mgr->spool);
813 isc_mempool_put(disp->mgr->spool, dispsock);
901 isc_mem_put(disp->mgr->mctx, buf, len);
904 LOCK(&disp->mgr->buffer_lock);
905 INSIST(disp->mgr->buffers > 0);
906 INSIST(len == disp->mgr->buffersize);
907 disp->mgr->buffers--;
908 bpool = disp->mgr->bpool;
909 UNLOCK(&disp->mgr->buffer_lock);
923 LOCK(&disp->mgr->buffer_lock);
924 bpool = disp->mgr->bpool;
925 disp->mgr->buffers++;
926 UNLOCK(&disp->mgr->buffer_lock);
931 LOCK(&disp->mgr->buffer_lock);
932 disp->mgr->buffers--;
933 UNLOCK(&disp->mgr->buffer_lock);
981 isc_mempool_put(disp->mgr->depool, ev);
988 ev = isc_mempool_get(disp->mgr->depool);
1043 dns_dispatchmgr_t *mgr;
1052 mgr = disp->mgr;
1053 qid = mgr->qid;
1057 disp->requests, disp->mgr->buffers, disp->recv_pending);
1136 if (disp->mgr->blackhole != NULL &&
1137 dns_acl_match(&netaddr, NULL, disp->mgr->blackhole,
1195 inc_stats(mgr, dns_resstatscounter_mismatch);
1203 inc_stats(mgr, dns_resstatscounter_mismatch);
1508 if (disp->mgr->buffers >= disp->mgr->maxbuffers)
1526 region.length = disp->mgr->buffersize;
1594 destroy_mgr_ok(dns_dispatchmgr_t *mgr) {
1595 mgr_log(mgr, LVL(90),
1598 MGR_IS_SHUTTINGDOWN(mgr), !ISC_LIST_EMPTY(mgr->list),
1599 isc_mempool_getallocated(mgr->depool),
1600 isc_mempool_getallocated(mgr->rpool),
1601 isc_mempool_getallocated(mgr->dpool));
1602 if (!MGR_IS_SHUTTINGDOWN(mgr))
1604 if (!ISC_LIST_EMPTY(mgr->list))
1606 if (isc_mempool_getallocated(mgr->depool) != 0)
1608 if (isc_mempool_getallocated(mgr->rpool) != 0)
1610 if (isc_mempool_getallocated(mgr->dpool) != 0)
1622 dns_dispatchmgr_t *mgr;
1624 mgr = *mgrp;
1627 mctx = mgr->mctx;
1629 mgr->magic = 0;
1630 mgr->mctx = NULL;
1631 DESTROYLOCK(&mgr->lock);
1632 mgr->state = 0;
1634 if (mgr->rngctx != NULL)
1635 isc_rng_detach(&mgr->rngctx);
1636 DESTROYLOCK(&mgr->rng_lock);
1638 isc_mempool_destroy(&mgr->depool);
1639 isc_mempool_destroy(&mgr->rpool);
1640 isc_mempool_destroy(&mgr->dpool);
1641 if (mgr->bpool != NULL)
1642 isc_mempool_destroy(&mgr->bpool);
1643 if (mgr->spool != NULL)
1644 isc_mempool_destroy(&mgr->spool);
1646 DESTROYLOCK(&mgr->spool_lock);
1647 DESTROYLOCK(&mgr->bpool_lock);
1648 DESTROYLOCK(&mgr->dpool_lock);
1649 DESTROYLOCK(&mgr->rpool_lock);
1650 DESTROYLOCK(&mgr->depool_lock);
1652 if (mgr->entropy != NULL)
1653 isc_entropy_detach(&mgr->entropy);
1654 if (mgr->qid != NULL)
1655 qid_destroy(mctx, &mgr->qid);
1657 DESTROYLOCK(&mgr->buffer_lock);
1659 if (mgr->blackhole != NULL)
1660 dns_acl_detach(&mgr->blackhole);
1662 if (mgr->stats != NULL)
1663 isc_stats_detach(&mgr->stats);
1665 if (mgr->v4ports != NULL) {
1666 isc_mem_put(mctx, mgr->v4ports,
1667 mgr->nv4ports * sizeof(in_port_t));
1669 if (mgr->v6ports != NULL) {
1670 isc_mem_put(mctx, mgr->v6ports,
1671 mgr->nv6ports * sizeof(in_port_t));
1673 isc_mem_put(mctx, mgr, sizeof(dns_dispatchmgr_t));
1678 open_socket(isc_socketmgr_t *mgr, isc_sockaddr_t *local,
1699 result = isc_socket_create(mgr, isc_sockaddr_pf(local),
1750 dns_dispatchmgr_t *mgr;
1758 mgr = isc_mem_get(mctx, sizeof(dns_dispatchmgr_t));
1759 if (mgr == NULL)
1762 mgr->mctx = NULL;
1763 isc_mem_attach(mctx, &mgr->mctx);
1765 mgr->blackhole = NULL;
1766 mgr->stats = NULL;
1767 mgr->rngctx = NULL;
1769 result = isc_mutex_init(&mgr->lock);
1773 result = isc_mutex_init(&mgr->rng_lock);
1777 result = isc_mutex_init(&mgr->buffer_lock);
1781 result = isc_mutex_init(&mgr->depool_lock);
1785 result = isc_mutex_init(&mgr->rpool_lock);
1789 result = isc_mutex_init(&mgr->dpool_lock);
1793 result = isc_mutex_init(&mgr->bpool_lock);
1797 result = isc_mutex_init(&mgr->spool_lock);
1801 mgr->depool = NULL;
1802 if (isc_mempool_create(mgr->mctx, sizeof(dns_dispatchevent_t),
1803 &mgr->depool) != ISC_R_SUCCESS) {
1808 mgr->rpool = NULL;
1809 if (isc_mempool_create(mgr->mctx, sizeof(dns_dispentry_t),
1810 &mgr->rpool) != ISC_R_SUCCESS) {
1815 mgr->dpool = NULL;
1816 if (isc_mempool_create(mgr->mctx, sizeof(dns_dispatch_t),
1817 &mgr->dpool) != ISC_R_SUCCESS) {
1822 isc_mempool_setname(mgr->depool, "dispmgr_depool");
1823 isc_mempool_setmaxalloc(mgr->depool, 32768);
1824 isc_mempool_setfreemax(mgr->depool, 32768);
1825 isc_mempool_associatelock(mgr->depool, &mgr->depool_lock);
1826 isc_mempool_setfillcount(mgr->depool, 32);
1828 isc_mempool_setname(mgr->rpool, "dispmgr_rpool");
1829 isc_mempool_setmaxalloc(mgr->rpool, 32768);
1830 isc_mempool_setfreemax(mgr->rpool, 32768);
1831 isc_mempool_associatelock(mgr->rpool, &mgr->rpool_lock);
1832 isc_mempool_setfillcount(mgr->rpool, 32);
1834 isc_mempool_setname(mgr->dpool, "dispmgr_dpool");
1835 isc_mempool_setmaxalloc(mgr->dpool, 32768);
1836 isc_mempool_setfreemax(mgr->dpool, 32768);
1837 isc_mempool_associatelock(mgr->dpool, &mgr->dpool_lock);
1838 isc_mempool_setfillcount(mgr->dpool, 32);
1840 mgr->buffers = 0;
1841 mgr->buffersize = 0;
1842 mgr->maxbuffers = 0;
1843 mgr->bpool = NULL;
1844 mgr->spool = NULL;
1845 mgr->entropy = NULL;
1846 mgr->qid = NULL;
1847 mgr->state = 0;
1848 ISC_LIST_INIT(mgr->list);
1849 mgr->v4ports = NULL;
1850 mgr->v6ports = NULL;
1851 mgr->nv4ports = 0;
1852 mgr->nv6ports = 0;
1853 mgr->magic = DNS_DISPATCHMGR_MAGIC;
1859 result = dns_dispatchmgr_setavailports(mgr,
1872 isc_entropy_attach(entropy, &mgr->entropy);
1874 result = isc_rng_create(mctx, mgr->entropy, &mgr->rngctx);
1878 *mgrp = mgr;
1882 isc_mempool_destroy(&mgr->dpool);
1884 isc_mempool_destroy(&mgr->rpool);
1886 isc_mempool_destroy(&mgr->depool);
1888 DESTROYLOCK(&mgr->spool_lock);
1890 DESTROYLOCK(&mgr->bpool_lock);
1892 DESTROYLOCK(&mgr->dpool_lock);
1894 DESTROYLOCK(&mgr->rpool_lock);
1896 DESTROYLOCK(&mgr->depool_lock);
1898 DESTROYLOCK(&mgr->buffer_lock);
1900 DESTROYLOCK(&mgr->rng_lock);
1902 DESTROYLOCK(&mgr->lock);
1904 isc_mem_put(mctx, mgr, sizeof(dns_dispatchmgr_t));
1911 dns_dispatchmgr_setblackhole(dns_dispatchmgr_t *mgr, dns_acl_t *blackhole) {
1912 REQUIRE(VALID_DISPATCHMGR(mgr));
1913 if (mgr->blackhole != NULL)
1914 dns_acl_detach(&mgr->blackhole);
1915 dns_acl_attach(blackhole, &mgr->blackhole);
1919 dns_dispatchmgr_getblackhole(dns_dispatchmgr_t *mgr) {
1920 REQUIRE(VALID_DISPATCHMGR(mgr));
1921 return (mgr->blackhole);
1925 dns_dispatchmgr_setblackportlist(dns_dispatchmgr_t *mgr,
1928 REQUIRE(VALID_DISPATCHMGR(mgr));
1936 dns_dispatchmgr_getblackportlist(dns_dispatchmgr_t *mgr) {
1937 REQUIRE(VALID_DISPATCHMGR(mgr));
1942 dns_dispatchmgr_setavailports(dns_dispatchmgr_t *mgr, isc_portset_t *v4portset,
1948 REQUIRE(VALID_DISPATCHMGR(mgr));
1955 v4ports = isc_mem_get(mgr->mctx, sizeof(in_port_t) * nv4ports);
1961 v6ports = isc_mem_get(mgr->mctx, sizeof(in_port_t) * nv6ports);
1964 isc_mem_put(mgr->mctx, v4ports,
1987 PORTBUFLOCK(mgr);
1988 if (mgr->v4ports != NULL) {
1989 isc_mem_put(mgr->mctx, mgr->v4ports,
1990 mgr->nv4ports * sizeof(in_port_t));
1992 mgr->v4ports = v4ports;
1993 mgr->nv4ports = nv4ports;
1995 if (mgr->v6ports != NULL) {
1996 isc_mem_put(mgr->mctx, mgr->v6ports,
1997 mgr->nv6ports * sizeof(in_port_t));
1999 mgr->v6ports = v6ports;
2000 mgr->nv6ports = nv6ports;
2001 PORTBUFUNLOCK(mgr);
2007 dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr,
2014 REQUIRE(VALID_DISPATCHMGR(mgr));
2036 LOCK(&mgr->buffer_lock);
2039 if (mgr->bpool != NULL) {
2048 if (maxbuffers > mgr->maxbuffers) {
2049 isc_mempool_setmaxalloc(mgr->bpool, maxbuffers);
2050 isc_mempool_setfreemax(mgr->bpool, maxbuffers);
2051 mgr->maxbuffers = maxbuffers;
2054 result = isc_mempool_create(mgr->mctx, buffersize, &mgr->bpool);
2056 UNLOCK(&mgr->buffer_lock);
2059 isc_mempool_setname(mgr->bpool, "dispmgr_bpool");
2060 isc_mempool_setmaxalloc(mgr->bpool, maxbuffers);
2061 isc_mempool_setfreemax(mgr->bpool, maxbuffers);
2062 isc_mempool_associatelock(mgr->bpool, &mgr->bpool_lock);
2063 isc_mempool_setfillcount(mgr->bpool, 32);
2067 if (mgr->spool != NULL) {
2069 isc_mempool_setmaxalloc(mgr->spool,
2071 isc_mempool_setfreemax(mgr->spool,
2074 UNLOCK(&mgr->buffer_lock);
2077 result = isc_mempool_create(mgr->mctx, sizeof(dispsocket_t),
2078 &mgr->spool);
2082 isc_mempool_setname(mgr->spool, "dispmgr_spool");
2083 isc_mempool_setmaxalloc(mgr->spool, maxrequests);
2084 isc_mempool_setfreemax(mgr->spool, maxrequests);
2085 isc_mempool_associatelock(mgr->spool, &mgr->spool_lock);
2086 isc_mempool_setfillcount(mgr->spool, 32);
2088 result = qid_allocate(mgr, buckets, increment, &mgr->qid, ISC_TRUE);
2092 mgr->buffersize = buffersize;
2093 mgr->maxbuffers = maxbuffers;
2094 UNLOCK(&mgr->buffer_lock);
2098 isc_mempool_destroy(&mgr->bpool);
2099 if (mgr->spool != NULL)
2100 isc_mempool_destroy(&mgr->spool);
2101 UNLOCK(&mgr->buffer_lock);
2107 dns_dispatchmgr_t *mgr;
2113 mgr = *mgrp;
2116 LOCK(&mgr->lock);
2117 mgr->state |= MGR_SHUTTINGDOWN;
2118 killit = destroy_mgr_ok(mgr);
2119 UNLOCK(&mgr->lock);
2121 mgr_log(mgr, LVL(90), "destroy: killit=%d", killit);
2124 destroy_mgr(&mgr);
2128 dns_dispatchmgr_setstats(dns_dispatchmgr_t *mgr, isc_stats_t *stats) {
2129 REQUIRE(VALID_DISPATCHMGR(mgr));
2130 REQUIRE(ISC_LIST_EMPTY(mgr->list));
2131 REQUIRE(mgr->stats == NULL);
2133 isc_stats_attach(stats, &mgr->stats);
2150 portavailable(dns_dispatchmgr_t *mgr, isc_socket_t *sock,
2161 PORTBUFLOCK(mgr);
2170 ports = mgr->v4ports;
2171 nports = mgr->nv4ports;
2173 ports = mgr->v6ports;
2174 nports = mgr->nv6ports;
2184 PORTBUFUNLOCK(mgr);
2206 !portavailable(disp->mgr, disp->socket, NULL)) {
2232 * Requires mgr be locked.
2242 dispatch_find(dns_dispatchmgr_t *mgr, isc_sockaddr_t *local,
2255 disp = ISC_LIST_HEAD(mgr->list);
2279 qid_allocate(dns_dispatchmgr_t *mgr, unsigned int buckets,
2287 REQUIRE(VALID_DISPATCHMGR(mgr));
2292 qid = isc_mem_get(mgr->mctx, sizeof(*qid));
2296 qid->qid_table = isc_mem_get(mgr->mctx,
2299 isc_mem_put(mgr->mctx, qid, sizeof(*qid));
2305 qid->sock_table = isc_mem_get(mgr->mctx, buckets *
2308 isc_mem_put(mgr->mctx, qid->qid_table,
2310 isc_mem_put(mgr->mctx, qid, sizeof(*qid));
2318 isc_mem_put(mgr->mctx, qid->sock_table,
2321 isc_mem_put(mgr->mctx, qid->qid_table,
2323 isc_mem_put(mgr->mctx, qid, sizeof(*qid));
2365 dispatch_allocate(dns_dispatchmgr_t *mgr, unsigned int maxrequests,
2371 REQUIRE(VALID_DISPATCHMGR(mgr));
2379 disp = isc_mempool_get(mgr->dpool);
2384 disp->mgr = mgr;
2405 isc_rng_attach(mgr->rngctx, &disp->rngctx);
2433 isc_mempool_put(mgr->dpool, disp);
2445 dns_dispatchmgr_t *mgr;
2452 mgr = disp->mgr;
2453 REQUIRE(VALID_DISPATCHMGR(mgr));
2466 isc_mempool_put(mgr->depool, disp->failsafe_ev);
2470 qid_destroy(mgr->mctx, &disp->qid);
2475 isc_mem_put(mgr->mctx, disp->port_table,
2486 disp->mgr = NULL;
2489 isc_mempool_put(mgr->dpool, disp);
2493 dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_socket_t *sock,
2502 return (dns_dispatch_createtcp2(mgr, sock, taskmgr, NULL, NULL,
2509 dns_dispatch_createtcp2(dns_dispatchmgr_t *mgr, isc_socket_t *sock,
2522 REQUIRE(VALID_DISPATCHMGR(mgr));
2530 LOCK(&mgr->lock);
2533 * dispatch_allocate() checks mgr for us.
2537 result = dispatch_allocate(mgr, maxrequests, &disp);
2539 UNLOCK(&mgr->lock);
2543 result = qid_allocate(mgr, buckets, increment, &disp->qid, ISC_FALSE);
2559 disp->ctlevent = isc_event_allocate(mgr->mctx, disp,
2570 dns_tcpmsg_init(mgr->mctx, disp->socket, &disp->tcpmsg);
2595 ISC_LIST_APPEND(mgr->list, disp, link);
2596 UNLOCK(&mgr->lock);
2598 mgr_log(mgr, LVL(90), "created TCP dispatcher %p", disp);
2614 UNLOCK(&mgr->lock);
2620 dns_dispatch_gettcp(dns_dispatchmgr_t *mgr, isc_sockaddr_t *destaddr,
2630 REQUIRE(VALID_DISPATCHMGR(mgr));
2638 LOCK(&mgr->lock);
2639 disp = ISC_LIST_HEAD(mgr->list);
2664 UNLOCK(&mgr->lock);
2669 dns_dispatch_gettcp2(dns_dispatchmgr_t *mgr, isc_sockaddr_t *destaddr,
2680 REQUIRE(VALID_DISPATCHMGR(mgr));
2690 LOCK(&mgr->lock);
2691 disp = ISC_LIST_HEAD(mgr->list);
2718 UNLOCK(&mgr->lock);
2725 disp = ISC_LIST_HEAD(mgr->list);
2741 UNLOCK(&mgr->lock);
2746 dns_dispatch_getudp_dup(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
2757 REQUIRE(VALID_DISPATCHMGR(mgr));
2768 result = dns_dispatchmgr_setudp(mgr, buffersize, maxbuffers,
2773 LOCK(&mgr->lock);
2784 result = dispatch_find(mgr, localaddr, attributes, mask, &disp);
2802 UNLOCK(&mgr->lock);
2814 result = dispatch_createudp(mgr, sockmgr, taskmgr, localaddr,
2821 UNLOCK(&mgr->lock);
2825 UNLOCK(&mgr->lock);
2832 dns_dispatch_getudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
2840 return (dns_dispatch_getudp_dup(mgr, sockmgr, taskmgr, localaddr,
2847 * mgr should be locked.
2855 get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp,
2880 nports = disp->mgr->nv4ports;
2881 ports = disp->mgr->v4ports;
2883 nports = disp->mgr->nv6ports;
2884 ports = disp->mgr->v6ports;
2932 else if (portavailable(mgr, sock, NULL))
2942 mgr_log(mgr, ISC_LOG_ERROR,
2961 dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr,
2975 * dispatch_allocate() checks mgr for us.
2978 result = dispatch_allocate(mgr, maxrequests, &disp);
2985 result = get_udpsocket(mgr, disp, sockmgr, localaddr, &sock,
2995 mgr_log(mgr, LVL(90), "dns_dispatch_createudp: Created"
3018 disp->port_table = isc_mem_get(mgr->mctx,
3026 result = isc_mempool_create(mgr->mctx, sizeof(dispportentry_t),
3053 disp->ctlevent = isc_event_allocate(mgr->mctx, disp,
3063 if (isc_mempool_create(mgr->mctx, sizeof(isc_socketevent_t),
3087 ISC_LIST_APPEND(mgr->list, disp, link);
3089 mgr_log(mgr, LVL(90), "created UDP dispatcher %p", disp);
3245 inc_stats(disp->mgr,
3268 inc_stats(disp->mgr, dns_resstatscounter_dispsockfail);
3304 res = isc_mempool_get(disp->mgr->rpool);
3335 inc_stats(disp->mgr, (qid == disp->mgr->qid) ?
3356 dec_stats(disp->mgr, (qid == disp->mgr->qid) ?
3362 isc_mempool_put(disp->mgr->rpool, res);
3454 dns_dispatchmgr_t *mgr;
3473 mgr = disp->mgr;
3474 REQUIRE(VALID_DISPATCHMGR(mgr));
3490 dec_stats(disp->mgr, (qid == disp->mgr->qid) ?
3558 isc_mempool_put(disp->mgr->rpool, res);
3726 INSIST(sevent->n <= disp->mgr->buffersize);
3729 isc_event_allocate(disp->mgr->mctx, NULL,
3742 newsevent->region.length = disp->mgr->buffersize;
3778 dns_dispatchmgr_t *mgr;
3785 mgr = source->mgr;
3809 LOCK(&mgr->lock);
3812 result = dispatch_createudp(mgr, sockmgr, taskmgr,
3822 UNLOCK(&mgr->lock);
3828 UNLOCK(&mgr->lock);
3889 dns_dispatchmgr_dump(dns_dispatchmgr_t *mgr) {
3893 disp = ISC_LIST_HEAD(mgr->list);