]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
count statistics in netmgr UDP code
authorEvan Hunt <each@isc.org>
Tue, 7 Jan 2020 04:26:47 +0000 (20:26 -0800)
committerEvan Hunt <each@isc.org>
Mon, 13 Jan 2020 22:09:37 +0000 (14:09 -0800)
- also restored a test in the statistics test which was changed when
  the netmgr was introduced because active sockets were not being
  counted.

bin/tests/system/statistics/tests.sh
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/udp.c

index ce82d0d2a8d24b4c522d063d4ecf61fd50f46e74..1a4c5a5778533a8954cb249a6a12c96c193edbd2 100644 (file)
@@ -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`
index 4f94e11a954850c9d0e7a515d3d22a65afefb805..80af9f09b358a8a6d1959d3cba3357dbad429b36 100644 (file)
@@ -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;
        }
index 5b870a13edfe374ff1caa2cd5f139ee9d48c0432..6b79d8e0bcfc7d9d80d2736c32dd4817cec26901 100644 (file)
@@ -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));
        }