From: George Thessalonikefs Date: Wed, 29 Jun 2022 08:51:54 +0000 (+0200) Subject: - Fix #704: [FR] Statistics counter for number of outgoing UDP queries X-Git-Tag: release-1.16.1rc1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8163181065ccbf298411ccf2fcd2e1d05284efb;p=thirdparty%2Funbound.git - Fix #704: [FR] Statistics counter for number of outgoing UDP queries sent; introduces 'num.query.udpout' to the 'unbound-control stats' command. --- diff --git a/contrib/metrics.awk b/contrib/metrics.awk index 5a7a2569c..ca48c035a 100644 --- a/contrib/metrics.awk +++ b/contrib/metrics.awk @@ -28,6 +28,7 @@ END { print "unbound_hits_queries{type=\"total.num.prefetch\"} " val["total.num.prefetch"]; print "unbound_hits_queries{type=\"num.query.tcp\"} " val["num.query.tcp"]; print "unbound_hits_queries{type=\"num.query.tcpout\"} " val["num.query.tcpout"]; + print "unbound_hits_queries{type=\"num.query.udpout\"} " val["num.query.udpout"]; print "unbound_hits_queries{type=\"num.query.tls\"} " val["num.query.tls"]; print "unbound_hits_queries{type=\"num.query.tls.resume\"} " val["num.query.tls.resume"]; print "unbound_hits_queries{type=\"num.query.ipv6\"} " val["num.query.ipv6"]; diff --git a/contrib/unbound_munin_ b/contrib/unbound_munin_ index 503752758..a756a5d1c 100755 --- a/contrib/unbound_munin_ +++ b/contrib/unbound_munin_ @@ -253,6 +253,7 @@ if test "$1" = "config" ; then p_config "total.num.prefetch" "cache prefetch" "ABSOLUTE" p_config "num.query.tcp" "TCP queries" "ABSOLUTE" p_config "num.query.tcpout" "TCP out queries" "ABSOLUTE" + p_config "num.query.udpout" "UDP out queries" "ABSOLUTE" p_config "num.query.tls" "TLS queries" "ABSOLUTE" p_config "num.query.tls.resume" "TLS resumes" "ABSOLUTE" p_config "num.query.ipv6" "IPv6 queries" "ABSOLUTE" @@ -452,7 +453,7 @@ hits) for x in `grep "^thread[0-9][0-9]*\.num\.queries=" $state | sed -e 's/=.*//'` total.num.queries \ total.num.cachehits total.num.prefetch num.query.tcp \ - num.query.tcpout num.query.tls num.query.tls.resume \ + num.query.tcpout num.query.udpout num.query.tls num.query.tls.resume \ num.query.ipv6 unwanted.queries \ unwanted.replies; do if grep "^"$x"=" $state >/dev/null 2>&1; then diff --git a/daemon/remote.c b/daemon/remote.c index 675ef4397..ec7a4d5d9 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -988,6 +988,8 @@ print_ext(RES* ssl, struct ub_stats_info* s) (unsigned long)s->svr.qtcp)) return 0; if(!ssl_printf(ssl, "num.query.tcpout"SQ"%lu\n", (unsigned long)s->svr.qtcp_outgoing)) return 0; + if(!ssl_printf(ssl, "num.query.udpout"SQ"%lu\n", + (unsigned long)s->svr.qudp_outgoing)) return 0; if(!ssl_printf(ssl, "num.query.tls"SQ"%lu\n", (unsigned long)s->svr.qtls)) return 0; if(!ssl_printf(ssl, "num.query.tls.resume"SQ"%lu\n", diff --git a/daemon/stats.c b/daemon/stats.c index d08f18dbb..57c428271 100644 --- a/daemon/stats.c +++ b/daemon/stats.c @@ -281,6 +281,7 @@ server_stats_compile(struct worker* worker, struct ub_stats_info* s, int reset) /* values from outside network */ s->svr.unwanted_replies = (long long)worker->back->unwanted_replies; s->svr.qtcp_outgoing = (long long)worker->back->num_tcp_outgoing; + s->svr.qudp_outgoing = (long long)worker->back->num_udp_outgoing; /* get and reset validator rrset bogus number */ s->svr.rrset_bogus = (long long)get_rrset_bogus(worker, reset); @@ -424,6 +425,7 @@ void server_stats_add(struct ub_stats_info* total, struct ub_stats_info* a) total->svr.qclass_big += a->svr.qclass_big; total->svr.qtcp += a->svr.qtcp; total->svr.qtcp_outgoing += a->svr.qtcp_outgoing; + total->svr.qudp_outgoing += a->svr.qudp_outgoing; total->svr.qtls += a->svr.qtls; total->svr.qtls_resume += a->svr.qtls_resume; total->svr.qhttps += a->svr.qhttps; diff --git a/daemon/worker.c b/daemon/worker.c index c41ab02f2..27626ce93 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -2217,6 +2217,7 @@ void worker_stats_clear(struct worker* worker) mesh_stats_clear(worker->env.mesh); worker->back->unwanted_replies = 0; worker->back->num_tcp_outgoing = 0; + worker->back->num_udp_outgoing = 0; } void worker_start_accept(void* arg) diff --git a/doc/Changelog b/doc/Changelog index bad7ca432..60909dded 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -3,6 +3,9 @@ 29 June 2022: George - Add debug option to the mini_tdir.sh test code. + - Fix #704: [FR] Statistics counter for number of outgoing UDP queries + sent; introduces 'num.query.udpout' to the 'unbound-control stats' + command. 28 June 2022: George - Show the output of the exact .rpl run that failed with 'make test'. diff --git a/doc/unbound-control.8.in b/doc/unbound-control.8.in index b15ab79d0..d3147be6f 100644 --- a/doc/unbound-control.8.in +++ b/doc/unbound-control.8.in @@ -552,6 +552,10 @@ Number of queries that were made using TCP towards the Unbound server. Number of queries that the Unbound server made using TCP outgoing towards other servers. .TP +.I num.query.udpout +Number of queries that the Unbound server made using UDP outgoing towards +other servers. +.TP .I num.query.tls Number of queries that were made using TLS towards the Unbound server. These are also counted in num.query.tcp, because TLS uses TCP. diff --git a/libunbound/unbound.h b/libunbound/unbound.h index ee8558759..c779d183e 100644 --- a/libunbound/unbound.h +++ b/libunbound/unbound.h @@ -725,6 +725,8 @@ struct ub_server_stats { long long qtcp; /** number of outgoing queries over TCP */ long long qtcp_outgoing; + /** number of outgoing queries over UDP */ + long long qudp_outgoing; /** number of queries over (DNS over) TLS */ long long qtls; /** number of queries over (DNS over) HTTPS */ diff --git a/services/outside_network.c b/services/outside_network.c index ec37a4a80..edb8ca13a 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -1608,6 +1608,7 @@ outside_network_create(struct comm_base *base, size_t bufsize, outnet->tcp_reuse_timeout= tcp_reuse_timeout; outnet->tcp_auth_query_timeout = tcp_auth_query_timeout; outnet->num_tcp_outgoing = 0; + outnet->num_udp_outgoing = 0; outnet->infra = infra; outnet->rnd = rnd; outnet->sslctx = sslctx; @@ -2142,6 +2143,7 @@ randomize_and_send_udp(struct pending* pend, sldns_buffer* packet, int timeout) portcomm_loweruse(outnet, pend->pc); return 0; } + outnet->num_udp_outgoing++; /* system calls to set timeout after sending UDP to make roundtrip smaller. */ diff --git a/services/outside_network.h b/services/outside_network.h index 4c5b96f83..c383b8f09 100644 --- a/services/outside_network.h +++ b/services/outside_network.h @@ -113,6 +113,8 @@ struct outside_network { /** if we perform udp-connect, connect() for UDP socket to mitigate * ICMP side channel leakage */ int udp_connect; + /** number of udp packets sent. */ + size_t num_udp_outgoing; /** array of outgoing IP4 interfaces */ struct port_if* ip4_ifs; diff --git a/smallapp/unbound-control.c b/smallapp/unbound-control.c index 89543e45d..d85eee3a4 100644 --- a/smallapp/unbound-control.c +++ b/smallapp/unbound-control.c @@ -354,6 +354,7 @@ static void print_extended(struct ub_stats_info* s) /* transport */ PR_UL("num.query.tcp", s->svr.qtcp); PR_UL("num.query.tcpout", s->svr.qtcp_outgoing); + PR_UL("num.query.udpout", s->svr.qudp_outgoing); PR_UL("num.query.tls", s->svr.qtls); PR_UL("num.query.tls_resume", s->svr.qtls_resume); PR_UL("num.query.ipv6", s->svr.qipv6); diff --git a/testdata/stat_values.tdir/stat_values.conf b/testdata/stat_values.tdir/stat_values.conf index 5cec691f5..dc4553920 100644 --- a/testdata/stat_values.tdir/stat_values.conf +++ b/testdata/stat_values.tdir/stat_values.conf @@ -1,5 +1,5 @@ server: - verbosity: 2 + verbosity: 5 num-threads: 1 interface: 127.0.0.1 port: @PORT@ @@ -11,6 +11,9 @@ server: do-not-query-localhost: no extended-statistics: yes identity: "stat_values" + outbound-msg-retry: 0 + root-key-sentinel: no + trust-anchor-signaling: no local-zone: local.zone static local-data: "www.local.zone A 192.0.2.1" diff --git a/testdata/stat_values.tdir/stat_values.test b/testdata/stat_values.tdir/stat_values.test index 1cd19fa2b..ef86a0471 100644 --- a/testdata/stat_values.tdir/stat_values.test +++ b/testdata/stat_values.tdir/stat_values.test @@ -186,6 +186,7 @@ num.query.opcode.QUERY=1 num.query.flags.RD=1 num.query.flags.AD=1 num.query.edns.present=1 +num.query.udpout=1 msg.cache.count=1 rrset.cache.count=1 infra.cache.count=1 @@ -223,6 +224,7 @@ num.query.flags.AD=1 num.query.flags.RD=1 num.query.opcode.QUERY=1 num.query.type.A=1 +num.query.udpout=1 msg.cache.count=1 rrset.cache.count=1 infra.cache.count=1" @@ -249,6 +251,7 @@ num.query.opcode.QUERY=1 num.query.flags.RD=1 num.query.flags.AD=1 num.query.edns.present=1 +num.query.udpout=1 msg.cache.count=2 rrset.cache.count=2 infra.cache.count=2 @@ -263,6 +266,7 @@ if grep "192.0.2.1" outfile; then else end 1 fi +sleep 1 # make sure the outgoing UDP (and the edns1xx0 retry) are accounted for. check_stats "\ total.num.queries=1 total.num.expired=1 @@ -274,6 +278,7 @@ num.query.flags.AD=1 num.query.flags.RD=1 num.query.opcode.QUERY=1 num.query.type.A=1 +num.query.udpout=2 total.num.cachemiss=1 msg.cache.count=2 rrset.cache.count=2 @@ -327,6 +332,7 @@ num.query.edns.present=1 num.query.flags.RD=1 num.query.opcode.QUERY=1 num.query.type.A=1 +num.query.udpout=1 total.num.queries=1 total.num.recursivereplies=1 msg.cache.count=3