diff --git a/daemon/remote.c b/daemon/remote.c index 07aa579e5..6c14a57f6 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -1052,6 +1052,12 @@ print_ext(RES* ssl, struct ub_stats_info* s) (unsigned long)s->svr.num_query_authzone_up)) return 0; if(!ssl_printf(ssl, "num.query.authzone.down"SQ"%lu\n", (unsigned long)s->svr.num_query_authzone_down)) return 0; +#ifdef CLIENT_SUBNET + if(!ssl_printf(ssl, "num.query.subnet"SQ"%lu\n", + (unsigned long)s->svr.num_query_subnet)) return 0; + if(!ssl_printf(ssl, "num.query.subnet_cache"SQ"%lu\n", + (unsigned long)s->svr.num_query_subnet_cache)) return 0; +#endif /* CLIENT_SUBNET */ return 1; } diff --git a/daemon/stats.c b/daemon/stats.c index d9e769426..cff01d903 100644 --- a/daemon/stats.c +++ b/daemon/stats.c @@ -63,6 +63,9 @@ #include "services/authzone.h" #include "validator/val_kcache.h" #include "validator/val_neg.h" +#ifdef CLIENT_SUBNET +#include "edns-subnet/subnetmod.h" +#endif /** add timers and the values do not overflow or become negative */ static void @@ -124,6 +127,33 @@ void server_stats_log(struct ub_server_stats* stats, struct worker* worker, (unsigned)worker->env.mesh->stats_jostled); } + +#ifdef CLIENT_SUBNET +/** Set the EDNS Subnet stats. */ +static void +set_subnet_stats(struct worker* worker, struct ub_server_stats* svr, + int reset) +{ + int m = modstack_find(&worker->env.mesh->mods, "subnet"); + struct subnet_env* sne; + if(m == -1) + return; + sne = (struct subnet_env*)worker->env.modinfo[m]; + if(reset && !worker->env.cfg->stat_cumulative) { + lock_rw_wrlock(&sne->biglock); + } else { + lock_rw_rdlock(&sne->biglock); + } + svr->num_query_subnet = (long long)(sne->num_msg_nocache + sne->num_msg_cache); + svr->num_query_subnet_cache = (long long)sne->num_msg_cache; + if(reset && !worker->env.cfg->stat_cumulative) { + sne->num_msg_cache = 0; + sne->num_msg_nocache = 0; + } + lock_rw_unlock(&sne->biglock); +} +#endif /* CLIENT_SUBNET */ + /** Set the neg cache stats. */ static void set_neg_cache_stats(struct worker* worker, struct ub_server_stats* svr, @@ -301,6 +331,13 @@ server_stats_compile(struct worker* worker, struct ub_stats_info* s, int reset) /* Set neg cache usage numbers */ set_neg_cache_stats(worker, &s->svr, reset); +#ifdef CLIENT_SUBNET + /* EDNS Subnet usage numbers */ + set_subnet_stats(worker, &s->svr, reset); +#else + s->svr.num_query_subnet = 0; + s->svr.num_query_subnet_cache = 0; +#endif /* get tcp accept usage */ s->svr.tcp_accept_usage = 0; diff --git a/doc/Changelog b/doc/Changelog index 2e57818da..932894899 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,6 +1,7 @@ 21 August 2018: Wouter - log-local-actions: yes option for unbound.conf that logs all the local zone actions, a patch from Saksham Manchanda (Secure64). + - #4146: num.query.subnet and num.query.subnet_cache counters. 17 August 2018: Ralph - Fix classification for QTYPE=CNAME queries when QNAME minimisation is diff --git a/doc/unbound-control.8.in b/doc/unbound-control.8.in index 01e028f15..ce64dc739 100644 --- a/doc/unbound-control.8.in +++ b/doc/unbound-control.8.in @@ -641,6 +641,14 @@ answered using cached data. The number of queries answered using cached NSEC records with NXDOMAIN RCODE. These queries would otherwise have been sent to the internet, but are now answered using cached data. +.TP +.I num.query.subnet +Number of queries that got an answer that contained EDNS client subnet data. +.TP +.I num.query.subnet_cache +Number of queries answered from the edns client subnet cache. These are +counted as cachemiss by the main counters, but hit the client subnet +specific cache, after getting processed by the edns client subnet module. .SH "FILES" .TP .I @ub_conf_file@ diff --git a/edns-subnet/subnetmod.c b/edns-subnet/subnetmod.c index ae2523b86..7793f0a4e 100644 --- a/edns-subnet/subnetmod.c +++ b/edns-subnet/subnetmod.c @@ -511,6 +511,7 @@ eval_response(struct module_qstate *qstate, int id, struct subnet_qstate *sq) lock_rw_wrlock(&sne->biglock); update_cache(qstate, id); + sne->num_msg_nocache++; lock_rw_unlock(&sne->biglock); if (sq->subnet_downstream) { @@ -693,6 +694,7 @@ subnetmod_operate(struct module_qstate *qstate, enum module_ev event, lock_rw_wrlock(&sne->biglock); if (lookup_and_reply(qstate, id, sq)) { + sne->num_msg_cache++; lock_rw_unlock(&sne->biglock); verbose(VERB_QUERY, "subnet: answered from cache"); qstate->ext_state[id] = module_finished; diff --git a/edns-subnet/subnetmod.h b/edns-subnet/subnetmod.h index c7f56327f..f417a64a4 100644 --- a/edns-subnet/subnetmod.h +++ b/edns-subnet/subnetmod.h @@ -61,6 +61,10 @@ struct subnet_env { /** allocation service */ struct alloc_cache alloc; lock_rw_type biglock; + /** number of messages from cache */ + size_t num_msg_cache; + /** number of messages not from cache */ + size_t num_msg_nocache; }; struct subnet_msg_cache_data { diff --git a/libunbound/unbound.h b/libunbound/unbound.h index 6bb0ef224..90766b062 100644 --- a/libunbound/unbound.h +++ b/libunbound/unbound.h @@ -765,6 +765,11 @@ struct ub_server_stats { /** number of times neg cache records were used to generate NXDOMAIN * responses. */ long long num_neg_cache_nxdomain; + /** number of queries answered from edns-subnet specific data */ + long long num_query_subnet; + /** number of queries answered from edns-subnet specific data, and + * the answer was from the edns-subnet cache. */ + long long num_query_subnet_cache; }; /** diff --git a/smallapp/unbound-control.c b/smallapp/unbound-control.c index f6597b79a..9e4c006f3 100644 --- a/smallapp/unbound-control.c +++ b/smallapp/unbound-control.c @@ -374,6 +374,10 @@ static void print_extended(struct ub_stats_info* s) #endif /* USE_DNSCRYPT */ PR_UL("num.query.authzone.up", s->svr.num_query_authzone_up); PR_UL("num.query.authzone.down", s->svr.num_query_authzone_down); +#ifdef CLIENT_SUBNET + PR_UL("num.query.subnet", s->svr.num_query_subnet); + PR_UL("num.query.subnet_cache", s->svr.num_query_subnet_cache); +#endif } /** print statistics out of memory structures */