/*%
* Index into socket stat counter arrays.
*/
-enum {
+typedef enum {
STATID_OPEN = 0,
STATID_OPENFAIL = 1,
STATID_CLOSE = 2,
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 {
*/
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.
*/
"\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) {
sock->children = NULL;
sock->nchildren = 0;
}
- if (sock->statsindex != NULL) {
- isc__nm_decstats(sock->mgr, sock->statsindex[STATID_ACTIVE]);
- }
sock->statichandle = NULL;
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:
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;
#endif
sock->magic = NMSOCK_MAGIC;
+
+ isc__nm_incstats(sock, STATID_ACTIVE);
}
void
}
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]);
}
}
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;
}
}
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);
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) {
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;
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
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;
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;
}
result = isc_quota_attach_cb(ssock->pquota, "a,
&ssock->quotacb);
if (result == ISC_R_QUOTA) {
- isc__nm_incstats(ssock->mgr,
- ssock->statsindex[STATID_ACCEPTFAIL]);
+ isc__nm_incstats(ssock, STATID_ACCEPTFAIL);
return;
}
}
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));
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);
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;
}
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);
}
}
ISC_UNREACHABLE();
}
- isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+ isc__nm_incstats(sock, STATID_CLOSE);
atomic_store(&sock->listening, false);
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);
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);
* 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;
}
}
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);
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) {
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;
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
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;
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;
}
result = isc_quota_attach_cb(ssock->pquota, "a,
&ssock->quotacb);
if (result == ISC_R_QUOTA) {
- isc__nm_incstats(ssock->mgr,
- ssock->statsindex[STATID_ACCEPTFAIL]);
+ isc__nm_incstats(ssock, STATID_ACCEPTFAIL);
return;
}
}
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);
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);
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;
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);
}
}
ISC_UNREACHABLE();
}
- isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+ isc__nm_incstats(sock, STATID_CLOSE);
atomic_store(&sock->listening, false);
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);
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);
* 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;
}
}
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);
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) {
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;
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
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;
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;
}
result = isc_quota_attach_cb(ssock->pquota, "a,
&ssock->quotacb);
if (result == ISC_R_QUOTA) {
- isc__nm_incstats(ssock->mgr,
- ssock->statsindex[STATID_ACCEPTFAIL]);
+ isc__nm_incstats(ssock, STATID_ACCEPTFAIL);
return;
}
}
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);
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);
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);
}
}
ISC_UNREACHABLE();
}
- isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+ isc__nm_incstats(sock, STATID_CLOSE);
atomic_store(&sock->listening, false);
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);
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;
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
&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;
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;
}
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);
}
}
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);
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;
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;
}
&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);
ISC_UNREACHABLE();
}
- isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]);
+ isc__nm_incstats(sock, STATID_CLOSE);
atomic_store(&sock->listening, false);
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);