statschannel.c 110 KB
Newer Older
1
/*
2
 * Copyright (C) 2008-2015  Internet Systems Consortium, Inc. ("ISC")
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

/*! \file */

#include <config.h>

#include <isc/buffer.h>
#include <isc/httpd.h>
23
#include <isc/json.h>
24
#include <isc/mem.h>
25
#include <isc/once.h>
26 27
#include <isc/print.h>
#include <isc/socket.h>
28
#include <isc/stats.h>
Evan Hunt's avatar
Evan Hunt committed
29
#include <isc/string.h>
30 31
#include <isc/task.h>

32
#include <dns/cache.h>
33 34
#include <dns/db.h>
#include <dns/opcode.h>
35
#include <dns/resolver.h>
36 37
#include <dns/rdataclass.h>
#include <dns/rdatatype.h>
38 39
#include <dns/stats.h>
#include <dns/view.h>
40
#include <dns/zt.h>
41 42 43 44 45

#include <named/log.h>
#include <named/server.h>
#include <named/statschannel.h>

46 47
#include "bind9.xsl.h"

48 49 50 51 52 53 54
struct ns_statschannel {
	/* Unlocked */
	isc_httpdmgr_t				*httpdmgr;
	isc_sockaddr_t				address;
	isc_mem_t				*mctx;

	/*
Francis Dupont's avatar
Francis Dupont committed
55
	 * Locked by channel lock: can be referenced and modified by both
Automatic Updater's avatar
Automatic Updater committed
56
	 * the server task and the channel task.
57 58 59 60 61 62 63 64
	 */
	isc_mutex_t				lock;
	dns_acl_t				*acl;

	/* Locked by server task */
	ISC_LINK(struct ns_statschannel)	link;
};

65 66
typedef struct
stats_dumparg {
67 68 69 70 71 72
	isc_statsformat_t	type;
	void			*arg;		/* type dependent argument */
	int			ncounters;	/* for general statistics */
	int			*counterindices; /* for general statistics */
	isc_uint64_t		*countervalues;	 /* for general statistics */
	isc_result_t		result;
73 74
} stats_dumparg_t;

75 76
static isc_once_t once = ISC_ONCE_INIT;

77 78 79 80 81 82
#if defined(HAVE_LIBXML2) || defined(HAVE_JSON)
#define EXTENDED_STATS
#else
#undef EXTENDED_STATS
#endif

83 84 85 86 87 88 89
/*%
 * Statistics descriptions.  These could be statistically initialized at
 * compile time, but we configure them run time in the init_desc() function
 * below so that they'll be less susceptible to counter name changes.
 */
static const char *nsstats_desc[dns_nsstatscounter_max];
static const char *resstats_desc[dns_resstatscounter_max];
90
static const char *adbstats_desc[dns_adbstats_max];
91
static const char *zonestats_desc[dns_zonestatscounter_max];
92
static const char *sockstats_desc[isc_sockstatscounter_max];
93
static const char *dnssecstats_desc[dns_dnssecstats_max];
Evan Hunt's avatar
Evan Hunt committed
94 95 96 97
static const char *udpinsizestats_desc[dns_sizecounter_in_max];
static const char *udpoutsizestats_desc[dns_sizecounter_out_max];
static const char *tcpinsizestats_desc[dns_sizecounter_in_max];
static const char *tcpoutsizestats_desc[dns_sizecounter_out_max];
98
#if defined(EXTENDED_STATS)
99 100
static const char *nsstats_xmldesc[dns_nsstatscounter_max];
static const char *resstats_xmldesc[dns_resstatscounter_max];
101
static const char *adbstats_xmldesc[dns_adbstats_max];
102
static const char *zonestats_xmldesc[dns_zonestatscounter_max];
103
static const char *sockstats_xmldesc[isc_sockstatscounter_max];
104
static const char *dnssecstats_xmldesc[dns_dnssecstats_max];
Evan Hunt's avatar
Evan Hunt committed
105 106 107 108
static const char *udpinsizestats_xmldesc[dns_sizecounter_in_max];
static const char *udpoutsizestats_xmldesc[dns_sizecounter_out_max];
static const char *tcpinsizestats_xmldesc[dns_sizecounter_in_max];
static const char *tcpoutsizestats_xmldesc[dns_sizecounter_out_max];
109 110 111
#else
#define nsstats_xmldesc NULL
#define resstats_xmldesc NULL
112
#define adbstats_xmldesc NULL
113
#define zonestats_xmldesc NULL
114
#define sockstats_xmldesc NULL
115
#define dnssecstats_xmldesc NULL
Evan Hunt's avatar
Evan Hunt committed
116 117 118 119
#define udpinsizestats_xmldesc NULL
#define udpoutsizestats_xmldesc NULL
#define tcpinsizestats_xmldesc NULL
#define tcpoutsizestats_xmldesc NULL
120
#endif	/* EXTENDED_STATS */
121

122 123
#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)

124 125 126 127 128 129 130
/*%
 * Mapping arrays to represent statistics counters in the order of our
 * preference, regardless of the order of counter indices.  For example,
 * nsstats_desc[nsstats_index[0]] will be the description that is shown first.
 */
static int nsstats_index[dns_nsstatscounter_max];
static int resstats_index[dns_resstatscounter_max];
131
static int adbstats_index[dns_adbstats_max];
132 133
static int zonestats_index[dns_zonestatscounter_max];
static int sockstats_index[isc_sockstatscounter_max];
134
static int dnssecstats_index[dns_dnssecstats_max];
Evan Hunt's avatar
Evan Hunt committed
135 136 137 138
static int udpinsizestats_index[dns_sizecounter_in_max];
static int udpoutsizestats_index[dns_sizecounter_out_max];
static int tcpinsizestats_index[dns_sizecounter_in_max];
static int tcpoutsizestats_index[dns_sizecounter_out_max];
139

140 141 142 143 144
static inline void
set_desc(int counter, int maxcounter, const char *fdesc, const char **fdescs,
	 const char *xdesc, const char **xdescs)
{
	REQUIRE(counter < maxcounter);
145 146 147
	REQUIRE(fdescs != NULL && fdescs[counter] == NULL);
#if defined(EXTENDED_STATS)
	REQUIRE(xdescs != NULL && xdescs[counter] == NULL);
148 149 150
#endif

	fdescs[counter] = fdesc;
151
#if defined(EXTENDED_STATS)
152 153 154 155 156 157 158 159
	xdescs[counter] = xdesc;
#else
	UNUSED(xdesc);
	UNUSED(xdescs);
#endif
}

static void
160
init_desc(void) {
161 162 163
	int i;

	/* Initialize name server statistics */
164 165
	for (i = 0; i < dns_nsstatscounter_max; i++)
		nsstats_desc[i] = NULL;
166
#if defined(EXTENDED_STATS)
167 168
	for (i = 0; i < dns_nsstatscounter_max; i++)
		nsstats_xmldesc[i] = NULL;
169
#endif
170 171 172 173 174

#define SET_NSSTATDESC(counterid, desc, xmldesc) \
	do { \
		set_desc(dns_nsstatscounter_ ## counterid, \
			 dns_nsstatscounter_max, \
Automatic Updater's avatar
Automatic Updater committed
175
			 desc, nsstats_desc, xmldesc, nsstats_xmldesc); \
176 177 178 179 180 181 182 183 184 185 186 187 188 189
		nsstats_index[i++] = dns_nsstatscounter_ ## counterid; \
	} while (0)

	i = 0;
	SET_NSSTATDESC(requestv4, "IPv4 requests received", "Requestv4");
	SET_NSSTATDESC(requestv6, "IPv6 requests received", "Requestv6");
	SET_NSSTATDESC(edns0in, "requests with EDNS(0) received", "ReqEdns0");
	SET_NSSTATDESC(badednsver,
		       "requests with unsupported EDNS version received",
		       "ReqBadEDNSVer");
	SET_NSSTATDESC(tsigin, "requests with TSIG received", "ReqTSIG");
	SET_NSSTATDESC(sig0in, "requests with SIG(0) received", "ReqSIG0");
	SET_NSSTATDESC(invalidsig, "requests with invalid signature",
		       "ReqBadSIG");
190
	SET_NSSTATDESC(requesttcp, "TCP requests received", "ReqTCP");
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
	SET_NSSTATDESC(authrej, "auth queries rejected", "AuthQryRej");
	SET_NSSTATDESC(recurserej, "recursive queries rejected", "RecQryRej");
	SET_NSSTATDESC(xfrrej, "transfer requests rejected", "XfrRej");
	SET_NSSTATDESC(updaterej, "update requests rejected", "UpdateRej");
	SET_NSSTATDESC(response, "responses sent", "Response");
	SET_NSSTATDESC(truncatedresp, "truncated responses sent",
		       "TruncatedResp");
	SET_NSSTATDESC(edns0out, "responses with EDNS(0) sent", "RespEDNS0");
	SET_NSSTATDESC(tsigout, "responses with TSIG sent", "RespTSIG");
	SET_NSSTATDESC(sig0out, "responses with SIG(0) sent", "RespSIG0");
	SET_NSSTATDESC(success, "queries resulted in successful answer",
		       "QrySuccess");
	SET_NSSTATDESC(authans, "queries resulted in authoritative answer",
		       "QryAuthAns");
	SET_NSSTATDESC(nonauthans,
		       "queries resulted in non authoritative answer",
		       "QryNoauthAns");
	SET_NSSTATDESC(referral, "queries resulted in referral answer",
		       "QryReferral");
	SET_NSSTATDESC(nxrrset, "queries resulted in nxrrset", "QryNxrrset");
	SET_NSSTATDESC(servfail, "queries resulted in SERVFAIL", "QrySERVFAIL");
	SET_NSSTATDESC(formerr, "queries resulted in FORMERR", "QryFORMERR");
	SET_NSSTATDESC(nxdomain, "queries resulted in NXDOMAIN", "QryNXDOMAIN");
214
	SET_NSSTATDESC(recursion, "queries caused recursion", "QryRecursion");
215 216 217 218 219 220 221 222 223 224 225 226 227 228
	SET_NSSTATDESC(duplicate, "duplicate queries received", "QryDuplicate");
	SET_NSSTATDESC(dropped, "queries dropped", "QryDropped");
	SET_NSSTATDESC(failure, "other query failures", "QryFailure");
	SET_NSSTATDESC(xfrdone, "requested transfers completed", "XfrReqDone");
	SET_NSSTATDESC(updatereqfwd, "update requests forwarded",
		       "UpdateReqFwd");
	SET_NSSTATDESC(updaterespfwd, "update responses forwarded",
		       "UpdateRespFwd");
	SET_NSSTATDESC(updatefwdfail, "update forward failed", "UpdateFwdFail");
	SET_NSSTATDESC(updatedone, "updates completed", "UpdateDone");
	SET_NSSTATDESC(updatefail, "updates failed", "UpdateFail");
	SET_NSSTATDESC(updatebadprereq,
		       "updates rejected due to prerequisite failure",
		       "UpdateBadPrereq");
229 230
	SET_NSSTATDESC(recursclients, "recursing clients",
			"RecursClients");
231
	SET_NSSTATDESC(dns64, "queries answered by DNS64", "DNS64");
Evan Hunt's avatar
Evan Hunt committed
232 233 234 235
	SET_NSSTATDESC(ratedropped, "responses dropped for rate limits",
		       "RateDropped");
	SET_NSSTATDESC(rateslipped, "responses truncated for rate limits",
		       "RateSlipped");
236 237
	SET_NSSTATDESC(rpz_rewrites, "response policy zone rewrites",
		       "RPZRewrites");
238 239
	SET_NSSTATDESC(udp, "UDP queries received", "QryUDP");
	SET_NSSTATDESC(tcp, "TCP queries received", "QryTCP");
240
	SET_NSSTATDESC(nsidopt, "NSID option received", "NSIDOpt");
Mark Andrews's avatar
Mark Andrews committed
241 242
	SET_NSSTATDESC(expireopt, "Expire option received", "ExpireOpt");
	SET_NSSTATDESC(otheropt, "Other EDNS option received", "OtherOpt");
243 244 245 246 247 248
	SET_NSSTATDESC(cookiein, "COOKIE option received", "CookieIn");
	SET_NSSTATDESC(cookienew, "COOKIE - client only", "CookieNew");
	SET_NSSTATDESC(cookiebadsize, "COOKIE - bad size", "CookieBadSize");
	SET_NSSTATDESC(cookiebadtime, "COOKIE - bad time", "CookieBadTime");
	SET_NSSTATDESC(cookienomatch, "COOKIE - no match", "CookieNoMatch");
	SET_NSSTATDESC(cookiematch, "COOKIE - match", "CookieMatch");
Evan Hunt's avatar
Evan Hunt committed
249
	SET_NSSTATDESC(ecsopt, "EDNS client subnet option recieved", "ECSOpt");
250
	SET_NSSTATDESC(nxdomainredirect,
251 252
		"queries resulted in NXDOMAIN that were redirected",
		"QryNXRedir");
253
	SET_NSSTATDESC(nxdomainredirect_rlookup,
254 255 256
		"queries resulted in NXDOMAIN that were redirected and "
		"resulted in a successful remote lookup",
		"QryNXRedirRLookup");
257
	SET_NSSTATDESC(badcookie, "sent badcookie response", "QryBADCOOKIE");
258
	INSIST(i == dns_nsstatscounter_max);
259 260

	/* Initialize resolver statistics */
261 262
	for (i = 0; i < dns_resstatscounter_max; i++)
		resstats_desc[i] = NULL;
263
#if defined(EXTENDED_STATS)
264 265
	for (i = 0; i < dns_resstatscounter_max; i++)
		resstats_xmldesc[i] = NULL;
266 267
#endif

268 269 270 271
#define SET_RESSTATDESC(counterid, desc, xmldesc) \
	do { \
		set_desc(dns_resstatscounter_ ## counterid, \
			 dns_resstatscounter_max, \
Automatic Updater's avatar
Automatic Updater committed
272
			 desc, resstats_desc, xmldesc, resstats_xmldesc); \
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
		resstats_index[i++] = dns_resstatscounter_ ## counterid; \
	} while (0)

	i = 0;
	SET_RESSTATDESC(queryv4, "IPv4 queries sent", "Queryv4");
	SET_RESSTATDESC(queryv6, "IPv6 queries sent", "Queryv6");
	SET_RESSTATDESC(responsev4, "IPv4 responses received", "Responsev4");
	SET_RESSTATDESC(responsev6, "IPv6 responses received", "Responsev6");
	SET_RESSTATDESC(nxdomain, "NXDOMAIN received", "NXDOMAIN");
	SET_RESSTATDESC(servfail, "SERVFAIL received", "SERVFAIL");
	SET_RESSTATDESC(formerr, "FORMERR received", "FORMERR");
	SET_RESSTATDESC(othererror, "other errors received", "OtherError");
	SET_RESSTATDESC(edns0fail, "EDNS(0) query failures", "EDNS0Fail");
	SET_RESSTATDESC(mismatch, "mismatch responses received", "Mismatch");
	SET_RESSTATDESC(truncated, "truncated responses received", "Truncated");
	SET_RESSTATDESC(lame, "lame delegations received", "Lame");
	SET_RESSTATDESC(retry, "query retries", "Retry");
	SET_RESSTATDESC(dispabort, "queries aborted due to quota",
			"QueryAbort");
	SET_RESSTATDESC(dispsockfail, "failures in opening query sockets",
			"QuerySockFail");
294 295
	SET_RESSTATDESC(disprequdp, "UDP queries in progress", "QueryCurUDP");
	SET_RESSTATDESC(dispreqtcp, "TCP queries in progress", "QueryCurTCP");
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
	SET_RESSTATDESC(querytimeout, "query timeouts", "QueryTimeout");
	SET_RESSTATDESC(gluefetchv4, "IPv4 NS address fetches", "GlueFetchv4");
	SET_RESSTATDESC(gluefetchv6, "IPv6 NS address fetches", "GlueFetchv6");
	SET_RESSTATDESC(gluefetchv4fail, "IPv4 NS address fetch failed",
			"GlueFetchv4Fail");
	SET_RESSTATDESC(gluefetchv6fail, "IPv6 NS address fetch failed",
			"GlueFetchv6Fail");
	SET_RESSTATDESC(val, "DNSSEC validation attempted", "ValAttempt");
	SET_RESSTATDESC(valsuccess, "DNSSEC validation succeeded", "ValOk");
	SET_RESSTATDESC(valnegsuccess, "DNSSEC NX validation succeeded",
			"ValNegOk");
	SET_RESSTATDESC(valfail, "DNSSEC validation failed", "ValFail");
	SET_RESSTATDESC(queryrtt0, "queries with RTT < "
			DNS_RESOLVER_QRYRTTCLASS0STR "ms",
			"QryRTT" DNS_RESOLVER_QRYRTTCLASS0STR);
	SET_RESSTATDESC(queryrtt1, "queries with RTT "
			DNS_RESOLVER_QRYRTTCLASS0STR "-"
			DNS_RESOLVER_QRYRTTCLASS1STR "ms",
			"QryRTT" DNS_RESOLVER_QRYRTTCLASS1STR);
	SET_RESSTATDESC(queryrtt2, "queries with RTT "
			DNS_RESOLVER_QRYRTTCLASS1STR "-"
			DNS_RESOLVER_QRYRTTCLASS2STR "ms",
			"QryRTT" DNS_RESOLVER_QRYRTTCLASS2STR);
	SET_RESSTATDESC(queryrtt3, "queries with RTT "
			DNS_RESOLVER_QRYRTTCLASS2STR "-"
			DNS_RESOLVER_QRYRTTCLASS3STR "ms",
			"QryRTT" DNS_RESOLVER_QRYRTTCLASS3STR);
	SET_RESSTATDESC(queryrtt4, "queries with RTT "
			DNS_RESOLVER_QRYRTTCLASS3STR "-"
			DNS_RESOLVER_QRYRTTCLASS4STR "ms",
			"QryRTT" DNS_RESOLVER_QRYRTTCLASS4STR);
	SET_RESSTATDESC(queryrtt5, "queries with RTT > "
			DNS_RESOLVER_QRYRTTCLASS4STR "ms",
			"QryRTT" DNS_RESOLVER_QRYRTTCLASS4STR "+");
330 331
	SET_RESSTATDESC(nfetch, "active fetches", "NumFetch");
	SET_RESSTATDESC(buckets, "bucket size", "BucketSize");
332
	SET_RESSTATDESC(refused, "REFUSED received", "REFUSED");
333 334 335 336 337 338
	SET_RESSTATDESC(cookienew, "COOKIE send with client cookie only",
			"ClientCookieOut");
	SET_RESSTATDESC(cookieout, "COOKIE sent with client and server cookie",
			"ServerCookieOut");
	SET_RESSTATDESC(cookiein, "COOKIE replies received", "CookieIn");
	SET_RESSTATDESC(cookieok, "COOKIE client ok", "CookieClientOk");
339
	SET_RESSTATDESC(badvers, "bad EDNS version", "BadEDNSVersion");
340
	SET_RESSTATDESC(badcookie, "bad cookie rcode", "BadCookieRcode");
Tinderbox User's avatar
Tinderbox User committed
341

342
	INSIST(i == dns_resstatscounter_max);
Automatic Updater's avatar
Automatic Updater committed
343

344 345 346
	/* Initialize adb statistics */
	for (i = 0; i < dns_adbstats_max; i++)
		adbstats_desc[i] = NULL;
347
#if defined(EXTENDED_STATS)
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
	for (i = 0; i < dns_adbstats_max; i++)
		adbstats_xmldesc[i] = NULL;
#endif

#define SET_ADBSTATDESC(id, desc, xmldesc) \
	do { \
		set_desc(dns_adbstats_ ## id, dns_adbstats_max, \
			 desc, adbstats_desc, xmldesc, adbstats_xmldesc); \
		adbstats_index[i++] = dns_adbstats_ ## id; \
	} while (0)
	i = 0;
	SET_ADBSTATDESC(nentries, "Address hash table size", "nentries");
	SET_ADBSTATDESC(entriescnt, "Addresses in hash table", "entriescnt");
	SET_ADBSTATDESC(nnames, "Name hash table size", "nnames");
	SET_ADBSTATDESC(namescnt, "Names in hash table", "namescnt");

	INSIST(i == dns_adbstats_max);

366
	/* Initialize zone statistics */
367 368
	for (i = 0; i < dns_zonestatscounter_max; i++)
		zonestats_desc[i] = NULL;
369
#if defined(EXTENDED_STATS)
370 371
	for (i = 0; i < dns_zonestatscounter_max; i++)
		zonestats_xmldesc[i] = NULL;
372
#endif
373 374 375 376 377

#define SET_ZONESTATDESC(counterid, desc, xmldesc) \
	do { \
		set_desc(dns_zonestatscounter_ ## counterid, \
			 dns_zonestatscounter_max, \
Automatic Updater's avatar
Automatic Updater committed
378
			 desc, zonestats_desc, xmldesc, zonestats_xmldesc); \
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
		zonestats_index[i++] = dns_zonestatscounter_ ## counterid; \
	} while (0)

	i = 0;
	SET_ZONESTATDESC(notifyoutv4, "IPv4 notifies sent", "NotifyOutv4");
	SET_ZONESTATDESC(notifyoutv6, "IPv6 notifies sent", "NotifyOutv6");
	SET_ZONESTATDESC(notifyinv4, "IPv4 notifies received", "NotifyInv4");
	SET_ZONESTATDESC(notifyinv6, "IPv6 notifies received", "NotifyInv6");
	SET_ZONESTATDESC(notifyrej, "notifies rejected", "NotifyRej");
	SET_ZONESTATDESC(soaoutv4, "IPv4 SOA queries sent", "SOAOutv4");
	SET_ZONESTATDESC(soaoutv6, "IPv6 SOA queries sent", "SOAOutv6");
	SET_ZONESTATDESC(axfrreqv4, "IPv4 AXFR requested", "AXFRReqv4");
	SET_ZONESTATDESC(axfrreqv6, "IPv6 AXFR requested", "AXFRReqv6");
	SET_ZONESTATDESC(ixfrreqv4, "IPv4 IXFR requested", "IXFRReqv4");
	SET_ZONESTATDESC(ixfrreqv6, "IPv6 IXFR requested", "IXFRReqv6");
394 395
	SET_ZONESTATDESC(xfrsuccess, "transfer requests succeeded",
			 "XfrSuccess");
396 397 398 399
	SET_ZONESTATDESC(xfrfail, "transfer requests failed", "XfrFail");
	INSIST(i == dns_zonestatscounter_max);

	/* Initialize socket statistics */
400 401
	for (i = 0; i < isc_sockstatscounter_max; i++)
		sockstats_desc[i] = NULL;
402
#if defined(EXTENDED_STATS)
403 404
	for (i = 0; i < isc_sockstatscounter_max; i++)
		sockstats_xmldesc[i] = NULL;
405 406 407 408 409 410
#endif

#define SET_SOCKSTATDESC(counterid, desc, xmldesc) \
	do { \
		set_desc(isc_sockstatscounter_ ## counterid, \
			 isc_sockstatscounter_max, \
Automatic Updater's avatar
Automatic Updater committed
411
			 desc, sockstats_desc, xmldesc, sockstats_xmldesc); \
412 413 414 415
		sockstats_index[i++] = isc_sockstatscounter_ ## counterid; \
	} while (0)

	i = 0;
Automatic Updater's avatar
Automatic Updater committed
416 417
	SET_SOCKSTATDESC(udp4open, "UDP/IPv4 sockets opened", "UDP4Open");
	SET_SOCKSTATDESC(udp6open, "UDP/IPv6 sockets opened", "UDP6Open");
418 419 420
	SET_SOCKSTATDESC(tcp4open, "TCP/IPv4 sockets opened", "TCP4Open");
	SET_SOCKSTATDESC(tcp6open, "TCP/IPv6 sockets opened", "TCP6Open");
	SET_SOCKSTATDESC(unixopen, "Unix domain sockets opened", "UnixOpen");
421
	SET_SOCKSTATDESC(rawopen, "Raw sockets opened", "RawOpen");
422
	SET_SOCKSTATDESC(udp4openfail, "UDP/IPv4 socket open failures",
Automatic Updater's avatar
Automatic Updater committed
423
			 "UDP4OpenFail");
424
	SET_SOCKSTATDESC(udp6openfail, "UDP/IPv6 socket open failures",
Automatic Updater's avatar
Automatic Updater committed
425
			 "UDP6OpenFail");
426 427 428 429 430 431
	SET_SOCKSTATDESC(tcp4openfail, "TCP/IPv4 socket open failures",
			 "TCP4OpenFail");
	SET_SOCKSTATDESC(tcp6openfail, "TCP/IPv6 socket open failures",
			 "TCP6OpenFail");
	SET_SOCKSTATDESC(unixopenfail, "Unix domain socket open failures",
			 "UnixOpenFail");
432 433
	SET_SOCKSTATDESC(rawopenfail, "Raw socket open failures",
			 "RawOpenFail");
434 435 436 437 438 439 440
	SET_SOCKSTATDESC(udp4close, "UDP/IPv4 sockets closed", "UDP4Close");
	SET_SOCKSTATDESC(udp6close, "UDP/IPv6 sockets closed", "UDP6Close");
	SET_SOCKSTATDESC(tcp4close, "TCP/IPv4 sockets closed", "TCP4Close");
	SET_SOCKSTATDESC(tcp6close, "TCP/IPv6 sockets closed", "TCP6Close");
	SET_SOCKSTATDESC(unixclose, "Unix domain sockets closed", "UnixClose");
	SET_SOCKSTATDESC(fdwatchclose, "FDwatch sockets closed",
			 "FDWatchClose");
441
	SET_SOCKSTATDESC(rawclose, "Raw sockets closed", "RawClose");
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
	SET_SOCKSTATDESC(udp4bindfail, "UDP/IPv4 socket bind failures",
			 "UDP4BindFail");
	SET_SOCKSTATDESC(udp6bindfail, "UDP/IPv6 socket bind failures",
			 "UDP6BindFail");
	SET_SOCKSTATDESC(tcp4bindfail, "TCP/IPv4 socket bind failures",
			 "TCP4BindFail");
	SET_SOCKSTATDESC(tcp6bindfail, "TCP/IPv6 socket bind failures",
			 "TCP6BindFail");
	SET_SOCKSTATDESC(unixbindfail, "Unix domain socket bind failures",
			 "UnixBindFail");
	SET_SOCKSTATDESC(fdwatchbindfail, "FDwatch socket bind failures",
			 "FdwatchBindFail");
	SET_SOCKSTATDESC(udp4connectfail, "UDP/IPv4 socket connect failures",
			 "UDP4ConnFail");
	SET_SOCKSTATDESC(udp6connectfail, "UDP/IPv6 socket connect failures",
			 "UDP6ConnFail");
	SET_SOCKSTATDESC(tcp4connectfail, "TCP/IPv4 socket connect failures",
			 "TCP4ConnFail");
	SET_SOCKSTATDESC(tcp6connectfail, "TCP/IPv6 socket connect failures",
			 "TCP6ConnFail");
	SET_SOCKSTATDESC(unixconnectfail, "Unix domain socket connect failures",
			 "UnixConnFail");
	SET_SOCKSTATDESC(fdwatchconnectfail, "FDwatch socket connect failures",
			 "FDwatchConnFail");
	SET_SOCKSTATDESC(udp4connect, "UDP/IPv4 connections established",
			 "UDP4Conn");
	SET_SOCKSTATDESC(udp6connect, "UDP/IPv6 connections established",
			 "UDP6Conn");
	SET_SOCKSTATDESC(tcp4connect, "TCP/IPv4 connections established",
			 "TCP4Conn");
	SET_SOCKSTATDESC(tcp6connect, "TCP/IPv6 connections established",
			 "TCP6Conn");
	SET_SOCKSTATDESC(unixconnect, "Unix domain connections established",
			 "UnixConn");
	SET_SOCKSTATDESC(fdwatchconnect,
			 "FDwatch domain connections established",
			 "FDwatchConn");
	SET_SOCKSTATDESC(tcp4acceptfail, "TCP/IPv4 connection accept failures",
			 "TCP4AcceptFail");
	SET_SOCKSTATDESC(tcp6acceptfail, "TCP/IPv6 connection accept failures",
			 "TCP6AcceptFail");
	SET_SOCKSTATDESC(unixacceptfail,
			 "Unix domain connection accept failures",
			 "UnixAcceptFail");
	SET_SOCKSTATDESC(tcp4accept, "TCP/IPv4 connections accepted",
			 "TCP4Accept");
	SET_SOCKSTATDESC(tcp6accept, "TCP/IPv6 connections accepted",
			 "TCP6Accept");
	SET_SOCKSTATDESC(unixaccept, "Unix domain connections accepted",
			 "UnixAccept");
	SET_SOCKSTATDESC(udp4sendfail, "UDP/IPv4 send errors", "UDP4SendErr");
	SET_SOCKSTATDESC(udp6sendfail, "UDP/IPv6 send errors", "UDP6SendErr");
	SET_SOCKSTATDESC(tcp4sendfail, "TCP/IPv4 send errors", "TCP4SendErr");
	SET_SOCKSTATDESC(tcp6sendfail, "TCP/IPv6 send errors", "TCP6SendErr");
	SET_SOCKSTATDESC(unixsendfail, "Unix domain send errors",
			 "UnixSendErr");
	SET_SOCKSTATDESC(fdwatchsendfail, "FDwatch send errors",
			 "FDwatchSendErr");
	SET_SOCKSTATDESC(udp4recvfail, "UDP/IPv4 recv errors", "UDP4RecvErr");
	SET_SOCKSTATDESC(udp6recvfail, "UDP/IPv6 recv errors", "UDP6RecvErr");
	SET_SOCKSTATDESC(tcp4recvfail, "TCP/IPv4 recv errors", "TCP4RecvErr");
	SET_SOCKSTATDESC(tcp6recvfail, "TCP/IPv6 recv errors", "TCP6RecvErr");
	SET_SOCKSTATDESC(unixrecvfail, "Unix domain recv errors",
			 "UnixRecvErr");
	SET_SOCKSTATDESC(fdwatchrecvfail, "FDwatch recv errors",
			 "FDwatchRecvErr");
508
	SET_SOCKSTATDESC(rawrecvfail, "Raw recv errors", "RawRecvErr");
509 510 511 512 513 514
	SET_SOCKSTATDESC(udp4active, "UDP/IPv4 sockets active", "UDP4Active");
	SET_SOCKSTATDESC(udp6active, "UDP/IPv6 sockets active", "UDP6Active");
	SET_SOCKSTATDESC(tcp4active, "TCP/IPv4 sockets active", "TCP4Active");
	SET_SOCKSTATDESC(tcp6active, "TCP/IPv6 sockets active", "TCP6Active");
	SET_SOCKSTATDESC(unixactive, "Unix domain sockets active",
			 "UnixActive");
515
	SET_SOCKSTATDESC(rawactive, "Raw sockets active", "RawActive");
516
	INSIST(i == isc_sockstatscounter_max);
517

518 519 520
	/* Initialize DNSSEC statistics */
	for (i = 0; i < dns_dnssecstats_max; i++)
		dnssecstats_desc[i] = NULL;
521
#if defined(EXTENDED_STATS)
522 523 524 525 526 527 528 529
	for (i = 0; i < dns_dnssecstats_max; i++)
		dnssecstats_xmldesc[i] = NULL;
#endif

#define SET_DNSSECSTATDESC(counterid, desc, xmldesc) \
	do { \
		set_desc(dns_dnssecstats_ ## counterid, \
			 dns_dnssecstats_max, \
530
			 desc, dnssecstats_desc, \
531 532 533 534 535 536 537 538 539 540 541 542 543 544
			 xmldesc, dnssecstats_xmldesc); \
		dnssecstats_index[i++] = dns_dnssecstats_ ## counterid; \
	} while (0)

	i = 0;
	SET_DNSSECSTATDESC(asis, "dnssec validation success with signer "
			   "\"as is\"", "DNSSECasis");
	SET_DNSSECSTATDESC(downcase, "dnssec validation success with signer "
			   "lower cased", "DNSSECdowncase");
	SET_DNSSECSTATDESC(wildcard, "dnssec validation of wildcard signature",
			   "DNSSECwild");
	SET_DNSSECSTATDESC(fail, "dnssec validation failures", "DNSSECfail");
	INSIST(i == dns_dnssecstats_max);

545 546 547 548 549
	/* Sanity check */
	for (i = 0; i < dns_nsstatscounter_max; i++)
		INSIST(nsstats_desc[i] != NULL);
	for (i = 0; i < dns_resstatscounter_max; i++)
		INSIST(resstats_desc[i] != NULL);
550 551
	for (i = 0; i < dns_adbstats_max; i++)
		INSIST(adbstats_desc[i] != NULL);
552 553
	for (i = 0; i < dns_zonestatscounter_max; i++)
		INSIST(zonestats_desc[i] != NULL);
554 555
	for (i = 0; i < isc_sockstatscounter_max; i++)
		INSIST(sockstats_desc[i] != NULL);
556 557
	for (i = 0; i < dns_dnssecstats_max; i++)
		INSIST(dnssecstats_desc[i] != NULL);
558
#if defined(EXTENDED_STATS)
559 560 561 562
	for (i = 0; i < dns_nsstatscounter_max; i++)
		INSIST(nsstats_xmldesc[i] != NULL);
	for (i = 0; i < dns_resstatscounter_max; i++)
		INSIST(resstats_xmldesc[i] != NULL);
563 564
	for (i = 0; i < dns_adbstats_max; i++)
		INSIST(adbstats_xmldesc[i] != NULL);
565 566
	for (i = 0; i < dns_zonestatscounter_max; i++)
		INSIST(zonestats_xmldesc[i] != NULL);
567 568
	for (i = 0; i < isc_sockstatscounter_max; i++)
		INSIST(sockstats_xmldesc[i] != NULL);
569 570
	for (i = 0; i < dns_dnssecstats_max; i++)
		INSIST(dnssecstats_xmldesc[i] != NULL);
571
#endif
Evan Hunt's avatar
Evan Hunt committed
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930

	/* Initialize traffic size statistics */
	for (i = 0; i < dns_sizecounter_in_max; i++) {
		udpinsizestats_desc[i] = NULL;
		tcpinsizestats_desc[i] = NULL;
#if defined(EXTENDED_STATS)
		udpinsizestats_xmldesc[i] = NULL;
		tcpinsizestats_xmldesc[i] = NULL;
#endif
	}
	for (i = 0; i < dns_sizecounter_out_max; i++) {
		udpoutsizestats_desc[i] = NULL;
		tcpoutsizestats_desc[i] = NULL;
#if defined(EXTENDED_STATS)
		udpoutsizestats_xmldesc[i] = NULL;
		tcpoutsizestats_xmldesc[i] = NULL;
#endif
	}

#define SET_SIZESTATDESC(counterid, desc, xmldesc, inout) \
	do { \
		set_desc(dns_sizecounter_ ## inout ## _ ## counterid, \
			 dns_sizecounter_ ## inout ## _max, \
			 desc, udp ## inout ## sizestats_desc, \
			 xmldesc, udp ## inout ## sizestats_xmldesc); \
		set_desc(dns_sizecounter_ ## inout ##  _ ## counterid, \
			 dns_sizecounter_ ## inout ## _max, \
			 desc, tcp ## inout ## sizestats_desc, \
			 xmldesc, tcp ## inout ## sizestats_xmldesc); \
		udp ## inout ## sizestats_index[i] = dns_sizecounter_ ## inout ## _ ## counterid; \
		tcp ## inout ## sizestats_index[i] = dns_sizecounter_ ## inout ## _ ## counterid; \
		i++; \
	} while (0)

	i = 0;
	SET_SIZESTATDESC(0, "requests received 0-15 bytes", "0-15", in);
	SET_SIZESTATDESC(16, "requests received 16-31 bytes", "16-31", in);
	SET_SIZESTATDESC(32, "requests received 32-47 bytes", "32-47", in);
	SET_SIZESTATDESC(48, "requests received 48-63 bytes", "48-63", in);
	SET_SIZESTATDESC(64, "requests received 64-79 bytes", "64-79", in);
	SET_SIZESTATDESC(80, "requests received 80-95 bytes", "80-95", in);
	SET_SIZESTATDESC(96, "requests received 96-111 bytes", "96-111", in);
	SET_SIZESTATDESC(112, "requests received 112-127 bytes", "112-127", in);
	SET_SIZESTATDESC(128, "requests received 128-143 bytes", "128-143", in);
	SET_SIZESTATDESC(144, "requests received 144-159 bytes", "144-159", in);
	SET_SIZESTATDESC(160, "requests received 160-175 bytes", "160-175", in);
	SET_SIZESTATDESC(176, "requests received 176-191 bytes", "176-191", in);
	SET_SIZESTATDESC(192, "requests received 192-207 bytes", "192-207", in);
	SET_SIZESTATDESC(208, "requests received 208-223 bytes", "208-223", in);
	SET_SIZESTATDESC(224, "requests received 224-239 bytes", "224-239", in);
	SET_SIZESTATDESC(240, "requests received 240-255 bytes", "240-255", in);
	SET_SIZESTATDESC(256, "requests received 256-271 bytes", "256-271", in);
	SET_SIZESTATDESC(272, "requests received 272-287 bytes", "272-287", in);
	SET_SIZESTATDESC(288, "requests received 288+ bytes", "288+", in);
	INSIST(i == dns_sizecounter_in_max);

	i = 0;
	SET_SIZESTATDESC(0, "responses sent 0-15 bytes", "0-15", out);
	SET_SIZESTATDESC(16, "responses sent 16-31 bytes", "16-31", out);
	SET_SIZESTATDESC(32, "responses sent 32-47 bytes", "32-47", out);
	SET_SIZESTATDESC(48, "responses sent 48-63 bytes", "48-63", out);
	SET_SIZESTATDESC(64, "responses sent 64-79 bytes", "64-79", out);
	SET_SIZESTATDESC(80, "responses sent 80-95 bytes", "80-95", out);
	SET_SIZESTATDESC(96, "responses sent 96-111 bytes", "96-111", out);
	SET_SIZESTATDESC(112, "responses sent 112-127 bytes", "112-127", out);
	SET_SIZESTATDESC(128, "responses sent 128-143 bytes", "128-143", out);
	SET_SIZESTATDESC(144, "responses sent 144-159 bytes", "144-159", out);
	SET_SIZESTATDESC(160, "responses sent 160-175 bytes", "160-175", out);
	SET_SIZESTATDESC(176, "responses sent 176-191 bytes", "176-191", out);
	SET_SIZESTATDESC(192, "responses sent 192-207 bytes", "192-207", out);
	SET_SIZESTATDESC(208, "responses sent 208-223 bytes", "208-223", out);
	SET_SIZESTATDESC(224, "responses sent 224-239 bytes", "224-239", out);
	SET_SIZESTATDESC(240, "responses sent 240-255 bytes", "240-255", out);
	SET_SIZESTATDESC(256, "responses sent 256-271 bytes", "256-271", out);
	SET_SIZESTATDESC(272, "responses sent 272-287 bytes", "272-287", out);
	SET_SIZESTATDESC(288, "responses sent 288-303 bytes", "288-303", out);
	SET_SIZESTATDESC(304, "responses sent 304-319 bytes", "304-319", out);
	SET_SIZESTATDESC(320, "responses sent 320-335 bytes", "320-335", out);
	SET_SIZESTATDESC(336, "responses sent 336-351 bytes", "336-351", out);
	SET_SIZESTATDESC(352, "responses sent 352-367 bytes", "352-367", out);
	SET_SIZESTATDESC(368, "responses sent 368-383 bytes", "368-383", out);
	SET_SIZESTATDESC(384, "responses sent 384-399 bytes", "384-399", out);
	SET_SIZESTATDESC(400, "responses sent 400-415 bytes", "400-415", out);
	SET_SIZESTATDESC(416, "responses sent 416-431 bytes", "416-431", out);
	SET_SIZESTATDESC(432, "responses sent 432-447 bytes", "432-447", out);
	SET_SIZESTATDESC(448, "responses sent 448-463 bytes", "448-463", out);
	SET_SIZESTATDESC(464, "responses sent 464-479 bytes", "464-479", out);
	SET_SIZESTATDESC(480, "responses sent 480-495 bytes", "480-495", out);
	SET_SIZESTATDESC(496, "responses sent 496-511 bytes", "496-511", out);
	SET_SIZESTATDESC(512, "responses sent 512-527 bytes", "512-527", out);
	SET_SIZESTATDESC(528, "responses sent 528-543 bytes", "528-543", out);
	SET_SIZESTATDESC(544, "responses sent 544-559 bytes", "544-559", out);
	SET_SIZESTATDESC(560, "responses sent 560-575 bytes", "560-575", out);
	SET_SIZESTATDESC(576, "responses sent 576-591 bytes", "576-591", out);
	SET_SIZESTATDESC(592, "responses sent 592-607 bytes", "592-607", out);
	SET_SIZESTATDESC(608, "responses sent 608-623 bytes", "608-623", out);
	SET_SIZESTATDESC(624, "responses sent 624-639 bytes", "624-639", out);
	SET_SIZESTATDESC(640, "responses sent 640-655 bytes", "640-655", out);
	SET_SIZESTATDESC(656, "responses sent 656-671 bytes", "656-671", out);
	SET_SIZESTATDESC(672, "responses sent 672-687 bytes", "672-687", out);
	SET_SIZESTATDESC(688, "responses sent 688-703 bytes", "688-703", out);
	SET_SIZESTATDESC(704, "responses sent 704-719 bytes", "704-719", out);
	SET_SIZESTATDESC(720, "responses sent 720-735 bytes", "720-735", out);
	SET_SIZESTATDESC(736, "responses sent 736-751 bytes", "736-751", out);
	SET_SIZESTATDESC(752, "responses sent 752-767 bytes", "752-767", out);
	SET_SIZESTATDESC(768, "responses sent 768-783 bytes", "768-783", out);
	SET_SIZESTATDESC(784, "responses sent 784-799 bytes", "784-799", out);
	SET_SIZESTATDESC(800, "responses sent 800-815 bytes", "800-815", out);
	SET_SIZESTATDESC(816, "responses sent 816-831 bytes", "816-831", out);
	SET_SIZESTATDESC(832, "responses sent 832-847 bytes", "832-847", out);
	SET_SIZESTATDESC(848, "responses sent 848-863 bytes", "848-863", out);
	SET_SIZESTATDESC(864, "responses sent 864-879 bytes", "864-879", out);
	SET_SIZESTATDESC(880, "responses sent 880-895 bytes", "880-895", out);
	SET_SIZESTATDESC(896, "responses sent 896-911 bytes", "896-911", out);
	SET_SIZESTATDESC(912, "responses sent 912-927 bytes", "912-927", out);
	SET_SIZESTATDESC(928, "responses sent 928-943 bytes", "928-943", out);
	SET_SIZESTATDESC(944, "responses sent 944-959 bytes", "944-959", out);
	SET_SIZESTATDESC(960, "responses sent 960-975 bytes", "960-975", out);
	SET_SIZESTATDESC(976, "responses sent 976-991 bytes", "976-991", out);
	SET_SIZESTATDESC(992, "responses sent 992-1007 bytes", "992-1007", out);
	SET_SIZESTATDESC(1008, "responses sent 1008-1023 bytes", "1008-1023", out);
	SET_SIZESTATDESC(1024, "responses sent 1024-1039 bytes", "1024-1039", out);
	SET_SIZESTATDESC(1040, "responses sent 1040-1055 bytes", "1040-1055", out);
	SET_SIZESTATDESC(1056, "responses sent 1056-1071 bytes", "1056-1071", out);
	SET_SIZESTATDESC(1072, "responses sent 1072-1087 bytes", "1072-1087", out);
	SET_SIZESTATDESC(1088, "responses sent 1088-1103 bytes", "1088-1103", out);
	SET_SIZESTATDESC(1104, "responses sent 1104-1119 bytes", "1104-1119", out);
	SET_SIZESTATDESC(1120, "responses sent 1120-1135 bytes", "1120-1135", out);
	SET_SIZESTATDESC(1136, "responses sent 1136-1151 bytes", "1136-1151", out);
	SET_SIZESTATDESC(1152, "responses sent 1152-1167 bytes", "1152-1167", out);
	SET_SIZESTATDESC(1168, "responses sent 1168-1183 bytes", "1168-1183", out);
	SET_SIZESTATDESC(1184, "responses sent 1184-1199 bytes", "1184-1199", out);
	SET_SIZESTATDESC(1200, "responses sent 1200-1215 bytes", "1200-1215", out);
	SET_SIZESTATDESC(1216, "responses sent 1216-1231 bytes", "1216-1231", out);
	SET_SIZESTATDESC(1232, "responses sent 1232-1247 bytes", "1232-1247", out);
	SET_SIZESTATDESC(1248, "responses sent 1248-1263 bytes", "1248-1263", out);
	SET_SIZESTATDESC(1264, "responses sent 1264-1279 bytes", "1264-1279", out);
	SET_SIZESTATDESC(1280, "responses sent 1280-1295 bytes", "1280-1295", out);
	SET_SIZESTATDESC(1296, "responses sent 1296-1311 bytes", "1296-1311", out);
	SET_SIZESTATDESC(1312, "responses sent 1312-1327 bytes", "1312-1327", out);
	SET_SIZESTATDESC(1328, "responses sent 1328-1343 bytes", "1328-1343", out);
	SET_SIZESTATDESC(1344, "responses sent 1344-1359 bytes", "1344-1359", out);
	SET_SIZESTATDESC(1360, "responses sent 1360-1375 bytes", "1360-1375", out);
	SET_SIZESTATDESC(1376, "responses sent 1376-1391 bytes", "1376-1391", out);
	SET_SIZESTATDESC(1392, "responses sent 1392-1407 bytes", "1392-1407", out);
	SET_SIZESTATDESC(1408, "responses sent 1408-1423 bytes", "1408-1423", out);
	SET_SIZESTATDESC(1424, "responses sent 1424-1439 bytes", "1424-1439", out);
	SET_SIZESTATDESC(1440, "responses sent 1440-1455 bytes", "1440-1455", out);
	SET_SIZESTATDESC(1456, "responses sent 1456-1471 bytes", "1456-1471", out);
	SET_SIZESTATDESC(1472, "responses sent 1472-1487 bytes", "1472-1487", out);
	SET_SIZESTATDESC(1488, "responses sent 1488-1503 bytes", "1488-1503", out);
	SET_SIZESTATDESC(1504, "responses sent 1504-1519 bytes", "1504-1519", out);
	SET_SIZESTATDESC(1520, "responses sent 1520-1535 bytes", "1520-1535", out);
	SET_SIZESTATDESC(1536, "responses sent 1536-1551 bytes", "1536-1551", out);
	SET_SIZESTATDESC(1552, "responses sent 1552-1567 bytes", "1552-1567", out);
	SET_SIZESTATDESC(1568, "responses sent 1568-1583 bytes", "1568-1583", out);
	SET_SIZESTATDESC(1584, "responses sent 1584-1599 bytes", "1584-1599", out);
	SET_SIZESTATDESC(1600, "responses sent 1600-1615 bytes", "1600-1615", out);
	SET_SIZESTATDESC(1616, "responses sent 1616-1631 bytes", "1616-1631", out);
	SET_SIZESTATDESC(1632, "responses sent 1632-1647 bytes", "1632-1647", out);
	SET_SIZESTATDESC(1648, "responses sent 1648-1663 bytes", "1648-1663", out);
	SET_SIZESTATDESC(1664, "responses sent 1664-1679 bytes", "1664-1679", out);
	SET_SIZESTATDESC(1680, "responses sent 1680-1695 bytes", "1680-1695", out);
	SET_SIZESTATDESC(1696, "responses sent 1696-1711 bytes", "1696-1711", out);
	SET_SIZESTATDESC(1712, "responses sent 1712-1727 bytes", "1712-1727", out);
	SET_SIZESTATDESC(1728, "responses sent 1728-1743 bytes", "1728-1743", out);
	SET_SIZESTATDESC(1744, "responses sent 1744-1759 bytes", "1744-1759", out);
	SET_SIZESTATDESC(1760, "responses sent 1760-1775 bytes", "1760-1775", out);
	SET_SIZESTATDESC(1776, "responses sent 1776-1791 bytes", "1776-1791", out);
	SET_SIZESTATDESC(1792, "responses sent 1792-1807 bytes", "1792-1807", out);
	SET_SIZESTATDESC(1808, "responses sent 1808-1823 bytes", "1808-1823", out);
	SET_SIZESTATDESC(1824, "responses sent 1824-1839 bytes", "1824-1839", out);
	SET_SIZESTATDESC(1840, "responses sent 1840-1855 bytes", "1840-1855", out);
	SET_SIZESTATDESC(1856, "responses sent 1856-1871 bytes", "1856-1871", out);
	SET_SIZESTATDESC(1872, "responses sent 1872-1887 bytes", "1872-1887", out);
	SET_SIZESTATDESC(1888, "responses sent 1888-1903 bytes", "1888-1903", out);
	SET_SIZESTATDESC(1904, "responses sent 1904-1919 bytes", "1904-1919", out);
	SET_SIZESTATDESC(1920, "responses sent 1920-1935 bytes", "1920-1935", out);
	SET_SIZESTATDESC(1936, "responses sent 1936-1951 bytes", "1936-1951", out);
	SET_SIZESTATDESC(1952, "responses sent 1952-1967 bytes", "1952-1967", out);
	SET_SIZESTATDESC(1968, "responses sent 1968-1983 bytes", "1968-1983", out);
	SET_SIZESTATDESC(1984, "responses sent 1984-1999 bytes", "1984-1999", out);
	SET_SIZESTATDESC(2000, "responses sent 2000-2015 bytes", "2000-2015", out);
	SET_SIZESTATDESC(2016, "responses sent 2016-2031 bytes", "2016-2031", out);
	SET_SIZESTATDESC(2032, "responses sent 2032-2047 bytes", "2032-2047", out);
	SET_SIZESTATDESC(2048, "responses sent 2048-2063 bytes", "2048-2063", out);
	SET_SIZESTATDESC(2064, "responses sent 2064-2079 bytes", "2064-2079", out);
	SET_SIZESTATDESC(2080, "responses sent 2080-2095 bytes", "2080-2095", out);
	SET_SIZESTATDESC(2096, "responses sent 2096-2111 bytes", "2096-2111", out);
	SET_SIZESTATDESC(2112, "responses sent 2112-2127 bytes", "2112-2127", out);
	SET_SIZESTATDESC(2128, "responses sent 2128-2143 bytes", "2128-2143", out);
	SET_SIZESTATDESC(2144, "responses sent 2144-2159 bytes", "2144-2159", out);
	SET_SIZESTATDESC(2160, "responses sent 2160-2175 bytes", "2160-2175", out);
	SET_SIZESTATDESC(2176, "responses sent 2176-2191 bytes", "2176-2191", out);
	SET_SIZESTATDESC(2192, "responses sent 2192-2207 bytes", "2192-2207", out);
	SET_SIZESTATDESC(2208, "responses sent 2208-2223 bytes", "2208-2223", out);
	SET_SIZESTATDESC(2224, "responses sent 2224-2239 bytes", "2224-2239", out);
	SET_SIZESTATDESC(2240, "responses sent 2240-2255 bytes", "2240-2255", out);
	SET_SIZESTATDESC(2256, "responses sent 2256-2271 bytes", "2256-2271", out);
	SET_SIZESTATDESC(2272, "responses sent 2272-2287 bytes", "2272-2287", out);
	SET_SIZESTATDESC(2288, "responses sent 2288-2303 bytes", "2288-2303", out);
	SET_SIZESTATDESC(2304, "responses sent 2304-2319 bytes", "2304-2319", out);
	SET_SIZESTATDESC(2320, "responses sent 2320-2335 bytes", "2320-2335", out);
	SET_SIZESTATDESC(2336, "responses sent 2336-2351 bytes", "2336-2351", out);
	SET_SIZESTATDESC(2352, "responses sent 2352-2367 bytes", "2352-2367", out);
	SET_SIZESTATDESC(2368, "responses sent 2368-2383 bytes", "2368-2383", out);
	SET_SIZESTATDESC(2384, "responses sent 2384-2399 bytes", "2384-2399", out);
	SET_SIZESTATDESC(2400, "responses sent 2400-2415 bytes", "2400-2415", out);
	SET_SIZESTATDESC(2416, "responses sent 2416-2431 bytes", "2416-2431", out);
	SET_SIZESTATDESC(2432, "responses sent 2432-2447 bytes", "2432-2447", out);
	SET_SIZESTATDESC(2448, "responses sent 2448-2463 bytes", "2448-2463", out);
	SET_SIZESTATDESC(2464, "responses sent 2464-2479 bytes", "2464-2479", out);
	SET_SIZESTATDESC(2480, "responses sent 2480-2495 bytes", "2480-2495", out);
	SET_SIZESTATDESC(2496, "responses sent 2496-2511 bytes", "2496-2511", out);
	SET_SIZESTATDESC(2512, "responses sent 2512-2527 bytes", "2512-2527", out);
	SET_SIZESTATDESC(2528, "responses sent 2528-2543 bytes", "2528-2543", out);
	SET_SIZESTATDESC(2544, "responses sent 2544-2559 bytes", "2544-2559", out);
	SET_SIZESTATDESC(2560, "responses sent 2560-2575 bytes", "2560-2575", out);
	SET_SIZESTATDESC(2576, "responses sent 2576-2591 bytes", "2576-2591", out);
	SET_SIZESTATDESC(2592, "responses sent 2592-2607 bytes", "2592-2607", out);
	SET_SIZESTATDESC(2608, "responses sent 2608-2623 bytes", "2608-2623", out);
	SET_SIZESTATDESC(2624, "responses sent 2624-2639 bytes", "2624-2639", out);
	SET_SIZESTATDESC(2640, "responses sent 2640-2655 bytes", "2640-2655", out);
	SET_SIZESTATDESC(2656, "responses sent 2656-2671 bytes", "2656-2671", out);
	SET_SIZESTATDESC(2672, "responses sent 2672-2687 bytes", "2672-2687", out);
	SET_SIZESTATDESC(2688, "responses sent 2688-2703 bytes", "2688-2703", out);
	SET_SIZESTATDESC(2704, "responses sent 2704-2719 bytes", "2704-2719", out);
	SET_SIZESTATDESC(2720, "responses sent 2720-2735 bytes", "2720-2735", out);
	SET_SIZESTATDESC(2736, "responses sent 2736-2751 bytes", "2736-2751", out);
	SET_SIZESTATDESC(2752, "responses sent 2752-2767 bytes", "2752-2767", out);
	SET_SIZESTATDESC(2768, "responses sent 2768-2783 bytes", "2768-2783", out);
	SET_SIZESTATDESC(2784, "responses sent 2784-2799 bytes", "2784-2799", out);
	SET_SIZESTATDESC(2800, "responses sent 2800-2815 bytes", "2800-2815", out);
	SET_SIZESTATDESC(2816, "responses sent 2816-2831 bytes", "2816-2831", out);
	SET_SIZESTATDESC(2832, "responses sent 2832-2847 bytes", "2832-2847", out);
	SET_SIZESTATDESC(2848, "responses sent 2848-2863 bytes", "2848-2863", out);
	SET_SIZESTATDESC(2864, "responses sent 2864-2879 bytes", "2864-2879", out);
	SET_SIZESTATDESC(2880, "responses sent 2880-2895 bytes", "2880-2895", out);
	SET_SIZESTATDESC(2896, "responses sent 2896-2911 bytes", "2896-2911", out);
	SET_SIZESTATDESC(2912, "responses sent 2912-2927 bytes", "2912-2927", out);
	SET_SIZESTATDESC(2928, "responses sent 2928-2943 bytes", "2928-2943", out);
	SET_SIZESTATDESC(2944, "responses sent 2944-2959 bytes", "2944-2959", out);
	SET_SIZESTATDESC(2960, "responses sent 2960-2975 bytes", "2960-2975", out);
	SET_SIZESTATDESC(2976, "responses sent 2976-2991 bytes", "2976-2991", out);
	SET_SIZESTATDESC(2992, "responses sent 2992-3007 bytes", "2992-3007", out);
	SET_SIZESTATDESC(3008, "responses sent 3008-3023 bytes", "3008-3023", out);
	SET_SIZESTATDESC(3024, "responses sent 3024-3039 bytes", "3024-3039", out);
	SET_SIZESTATDESC(3040, "responses sent 3040-3055 bytes", "3040-3055", out);
	SET_SIZESTATDESC(3056, "responses sent 3056-3071 bytes", "3056-3071", out);
	SET_SIZESTATDESC(3072, "responses sent 3072-3087 bytes", "3072-3087", out);
	SET_SIZESTATDESC(3088, "responses sent 3088-3103 bytes", "3088-3103", out);
	SET_SIZESTATDESC(3104, "responses sent 3104-3119 bytes", "3104-3119", out);
	SET_SIZESTATDESC(3120, "responses sent 3120-3135 bytes", "3120-3135", out);
	SET_SIZESTATDESC(3136, "responses sent 3136-3151 bytes", "3136-3151", out);
	SET_SIZESTATDESC(3152, "responses sent 3152-3167 bytes", "3152-3167", out);
	SET_SIZESTATDESC(3168, "responses sent 3168-3183 bytes", "3168-3183", out);
	SET_SIZESTATDESC(3184, "responses sent 3184-3199 bytes", "3184-3199", out);
	SET_SIZESTATDESC(3200, "responses sent 3200-3215 bytes", "3200-3215", out);
	SET_SIZESTATDESC(3216, "responses sent 3216-3231 bytes", "3216-3231", out);
	SET_SIZESTATDESC(3232, "responses sent 3232-3247 bytes", "3232-3247", out);
	SET_SIZESTATDESC(3248, "responses sent 3248-3263 bytes", "3248-3263", out);
	SET_SIZESTATDESC(3264, "responses sent 3264-3279 bytes", "3264-3279", out);
	SET_SIZESTATDESC(3280, "responses sent 3280-3295 bytes", "3280-3295", out);
	SET_SIZESTATDESC(3296, "responses sent 3296-3311 bytes", "3296-3311", out);
	SET_SIZESTATDESC(3312, "responses sent 3312-3327 bytes", "3312-3327", out);
	SET_SIZESTATDESC(3328, "responses sent 3328-3343 bytes", "3328-3343", out);
	SET_SIZESTATDESC(3344, "responses sent 3344-3359 bytes", "3344-3359", out);
	SET_SIZESTATDESC(3360, "responses sent 3360-3375 bytes", "3360-3375", out);
	SET_SIZESTATDESC(3376, "responses sent 3376-3391 bytes", "3376-3391", out);
	SET_SIZESTATDESC(3392, "responses sent 3392-3407 bytes", "3392-3407", out);
	SET_SIZESTATDESC(3408, "responses sent 3408-3423 bytes", "3408-3423", out);
	SET_SIZESTATDESC(3424, "responses sent 3424-3439 bytes", "3424-3439", out);
	SET_SIZESTATDESC(3440, "responses sent 3440-3455 bytes", "3440-3455", out);
	SET_SIZESTATDESC(3456, "responses sent 3456-3471 bytes", "3456-3471", out);
	SET_SIZESTATDESC(3472, "responses sent 3472-3487 bytes", "3472-3487", out);
	SET_SIZESTATDESC(3488, "responses sent 3488-3503 bytes", "3488-3503", out);
	SET_SIZESTATDESC(3504, "responses sent 3504-3519 bytes", "3504-3519", out);
	SET_SIZESTATDESC(3520, "responses sent 3520-3535 bytes", "3520-3535", out);
	SET_SIZESTATDESC(3536, "responses sent 3536-3551 bytes", "3536-3551", out);
	SET_SIZESTATDESC(3552, "responses sent 3552-3567 bytes", "3552-3567", out);
	SET_SIZESTATDESC(3568, "responses sent 3568-3583 bytes", "3568-3583", out);
	SET_SIZESTATDESC(3584, "responses sent 3584-3599 bytes", "3584-3599", out);
	SET_SIZESTATDESC(3600, "responses sent 3600-3615 bytes", "3600-3615", out);
	SET_SIZESTATDESC(3616, "responses sent 3616-3631 bytes", "3616-3631", out);
	SET_SIZESTATDESC(3632, "responses sent 3632-3647 bytes", "3632-3647", out);
	SET_SIZESTATDESC(3648, "responses sent 3648-3663 bytes", "3648-3663", out);
	SET_SIZESTATDESC(3664, "responses sent 3664-3679 bytes", "3664-3679", out);
	SET_SIZESTATDESC(3680, "responses sent 3680-3695 bytes", "3680-3695", out);
	SET_SIZESTATDESC(3696, "responses sent 3696-3711 bytes", "3696-3711", out);
	SET_SIZESTATDESC(3712, "responses sent 3712-3727 bytes", "3712-3727", out);
	SET_SIZESTATDESC(3728, "responses sent 3728-3743 bytes", "3728-3743", out);
	SET_SIZESTATDESC(3744, "responses sent 3744-3759 bytes", "3744-3759", out);
	SET_SIZESTATDESC(3760, "responses sent 3760-3775 bytes", "3760-3775", out);
	SET_SIZESTATDESC(3776, "responses sent 3776-3791 bytes", "3776-3791", out);
	SET_SIZESTATDESC(3792, "responses sent 3792-3807 bytes", "3792-3807", out);
	SET_SIZESTATDESC(3808, "responses sent 3808-3823 bytes", "3808-3823", out);
	SET_SIZESTATDESC(3824, "responses sent 3824-3839 bytes", "3824-3839", out);
	SET_SIZESTATDESC(3840, "responses sent 3840-3855 bytes", "3840-3855", out);
	SET_SIZESTATDESC(3856, "responses sent 3856-3871 bytes", "3856-3871", out);
	SET_SIZESTATDESC(3872, "responses sent 3872-3887 bytes", "3872-3887", out);
	SET_SIZESTATDESC(3888, "responses sent 3888-3903 bytes", "3888-3903", out);
	SET_SIZESTATDESC(3904, "responses sent 3904-3919 bytes", "3904-3919", out);
	SET_SIZESTATDESC(3920, "responses sent 3920-3935 bytes", "3920-3935", out);
	SET_SIZESTATDESC(3936, "responses sent 3936-3951 bytes", "3936-3951", out);
	SET_SIZESTATDESC(3952, "responses sent 3952-3967 bytes", "3952-3967", out);
	SET_SIZESTATDESC(3968, "responses sent 3968-3983 bytes", "3968-3983", out);
	SET_SIZESTATDESC(3984, "responses sent 3984-3999 bytes", "3984-3999", out);
	SET_SIZESTATDESC(4000, "responses sent 4000-4015 bytes", "4000-4015", out);
	SET_SIZESTATDESC(4016, "responses sent 4016-4031 bytes", "4016-4031", out);
	SET_SIZESTATDESC(4032, "responses sent 4032-4047 bytes", "4032-4047", out);
	SET_SIZESTATDESC(4048, "responses sent 4048-4063 bytes", "4048-4063", out);
	SET_SIZESTATDESC(4064, "responses sent 4064-4079 bytes", "4064-4079", out);
	SET_SIZESTATDESC(4080, "responses sent 4080-4095 bytes", "4080-4095", out);
	SET_SIZESTATDESC(4096, "responses sent 4096+ bytes", "4096+", out);
	INSIST(i == dns_sizecounter_out_max);

	/* Sanity check */
	for (i = 0; i < dns_nsstatscounter_max; i++)
		INSIST(nsstats_desc[i] != NULL);
	for (i = 0; i < dns_resstatscounter_max; i++)
		INSIST(resstats_desc[i] != NULL);
	for (i = 0; i < dns_adbstats_max; i++)
		INSIST(adbstats_desc[i] != NULL);
	for (i = 0; i < dns_zonestatscounter_max; i++)
		INSIST(zonestats_desc[i] != NULL);
	for (i = 0; i < isc_sockstatscounter_max; i++)
		INSIST(sockstats_desc[i] != NULL);
	for (i = 0; i < dns_dnssecstats_max; i++)
		INSIST(dnssecstats_desc[i] != NULL);
	for (i = 0; i < dns_sizecounter_in_max; i++) {
		INSIST(udpinsizestats_desc[i] != NULL);
		INSIST(tcpinsizestats_desc[i] != NULL);
	}
	for (i = 0; i < dns_sizecounter_out_max; i++) {
		INSIST(udpoutsizestats_desc[i] != NULL);
		INSIST(tcpoutsizestats_desc[i] != NULL);
	}
#if defined(EXTENDED_STATS)
	for (i = 0; i < dns_nsstatscounter_max; i++)
		INSIST(nsstats_xmldesc[i] != NULL);
	for (i = 0; i < dns_resstatscounter_max; i++)
		INSIST(resstats_xmldesc[i] != NULL);
	for (i = 0; i < dns_adbstats_max; i++)
		INSIST(adbstats_xmldesc[i] != NULL);
	for (i = 0; i < dns_zonestatscounter_max; i++)
		INSIST(zonestats_xmldesc[i] != NULL);
	for (i = 0; i < isc_sockstatscounter_max; i++)
		INSIST(sockstats_xmldesc[i] != NULL);
	for (i = 0; i < dns_dnssecstats_max; i++)
		INSIST(dnssecstats_xmldesc[i] != NULL);
	for (i = 0; i < dns_sizecounter_in_max; i++) {
		INSIST(udpinsizestats_xmldesc[i] != NULL);
		INSIST(tcpinsizestats_xmldesc[i] != NULL);
	}
	for (i = 0; i < dns_sizecounter_out_max; i++) {
		INSIST(udpoutsizestats_xmldesc[i] != NULL);
		INSIST(tcpoutsizestats_xmldesc[i] != NULL);
	}
#endif
931 932 933 934 935
}

/*%
 * Dump callback functions.
 */
936
static void
937
generalstat_dump(isc_statscounter_t counter, isc_uint64_t val, void *arg) {
938
	stats_dumparg_t *dumparg = arg;
939 940 941 942 943

	REQUIRE(counter < dumparg->ncounters);
	dumparg->countervalues[counter] = val;
}

944
static isc_result_t
945
dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg,
946 947 948
	      const char *category, const char **desc, int ncounters,
	      int *indices, isc_uint64_t *values, int options)
{
949
	int i, idx;
950 951
	isc_uint64_t value;
	stats_dumparg_t dumparg;
952 953 954
	FILE *fp;
#ifdef HAVE_LIBXML2
	xmlTextWriterPtr writer;
955
	int xmlrc;
956
#endif
957 958 959
#ifdef HAVE_JSON
	json_object *job, *cat, *counter;
#endif
960

961
#if !defined(EXTENDED_STATS)
962 963 964
	UNUSED(category);
#endif

965 966 967 968
	dumparg.type = type;
	dumparg.ncounters = ncounters;
	dumparg.counterindices = indices;
	dumparg.countervalues = values;
969

970 971
	memset(values, 0, sizeof(values[0]) * ncounters);
	isc_stats_dump(stats, generalstat_dump, &dumparg, options);
972

973 974 975 976 977 978 979 980 981 982 983 984
#ifdef HAVE_JSON
	cat = job = (json_object *) arg;
	if (ncounters > 0 && type == isc_statsformat_json) {
		if (category != NULL) {
			cat = json_object_new_object();
			if (cat == NULL)
				return (ISC_R_NOMEMORY);
			json_object_object_add(job, category, cat);
		}
	}
#endif

985
	for (i = 0; i < ncounters; i++) {
986 987
		idx = indices[i];
		value = values[idx];
988 989 990 991 992

		if (value == 0 && (options & ISC_STATSDUMP_VERBOSE) == 0)
			continue;

		switch (dumparg.type) {
993
		case isc_statsformat_file:
994 995
			fp = arg;
			fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n",
996
				value, desc[idx]);
997
			break;
998
		case isc_statsformat_xml:
999
#ifdef HAVE_LIBXML2
1000
			writer = (xmlTextWriterPtr) arg;
1001 1002

			if (category != NULL) {
1003
				/* <NameOfCategory> */
1004 1005 1006
				TRY0(xmlTextWriterStartElement(writer,
							       ISC_XMLCHAR
							       category));
1007 1008

				/* <name> inside category */
1009 1010 1011 1012 1013
				TRY0(xmlTextWriterStartElement(writer,
							       ISC_XMLCHAR
							       "name"));
				TRY0(xmlTextWriterWriteString(writer,
							      ISC_XMLCHAR
1014
							      desc[idx]));
1015 1016
				TRY0(xmlTextWriterEndElement(writer));
				/* </name> */
1017

1018
				/* <counter> */
1019 1020 1021
				TRY0(xmlTextWriterStartElement(writer,
							       ISC_XMLCHAR
							       "counter"));
1022 1023 1024 1025 1026 1027 1028 1029
				TRY0(xmlTextWriterWriteFormatString(writer,
					"%" ISC_PRINT_QUADFORMAT "u", value));

				TRY0(xmlTextWriterEndElement(writer));
				/* </counter> */
				TRY0(xmlTextWriterEndElement(writer));
				/* </NameOfCategory> */

1030
			} else {
1031 1032
				TRY0(xmlTextWriterStartElement(writer,
							       ISC_XMLCHAR
1033 1034 1035 1036 1037
							       "counter"));
				TRY0(xmlTextWriterWriteAttribute(writer,
								 ISC_XMLCHAR
								 "name",
								 ISC_XMLCHAR
1038
								 desc[idx]));
1039 1040 1041 1042
				TRY0(xmlTextWriterWriteFormatString(writer,
					"%" ISC_PRINT_QUADFORMAT "u", value));
				TRY0(xmlTextWriterEndElement(writer));
				/* counter */
1043
			}
1044

1045
#endif
1046
			break;
1047 1048 1049 1050 1051
		case isc_statsformat_json:
#ifdef HAVE_JSON
			counter = json_object_new_int64(value);
			if (counter == NULL)
				return (ISC_R_NOMEMORY);
1052
			json_object_object_add(cat, desc[idx], counter);
1053
#endif
Mark Andrews's avatar
Mark Andrews committed
1054
			break;
1055
		}
1056
	}
1057 1058 1059
	return (ISC_R_SUCCESS);
#ifdef HAVE_LIBXML2
 error:
1060 1061
	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
		      ISC_LOG_ERROR, "failed at dump_counters()");
1062 1063
	return (ISC_R_FAILURE);
#endif
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
}

static void
rdtypestat_dump(dns_rdatastatstype_t type, isc_uint64_t val, void *arg) {
	char typebuf[64];
	const char *typestr;
	stats_dumparg_t *dumparg = arg;
	FILE *fp;
#ifdef HAVE_LIBXML2
	xmlTextWriterPtr writer;
1074
	int xmlrc;
1075
#endif
1076 1077 1078
#ifdef HAVE_JSON
	json_object *zoneobj, *obj;
#endif
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088

	if ((DNS_RDATASTATSTYPE_ATTR(type) & DNS_RDATASTATSTYPE_ATTR_OTHERTYPE)
	    == 0) {
		dns_rdatatype_format(DNS_RDATASTATSTYPE_BASE(type), typebuf,
				     sizeof(typebuf));
		typestr = typebuf;
	} else
		typestr = "Others";

	switch (dumparg->type) {
1089
	case isc_statsformat_file:
1090 1091 1092
		fp = dumparg->arg;
		fprintf(fp, "%20" ISC_PRINT_QUADFORMAT "u %s\n", val, typestr);
		break;
1093
	case isc_statsformat_xml:
1094 1095 1096 1097
#ifdef HAVE_LIBXML2
		writer = dumparg->arg;


1098
		TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counter"));
1099 1100 1101
		TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "name",
						 ISC_XMLCHAR typestr));

1102
		TRY0(xmlTextWriterWriteFormatString(writer,
1103
					       "%" ISC_PRINT_QUADFORMAT "u",
1104
					       val));
1105

1106
		TRY0(xmlTextWriterEndElement(writer)); /* type */
1107 1108 1109 1110 1111 1112 1113 1114 1115
#endif
		break;
	case isc_statsformat_json:
#ifdef HAVE_JSON
		zoneobj = (json_object *) dumparg->arg;
		obj = json_object_new_int64(val);
		if (obj == NULL)
			return;
		json_object_object_add(zoneobj, typestr, obj);
1116 1117 1118
#endif
		break;
	}
1119 1120 1121
	return;
#ifdef HAVE_LIBXML2
 error:
1122 1123
	isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
		      ISC_LOG_ERROR, "failed at rdtypestat_dump()");
1124 1125 1126
	dumparg->result = ISC_R_FAILURE;
	return;
#endif
1127 1128 1129 1130 1131 1132 1133 1134 1135
}

static void
rdatasetstats_dump(dns_rdatastatstype_t type, isc_uint64_t val, void *arg) {
	stats_dumparg_t *dumparg = arg;
	FILE *fp;
	char typebuf[64];
	const char *typestr;
	isc_boolean_t nxrrset = ISC_FALSE;
1136
	isc_boolean_t stale = ISC_FALSE;
1137 1138
#ifdef HAVE_LIBXML2
	xmlTextWriterPtr writer;
1139
	int xmlrc;
1140
#endif
1141 1142 1143 1144
#ifdef HAVE_JSON
	json_object *zoneobj, *obj;
	char buf[1024];
#endif
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161

	if ((DNS_RDATASTATSTYPE_ATTR(type) & DNS_RDATASTATSTYPE_ATTR_NXDOMAIN)
	    != 0) {
		typestr = "NXDOMAIN";
	} else if ((DNS_RDATASTATSTYPE_ATTR(type) &
		    DNS_RDATASTATSTYPE_ATTR_OTHERTYPE) != 0) {
		typestr = "Others";
	} else {
		dns_rdatatype_format(DNS_RDATASTATSTYPE_BASE(type), typebuf,
				     sizeof(typebuf));
		typestr = typebuf;
	}

	if ((DNS_RDATASTATSTYPE_ATTR(type) & DNS_RDATASTATSTYPE_ATTR_NXRRSET)
	    != 0)
		nxrrset = ISC_TRUE;

1162 1163 1164 1165
	if ((DNS_RDATASTATSTYPE_ATTR(type) & DNS_RDATASTATSTYPE_ATTR_STALE)
	    != 0)
		stale = ISC_TRUE;

1166
	switch (dumparg->type) {
1167
	case isc_statsformat_file:
1168
		fp = dumparg->arg;
1169 1170