2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

netmgr refactoring: use generic functions when operating on sockets.

tcpdns used transport-specific functions to operate on the outer socket.
Use generic ones instead, and select the proper call in netmgr.c.
Make the missing functions (e.g. isc_nm_read) generic and add type-specific
calls (isc__nm_tcp_read). This is the preparation for netmgr TLS layer.
This commit is contained in:
Witold Kręcicki 2020-03-20 11:55:10 +01:00 committed by Witold Krecicki
parent aed3927592
commit 5fedd21e16
8 changed files with 114 additions and 41 deletions

View File

@ -177,9 +177,9 @@ isc_nm_listenudp(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_recv_cb_t cb,
*/ */
void void
isc_nm_udp_stoplistening(isc_nmsocket_t *sock); isc_nm_stoplistening(isc_nmsocket_t *sock);
/*%< /*%<
* Stop listening for UDP packets on socket 'sock'. * Stop listening on socket 'sock'.
*/ */
void void
@ -251,12 +251,6 @@ isc_nm_listentcp(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_cb_t cb,
* prepended with a two-byte length field, and handles buffering. * prepended with a two-byte length field, and handles buffering.
*/ */
void
isc_nm_tcp_stoplistening(isc_nmsocket_t *sock);
/*%<
* Stop listening on TCP socket 'sock'.
*/
isc_result_t isc_result_t
isc_nm_listentcpdns(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_recv_cb_t cb, isc_nm_listentcpdns(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_recv_cb_t cb,
void *cbarg, isc_nm_cb_t accept_cb, void *accept_cbarg, void *cbarg, isc_nm_cb_t accept_cb, void *accept_cbarg,
@ -285,12 +279,6 @@ isc_nm_listentcpdns(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_recv_cb_t cb,
* 'quota' is passed to isc_nm_listentcp() when opening the raw TCP socket. * 'quota' is passed to isc_nm_listentcp() when opening the raw TCP socket.
*/ */
void
isc_nm_tcpdns_stoplistening(isc_nmsocket_t *sock);
/*%<
* Stop listening on TCPDNS socket 'sock'.
*/
void void
isc_nm_tcpdns_sequential(isc_nmhandle_t *handle); isc_nm_tcpdns_sequential(isc_nmhandle_t *handle);
/*%< /*%<

View File

@ -124,6 +124,8 @@ struct isc_nmiface {
typedef enum isc__netievent_type { typedef enum isc__netievent_type {
netievent_udpsend, netievent_udpsend,
netievent_udprecv, netievent_udprecv,
netievent_udpstop,
netievent_tcpconnect, netievent_tcpconnect,
netievent_tcpsend, netievent_tcpsend,
netievent_tcprecv, netievent_tcprecv,
@ -131,13 +133,13 @@ typedef enum isc__netievent_type {
netievent_tcppauseread, netievent_tcppauseread,
netievent_tcpchildlisten, netievent_tcpchildlisten,
netievent_tcpchildstop, netievent_tcpchildstop,
netievent_closecb,
netievent_shutdown,
netievent_stop,
netievent_udpstop,
netievent_tcpstop, netievent_tcpstop,
netievent_tcpclose, netievent_tcpclose,
netievent_tcpdnsclose, netievent_tcpdnsclose,
netievent_closecb,
netievent_shutdown,
netievent_stop,
netievent_prio = 0xff, /* event type values higher than this netievent_prio = 0xff, /* event type values higher than this
* will be treated as high-priority * will be treated as high-priority
* events, which can be processed * events, which can be processed
@ -647,6 +649,9 @@ isc__nm_udp_send(isc_nmhandle_t *handle, isc_region_t *region, isc_nm_cb_t cb,
* Back-end implementation of isc_nm_send() for UDP handles. * Back-end implementation of isc_nm_send() for UDP handles.
*/ */
void
isc__nm_udp_stoplistening(isc_nmsocket_t *sock);
void void
isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0); isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0);
@ -665,11 +670,26 @@ isc__nm_tcp_send(isc_nmhandle_t *handle, isc_region_t *region, isc_nm_cb_t cb,
* Back-end implementation of isc_nm_send() for TCP handles. * Back-end implementation of isc_nm_send() for TCP handles.
*/ */
isc_result_t
isc__nm_tcp_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg);
void void
isc__nm_tcp_close(isc_nmsocket_t *sock); isc__nm_tcp_close(isc_nmsocket_t *sock);
/*%< /*%<
* Close a TCP socket. * Close a TCP socket.
*/ */
isc_result_t
isc__nm_tcp_pauseread(isc_nmsocket_t *sock);
/*%<
* Pause reading on this socket, while still remembering the callback.
*/
isc_result_t
isc__nm_tcp_resumeread(isc_nmsocket_t *sock);
/*%<
* Resume reading from socket.
*
*/
void void
isc__nm_tcp_shutdown(isc_nmsocket_t *sock); isc__nm_tcp_shutdown(isc_nmsocket_t *sock);
@ -677,6 +697,9 @@ isc__nm_tcp_shutdown(isc_nmsocket_t *sock);
* Called on shutdown to close and clean up a listening TCP socket. * Called on shutdown to close and clean up a listening TCP socket.
*/ */
void
isc__nm_tcp_stoplistening(isc_nmsocket_t *sock);
void void
isc__nm_async_tcpconnect(isc__networker_t *worker, isc__netievent_t *ev0); isc__nm_async_tcpconnect(isc__networker_t *worker, isc__netievent_t *ev0);
void void
@ -694,6 +717,10 @@ isc__nm_async_startread(isc__networker_t *worker, isc__netievent_t *ev0);
void void
isc__nm_async_pauseread(isc__networker_t *worker, isc__netievent_t *ev0); isc__nm_async_pauseread(isc__networker_t *worker, isc__netievent_t *ev0);
void void
isc__nm_async_tcp_startread(isc__networker_t *worker, isc__netievent_t *ev0);
void
isc__nm_async_tcp_pauseread(isc__networker_t *worker, isc__netievent_t *ev0);
void
isc__nm_async_tcpclose(isc__networker_t *worker, isc__netievent_t *ev0); isc__nm_async_tcpclose(isc__networker_t *worker, isc__netievent_t *ev0);
/*%< /*%<
* Callback handlers for asynchronous TCP events (connect, listen, * Callback handlers for asynchronous TCP events (connect, listen,
@ -713,6 +740,9 @@ isc__nm_tcpdns_close(isc_nmsocket_t *sock);
* Close a TCPDNS socket. * Close a TCPDNS socket.
*/ */
void
isc__nm_tcpdns_stoplistening(isc_nmsocket_t *sock);
void void
isc__nm_async_tcpdnsclose(isc__networker_t *worker, isc__netievent_t *ev0); isc__nm_async_tcpdnsclose(isc__networker_t *worker, isc__netievent_t *ev0);

View File

@ -607,10 +607,10 @@ process_queue(isc__networker_t *worker, isc_queue_t *queue) {
isc__nm_async_tcpchildlisten(worker, ievent); isc__nm_async_tcpchildlisten(worker, ievent);
break; break;
case netievent_tcpstartread: case netievent_tcpstartread:
isc__nm_async_startread(worker, ievent); isc__nm_async_tcp_startread(worker, ievent);
break; break;
case netievent_tcppauseread: case netievent_tcppauseread:
isc__nm_async_pauseread(worker, ievent); isc__nm_async_tcp_pauseread(worker, ievent);
break; break;
case netievent_tcpsend: case netievent_tcpsend:
isc__nm_async_tcpsend(worker, ievent); isc__nm_async_tcpsend(worker, ievent);
@ -1321,6 +1321,62 @@ isc_nm_send(isc_nmhandle_t *handle, isc_region_t *region, isc_nm_cb_t cb,
} }
} }
isc_result_t
isc_nm_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
REQUIRE(VALID_NMHANDLE(handle));
switch (handle->sock->type) {
case isc_nm_tcpsocket:
return (isc__nm_tcp_read(handle, cb, cbarg));
default:
INSIST(0);
ISC_UNREACHABLE();
}
}
isc_result_t
isc_nm_pauseread(isc_nmsocket_t *sock) {
REQUIRE(VALID_NMSOCK(sock));
switch (sock->type) {
case isc_nm_tcpsocket:
return (isc__nm_tcp_pauseread(sock));
default:
INSIST(0);
ISC_UNREACHABLE();
}
}
isc_result_t
isc_nm_resumeread(isc_nmsocket_t *sock) {
REQUIRE(VALID_NMSOCK(sock));
switch (sock->type) {
case isc_nm_tcpsocket:
return (isc__nm_tcp_resumeread(sock));
default:
INSIST(0);
ISC_UNREACHABLE();
}
}
void
isc_nm_stoplistening(isc_nmsocket_t *sock) {
REQUIRE(VALID_NMSOCK(sock));
switch (sock->type) {
case isc_nm_udplistener:
isc__nm_udp_stoplistening(sock);
break;
case isc_nm_tcpdnslistener:
isc__nm_tcpdns_stoplistening(sock);
break;
case isc_nm_tcplistener:
isc__nm_tcp_stoplistening(sock);
break;
default:
INSIST(0);
ISC_UNREACHABLE();
}
}
void void
isc__nm_async_closecb(isc__networker_t *worker, isc__netievent_t *ev0) { isc__nm_async_closecb(isc__networker_t *worker, isc__netievent_t *ev0) {
isc__netievent_closecb_t *ievent = (isc__netievent_closecb_t *)ev0; isc__netievent_closecb_t *ievent = (isc__netievent_closecb_t *)ev0;

View File

@ -377,7 +377,7 @@ isc__nm_async_tcpchildlisten(isc__networker_t *worker, isc__netievent_t *ev0) {
} }
void void
isc_nm_tcp_stoplistening(isc_nmsocket_t *sock) { isc__nm_tcp_stoplistening(isc_nmsocket_t *sock) {
isc__netievent_tcpstop_t *ievent = NULL; isc__netievent_tcpstop_t *ievent = NULL;
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
@ -519,7 +519,7 @@ readtimeout_cb(uv_timer_t *handle) {
} }
isc_result_t isc_result_t
isc_nm_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) { isc__nm_tcp_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
isc_nmsocket_t *sock = NULL; isc_nmsocket_t *sock = NULL;
isc__netievent_startread_t *ievent = NULL; isc__netievent_startread_t *ievent = NULL;
@ -534,8 +534,8 @@ isc_nm_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
ievent->sock = sock; ievent->sock = sock;
if (sock->tid == isc_nm_tid()) { if (sock->tid == isc_nm_tid()) {
isc__nm_async_startread(&sock->mgr->workers[sock->tid], isc__nm_async_tcp_startread(&sock->mgr->workers[sock->tid],
(isc__netievent_t *)ievent); (isc__netievent_t *)ievent);
isc__nm_put_ievent(sock->mgr, ievent); isc__nm_put_ievent(sock->mgr, ievent);
} else { } else {
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid], isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
@ -546,7 +546,7 @@ isc_nm_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) {
} }
void void
isc__nm_async_startread(isc__networker_t *worker, isc__netievent_t *ev0) { isc__nm_async_tcp_startread(isc__networker_t *worker, isc__netievent_t *ev0) {
isc__netievent_startread_t *ievent = (isc__netievent_startread_t *)ev0; isc__netievent_startread_t *ievent = (isc__netievent_startread_t *)ev0;
isc_nmsocket_t *sock = ievent->sock; isc_nmsocket_t *sock = ievent->sock;
int r; int r;
@ -569,7 +569,7 @@ isc__nm_async_startread(isc__networker_t *worker, isc__netievent_t *ev0) {
} }
isc_result_t isc_result_t
isc_nm_pauseread(isc_nmsocket_t *sock) { isc__nm_tcp_pauseread(isc_nmsocket_t *sock) {
isc__netievent_pauseread_t *ievent = NULL; isc__netievent_pauseread_t *ievent = NULL;
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
@ -583,8 +583,8 @@ isc_nm_pauseread(isc_nmsocket_t *sock) {
ievent->sock = sock; ievent->sock = sock;
if (sock->tid == isc_nm_tid()) { if (sock->tid == isc_nm_tid()) {
isc__nm_async_pauseread(&sock->mgr->workers[sock->tid], isc__nm_async_tcp_pauseread(&sock->mgr->workers[sock->tid],
(isc__netievent_t *)ievent); (isc__netievent_t *)ievent);
isc__nm_put_ievent(sock->mgr, ievent); isc__nm_put_ievent(sock->mgr, ievent);
} else { } else {
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid], isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],
@ -595,7 +595,7 @@ isc_nm_pauseread(isc_nmsocket_t *sock) {
} }
void void
isc__nm_async_pauseread(isc__networker_t *worker, isc__netievent_t *ev0) { isc__nm_async_tcp_pauseread(isc__networker_t *worker, isc__netievent_t *ev0) {
isc__netievent_pauseread_t *ievent = (isc__netievent_pauseread_t *)ev0; isc__netievent_pauseread_t *ievent = (isc__netievent_pauseread_t *)ev0;
isc_nmsocket_t *sock = ievent->sock; isc_nmsocket_t *sock = ievent->sock;
@ -609,7 +609,7 @@ isc__nm_async_pauseread(isc__networker_t *worker, isc__netievent_t *ev0) {
} }
isc_result_t isc_result_t
isc_nm_resumeread(isc_nmsocket_t *sock) { isc__nm_tcp_resumeread(isc_nmsocket_t *sock) {
isc__netievent_startread_t *ievent = NULL; isc__netievent_startread_t *ievent = NULL;
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
@ -625,8 +625,8 @@ isc_nm_resumeread(isc_nmsocket_t *sock) {
ievent->sock = sock; ievent->sock = sock;
if (sock->tid == isc_nm_tid()) { if (sock->tid == isc_nm_tid()) {
isc__nm_async_startread(&sock->mgr->workers[sock->tid], isc__nm_async_tcp_startread(&sock->mgr->workers[sock->tid],
(isc__netievent_t *)ievent); (isc__netievent_t *)ievent);
isc__nm_put_ievent(sock->mgr, ievent); isc__nm_put_ievent(sock->mgr, ievent);
} else { } else {
isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid], isc__nm_enqueue_ievent(&sock->mgr->workers[sock->tid],

View File

@ -316,7 +316,7 @@ isc_nm_listentcpdns(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_recv_cb_t cb,
} }
void void
isc_nm_tcpdns_stoplistening(isc_nmsocket_t *sock) { isc__nm_tcpdns_stoplistening(isc_nmsocket_t *sock) {
REQUIRE(VALID_NMSOCK(sock)); REQUIRE(VALID_NMSOCK(sock));
REQUIRE(sock->type == isc_nm_tcpdnslistener); REQUIRE(sock->type == isc_nm_tcpdnslistener);
@ -326,7 +326,7 @@ isc_nm_tcpdns_stoplistening(isc_nmsocket_t *sock) {
sock->rcbarg = NULL; sock->rcbarg = NULL;
if (sock->outer != NULL) { if (sock->outer != NULL) {
isc_nm_tcp_stoplistening(sock->outer); isc_nm_stoplistening(sock->outer);
isc_nmsocket_detach(&sock->outer); isc_nmsocket_detach(&sock->outer);
} }
} }
@ -494,7 +494,7 @@ isc__nm_tcpdns_send(isc_nmhandle_t *handle, isc_region_t *region,
*(uint16_t *)t->region.base = htons(region->length); *(uint16_t *)t->region.base = htons(region->length);
memmove(t->region.base + 2, region->base, region->length); memmove(t->region.base + 2, region->base, region->length);
return (isc__nm_tcp_send(t->handle, &t->region, tcpdnssend_cb, t)); return (isc_nm_send(t->handle, &t->region, tcpdnssend_cb, t));
} }
static void static void

View File

@ -219,7 +219,7 @@ stoplistening(isc_nmsocket_t *sock) {
} }
void void
isc_nm_udp_stoplistening(isc_nmsocket_t *sock) { isc__nm_udp_stoplistening(isc_nmsocket_t *sock) {
isc__netievent_udpstop_t *ievent = NULL; isc__netievent_udpstop_t *ievent = NULL;
/* We can't be launched from network thread, we'd deadlock */ /* We can't be launched from network thread, we'd deadlock */

View File

@ -461,14 +461,13 @@ isc_nm_maxudp
isc_nm_send isc_nm_send
isc_nm_setstats isc_nm_setstats
isc_nm_start isc_nm_start
isc_nm_stoplistening
isc_nm_tcp_gettimeouts isc_nm_tcp_gettimeouts
isc_nm_tcp_settimeouts isc_nm_tcp_settimeouts
isc_nmsocket_detach
isc_nm_tcpdns_keepalive isc_nm_tcpdns_keepalive
isc_nm_tcpdns_sequential isc_nm_tcpdns_sequential
isc_nm_tcpdns_stoplistening
isc_nm_tid isc_nm_tid
isc_nm_udp_stoplistening isc_nmsocket_detach
isc__nm_acquire_interlocked isc__nm_acquire_interlocked
isc__nm_drop_interlocked isc__nm_drop_interlocked
isc__nm_acquire_interlocked_force isc__nm_acquire_interlocked_force

View File

@ -553,11 +553,11 @@ cleanup_interface:
void void
ns_interface_shutdown(ns_interface_t *ifp) { ns_interface_shutdown(ns_interface_t *ifp) {
if (ifp->udplistensocket != NULL) { if (ifp->udplistensocket != NULL) {
isc_nm_udp_stoplistening(ifp->udplistensocket); isc_nm_stoplistening(ifp->udplistensocket);
isc_nmsocket_detach(&ifp->udplistensocket); isc_nmsocket_detach(&ifp->udplistensocket);
} }
if (ifp->tcplistensocket != NULL) { if (ifp->tcplistensocket != NULL) {
isc_nm_tcpdns_stoplistening(ifp->tcplistensocket); isc_nm_stoplistening(ifp->tcplistensocket);
isc_nmsocket_detach(&ifp->tcplistensocket); isc_nmsocket_detach(&ifp->tcplistensocket);
} }
if (ifp->clientmgr != NULL) { if (ifp->clientmgr != NULL) {