1/*
2 * Copyright (C) 2004-2009, 2012  Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001  Internet Software Consortium.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
16 */
17
18/* $Id$ */
19
20#ifndef DNS_STATS_H
21#define DNS_STATS_H 1
22
23/*! \file dns/stats.h */
24
25#include <dns/types.h>
26
27/*%
28 * Statistics counters.  Used as isc_statscounter_t values.
29 */
30enum {
31	/*%
32	 * Resolver statistics counters.
33	 */
34	dns_resstatscounter_queryv4 = 0,
35	dns_resstatscounter_queryv6 = 1,
36	dns_resstatscounter_responsev4 = 2,
37	dns_resstatscounter_responsev6 = 3,
38	dns_resstatscounter_nxdomain = 4,
39	dns_resstatscounter_servfail = 5,
40	dns_resstatscounter_formerr = 6,
41	dns_resstatscounter_othererror = 7,
42	dns_resstatscounter_edns0fail = 8,
43	dns_resstatscounter_mismatch = 9,
44	dns_resstatscounter_truncated = 10,
45	dns_resstatscounter_lame = 11,
46	dns_resstatscounter_retry = 12,
47	dns_resstatscounter_gluefetchv4 = 13,
48	dns_resstatscounter_gluefetchv6 = 14,
49	dns_resstatscounter_gluefetchv4fail = 15,
50	dns_resstatscounter_gluefetchv6fail = 16,
51	dns_resstatscounter_val = 17,
52	dns_resstatscounter_valsuccess = 18,
53	dns_resstatscounter_valnegsuccess = 19,
54	dns_resstatscounter_valfail = 20,
55	dns_resstatscounter_dispabort = 21,
56	dns_resstatscounter_dispsockfail = 22,
57	dns_resstatscounter_querytimeout = 23,
58	dns_resstatscounter_queryrtt0 = 24,
59	dns_resstatscounter_queryrtt1 = 25,
60	dns_resstatscounter_queryrtt2 = 26,
61	dns_resstatscounter_queryrtt3 = 27,
62	dns_resstatscounter_queryrtt4 = 28,
63	dns_resstatscounter_queryrtt5 = 29,
64
65	dns_resstatscounter_max = 30,
66
67	/*%
68	 * Zone statistics counters.
69	 */
70	dns_zonestatscounter_notifyoutv4 = 0,
71	dns_zonestatscounter_notifyoutv6 = 1,
72	dns_zonestatscounter_notifyinv4 = 2,
73	dns_zonestatscounter_notifyinv6 = 3,
74	dns_zonestatscounter_notifyrej = 4,
75	dns_zonestatscounter_soaoutv4 = 5,
76	dns_zonestatscounter_soaoutv6 = 6,
77	dns_zonestatscounter_axfrreqv4 = 7,
78	dns_zonestatscounter_axfrreqv6 = 8,
79	dns_zonestatscounter_ixfrreqv4 = 9,
80	dns_zonestatscounter_ixfrreqv6 = 10,
81	dns_zonestatscounter_xfrsuccess = 11,
82	dns_zonestatscounter_xfrfail = 12,
83
84	dns_zonestatscounter_max = 13,
85
86	/*%
87	* Query statistics counters (obsolete).
88	*/
89	dns_statscounter_success = 0,    /*%< Successful lookup */
90	dns_statscounter_referral = 1,   /*%< Referral result */
91	dns_statscounter_nxrrset = 2,    /*%< NXRRSET result */
92	dns_statscounter_nxdomain = 3,   /*%< NXDOMAIN result */
93	dns_statscounter_recursion = 4,  /*%< Recursion was used */
94	dns_statscounter_failure = 5,    /*%< Some other failure */
95	dns_statscounter_duplicate = 6,  /*%< Duplicate query */
96	dns_statscounter_dropped = 7	 /*%< Duplicate query (dropped) */
97};
98
99#define DNS_STATS_NCOUNTERS 8
100
101#if 0
102/*%<
103 * Flag(s) for dns_xxxstats_dump().  DNS_STATSDUMP_VERBOSE is obsolete.
104 * ISC_STATSDUMP_VERBOSE should be used instead.  These two values are
105 * intentionally defined to be the same value to ensure binary compatibility.
106 */
107#define DNS_STATSDUMP_VERBOSE	0x00000001 /*%< dump 0-value counters */
108#endif
109
110/*%<
111 * (Obsoleted)
112 */
113LIBDNS_EXTERNAL_DATA extern const char *dns_statscounter_names[];
114
115/*%
116 * Attributes for statistics counters of RRset and Rdatatype types.
117 *
118 * _OTHERTYPE
119 *	The rdata type is not explicitly supported and the corresponding counter
120 *	is counted for other such types, too.  When this attribute is set,
121 *	the base type is of no use.
122 *
123 * _NXRRSET
124 * 	RRset type counters only.  Indicates the RRset is non existent.
125 *
126 * _NXDOMAIN
127 *	RRset type counters only.  Indicates a non existent name.  When this
128 *	attribute is set, the base type is of no use.
129 */
130#define DNS_RDATASTATSTYPE_ATTR_OTHERTYPE	0x0001
131#define DNS_RDATASTATSTYPE_ATTR_NXRRSET		0x0002
132#define DNS_RDATASTATSTYPE_ATTR_NXDOMAIN	0x0004
133
134/*%<
135 * Conversion macros among dns_rdatatype_t, attributes and isc_statscounter_t.
136 */
137#define DNS_RDATASTATSTYPE_BASE(type)	((dns_rdatatype_t)((type) & 0xFFFF))
138#define DNS_RDATASTATSTYPE_ATTR(type)	((type) >> 16)
139#define DNS_RDATASTATSTYPE_VALUE(b, a)	(((a) << 16) | (b))
140
141/*%<
142 * Types of dump callbacks.
143 */
144typedef void (*dns_generalstats_dumper_t)(isc_statscounter_t, isc_uint64_t,
145					  void *);
146typedef void (*dns_rdatatypestats_dumper_t)(dns_rdatastatstype_t, isc_uint64_t,
147					    void *);
148typedef void (*dns_opcodestats_dumper_t)(dns_opcode_t, isc_uint64_t, void *);
149
150ISC_LANG_BEGINDECLS
151
152isc_result_t
153dns_generalstats_create(isc_mem_t *mctx, dns_stats_t **statsp, int ncounters);
154/*%<
155 * Create a statistics counter structure of general type.  It counts a general
156 * set of counters indexed by an ID between 0 and ncounters -1.
157 * This function is obsolete.  A more general function, isc_stats_create(),
158 * should be used.
159 *
160 * Requires:
161 *\li	'mctx' must be a valid memory context.
162 *
163 *\li	'statsp' != NULL && '*statsp' == NULL.
164 *
165 * Returns:
166 *\li	ISC_R_SUCCESS	-- all ok
167 *
168 *\li	anything else	-- failure
169 */
170
171isc_result_t
172dns_rdatatypestats_create(isc_mem_t *mctx, dns_stats_t **statsp);
173/*%<
174 * Create a statistics counter structure per rdatatype.
175 *
176 * Requires:
177 *\li	'mctx' must be a valid memory context.
178 *
179 *\li	'statsp' != NULL && '*statsp' == NULL.
180 *
181 * Returns:
182 *\li	ISC_R_SUCCESS	-- all ok
183 *
184 *\li	anything else	-- failure
185 */
186
187isc_result_t
188dns_rdatasetstats_create(isc_mem_t *mctx, dns_stats_t **statsp);
189/*%<
190 * Create a statistics counter structure per RRset.
191 *
192 * Requires:
193 *\li	'mctx' must be a valid memory context.
194 *
195 *\li	'statsp' != NULL && '*statsp' == NULL.
196 *
197 * Returns:
198 *\li	ISC_R_SUCCESS	-- all ok
199 *
200 *\li	anything else	-- failure
201 */
202
203isc_result_t
204dns_opcodestats_create(isc_mem_t *mctx, dns_stats_t **statsp);
205/*%<
206 * Create a statistics counter structure per opcode.
207 *
208 * Requires:
209 *\li	'mctx' must be a valid memory context.
210 *
211 *\li	'statsp' != NULL && '*statsp' == NULL.
212 *
213 * Returns:
214 *\li	ISC_R_SUCCESS	-- all ok
215 *
216 *\li	anything else	-- failure
217 */
218
219void
220dns_stats_attach(dns_stats_t *stats, dns_stats_t **statsp);
221/*%<
222 * Attach to a statistics set.
223 *
224 * Requires:
225 *\li	'stats' is a valid dns_stats_t.
226 *
227 *\li	'statsp' != NULL && '*statsp' == NULL
228 */
229
230void
231dns_stats_detach(dns_stats_t **statsp);
232/*%<
233 * Detaches from the statistics set.
234 *
235 * Requires:
236 *\li	'statsp' != NULL and '*statsp' is a valid dns_stats_t.
237 */
238
239void
240dns_generalstats_increment(dns_stats_t *stats, isc_statscounter_t counter);
241/*%<
242 * Increment the counter-th counter of stats.  This function is obsolete.
243 * A more general function, isc_stats_increment(), should be used.
244 *
245 * Requires:
246 *\li	'stats' is a valid dns_stats_t created by dns_generalstats_create().
247 *
248 *\li	counter is less than the maximum available ID for the stats specified
249 *	on creation.
250 */
251
252void
253dns_rdatatypestats_increment(dns_stats_t *stats, dns_rdatatype_t type);
254/*%<
255 * Increment the statistics counter for 'type'.
256 *
257 * Requires:
258 *\li	'stats' is a valid dns_stats_t created by dns_rdatatypestats_create().
259 */
260
261void
262dns_rdatasetstats_increment(dns_stats_t *stats, dns_rdatastatstype_t rrsettype);
263/*%<
264 * Increment the statistics counter for 'rrsettype'.
265 *
266 * Requires:
267 *\li	'stats' is a valid dns_stats_t created by dns_rdatasetstats_create().
268 */
269
270void
271dns_rdatasetstats_decrement(dns_stats_t *stats, dns_rdatastatstype_t rrsettype);
272/*%<
273 * Decrement the statistics counter for 'rrsettype'.
274 *
275 * Requires:
276 *\li	'stats' is a valid dns_stats_t created by dns_rdatasetstats_create().
277 */
278
279void
280dns_opcodestats_increment(dns_stats_t *stats, dns_opcode_t code);
281/*%<
282 * Increment the statistics counter for 'code'.
283 *
284 * Requires:
285 *\li	'stats' is a valid dns_stats_t created by dns_opcodestats_create().
286 */
287
288void
289dns_generalstats_dump(dns_stats_t *stats, dns_generalstats_dumper_t dump_fn,
290		      void *arg, unsigned int options);
291/*%<
292 * Dump the current statistics counters in a specified way.  For each counter
293 * in stats, dump_fn is called with its current value and the given argument
294 * arg.  By default counters that have a value of 0 is skipped; if options has
295 * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped.
296 *
297 * This function is obsolete.  A more general function, isc_stats_dump(),
298 * should be used.
299 *
300 * Requires:
301 *\li	'stats' is a valid dns_stats_t created by dns_generalstats_create().
302 */
303
304void
305dns_rdatatypestats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn,
306			void *arg, unsigned int options);
307/*%<
308 * Dump the current statistics counters in a specified way.  For each counter
309 * in stats, dump_fn is called with the corresponding type in the form of
310 * dns_rdatastatstype_t, the current counter value and the given argument
311 * arg.  By default counters that have a value of 0 is skipped; if options has
312 * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped.
313 *
314 * Requires:
315 *\li	'stats' is a valid dns_stats_t created by dns_generalstats_create().
316 */
317
318void
319dns_rdatasetstats_dump(dns_stats_t *stats, dns_rdatatypestats_dumper_t dump_fn,
320		       void *arg, unsigned int options);
321/*%<
322 * Dump the current statistics counters in a specified way.  For each counter
323 * in stats, dump_fn is called with the corresponding type in the form of
324 * dns_rdatastatstype_t, the current counter value and the given argument
325 * arg.  By default counters that have a value of 0 is skipped; if options has
326 * the ISC_STATSDUMP_VERBOSE flag, even such counters are dumped.
327 *
328 * Requires:
329 *\li	'stats' is a valid dns_stats_t created by dns_generalstats_create().
330 */
331
332void
333dns_opcodestats_dump(dns_stats_t *stats, dns_opcodestats_dumper_t dump_fn,
334		     void *arg, unsigned int options);
335/*%<
336 * Dump the current statistics counters in a specified way.  For each counter
337 * in stats, dump_fn is called with the corresponding opcode, the current
338 * counter value and the given argument arg.  By default counters that have a
339 * value of 0 is skipped; if options has the ISC_STATSDUMP_VERBOSE flag, even
340 * such counters are dumped.
341 *
342 * Requires:
343 *\li	'stats' is a valid dns_stats_t created by dns_generalstats_create().
344 */
345
346isc_result_t
347dns_stats_alloccounters(isc_mem_t *mctx, isc_uint64_t **ctrp);
348/*%<
349 * Allocate an array of query statistics counters from the memory
350 * context 'mctx'.
351 *
352 * This function is obsoleted.  Use dns_xxxstats_create() instead.
353 */
354
355void
356dns_stats_freecounters(isc_mem_t *mctx, isc_uint64_t **ctrp);
357/*%<
358 * Free an array of query statistics counters allocated from the memory
359 * context 'mctx'.
360 *
361 * This function is obsoleted.  Use dns_stats_destroy() instead.
362 */
363
364ISC_LANG_ENDDECLS
365
366#endif /* DNS_STATS_H */
367