From: Ondřej Surý Date: Thu, 23 Mar 2023 21:37:55 +0000 (+0100) Subject: Convert accepting new TCP connection to to isc_async callback X-Git-Tag: v9.19.12~66^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e18541287231b721c9cdb7e492697a2a80fd83fc;p=thirdparty%2Fbind9.git Convert accepting new TCP connection to to isc_async callback Simplify the acception the new TCP connection by using the isc_async API from the loopmgr instead of using the asychronous netievent mechanism in the netmgr. --- diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index c7f18eb0ff1..acee7fb8fe7 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -250,8 +250,6 @@ struct isc_nmhandle { }; typedef enum isc__netievent_type { - netievent_tcpaccept, - netievent_tlsclose, netievent_tlssend, netievent_tlsconnect, @@ -1281,13 +1279,6 @@ isc__nm_tcp_settimeout(isc_nmhandle_t *handle, uint32_t timeout); void isc__nmhandle_tcp_set_manual_timer(isc_nmhandle_t *handle, const bool manual); -void -isc__nm_async_tcpaccept(isc__networker_t *worker, isc__netievent_t *ev0); -/*%< - * Callback handlers for asynchronous TCP events (connect, listen, - * stoplisten, send, read, pause, close). - */ - void isc__nm_tcp_senddns(isc_nmhandle_t *handle, const isc_region_t *region, isc_nm_cb_t cb, void *cbarg); @@ -1695,8 +1686,6 @@ NETIEVENT_SOCKET_REQ_TYPE(tlssend); NETIEVENT_SOCKET_REQ_RESULT_TYPE(sendcb); -NETIEVENT_SOCKET_QUOTA_TYPE(tcpaccept); - NETIEVENT_SOCKET_TYPE(streamdnsread); NETIEVENT_SOCKET_HANDLE_TYPE(streamdnscancel); @@ -1719,8 +1708,6 @@ NETIEVENT_SOCKET_REQ_DECL(tlssend); NETIEVENT_SOCKET_REQ_RESULT_DECL(sendcb); -NETIEVENT_SOCKET_QUOTA_DECL(tcpaccept); - NETIEVENT_SOCKET_DECL(streamdnsread); NETIEVENT_SOCKET_HANDLE_DECL(streamdnscancel); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 6059c7850b3..2a05a3fc63b 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -439,8 +439,6 @@ process_netievent(void *arg) { isc__networker_t *worker = ievent->worker; switch (ievent->type) { - NETIEVENT_CASE(tcpaccept); - NETIEVENT_CASE(tlssend); NETIEVENT_CASE(tlsclose); NETIEVENT_CASE(tlsdobio); @@ -490,8 +488,6 @@ NETIEVENT_SOCKET_HTTP_EPS_DEF(httpendpoints); NETIEVENT_SOCKET_REQ_DEF(tlssend); -NETIEVENT_SOCKET_QUOTA_DEF(tcpaccept); - NETIEVENT_SOCKET_DEF(streamdnsread); NETIEVENT_SOCKET_HANDLE_DEF(streamdnscancel); diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index 2cc936009a7..66c3a0f9e48 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -70,10 +70,10 @@ static void tcp_close_cb(uv_handle_t *uvhandle); static isc_result_t -accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota); +accept_connection(isc_nmsocket_t *ssock); static void -quota_accept_cb(isc_quota_t *quota, void *sock0); +quota_accept_cb(isc_quota_t *quota, void *arg); static void failed_accept_cb(isc_nmsocket_t *sock, isc_result_t eresult); @@ -451,7 +451,6 @@ start_tcp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock, * increasing quota unnecessarily. */ csock->pquota = sock->pquota; - isc_quota_cb_init(&csock->quotacb, quota_accept_cb, csock); if (mgr->load_balance_sockets) { UNUSED(fd); @@ -553,7 +552,6 @@ static void tcp_connection_cb(uv_stream_t *server, int status) { isc_nmsocket_t *ssock = uv_handle_get_data((uv_handle_t *)server); isc_result_t result; - isc_quota_t *quota = NULL; if (status != 0) { result = isc_uverr2result(status); @@ -569,6 +567,8 @@ tcp_connection_cb(uv_stream_t *server, int status) { } if (ssock->pquota != NULL) { + isc_quota_t *quota = NULL; + isc_quota_cb_init(&ssock->quotacb, quota_accept_cb, ssock); result = isc_quota_attach_cb(ssock->pquota, "a, &ssock->quotacb); if (result == ISC_R_QUOTA) { @@ -577,7 +577,7 @@ tcp_connection_cb(uv_stream_t *server, int status) { } } - result = accept_connection(ssock, quota); + result = accept_connection(ssock); done: isc__nm_accept_connection_log(ssock, result, can_log_tcp_quota()); } @@ -834,42 +834,40 @@ free: isc__nm_free_uvbuf(sock, buf); } +/* + * This is called after we get a quota_accept_cb() callback. + */ static void -quota_accept_cb(isc_quota_t *quota, void *sock0) { - isc_nmsocket_t *sock = (isc_nmsocket_t *)sock0; - isc__netievent_tcpaccept_t *ievent = NULL; +tcpaccept_cb(void *arg) { + isc_nmsocket_t *sock = arg; REQUIRE(VALID_NMSOCK(sock)); + REQUIRE(sock->tid == isc_tid()); - /* - * Create a tcpaccept event and pass it using the async channel. This - * needs to be asynchronous, because the quota might have been released - * by a different child socket. - */ - ievent = isc__nm_get_netievent_tcpaccept(sock->worker, sock, quota); - isc__nm_enqueue_ievent(sock->worker, (isc__netievent_t *)ievent); + isc_result_t result = accept_connection(sock); + isc__nm_accept_connection_log(sock, result, can_log_tcp_quota()); + sock->pquota = NULL; + isc__nmsocket_detach(&sock); } -/* - * This is called after we get a quota_accept_cb() callback. - */ -void -isc__nm_async_tcpaccept(isc__networker_t *worker, isc__netievent_t *ev0) { - isc__netievent_tcpaccept_t *ievent = (isc__netievent_tcpaccept_t *)ev0; - isc_nmsocket_t *sock = ievent->sock; - isc_result_t result; - - UNUSED(worker); +static void +quota_accept_cb(isc_quota_t *quota, void *arg) { + isc_nmsocket_t *sock = arg; REQUIRE(VALID_NMSOCK(sock)); - REQUIRE(sock->tid == isc_tid()); - result = accept_connection(sock, ievent->quota); - isc__nm_accept_connection_log(sock, result, can_log_tcp_quota()); + UNUSED(quota); + + /* + * This needs to be asynchronous, because the quota might have been + * released by a different child socket. + */ + isc__nmsocket_attach(sock, &(isc_nmsocket_t *){ NULL }); + isc_async_run(sock->worker->loop, tcpaccept_cb, sock); } static isc_result_t -accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { +accept_connection(isc_nmsocket_t *ssock) { isc_nmsocket_t *csock = NULL; isc__networker_t *worker = NULL; int r; @@ -882,9 +880,10 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { REQUIRE(ssock->tid == isc_tid()); if (isc__nmsocket_closing(ssock)) { - if (quota != NULL) { - isc_quota_detach("a); + if (ssock->pquota != NULL) { + isc_quota_detach(&ssock->pquota); } + return (ISC_R_CANCELED); } @@ -896,8 +895,8 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) { isc__nmsocket_attach(ssock, &csock->server); csock->recv_cb = ssock->recv_cb; csock->recv_cbarg = ssock->recv_cbarg; - csock->quota = quota; atomic_init(&csock->accepting, true); + csock->quota = ssock->pquota; worker = csock->worker;