2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

Dispatch API simplification

- Many dispatch attributes can be set implicitly instead of being passed
  in. we can infer whether to set DNS_DISPATCHATTR_TCP or _UDP from
  whether we're calling dns_dispatch_createtcp() or _createudp().  we
  can also infer DNS_DISPATCHATTR_IPV4 or _IPV6 from the addresses or
  the socket that were passed in.

- We no longer use dup'd sockets in UDP dispatches, so the 'dup_socket'
  parameter has been removed from dns_dispatch_createudp(), along with
  the code implementing it. also removed isc_socket_dup() since it no
  longer has any callers.

- The 'buffersize' parameter was ignored and has now been removed;
  buffersize is now fixed at 4096.

- Maxbuffers and maxrequests don't need to be passed in on every call to
  dns_dispatch_createtcp() and _createudp().

  In all current uses, the value for mgr->maxbuffers will either be
  raised once from its default of 20000 to 32768, or else left
  alone. (passing in a value lower than 20000 does not lower it.) there
  isn't enough difference between these values for there to be any need
  to configure this.

  The value for disp->maxrequests controls both the quota of concurrent
  requests for a dispatch and also the size of the dispatch socket
  memory pool. it's not clear that this quota is necessary at all. the
  memory pool size currently starts at 32768, but is sometimes lowered
  to 4096, which is definitely unnecessary.

  This commit sets both values permanently to 32768.

- Previously TCP dispatches allocated their own separate QID table,
  which didn't incorporate a port table. this commit removes
  per-dispatch QID tables and shares the same table between all
  dispatches. since dispatches are created for each TCP socket, this may
  speed up the dispatch allocation process. there may be a slight
  increase in lock contention since all dispatches are sharing a single
  QID table, but since TCP sockets are used less often than UDP
  sockets (which were already sharing a QID table), it should not be a
  substantial change.

- The dispatch port table was being used to determine whether a port was
  already in use; if so, then a UDP socket would be bound with
  REUSEADDR. this commit removes the port table, and always binds UDP
  sockets that way.
This commit is contained in:
Evan Hunt
2020-12-17 00:43:00 -08:00
committed by Ondřej Surý
parent 9fd375217d
commit f439eb5d99
16 changed files with 273 additions and 796 deletions

View File

@@ -2140,15 +2140,11 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
*/
} else {
if (have_addr) {
unsigned int attrs;
attrs = DNS_DISPATCHATTR_UDP;
switch (isc_sockaddr_pf(&addr)) {
case AF_INET:
attrs |= DNS_DISPATCHATTR_IPV4;
dscp = dns_resolver_getquerydscp4(fctx->res);
break;
case AF_INET6:
attrs |= DNS_DISPATCHATTR_IPV6;
dscp = dns_resolver_getquerydscp6(fctx->res);
break;
default:
@@ -2157,8 +2153,7 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
}
result = dns_dispatch_createudp(
res->dispatchmgr, res->socketmgr, res->taskmgr,
&addr, 20000, 32768, 16411, 16433, attrs,
&query->dispatch);
&addr, 0, &query->dispatch);
if (result != ISC_R_SUCCESS) {
goto cleanup_query;
}
@@ -2941,7 +2936,6 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
bool retry = false;
isc_interval_t interval;
isc_result_t result;
unsigned int attrs;
fetchctx_t *fctx;
REQUIRE(event->ev_type == ISC_SOCKEVENT_CONNECT);
@@ -2970,6 +2964,8 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
isc_socket_detach(&query->tcpsocket);
resquery_destroy(&query);
} else {
int attrs = 0;
switch (sevent->result) {
case ISC_R_SUCCESS:
@@ -2997,20 +2993,11 @@ resquery_connected(isc_task_t *task, isc_event_t *event) {
* We are connected. Create a dispatcher and
* send the query.
*/
attrs = DNS_DISPATCHATTR_TCP |
DNS_DISPATCHATTR_PRIVATE |
DNS_DISPATCHATTR_CONNECTED;
if (isc_sockaddr_pf(&query->addrinfo->sockaddr) ==
AF_INET) {
attrs |= DNS_DISPATCHATTR_IPV4;
} else {
attrs |= DNS_DISPATCHATTR_IPV6;
}
attrs = DNS_DISPATCHATTR_CONNECTED;
result = dns_dispatch_createtcp(
query->dispatchmgr, query->tcpsocket,
query->fctx->res->taskmgr, NULL, NULL, 4096, 2,
1, 1, 3, attrs, &query->dispatch);
query->fctx->res->taskmgr, NULL, NULL, attrs,
&query->dispatch);
/*
* Regardless of whether dns_dispatch_create()