2000-12-01 23:49:59 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-12-01 23:49:59 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2000-12-01 23:49:59 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2000-12-01 23:49:59 +00:00
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2018-03-28 14:19:37 +02:00
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
#include <isc/magic.h>
|
2000-12-01 23:49:59 +00:00
|
|
|
#include <isc/mem.h>
|
2019-05-17 13:35:51 +02:00
|
|
|
#include <isc/refcount.h>
|
2009-01-27 22:30:00 +00:00
|
|
|
#include <isc/stats.h>
|
2008-01-24 02:00:44 +00:00
|
|
|
#include <isc/util.h>
|
2000-12-01 23:49:59 +00:00
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
#include <dns/opcode.h>
|
|
|
|
#include <dns/rdatatype.h>
|
2000-12-01 23:49:59 +00:00
|
|
|
#include <dns/stats.h>
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#define DNS_STATS_MAGIC ISC_MAGIC('D', 's', 't', 't')
|
|
|
|
#define DNS_STATS_VALID(x) ISC_MAGIC_VALID(x, DNS_STATS_MAGIC)
|
2008-04-03 05:55:52 +00:00
|
|
|
|
|
|
|
/*%
|
|
|
|
* Statistics types.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
dns_statstype_general = 0,
|
|
|
|
dns_statstype_rdtype = 1,
|
|
|
|
dns_statstype_rdataset = 2,
|
2016-06-23 08:44:54 +10:00
|
|
|
dns_statstype_opcode = 3,
|
2019-06-19 16:02:50 +02:00
|
|
|
dns_statstype_rcode = 4,
|
|
|
|
dns_statstype_dnssec = 5
|
2008-04-03 05:55:52 +00:00
|
|
|
} dns_statstype_t;
|
|
|
|
|
|
|
|
/*%
|
|
|
|
* It doesn't make sense to have 2^16 counters for all possible types since
|
2020-01-17 08:41:06 +01:00
|
|
|
* most of them won't be used. We have counters for the first 256 types.
|
|
|
|
*
|
|
|
|
* A rdtypecounter is now 8 bits for RRtypes and 3 bits for flags:
|
|
|
|
*
|
|
|
|
* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
|
|
|
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
|
|
|
* | | | | | | S |NX| RRType |
|
|
|
|
* +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|
|
|
|
*
|
|
|
|
* If the 8 bits for RRtype are all zero, this is an Other RRtype.
|
2008-04-03 05:55:52 +00:00
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
#define RDTYPECOUNTER_MAXTYPE 0x00ff
|
2020-01-17 08:41:06 +01:00
|
|
|
|
2012-06-08 16:32:44 +10:00
|
|
|
/*
|
2020-01-17 08:41:06 +01:00
|
|
|
*
|
|
|
|
* Bit 7 is the NXRRSET (NX) flag and indicates whether this is a
|
|
|
|
* positive (0) or a negative (1) RRset.
|
2012-06-08 16:32:44 +10:00
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
#define RDTYPECOUNTER_NXRRSET 0x0100
|
2020-01-17 08:41:06 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Then bit 5 and 6 mostly tell you if this counter is for an active,
|
|
|
|
* stale, or ancient RRtype:
|
|
|
|
*
|
|
|
|
* S = 0 (0b00) means Active
|
|
|
|
* S = 1 (0b01) means Stale
|
|
|
|
* S = 2 (0b10) means Ancient
|
|
|
|
*
|
|
|
|
* Since a counter cannot be stale and ancient at the same time, we
|
|
|
|
* treat S = 0x11 as a special case to deal with NXDOMAIN counters.
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
#define RDTYPECOUNTER_STALE (1 << 9)
|
|
|
|
#define RDTYPECOUNTER_ANCIENT (1 << 10)
|
2020-01-17 08:41:06 +01:00
|
|
|
#define RDTYPECOUNTER_NXDOMAIN ((1 << 9) | (1 << 10))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* S = 0x11 indicates an NXDOMAIN counter and in this case the RRtype
|
|
|
|
* field signals the expiry of this cached item:
|
|
|
|
*
|
|
|
|
* RRType = 0 (0b00) means Active
|
|
|
|
* RRType = 1 (0b01) means Stale
|
|
|
|
* RRType = 2 (0b02) means Ancient
|
|
|
|
*
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
#define RDTYPECOUNTER_NXDOMAIN_STALE 1
|
2020-01-17 08:41:06 +01:00
|
|
|
#define RDTYPECOUNTER_NXDOMAIN_ANCIENT 2
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The maximum value for rdtypecounter is for an ancient NXDOMAIN.
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
#define RDTYPECOUNTER_MAXVAL 0x0602
|
2000-12-01 23:49:59 +00:00
|
|
|
|
2019-08-07 15:11:57 +02:00
|
|
|
/* dnssec maximum key id */
|
|
|
|
static int dnssec_keyid_max = 65535;
|
|
|
|
|
2008-01-24 02:00:44 +00:00
|
|
|
struct dns_stats {
|
2008-04-03 05:55:52 +00:00
|
|
|
unsigned int magic;
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_statstype_t type;
|
|
|
|
isc_mem_t * mctx;
|
|
|
|
isc_stats_t * counters;
|
2019-05-17 13:35:51 +02:00
|
|
|
isc_refcount_t references;
|
2009-01-27 22:30:00 +00:00
|
|
|
};
|
2008-04-03 05:55:52 +00:00
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
typedef struct rdatadumparg {
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatypestats_dumper_t fn;
|
|
|
|
void * arg;
|
2009-01-27 22:30:00 +00:00
|
|
|
} rdatadumparg_t;
|
2008-04-03 05:55:52 +00:00
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
typedef struct opcodedumparg {
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_opcodestats_dumper_t fn;
|
|
|
|
void * arg;
|
2009-01-27 22:30:00 +00:00
|
|
|
} opcodedumparg_t;
|
2008-01-24 02:00:44 +00:00
|
|
|
|
2016-06-23 08:44:54 +10:00
|
|
|
typedef struct rcodedumparg {
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rcodestats_dumper_t fn;
|
|
|
|
void * arg;
|
2016-06-23 08:44:54 +10:00
|
|
|
} rcodedumparg_t;
|
2019-06-19 16:02:50 +02:00
|
|
|
typedef struct dnssecsigndumparg {
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_dnssecsignstats_dumper_t fn;
|
|
|
|
void * arg;
|
2019-06-19 16:02:50 +02:00
|
|
|
} dnssecsigndumparg_t;
|
2016-06-23 08:44:54 +10:00
|
|
|
|
2008-01-24 02:00:44 +00:00
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_stats_attach(dns_stats_t *stats, dns_stats_t **statsp)
|
|
|
|
{
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(DNS_STATS_VALID(stats));
|
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
|
|
|
|
2019-05-17 13:35:51 +02:00
|
|
|
isc_refcount_increment(&stats->references);
|
2008-04-03 05:55:52 +00:00
|
|
|
|
|
|
|
*statsp = stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_stats_detach(dns_stats_t **statsp)
|
|
|
|
{
|
2008-01-24 02:00:44 +00:00
|
|
|
dns_stats_t *stats;
|
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(statsp != NULL && DNS_STATS_VALID(*statsp));
|
2008-01-24 02:00:44 +00:00
|
|
|
|
|
|
|
stats = *statsp;
|
2008-04-03 05:55:52 +00:00
|
|
|
*statsp = NULL;
|
2008-01-24 02:00:44 +00:00
|
|
|
|
2019-05-17 13:35:51 +02:00
|
|
|
if (isc_refcount_decrement(&stats->references) == 1) {
|
2019-07-23 08:27:30 -04:00
|
|
|
isc_refcount_destroy(&stats->references);
|
2009-01-27 22:30:00 +00:00
|
|
|
isc_stats_detach(&stats->counters);
|
2008-04-03 05:55:52 +00:00
|
|
|
isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
|
|
|
|
}
|
2008-01-24 02:00:44 +00:00
|
|
|
}
|
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
/*%
|
|
|
|
* Create methods
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
2012-06-08 16:32:44 +10:00
|
|
|
create_stats(isc_mem_t *mctx, dns_statstype_t type, int ncounters,
|
2009-01-27 22:30:00 +00:00
|
|
|
dns_stats_t **statsp)
|
|
|
|
{
|
|
|
|
dns_stats_t *stats;
|
|
|
|
isc_result_t result;
|
2008-01-24 02:00:44 +00:00
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
stats = isc_mem_get(mctx, sizeof(*stats));
|
2008-04-03 05:55:52 +00:00
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
stats->counters = NULL;
|
2019-05-17 13:35:51 +02:00
|
|
|
isc_refcount_init(&stats->references, 1);
|
2009-01-27 22:30:00 +00:00
|
|
|
|
|
|
|
result = isc_stats_create(mctx, &stats->counters, ncounters);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2009-01-27 22:30:00 +00:00
|
|
|
goto clean_mutex;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-01-27 22:30:00 +00:00
|
|
|
|
|
|
|
stats->magic = DNS_STATS_MAGIC;
|
|
|
|
stats->type = type;
|
|
|
|
stats->mctx = NULL;
|
|
|
|
isc_mem_attach(mctx, &stats->mctx);
|
|
|
|
*statsp = stats;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
clean_mutex:
|
2009-01-27 22:30:00 +00:00
|
|
|
isc_mem_put(mctx, stats, sizeof(*stats));
|
|
|
|
|
|
|
|
return (result);
|
2008-01-24 02:00:44 +00:00
|
|
|
}
|
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_generalstats_create(isc_mem_t *mctx, dns_stats_t **statsp, int ncounters)
|
|
|
|
{
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
|
|
|
|
|
|
|
return (create_stats(mctx, dns_statstype_general, ncounters, statsp));
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatypestats_create(isc_mem_t *mctx, dns_stats_t **statsp)
|
|
|
|
{
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
|
|
|
|
2020-01-17 08:41:06 +01:00
|
|
|
/*
|
|
|
|
* Create rdtype statistics for the first 255 RRtypes,
|
|
|
|
* plus one additional for other RRtypes.
|
|
|
|
*/
|
|
|
|
return (create_stats(mctx, dns_statstype_rdtype,
|
2020-02-12 13:59:18 +01:00
|
|
|
(RDTYPECOUNTER_MAXTYPE + 1), statsp));
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatasetstats_create(isc_mem_t *mctx, dns_stats_t **statsp)
|
|
|
|
{
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
|
|
|
|
|
|
|
return (create_stats(mctx, dns_statstype_rdataset,
|
2020-02-12 13:59:18 +01:00
|
|
|
(RDTYPECOUNTER_MAXVAL + 1), statsp));
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_opcodestats_create(isc_mem_t *mctx, dns_stats_t **statsp)
|
|
|
|
{
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
|
|
|
|
|
|
|
return (create_stats(mctx, dns_statstype_opcode, 16, statsp));
|
|
|
|
}
|
|
|
|
|
2016-06-23 08:44:54 +10:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rcodestats_create(isc_mem_t *mctx, dns_stats_t **statsp)
|
|
|
|
{
|
2016-06-23 08:44:54 +10:00
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
return (create_stats(mctx, dns_statstype_rcode, dns_rcode_badcookie + 1,
|
|
|
|
statsp));
|
2016-06-23 08:44:54 +10:00
|
|
|
}
|
|
|
|
|
2019-06-19 16:02:50 +02:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_dnssecsignstats_create(isc_mem_t *mctx, dns_stats_t **statsp)
|
|
|
|
{
|
2019-06-19 16:02:50 +02:00
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
return (create_stats(mctx, dns_statstype_dnssec, dnssec_keyid_max,
|
|
|
|
statsp));
|
2019-06-19 16:02:50 +02:00
|
|
|
}
|
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
/*%
|
|
|
|
* Increment/Decrement methods
|
|
|
|
*/
|
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_generalstats_increment(dns_stats_t *stats, isc_statscounter_t counter)
|
|
|
|
{
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_general);
|
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
isc_stats_increment(stats->counters, counter);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
inline static isc_statscounter_t
|
|
|
|
rdatatype2counter(dns_rdatatype_t type)
|
|
|
|
{
|
2020-01-17 08:41:06 +01:00
|
|
|
if (type > (dns_rdatatype_t)RDTYPECOUNTER_MAXTYPE) {
|
2020-02-13 21:48:23 +01:00
|
|
|
return (0);
|
2020-01-17 08:41:06 +01:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
return ((isc_statscounter_t)type);
|
2020-01-17 08:41:06 +01:00
|
|
|
}
|
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatypestats_increment(dns_stats_t *stats, dns_rdatatype_t type)
|
|
|
|
{
|
2020-01-17 08:41:06 +01:00
|
|
|
isc_statscounter_t counter;
|
2008-04-03 05:55:52 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_rdtype);
|
|
|
|
|
2020-01-17 08:41:06 +01:00
|
|
|
counter = rdatatype2counter(type);
|
|
|
|
isc_stats_increment(stats->counters, counter);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
update_rdatasetstats(dns_stats_t *stats, dns_rdatastatstype_t rrsettype,
|
2018-04-17 08:29:14 -07:00
|
|
|
bool increment)
|
2008-04-03 05:55:52 +00:00
|
|
|
{
|
2020-01-17 08:41:06 +01:00
|
|
|
isc_statscounter_t counter;
|
2008-04-03 05:55:52 +00:00
|
|
|
|
|
|
|
if ((DNS_RDATASTATSTYPE_ATTR(rrsettype) &
|
|
|
|
DNS_RDATASTATSTYPE_ATTR_NXDOMAIN) != 0) {
|
2020-01-17 08:41:06 +01:00
|
|
|
counter = RDTYPECOUNTER_NXDOMAIN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is an NXDOMAIN counter, save the expiry value
|
|
|
|
* (active, stale, or ancient) value in the RRtype part.
|
|
|
|
*/
|
|
|
|
if ((DNS_RDATASTATSTYPE_ATTR(rrsettype) &
|
|
|
|
DNS_RDATASTATSTYPE_ATTR_ANCIENT) != 0) {
|
|
|
|
counter |= RDTYPECOUNTER_NXDOMAIN_ANCIENT;
|
2020-02-12 13:59:18 +01:00
|
|
|
} else if ((DNS_RDATASTATSTYPE_ATTR(rrsettype) &
|
|
|
|
DNS_RDATASTATSTYPE_ATTR_STALE) != 0) {
|
2020-01-17 08:41:06 +01:00
|
|
|
counter += RDTYPECOUNTER_NXDOMAIN_STALE;
|
|
|
|
}
|
2008-04-03 05:55:52 +00:00
|
|
|
} else {
|
2020-01-17 08:41:06 +01:00
|
|
|
counter = rdatatype2counter(DNS_RDATASTATSTYPE_BASE(rrsettype));
|
2008-04-03 05:55:52 +00:00
|
|
|
|
|
|
|
if ((DNS_RDATASTATSTYPE_ATTR(rrsettype) &
|
2020-01-17 08:41:06 +01:00
|
|
|
DNS_RDATASTATSTYPE_ATTR_NXRRSET) != 0) {
|
|
|
|
counter |= RDTYPECOUNTER_NXRRSET;
|
|
|
|
}
|
2008-04-03 05:55:52 +00:00
|
|
|
|
2020-01-17 08:41:06 +01:00
|
|
|
if ((DNS_RDATASTATSTYPE_ATTR(rrsettype) &
|
|
|
|
DNS_RDATASTATSTYPE_ATTR_ANCIENT) != 0) {
|
|
|
|
counter |= RDTYPECOUNTER_ANCIENT;
|
2020-02-12 13:59:18 +01:00
|
|
|
} else if ((DNS_RDATASTATSTYPE_ATTR(rrsettype) &
|
|
|
|
DNS_RDATASTATSTYPE_ATTR_STALE) != 0) {
|
2020-01-17 08:41:06 +01:00
|
|
|
counter |= RDTYPECOUNTER_STALE;
|
|
|
|
}
|
2019-08-07 13:24:25 +02:00
|
|
|
}
|
|
|
|
|
2012-06-08 16:32:44 +10:00
|
|
|
if (increment) {
|
2009-01-27 22:30:00 +00:00
|
|
|
isc_stats_increment(stats->counters, counter);
|
2012-06-08 16:32:44 +10:00
|
|
|
} else {
|
2009-01-27 22:30:00 +00:00
|
|
|
isc_stats_decrement(stats->counters, counter);
|
2012-06-08 16:32:44 +10:00
|
|
|
}
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_rdatasetstats_increment(dns_stats_t *stats, dns_rdatastatstype_t rrsettype)
|
|
|
|
{
|
|
|
|
REQUIRE(DNS_STATS_VALID(stats) &&
|
|
|
|
stats->type == dns_statstype_rdataset);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
update_rdatasetstats(stats, rrsettype, true);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_rdatasetstats_decrement(dns_stats_t *stats, dns_rdatastatstype_t rrsettype)
|
|
|
|
{
|
|
|
|
REQUIRE(DNS_STATS_VALID(stats) &&
|
|
|
|
stats->type == dns_statstype_rdataset);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
update_rdatasetstats(stats, rrsettype, false);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
2012-06-08 16:32:44 +10:00
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_opcodestats_increment(dns_stats_t *stats, dns_opcode_t code)
|
|
|
|
{
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_opcode);
|
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
isc_stats_increment(stats->counters, (isc_statscounter_t)code);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 08:44:54 +10:00
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rcodestats_increment(dns_stats_t *stats, dns_rcode_t code)
|
|
|
|
{
|
2016-06-23 08:44:54 +10:00
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_rcode);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (code <= dns_rcode_badcookie) {
|
2016-06-23 08:44:54 +10:00
|
|
|
isc_stats_increment(stats->counters, (isc_statscounter_t)code);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2016-06-23 08:44:54 +10:00
|
|
|
}
|
|
|
|
|
2019-06-19 16:02:50 +02:00
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_dnssecsignstats_increment(dns_stats_t *stats, dns_keytag_t id)
|
|
|
|
{
|
2019-06-19 16:02:50 +02:00
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_dnssec);
|
|
|
|
|
|
|
|
isc_stats_increment(stats->counters, (isc_statscounter_t)id);
|
|
|
|
}
|
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
/*%
|
|
|
|
* Dump methods
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
dns_generalstats_dump(dns_stats_t *stats, dns_generalstats_dumper_t dump_fn,
|
|
|
|
void *arg, unsigned int options)
|
|
|
|
{
|
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_general);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_stats_dump(stats->counters, (isc_stats_dumper_t)dump_fn, arg,
|
|
|
|
options);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-03-28 14:19:37 +02:00
|
|
|
dump_rdentry(int rdcounter, uint64_t value, dns_rdatastatstype_t attributes,
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatypestats_dumper_t dump_fn, void *arg)
|
2008-04-03 05:55:52 +00:00
|
|
|
{
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_rdatatype_t rdtype = dns_rdatatype_none; /* sentinel */
|
2008-04-03 05:55:52 +00:00
|
|
|
dns_rdatastatstype_t type;
|
|
|
|
|
2020-01-17 08:41:06 +01:00
|
|
|
if ((rdcounter & RDTYPECOUNTER_MAXTYPE) == 0) {
|
2008-04-03 05:55:52 +00:00
|
|
|
attributes |= DNS_RDATASTATSTYPE_ATTR_OTHERTYPE;
|
2020-01-17 08:41:06 +01:00
|
|
|
} else {
|
|
|
|
rdtype = (dns_rdatatype_t)(rdcounter & RDTYPECOUNTER_MAXTYPE);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
type = DNS_RDATASTATSTYPE_VALUE((dns_rdatastatstype_t)rdtype,
|
|
|
|
attributes);
|
2009-01-27 22:30:00 +00:00
|
|
|
dump_fn(type, value, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
rdatatype_dumpcb(isc_statscounter_t counter, uint64_t value, void *arg)
|
|
|
|
{
|
2009-01-27 22:30:00 +00:00
|
|
|
rdatadumparg_t *rdatadumparg = arg;
|
|
|
|
|
|
|
|
dump_rdentry(counter, value, 0, rdatadumparg->fn, rdatadumparg->arg);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_rdatatypestats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn,
|
2009-01-27 22:30:00 +00:00
|
|
|
void *arg0, unsigned int options)
|
2008-04-03 05:55:52 +00:00
|
|
|
{
|
2009-01-27 22:30:00 +00:00
|
|
|
rdatadumparg_t arg;
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_rdtype);
|
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
arg.fn = dump_fn;
|
|
|
|
arg.arg = arg0;
|
|
|
|
isc_stats_dump(stats->counters, rdatatype_dumpcb, &arg, options);
|
|
|
|
}
|
2008-04-03 05:55:52 +00:00
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
rdataset_dumpcb(isc_statscounter_t counter, uint64_t value, void *arg)
|
|
|
|
{
|
2009-01-27 22:30:00 +00:00
|
|
|
rdatadumparg_t *rdatadumparg = arg;
|
2020-02-12 13:59:18 +01:00
|
|
|
unsigned int attributes = 0;
|
2020-01-17 08:41:06 +01:00
|
|
|
|
|
|
|
if ((counter & RDTYPECOUNTER_NXDOMAIN) == RDTYPECOUNTER_NXDOMAIN) {
|
|
|
|
attributes |= DNS_RDATASTATSTYPE_ATTR_NXDOMAIN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is an NXDOMAIN counter, check the RRtype part for the
|
|
|
|
* expiry value (active, stale, or ancient).
|
|
|
|
*/
|
|
|
|
if ((counter & RDTYPECOUNTER_MAXTYPE) ==
|
|
|
|
RDTYPECOUNTER_NXDOMAIN_STALE) {
|
|
|
|
attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
|
|
|
} else if ((counter & RDTYPECOUNTER_MAXTYPE) ==
|
2020-02-12 13:59:18 +01:00
|
|
|
RDTYPECOUNTER_NXDOMAIN_ANCIENT) {
|
2020-01-17 08:41:06 +01:00
|
|
|
attributes |= DNS_RDATASTATSTYPE_ATTR_ANCIENT;
|
|
|
|
}
|
2019-08-07 13:24:25 +02:00
|
|
|
} else {
|
2020-01-17 08:41:06 +01:00
|
|
|
if ((counter & RDTYPECOUNTER_MAXTYPE) == 0) {
|
|
|
|
attributes |= DNS_RDATASTATSTYPE_ATTR_OTHERTYPE;
|
|
|
|
}
|
|
|
|
if ((counter & RDTYPECOUNTER_NXRRSET) != 0) {
|
|
|
|
attributes |= DNS_RDATASTATSTYPE_ATTR_NXRRSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((counter & RDTYPECOUNTER_STALE) != 0) {
|
|
|
|
attributes |= DNS_RDATASTATSTYPE_ATTR_STALE;
|
|
|
|
} else if ((counter & RDTYPECOUNTER_ANCIENT) != 0) {
|
|
|
|
attributes |= DNS_RDATASTATSTYPE_ATTR_ANCIENT;
|
|
|
|
}
|
2019-08-07 13:24:25 +02:00
|
|
|
}
|
|
|
|
|
2020-01-17 08:41:06 +01:00
|
|
|
dump_rdentry(counter, value, attributes, rdatadumparg->fn,
|
2019-08-07 13:24:25 +02:00
|
|
|
rdatadumparg->arg);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_rdatasetstats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn,
|
2009-01-27 22:30:00 +00:00
|
|
|
void *arg0, unsigned int options)
|
2008-04-03 05:55:52 +00:00
|
|
|
{
|
2009-01-27 22:30:00 +00:00
|
|
|
rdatadumparg_t arg;
|
2008-04-03 05:55:52 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_STATS_VALID(stats) &&
|
|
|
|
stats->type == dns_statstype_rdataset);
|
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
arg.fn = dump_fn;
|
|
|
|
arg.arg = arg0;
|
|
|
|
isc_stats_dump(stats->counters, rdataset_dumpcb, &arg, options);
|
|
|
|
}
|
2008-04-03 05:55:52 +00:00
|
|
|
|
2019-06-19 16:02:50 +02:00
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
dnssec_dumpcb(isc_statscounter_t counter, uint64_t value, void *arg)
|
|
|
|
{
|
2019-06-19 16:02:50 +02:00
|
|
|
dnssecsigndumparg_t *dnssecarg = arg;
|
|
|
|
|
|
|
|
dnssecarg->fn((dns_keytag_t)counter, value, dnssecarg->arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_dnssecsignstats_dump(dns_stats_t * stats,
|
|
|
|
dns_dnssecsignstats_dumper_t dump_fn, void *arg0,
|
|
|
|
unsigned int options)
|
2019-06-19 16:02:50 +02:00
|
|
|
{
|
|
|
|
dnssecsigndumparg_t arg;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_dnssec);
|
2019-06-19 16:02:50 +02:00
|
|
|
|
|
|
|
arg.fn = dump_fn;
|
|
|
|
arg.arg = arg0;
|
|
|
|
isc_stats_dump(stats->counters, dnssec_dumpcb, &arg, options);
|
|
|
|
}
|
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
opcode_dumpcb(isc_statscounter_t counter, uint64_t value, void *arg)
|
|
|
|
{
|
2009-01-27 22:30:00 +00:00
|
|
|
opcodedumparg_t *opcodearg = arg;
|
2008-04-03 05:55:52 +00:00
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
opcodearg->fn((dns_opcode_t)counter, value, opcodearg->arg);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 08:44:54 +10:00
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
rcode_dumpcb(isc_statscounter_t counter, uint64_t value, void *arg)
|
|
|
|
{
|
2016-06-23 08:44:54 +10:00
|
|
|
rcodedumparg_t *rcodearg = arg;
|
|
|
|
|
|
|
|
rcodearg->fn((dns_rcode_t)counter, value, rcodearg->arg);
|
|
|
|
}
|
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
void
|
|
|
|
dns_opcodestats_dump(dns_stats_t *stats, dns_opcodestats_dumper_t dump_fn,
|
2009-01-27 22:30:00 +00:00
|
|
|
void *arg0, unsigned int options)
|
2008-04-03 05:55:52 +00:00
|
|
|
{
|
2009-01-27 22:30:00 +00:00
|
|
|
opcodedumparg_t arg;
|
2008-04-03 05:55:52 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_opcode);
|
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
arg.fn = dump_fn;
|
|
|
|
arg.arg = arg0;
|
|
|
|
isc_stats_dump(stats->counters, opcode_dumpcb, &arg, options);
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
|
|
|
|
2016-06-23 08:44:54 +10:00
|
|
|
void
|
|
|
|
dns_rcodestats_dump(dns_stats_t *stats, dns_rcodestats_dumper_t dump_fn,
|
2020-02-12 13:59:18 +01:00
|
|
|
void *arg0, unsigned int options)
|
2016-06-23 08:44:54 +10:00
|
|
|
{
|
|
|
|
rcodedumparg_t arg;
|
|
|
|
|
|
|
|
REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_rcode);
|
|
|
|
|
|
|
|
arg.fn = dump_fn;
|
|
|
|
arg.arg = arg0;
|
|
|
|
isc_stats_dump(stats->counters, rcode_dumpcb, &arg, options);
|
|
|
|
}
|
|
|
|
|
2008-01-24 02:00:44 +00:00
|
|
|
/***
|
2008-04-03 05:55:52 +00:00
|
|
|
*** Obsolete variables and functions follow:
|
2008-01-24 02:00:44 +00:00
|
|
|
***/
|
2020-02-12 13:59:18 +01:00
|
|
|
LIBDNS_EXTERNAL_DATA const char *dns_statscounter_names[DNS_STATS_NCOUNTERS] = {
|
|
|
|
"success", "referral", "nxrrset", "nxdomain",
|
|
|
|
"recursion", "failure", "duplicate", "dropped"
|
|
|
|
};
|
2008-04-03 05:55:52 +00:00
|
|
|
|
2000-12-01 23:49:59 +00:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_stats_alloccounters(isc_mem_t *mctx, uint64_t **ctrp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
uint64_t *p = isc_mem_get(mctx, DNS_STATS_NCOUNTERS * sizeof(uint64_t));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (p == NULL) {
|
2000-12-01 23:49:59 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
for (i = 0; i < DNS_STATS_NCOUNTERS; i++) {
|
2000-12-01 23:49:59 +00:00
|
|
|
p[i] = 0;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-01 23:49:59 +00:00
|
|
|
*ctrp = p;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_stats_freecounters(isc_mem_t *mctx, uint64_t **ctrp)
|
|
|
|
{
|
2018-03-28 14:19:37 +02:00
|
|
|
isc_mem_put(mctx, *ctrp, DNS_STATS_NCOUNTERS * sizeof(uint64_t));
|
2000-12-01 23:49:59 +00:00
|
|
|
*ctrp = NULL;
|
|
|
|
}
|