From: Evan Hunt Date: Tue, 7 Jan 2020 04:26:47 +0000 (-0800) Subject: count statistics in netmgr UDP code X-Git-Tag: v9.15.8~13^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90a1dabe7428ace035675816f0e8607026d64219;p=thirdparty%2Fbind9.git count statistics in netmgr UDP code - also restored a test in the statistics test which was changed when the netmgr was introduced because active sockets were not being counted. --- diff --git a/bin/tests/system/statistics/tests.sh b/bin/tests/system/statistics/tests.sh index ce82d0d2a8d..1a4c5a57785 100644 --- a/bin/tests/system/statistics/tests.sh +++ b/bin/tests/system/statistics/tests.sh @@ -71,7 +71,7 @@ $RNDCCMD -s 10.53.0.3 stats > /dev/null 2>&1 [ -f ns3/named.stats ] || ret=1 if [ ! "$CYGWIN" ]; then nsock0nstat=`grep "UDP/IPv4 sockets active" ns3/named.stats | awk '{print $1}'` - [ 0 -eq ${nsock0nstat:-0} ] || ret=1 + [ 0 -ne ${nsock0nstat:-0} ] || ret=1 fi if [ $ret != 0 ]; then echo_i "failed"; fi status=`expr $status + $ret` diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 4f94e11a954..80af9f09b35 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -855,6 +855,8 @@ isc__nmsocket_prep_destroy(isc_nmsocket_t *sock) { if (sock->children != NULL) { for (int i = 0; i < sock->nchildren; i++) { atomic_store(&sock->children[i].active, false); + isc__nm_decstats(sock->mgr, + sock->statsindex[STATID_ACTIVE]); } } @@ -950,6 +952,7 @@ isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, } else { sock->statsindex = udp6statsindex; } + isc__nm_incstats(sock->mgr, sock->statsindex[STATID_ACTIVE]); break; case isc_nm_tcpsocket: case isc_nm_tcplistener: @@ -960,6 +963,7 @@ isc__nmsocket_init(isc_nmsocket_t *sock, isc_nm_t *mgr, sock->statsindex = tcp6statsindex; } break; + isc__nm_incstats(sock->mgr, sock->statsindex[STATID_ACTIVE]); default: break; } diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index 5b870a13edf..6b79d8e0bcf 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -117,6 +117,7 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) { isc__netievent_udplisten_t *ievent = (isc__netievent_udplisten_t *) ev0; isc_nmsocket_t *sock = ievent->sock; + int r, flags = 0; REQUIRE(sock->type == isc_nm_udpsocket); REQUIRE(sock->iface != NULL); @@ -127,19 +128,30 @@ isc__nm_async_udplisten(isc__networker_t *worker, isc__netievent_t *ev0) { isc_nmsocket_attach(sock, (isc_nmsocket_t **)&sock->uv_handle.udp.data); - uv_udp_open(&sock->uv_handle.udp, sock->fd); - int flags = 0; + r = uv_udp_open(&sock->uv_handle.udp, sock->fd); + if (r == 0) { + isc__nm_incstats(sock->mgr, sock->statsindex[STATID_OPEN]); + } else { + isc__nm_incstats(sock->mgr, + sock->statsindex[STATID_OPENFAIL]); + } + if (sock->iface->addr.type.sa.sa_family == AF_INET6) { flags = UV_UDP_IPV6ONLY; } - uv_udp_bind(&sock->uv_handle.udp, - &sock->parent->iface->addr.type.sa, flags); + + r = uv_udp_bind(&sock->uv_handle.udp, + &sock->parent->iface->addr.type.sa, flags); + if (r < 0) { + isc__nm_incstats(sock->mgr, + sock->statsindex[STATID_BINDFAIL]); + } + uv_recv_buffer_size(&sock->uv_handle.handle, &(int){16 * 1024 * 1024}); uv_send_buffer_size(&sock->uv_handle.handle, &(int){16 * 1024 * 1024}); - uv_udp_recv_start(&sock->uv_handle.udp, isc__nm_alloc_cb, - udp_recv_cb); + uv_udp_recv_start(&sock->uv_handle.udp, isc__nm_alloc_cb, udp_recv_cb); } static void @@ -157,6 +169,8 @@ stop_udp_child(isc_nmsocket_t *sock) { uv_udp_recv_stop(&sock->uv_handle.udp); uv_close((uv_handle_t *) &sock->uv_handle.udp, udp_close_cb); + isc__nm_incstats(sock->mgr, sock->statsindex[STATID_CLOSE]); + LOCK(&sock->parent->lock); atomic_fetch_sub(&sock->parent->rchildren, 1); UNLOCK(&sock->parent->lock); @@ -258,10 +272,9 @@ isc__nm_async_udpstop(isc__networker_t *worker, isc__netievent_t *ev0) { } /* - * udp_recv_cb handles incoming UDP packet from uv. - * The buffer here is reused for a series of packets, - * so we need to allocate a new one. This new one can - * be reused to send the response then. + * udp_recv_cb handles incoming UDP packet from uv. The buffer here is + * reused for a series of packets, so we need to allocate a new one. This + * new one can be reused to send the response then. */ static void udp_recv_cb(uv_udp_t *handle, ssize_t nrecv, const uv_buf_t *buf, @@ -434,6 +447,8 @@ udp_send_cb(uv_udp_send_t *req, int status) { if (status < 0) { result = isc__nm_uverr2result(status); + isc__nm_incstats(uvreq->sock->mgr, + uvreq->sock->statsindex[STATID_SENDFAIL]); } uvreq->cb.send(uvreq->handle, result, uvreq->cbarg); @@ -459,6 +474,8 @@ udp_send_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req, &sock->uv_handle.udp, &req->uvbuf, 1, &peer->type.sa, udp_send_cb); if (rv < 0) { + isc__nm_incstats(req->sock->mgr, + req->sock->statsindex[STATID_SENDFAIL]); return (isc__nm_uverr2result(rv)); }