From: Evan Hunt Date: Sat, 19 Dec 2020 09:34:41 +0000 (-0800) Subject: Move isc_socket_connect() calls into dispatch X-Git-Tag: v9.17.19~15^2~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9f9a327b223c4b3f31d17c41cae8e9e6f9639095;p=thirdparty%2Fbind9.git Move isc_socket_connect() calls into dispatch dns_dispatch_connect() connects a dispatch socket (for TCP) or a dispatch entry socket (for UDP). This is the next step in moving all uses of the isc_socket code into the dispatch module. This API is temporary; it needs to be cleaned up further so that it can be called the same way for both TCP and UDP. --- diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index f021b711072..2f65f7d4c74 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -71,22 +71,6 @@ struct dns_dispatchmgr { isc_refcount_t irefs; - /*% - * Locked by qid->lock if qid exists; otherwise, can be used without - * being locked. - * - * Memory footprint considerations: this is a simple implementation of - * available ports, i.e., an ordered array of the actual port numbers. - * This will require about 256KB of memory in the worst case (128KB for - * each of IPv4 and IPv6). We could reduce it by representing it as a - * more sophisticated way such as a list (or array) of ranges that are - * searched to identify a specific port. Our decision here is the saved - * memory isn't worth the implementation complexity, considering the - * fact that the whole BIND9 process (which is mainly named) already - * requires a pretty large memory footprint. We may, however, have to - * revisit the decision when we want to use it as a separate module for - * an environment where memory requirement is severer. - */ in_port_t *v4ports; /*%< available ports for IPv4 */ unsigned int nv4ports; /*%< # of available ports for IPv4 */ in_port_t *v6ports; /*%< available ports for IPv4 */ @@ -2591,6 +2575,28 @@ dns_dispatch_removeresponse(dns_dispentry_t **resp, } } +isc_result_t +dns_dispatch_connect(dns_dispatch_t *disp, dns_dispentry_t *resp, + isc_task_t *task, isc_taskaction_t action, void *arg) { + isc_socket_t *sock = NULL; + isc_sockaddr_t *address = NULL; + + if (resp != NULL) { + REQUIRE(VALID_RESPONSE(resp)); + sock = resp->dispsocket->socket; + address = &resp->host; + } else if (disp != NULL) { + REQUIRE(VALID_DISPATCH(disp)); + sock = disp->socket; + address = &disp->peer; + } else { + INSIST(0); + ISC_UNREACHABLE(); + } + + return (isc_socket_connect(sock, address, task, action, arg)); +} + /* * disp must be locked. */ diff --git a/lib/dns/include/dns/dispatch.h b/lib/dns/include/dns/dispatch.h index 69e0d81c62c..2854a7bcb6f 100644 --- a/lib/dns/include/dns/dispatch.h +++ b/lib/dns/include/dns/dispatch.h @@ -264,6 +264,18 @@ dns_dispatch_detach(dns_dispatch_t **dispp); *\li dispp != NULL and *dispp be a valid dispatch. */ +isc_result_t +dns_dispatch_connect(dns_dispatch_t *disp, dns_dispentry_t *resp, + isc_task_t *task, isc_taskaction_t action, void *arg); +/*%< + * Connect the UDP socket in 'resp' or the TCP socket in 'disp' to the + * remote server, and run the specified callback. + * + * Requires: + *\li 'resp' is NULL and 'disp' is valid, or + *\li 'disp' is NULL and 'resp' is valid. + */ + void dns_dispatch_starttcp(dns_dispatch_t *disp); /*%< diff --git a/lib/dns/request.c b/lib/dns/request.c index 960ff04d95f..1a16f2d0e55 100644 --- a/lib/dns/request.c +++ b/lib/dns/request.c @@ -729,8 +729,8 @@ again: request->destaddr = *destaddr; if (tcp && !connected) { - result = isc_socket_connect(sock, destaddr, task, req_connected, - request); + result = dns_dispatch_connect(request->dispatch, NULL, task, + req_connected, request); if (result != ISC_R_SUCCESS) { goto unlink; } @@ -912,8 +912,8 @@ use_tcp: request->destaddr = *destaddr; if (tcp && !connected) { - result = isc_socket_connect(sock, destaddr, task, req_connected, - request); + result = dns_dispatch_connect(request->dispatch, NULL, task, + req_connected, request); if (result != ISC_R_SUCCESS) { goto unlink; } diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 5d156e5edc2..59079b0c5f0 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -2165,14 +2165,11 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, query->magic = QUERY_MAGIC; if ((query->options & DNS_FETCHOPT_TCP) != 0) { - isc_socket_t *sock = NULL; - /* * Connect to the remote server. */ - sock = dns_dispatch_getsocket(query->dispatch); - result = isc_socket_connect(sock, &addrinfo->sockaddr, task, - resquery_connected, query); + result = dns_dispatch_connect(query->dispatch, NULL, task, + resquery_connected, query); if (result != ISC_R_SUCCESS) { goto cleanup_dispatch; } @@ -2314,11 +2311,6 @@ addr2buf(void *buf, const size_t bufsize, const isc_sockaddr_t *sockaddr) { return (0); } -static inline isc_socket_t * -query2sock(const resquery_t *query) { - return (dns_dispatch_getentrysocket(query->dispentry)); -} - static inline size_t add_serveraddr(uint8_t *buf, const size_t bufsize, const resquery_t *query) { return (addr2buf(buf, bufsize, &query->addrinfo->sockaddr)); @@ -2371,17 +2363,17 @@ issecuredomain(dns_view_t *view, const dns_name_t *name, dns_rdatatype_t type, static isc_result_t resquery_send(resquery_t *query) { - fetchctx_t *fctx; + fetchctx_t *fctx = NULL; isc_result_t result; dns_name_t *qname = NULL; dns_rdataset_t *qrdataset = NULL; isc_region_t r; - dns_resolver_t *res; + dns_resolver_t *res = NULL; isc_task_t *task; isc_socket_t *sock; isc_buffer_t tcpbuffer; - isc_sockaddr_t *address; - isc_buffer_t *buffer; + isc_sockaddr_t *address = NULL; + isc_buffer_t *buffer = NULL; isc_netaddr_t ipaddr; dns_tsigkey_t *tsigkey = NULL; dns_peer_t *peer = NULL; @@ -2406,7 +2398,6 @@ resquery_send(resquery_t *query) { res = fctx->res; task = res->buckets[fctx->bucketnum].task; - address = NULL; if (tcp) { /* @@ -2805,22 +2796,20 @@ resquery_send(resquery_t *query) { */ dns_message_reset(fctx->qmessage, DNS_MESSAGE_INTENTRENDER); - sock = query2sock(query); - - /* - * Send the query! - */ if (!tcp) { - address = &query->addrinfo->sockaddr; - result = isc_socket_connect(sock, address, task, - resquery_udpconnected, query); + /* Connect the UDP socket */ + result = dns_dispatch_connect(NULL, query->dispentry, task, + resquery_udpconnected, query); if (result != ISC_R_SUCCESS) { goto cleanup_message; } query->connects++; } + isc_buffer_usedregion(buffer, &r); + sock = dns_dispatch_getentrysocket(query->dispentry); + /* * XXXRTH Make sure we don't send to ourselves! We should probably * prune out these addresses when we get them from the ADB. @@ -2841,6 +2830,7 @@ resquery_send(resquery_t *query) { } } + address = tcp ? NULL : &query->addrinfo->sockaddr; result = isc_socket_sendto2(sock, &r, task, address, NULL, &query->sendevent, 0); INSIST(result == ISC_R_SUCCESS); @@ -9848,8 +9838,7 @@ rctx_logpacket(respctx_t *rctx) { dtmsgtype = DNS_DTTYPE_RR; } - sock = query2sock(rctx->query); - + sock = dns_dispatch_getentrysocket(rctx->query); if (sock != NULL) { result = isc_socket_getsockname(sock, &localaddr); if (result == ISC_R_SUCCESS) { diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index fe3b233a0fc..0dc30883970 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -956,7 +956,6 @@ xfrin_start(dns_xfrin_ctx_t *xfr) { ISC_UNREACHABLE(); } - /* TODO isc_socket_dscp(xfr->socket, xfr->dscp); */ return (ISC_R_SUCCESS); failure: @@ -1035,6 +1034,7 @@ xfrin_connect_done(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { xfr->handle = handle; sockaddr = isc_nmhandle_peeraddr(handle); isc_sockaddr_format(&sockaddr, sourcetext, sizeof(sourcetext)); + /* TODO set DSCP */ if (xfr->tsigkey != NULL && xfr->tsigkey->key != NULL) { dns_name_format(dst_key_name(xfr->tsigkey->key), signerbuf,