]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
netmgr: refactor isc__nm_incstats() and isc__nm_decstats()
authorEvan Hunt <each@isc.org>
Sat, 2 Oct 2021 23:26:43 +0000 (16:26 -0700)
committerEvan Hunt <each@isc.org>
Fri, 15 Oct 2021 07:40:37 +0000 (00:40 -0700)
After support for route/netlink sockets is merged, not all sockets
will have stats counters associated with them, so it's now necessary
to check whether socket stats exist before incrementing or decrementing
them. rather than relying on the caller for this, we now just pass the
socket and an index, and the correct stats counter will be updated if
it exists.

lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/tcp.c
lib/isc/netmgr/tcpdns.c
lib/isc/netmgr/tlsdns.c
lib/isc/netmgr/udp.c

index 8fc2b4fcd19514229394b7c4d8b3e9ac856d285a..c776aa08b3bb376dc7ddb9d8f12fe47e76d1b660 100644 (file)
@@ -732,7 +732,7 @@ typedef enum isc_nmsocket_type {
 /*%
  * Index into socket stat counter arrays.
  */
-enum {
+typedef enum {
        STATID_OPEN = 0,
        STATID_OPENFAIL = 1,
        STATID_CLOSE = 2,
@@ -743,8 +743,9 @@ enum {
        STATID_ACCEPT = 7,
        STATID_SENDFAIL = 8,
        STATID_RECVFAIL = 9,
-       STATID_ACTIVE = 10
-};
+       STATID_ACTIVE = 10,
+       STATID_MAX = 11,
+} isc__nm_statid_t;
 
 #if HAVE_LIBNGHTTP2
 typedef struct isc_nmsocket_tls_send_req {
@@ -1755,13 +1756,13 @@ isc__nm_acquire_interlocked_force(isc_nm_t *mgr);
  */
 
 void
-isc__nm_incstats(isc_nm_t *mgr, isc_statscounter_t counterid);
+isc__nm_incstats(isc_nmsocket_t *sock, isc__nm_statid_t id);
 /*%<
  * Increment socket-related statistics counters.
  */
 
 void
-isc__nm_decstats(isc_nm_t *mgr, isc_statscounter_t counterid);
+isc__nm_decstats(isc_nmsocket_t *sock, isc__nm_statid_t id);
 /*%<
  * Decrement socket-related statistics counters.
  */
index 80a2224edfc5a40edecd0a72260924b98caa9028..259e097da267a660554c1be87d86be391b11ce58 100644 (file)
@@ -1192,6 +1192,8 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) {
                         "\n",
                         sock, isc_refcount_current(&sock->references));
 
+       isc__nm_decstats(sock, STATID_ACTIVE);
+
        atomic_store(&sock->destroying, true);
 
        if (sock->parent == NULL && sock->children != NULL) {
@@ -1221,9 +1223,6 @@ nmsocket_cleanup(isc_nmsocket_t *sock, bool dofree FLARG) {
                sock->children = NULL;
                sock->nchildren = 0;
        }
-       if (sock->statsindex != NULL) {
-               isc__nm_decstats(sock->mgr, sock->statsindex[STATID_ACTIVE]);
-       }
 
        sock->statichandle = NULL;
 
@@ -1486,12 +1485,17 @@ isc___nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
        switch (type) {
        case isc_nm_udpsocket:
        case isc_nm_udplistener:
-               if (family == AF_INET) {
+               switch (family) {
+               case AF_INET:
                        sock->statsindex = udp4statsindex;
-               } else {
+                       break;
+               case AF_INET6:
                        sock->statsindex = udp6statsindex;
+                       break;
+               default:
+                       INSIST(0);
+                       ISC_UNREACHABLE();
                }
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_ACTIVE]);
                break;
        case isc_nm_tcpsocket:
        case isc_nm_tcplistener:
@@ -1501,12 +1505,17 @@ isc___nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
        case isc_nm_tlsdnslistener:
        case isc_nm_httpsocket:
        case isc_nm_httplistener:
-               if (family == AF_INET) {
+               switch (family) {
+               case AF_INET:
                        sock->statsindex = tcp4statsindex;
-               } else {
+                       break;
+               case AF_INET6:
                        sock->statsindex = tcp6statsindex;
+                       break;
+               default:
+                       INSIST(0);
+                       ISC_UNREACHABLE();
                }
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_ACTIVE]);
                break;
        default:
                break;
@@ -1545,6 +1554,8 @@ isc___nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, isc_nmsocket_type type,
 #endif
 
        sock->magic = NMSOCK_MAGIC;
+
+       isc__nm_incstats(sock, STATID_ACTIVE);
 }
 
 void
@@ -2926,22 +2937,22 @@ isc_nm_setstats(isc_nm_t *mgr, isc_stats_t *stats) {
 }
 
 void
-isc__nm_incstats(isc_nm_t *mgr, isc_statscounter_t counterid) {
-       REQUIRE(VALID_NM(mgr));
-       REQUIRE(counterid != -1);
+isc__nm_incstats(isc_nmsocket_t *sock, isc__nm_statid_t id) {
+       REQUIRE(VALID_NMSOCK(sock));
+       REQUIRE(id < STATID_MAX);
 
-       if (mgr->stats != NULL) {
-               isc_stats_increment(mgr->stats, counterid);
+       if (sock->statsindex != NULL && sock->mgr->stats != NULL) {
+               isc_stats_increment(sock->mgr->stats, sock->statsindex[id]);
        }
 }
 
 void
-isc__nm_decstats(isc_nm_t *mgr, isc_statscounter_t counterid) {
-       REQUIRE(VALID_NM(mgr));
-       REQUIRE(counterid != -1);
+isc__nm_decstats(isc_nmsocket_t *sock, isc__nm_statid_t id) {
+       REQUIRE(VALID_NMSOCK(sock));
+       REQUIRE(id < STATID_MAX);
 
-       if (mgr->stats != NULL) {
-               isc_stats_decrement(mgr->stats, counterid);
+       if (sock->statsindex != NULL && sock->mgr->stats != NULL) {
+               isc_stats_decrement(sock->mgr->stats, sock->statsindex[id]);
        }
 }
 
index e5bbd1822b012094654dff3f89784138922568bb..382018944e2138fc1a36c3be837258975ca20efc 100644 (file)
@@ -144,16 +144,15 @@ tcp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
        r = uv_tcp_open(&sock->uv_handle.tcp, sock->fd);
        if (r != 0) {
                isc__nm_closesocket(sock->fd);
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPENFAIL]);
+               isc__nm_incstats(sock, STATID_OPENFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPEN]);
+       isc__nm_incstats(sock, STATID_OPEN);
 
        if (req->local.length != 0) {
                r = uv_tcp_bind(&sock->uv_handle.tcp, &req->local.type.sa, 0);
                if (r != 0) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_BINDFAIL]);
+                       isc__nm_incstats(sock, STATID_BINDFAIL);
                        goto done;
                }
        }
@@ -164,11 +163,10 @@ tcp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
        r = uv_tcp_connect(&req->uv_req.connect, &sock->uv_handle.tcp,
                           &req->peer.type.sa, tcp_connect_cb);
        if (r != 0) {
-               isc__nm_incstats(sock->mgr,
-                                sock->statsindex[STATID_CONNECTFAIL]);
+               isc__nm_incstats(sock, STATID_CONNECTFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CONNECT]);
+       isc__nm_incstats(sock, STATID_CONNECT);
 
        uv_handle_set_data((uv_handle_t *)&sock->timer, &req->uv_req.connect);
        isc__nmsocket_timer_start(sock);
@@ -266,7 +264,7 @@ tcp_connect_cb(uv_connect_t *uvreq, int status) {
                goto error;
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CONNECT]);
+       isc__nm_incstats(sock, STATID_CONNECT);
        r = uv_tcp_getpeername(&sock->uv_handle.tcp, (struct sockaddr *)&ss,
                               &(int){ sizeof(ss) });
        if (r != 0) {
@@ -536,10 +534,10 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
        r = uv_tcp_open(&sock->uv_handle.tcp, sock->fd);
        if (r < 0) {
                isc__nm_closesocket(sock->fd);
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPENFAIL]);
+               isc__nm_incstats(sock, STATID_OPENFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPEN]);
+       isc__nm_incstats(sock, STATID_OPEN);
 
        if (sa_family == AF_INET6) {
                flags = UV_TCP_IPV6ONLY;
@@ -549,7 +547,7 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
        r = isc_uv_tcp_freebind(&sock->uv_handle.tcp, &sock->iface.type.sa,
                                flags);
        if (r < 0) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_BINDFAIL]);
+               isc__nm_incstats(sock, STATID_BINDFAIL);
                goto done;
        }
 #else
@@ -557,8 +555,7 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
                r = isc_uv_tcp_freebind(&sock->uv_handle.tcp,
                                        &sock->iface.type.sa, flags);
                if (r < 0) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_BINDFAIL]);
+                       isc__nm_incstats(sock, STATID_BINDFAIL);
                        goto done;
                }
                sock->parent->uv_handle.tcp.flags = sock->uv_handle.tcp.flags;
@@ -582,7 +579,7 @@ isc__nm_async_tcplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
                              ISC_LOGMODULE_NETMGR, ISC_LOG_ERROR,
                              "uv_listen failed: %s",
                              isc_result_totext(isc__nm_uverr2result(r)));
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_BINDFAIL]);
+               isc__nm_incstats(sock, STATID_BINDFAIL);
                goto done;
        }
 
@@ -627,8 +624,7 @@ tcp_connection_cb(uv_stream_t *server, int status) {
                result = isc_quota_attach_cb(ssock->pquota, &quota,
                                             &ssock->quotacb);
                if (result == ISC_R_QUOTA) {
-                       isc__nm_incstats(ssock->mgr,
-                                        ssock->statsindex[STATID_ACCEPTFAIL]);
+                       isc__nm_incstats(ssock, STATID_ACCEPTFAIL);
                        return;
                }
        }
@@ -868,8 +864,7 @@ isc__nm_tcp_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {
 
        if (nread < 0) {
                if (nread != UV_EOF) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_RECVFAIL]);
+                       isc__nm_incstats(sock, STATID_RECVFAIL);
                }
 
                isc__nm_tcp_failed_read_cb(sock, isc__nm_uverr2result(nread));
@@ -1028,7 +1023,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
 
        atomic_store(&csock->accepting, false);
 
-       isc__nm_incstats(csock->mgr, csock->statsindex[STATID_ACCEPT]);
+       isc__nm_incstats(csock, STATID_ACCEPT);
 
        csock->read_timeout = atomic_load(&csock->mgr->init);
 
@@ -1096,7 +1091,7 @@ tcp_send_cb(uv_write_t *req, int status) {
        isc_nmsocket_t *sock = uvreq->sock;
 
        if (status < 0) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_SENDFAIL]);
+               isc__nm_incstats(sock, STATID_SENDFAIL);
                failed_send_cb(sock, uvreq, isc__nm_uverr2result(status));
                return;
        }
@@ -1120,7 +1115,7 @@ isc__nm_async_tcpsend(isc__networker_t *worker, isc__netievent_t *ev0) {
 
        result = tcp_send_direct(sock, uvreq);
        if (result != ISC_R_SUCCESS) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_SENDFAIL]);
+               isc__nm_incstats(sock, STATID_SENDFAIL);
                failed_send_cb(sock, uvreq, result);
        }
 }
@@ -1162,7 +1157,7 @@ tcp_stop_cb(uv_handle_t *handle) {
                ISC_UNREACHABLE();
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+       isc__nm_incstats(sock, STATID_CLOSE);
 
        atomic_store(&sock->listening, false);
 
@@ -1181,7 +1176,7 @@ tcp_close_sock(isc_nmsocket_t *sock) {
                ISC_UNREACHABLE();
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+       isc__nm_incstats(sock, STATID_CLOSE);
 
        if (sock->server != NULL) {
                isc__nmsocket_detach(&sock->server);
index 9f4a7fc595efb141c6db5a73349fd67edb08be21..fb8308d6db4ec9a9cccd83b5ecf25f74c727b44e 100644 (file)
@@ -114,10 +114,10 @@ tcpdns_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
        r = uv_tcp_open(&sock->uv_handle.tcp, sock->fd);
        if (r != 0) {
                isc__nm_closesocket(sock->fd);
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPENFAIL]);
+               isc__nm_incstats(sock, STATID_OPENFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPEN]);
+       isc__nm_incstats(sock, STATID_OPEN);
 
        if (req->local.length != 0) {
                r = uv_tcp_bind(&sock->uv_handle.tcp, &req->local.type.sa, 0);
@@ -126,8 +126,7 @@ tcpdns_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
                 * to be ignored
                 */
                if (r != 0 && r != UV_EINVAL) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_BINDFAIL]);
+                       isc__nm_incstats(sock, STATID_BINDFAIL);
                        goto done;
                }
        }
@@ -138,11 +137,10 @@ tcpdns_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
        r = uv_tcp_connect(&req->uv_req.connect, &sock->uv_handle.tcp,
                           &req->peer.type.sa, tcpdns_connect_cb);
        if (r != 0) {
-               isc__nm_incstats(sock->mgr,
-                                sock->statsindex[STATID_CONNECTFAIL]);
+               isc__nm_incstats(sock, STATID_CONNECTFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CONNECT]);
+       isc__nm_incstats(sock, STATID_CONNECT);
 
        uv_handle_set_data((uv_handle_t *)&sock->timer, &req->uv_req.connect);
        isc__nmsocket_timer_start(sock);
@@ -233,7 +231,7 @@ tcpdns_connect_cb(uv_connect_t *uvreq, int status) {
                goto error;
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CONNECT]);
+       isc__nm_incstats(sock, STATID_CONNECT);
        r = uv_tcp_getpeername(&sock->uv_handle.tcp, (struct sockaddr *)&ss,
                               &(int){ sizeof(ss) });
        if (r != 0) {
@@ -505,10 +503,10 @@ isc__nm_async_tcpdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) {
        r = uv_tcp_open(&sock->uv_handle.tcp, sock->fd);
        if (r < 0) {
                isc__nm_closesocket(sock->fd);
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPENFAIL]);
+               isc__nm_incstats(sock, STATID_OPENFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPEN]);
+       isc__nm_incstats(sock, STATID_OPEN);
 
        if (sa_family == AF_INET6) {
                flags = UV_TCP_IPV6ONLY;
@@ -518,7 +516,7 @@ isc__nm_async_tcpdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) {
        r = isc_uv_tcp_freebind(&sock->uv_handle.tcp, &sock->iface.type.sa,
                                flags);
        if (r < 0) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_BINDFAIL]);
+               isc__nm_incstats(sock, STATID_BINDFAIL);
                goto done;
        }
 #else
@@ -526,8 +524,7 @@ isc__nm_async_tcpdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) {
                r = isc_uv_tcp_freebind(&sock->uv_handle.tcp,
                                        &sock->iface.type.sa, flags);
                if (r < 0) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_BINDFAIL]);
+                       isc__nm_incstats(sock, STATID_BINDFAIL);
                        goto done;
                }
                sock->parent->uv_handle.tcp.flags = sock->uv_handle.tcp.flags;
@@ -551,7 +548,7 @@ isc__nm_async_tcpdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) {
                              ISC_LOGMODULE_NETMGR, ISC_LOG_ERROR,
                              "uv_listen failed: %s",
                              isc_result_totext(isc__nm_uverr2result(r)));
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_BINDFAIL]);
+               isc__nm_incstats(sock, STATID_BINDFAIL);
                goto done;
        }
 
@@ -596,8 +593,7 @@ tcpdns_connection_cb(uv_stream_t *server, int status) {
                result = isc_quota_attach_cb(ssock->pquota, &quota,
                                             &ssock->quotacb);
                if (result == ISC_R_QUOTA) {
-                       isc__nm_incstats(ssock->mgr,
-                                        ssock->statsindex[STATID_ACCEPTFAIL]);
+                       isc__nm_incstats(ssock, STATID_ACCEPTFAIL);
                        return;
                }
        }
@@ -842,8 +838,7 @@ isc__nm_tcpdns_read_cb(uv_stream_t *stream, ssize_t nread,
 
        if (nread < 0) {
                if (nread != UV_EOF) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_RECVFAIL]);
+                       isc__nm_incstats(sock, STATID_RECVFAIL);
                }
 
                isc__nm_failed_read_cb(sock, isc__nm_uverr2result(nread), true);
@@ -1012,7 +1007,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
 
        atomic_store(&csock->accepting, false);
 
-       isc__nm_incstats(csock->mgr, csock->statsindex[STATID_ACCEPT]);
+       isc__nm_incstats(csock, STATID_ACCEPT);
 
        csock->read_timeout = atomic_load(&csock->mgr->init);
 
@@ -1098,7 +1093,7 @@ tcpdns_send_cb(uv_write_t *req, int status) {
        sock = uvreq->sock;
 
        if (status < 0) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_SENDFAIL]);
+               isc__nm_incstats(sock, STATID_SENDFAIL);
                isc__nm_failed_send_cb(sock, uvreq,
                                       isc__nm_uverr2result(status));
                return;
@@ -1174,7 +1169,7 @@ isc__nm_async_tcpdnssend(isc__networker_t *worker, isc__netievent_t *ev0) {
 
 fail:
        if (result != ISC_R_SUCCESS) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_SENDFAIL]);
+               isc__nm_incstats(sock, STATID_SENDFAIL);
                isc__nm_failed_send_cb(sock, uvreq, result);
        }
 }
@@ -1195,7 +1190,7 @@ tcpdns_stop_cb(uv_handle_t *handle) {
                ISC_UNREACHABLE();
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+       isc__nm_incstats(sock, STATID_CLOSE);
 
        atomic_store(&sock->listening, false);
 
@@ -1214,7 +1209,7 @@ tcpdns_close_sock(isc_nmsocket_t *sock) {
                ISC_UNREACHABLE();
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+       isc__nm_incstats(sock, STATID_CLOSE);
 
        if (sock->server != NULL) {
                isc__nmsocket_detach(&sock->server);
index 72bb4ac4baac2f3e3e3b252e6e36b763a02de9f2..27895aa716470213e5edda1e7f0f8798fa4126ed 100644 (file)
@@ -131,10 +131,10 @@ tlsdns_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
        r = uv_tcp_open(&sock->uv_handle.tcp, sock->fd);
        if (r != 0) {
                isc__nm_closesocket(sock->fd);
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPENFAIL]);
+               isc__nm_incstats(sock, STATID_OPENFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPEN]);
+       isc__nm_incstats(sock, STATID_OPEN);
 
        if (req->local.length != 0) {
                r = uv_tcp_bind(&sock->uv_handle.tcp, &req->local.type.sa, 0);
@@ -143,8 +143,7 @@ tlsdns_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
                 * to be ignored
                 */
                if (r != 0 && r != UV_EINVAL) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_BINDFAIL]);
+                       isc__nm_incstats(sock, STATID_BINDFAIL);
                        goto done;
                }
        }
@@ -155,11 +154,10 @@ tlsdns_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
        r = uv_tcp_connect(&req->uv_req.connect, &sock->uv_handle.tcp,
                           &req->peer.type.sa, tlsdns_connect_cb);
        if (r != 0) {
-               isc__nm_incstats(sock->mgr,
-                                sock->statsindex[STATID_CONNECTFAIL]);
+               isc__nm_incstats(sock, STATID_CONNECTFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CONNECT]);
+       isc__nm_incstats(sock, STATID_CONNECT);
 
        uv_handle_set_data((uv_handle_t *)&sock->timer, &req->uv_req.connect);
        isc__nmsocket_timer_start(sock);
@@ -249,7 +247,7 @@ tlsdns_connect_cb(uv_connect_t *uvreq, int status) {
                goto error;
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CONNECT]);
+       isc__nm_incstats(sock, STATID_CONNECT);
        r = uv_tcp_getpeername(&sock->uv_handle.tcp, (struct sockaddr *)&ss,
                               &(int){ sizeof(ss) });
        if (r != 0) {
@@ -579,10 +577,10 @@ isc__nm_async_tlsdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) {
        r = uv_tcp_open(&sock->uv_handle.tcp, sock->fd);
        if (r < 0) {
                isc__nm_closesocket(sock->fd);
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPENFAIL]);
+               isc__nm_incstats(sock, STATID_OPENFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPEN]);
+       isc__nm_incstats(sock, STATID_OPEN);
 
        if (sa_family == AF_INET6) {
                flags = UV_TCP_IPV6ONLY;
@@ -592,7 +590,7 @@ isc__nm_async_tlsdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) {
        r = isc_uv_tcp_freebind(&sock->uv_handle.tcp, &sock->iface.type.sa,
                                flags);
        if (r < 0) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_BINDFAIL]);
+               isc__nm_incstats(sock, STATID_BINDFAIL);
                goto done;
        }
 #else
@@ -600,8 +598,7 @@ isc__nm_async_tlsdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) {
                r = isc_uv_tcp_freebind(&sock->uv_handle.tcp,
                                        &sock->iface.type.sa, flags);
                if (r < 0) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_BINDFAIL]);
+                       isc__nm_incstats(sock, STATID_BINDFAIL);
                        goto done;
                }
                sock->parent->uv_handle.tcp.flags = sock->uv_handle.tcp.flags;
@@ -626,7 +623,7 @@ isc__nm_async_tlsdnslisten(isc__networker_t *worker, isc__netievent_t *ev0) {
                              ISC_LOGMODULE_NETMGR, ISC_LOG_ERROR,
                              "uv_listen failed: %s",
                              isc_result_totext(isc__nm_uverr2result(r)));
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_BINDFAIL]);
+               isc__nm_incstats(sock, STATID_BINDFAIL);
                goto done;
        }
 
@@ -671,8 +668,7 @@ tlsdns_connection_cb(uv_stream_t *server, int status) {
                result = isc_quota_attach_cb(ssock->pquota, &quota,
                                             &ssock->quotacb);
                if (result == ISC_R_QUOTA) {
-                       isc__nm_incstats(ssock->mgr,
-                                        ssock->statsindex[STATID_ACCEPTFAIL]);
+                       isc__nm_incstats(ssock, STATID_ACCEPTFAIL);
                        return;
                }
        }
@@ -1354,8 +1350,7 @@ isc__nm_tlsdns_read_cb(uv_stream_t *stream, ssize_t nread,
 
        if (nread < 0) {
                if (nread != UV_EOF) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_RECVFAIL]);
+                       isc__nm_incstats(sock, STATID_RECVFAIL);
                }
 
                isc__nm_failed_read_cb(sock, isc__nm_uverr2result(nread), true);
@@ -1555,7 +1550,7 @@ accept_connection(isc_nmsocket_t *ssock, isc_quota_t *quota) {
 
        atomic_store(&csock->accepting, false);
 
-       isc__nm_incstats(csock->mgr, csock->statsindex[STATID_ACCEPT]);
+       isc__nm_incstats(csock, STATID_ACCEPT);
 
        csock->read_timeout = atomic_load(&csock->mgr->init);
 
@@ -1647,7 +1642,7 @@ isc__nm_async_tlsdnssend(isc__networker_t *worker, isc__netievent_t *ev0) {
 
        result = tlsdns_send_direct(sock, uvreq);
        if (result != ISC_R_SUCCESS) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_SENDFAIL]);
+               isc__nm_incstats(sock, STATID_SENDFAIL);
                isc__nm_failed_send_cb(sock, uvreq, result);
        }
 }
@@ -1747,7 +1742,7 @@ tlsdns_stop_cb(uv_handle_t *handle) {
                ISC_UNREACHABLE();
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+       isc__nm_incstats(sock, STATID_CLOSE);
 
        atomic_store(&sock->listening, false);
 
@@ -1771,7 +1766,7 @@ tlsdns_close_sock(isc_nmsocket_t *sock) {
                ISC_UNREACHABLE();
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+       isc__nm_incstats(sock, STATID_CLOSE);
 
        if (sock->server != NULL) {
                isc__nmsocket_detach(&sock->server);
index f4de7d3e737b183bd8d1518ab2cc2d6d016cbca3..3982d49e7f87eed26a7ac29b44eb80ff108343d4 100644 (file)
@@ -230,10 +230,10 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
        r = uv_udp_open(&sock->uv_handle.udp, sock->fd);
        if (r < 0) {
                isc__nm_closesocket(sock->fd);
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPENFAIL]);
+               isc__nm_incstats(sock, STATID_OPENFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPEN]);
+       isc__nm_incstats(sock, STATID_OPEN);
 
        if (sa_family == AF_INET6) {
                uv_bind_flags |= UV_UDP_IPV6ONLY;
@@ -243,7 +243,7 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
        r = isc_uv_udp_freebind(&sock->uv_handle.udp,
                                &sock->parent->iface.type.sa, uv_bind_flags);
        if (r < 0) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_BINDFAIL]);
+               isc__nm_incstats(sock, STATID_BINDFAIL);
                goto done;
        }
 #else
@@ -253,8 +253,7 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
                                        &sock->parent->iface.type.sa,
                                        uv_bind_flags);
                if (r < 0) {
-                       isc__nm_incstats(sock->mgr,
-                                        sock->statsindex[STATID_BINDFAIL]);
+                       isc__nm_incstats(sock, STATID_BINDFAIL);
                        goto done;
                }
                sock->parent->uv_handle.udp.flags = sock->uv_handle.udp.flags;
@@ -270,7 +269,7 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) {
        r = uv_udp_recv_start(&sock->uv_handle.udp, isc__nm_alloc_cb,
                              udp_recv_cb);
        if (r != 0) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_BINDFAIL]);
+               isc__nm_incstats(sock, STATID_BINDFAIL);
                goto done;
        }
 
@@ -526,7 +525,7 @@ isc__nm_async_udpsend(isc__networker_t *worker, isc__netievent_t *ev0) {
 
        result = udp_send_direct(sock, uvreq, &ievent->peer);
        if (result != ISC_R_SUCCESS) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_SENDFAIL]);
+               isc__nm_incstats(sock, STATID_SENDFAIL);
                isc__nm_failed_send_cb(sock, uvreq, result);
        }
 }
@@ -546,7 +545,7 @@ udp_send_cb(uv_udp_send_t *req, int status) {
 
        if (status < 0) {
                result = isc__nm_uverr2result(status);
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_SENDFAIL]);
+               isc__nm_incstats(sock, STATID_SENDFAIL);
        }
 
        isc__nm_sendcb(sock, uvreq, result, false);
@@ -622,10 +621,10 @@ udp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
 
        r = uv_udp_open(&sock->uv_handle.udp, sock->fd);
        if (r != 0) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPENFAIL]);
+               isc__nm_incstats(sock, STATID_OPENFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPEN]);
+       isc__nm_incstats(sock, STATID_OPEN);
 
        if (sock->iface.type.sa.sa_family == AF_INET6) {
                uv_bind_flags |= UV_UDP_IPV6ONLY;
@@ -634,7 +633,7 @@ udp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
        r = uv_udp_bind(&sock->uv_handle.udp, &sock->iface.type.sa,
                        uv_bind_flags);
        if (r != 0) {
-               isc__nm_incstats(sock->mgr, sock->statsindex[STATID_BINDFAIL]);
+               isc__nm_incstats(sock, STATID_BINDFAIL);
                goto done;
        }
 
@@ -650,11 +649,10 @@ udp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) {
                                       &req->peer.type.sa);
        } while (r == UV_EADDRINUSE && --tries > 0);
        if (r != 0) {
-               isc__nm_incstats(sock->mgr,
-                                sock->statsindex[STATID_CONNECTFAIL]);
+               isc__nm_incstats(sock, STATID_CONNECTFAIL);
                goto done;
        }
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CONNECT]);
+       isc__nm_incstats(sock, STATID_CONNECT);
 
        atomic_store(&sock->connecting, false);
        atomic_store(&sock->connected, true);
@@ -930,7 +928,7 @@ udp_stop_cb(uv_handle_t *handle) {
                ISC_UNREACHABLE();
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+       isc__nm_incstats(sock, STATID_CLOSE);
 
        atomic_store(&sock->listening, false);
 
@@ -952,7 +950,7 @@ udp_close_cb(uv_handle_t *handle) {
                ISC_UNREACHABLE();
        }
 
-       isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+       isc__nm_incstats(sock, STATID_CLOSE);
 
        if (sock->server != NULL) {
                isc__nmsocket_detach(&sock->server);