* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: server.h,v 1.46 2000/11/30 19:38:03 gson Exp $ */
+/* $Id: server.h,v 1.47 2000/12/01 23:49:52 gson Exp $ */
#ifndef NAMED_SERVER_H
#define NAMED_SERVER_H 1
isc_boolean_t flushonshutdown;
isc_boolean_t log_queries; /* For BIND 8 compatibility */
- char * statsfile;
- FILE * statsfp;
- isc_uint64_t globalcount[DNS_ZONE_COUNTSIZE];
+ char * statsfile; /* Statistics file name */
+ isc_uint64_t * querystats; /* Query statistics counters */
};
#define NS_SERVER_MAGIC 0x53564552 /* SVER */
* Toggle logging of queries, as in BIND 8.
*/
+/*
+ * Dump the current statistics to the statstics file.
+ */
isc_result_t
ns_server_dumpstats(ns_server_t *server);
-void
-ns_server_querycount(dns_zone_t *zone, isc_boolean_t is_zone,
- dns_zonecount_t counter);
-
#endif /* NAMED_SERVER_H */
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: query.c,v 1.156 2000/11/30 00:25:09 gson Exp $ */
+/* $Id: query.c,v 1.157 2000/12/01 23:49:47 gson Exp $ */
#include <config.h>
#include <dns/rdatatype.h>
#include <dns/resolver.h>
#include <dns/result.h>
+#include <dns/stats.h>
#include <dns/tkey.h>
#include <dns/view.h>
#include <dns/zone.h>
static void
query_find(ns_client_t *client, dns_fetchevent_t *event);
+/*
+ * Increment query statistics counters.
+ */
+static void
+count_query(dns_zone_t *zone, isc_boolean_t is_zone, dns_statscounter_t counter)
+{
+ REQUIRE(counter < dns_stats_ncounters());
+
+ ns_g_server->querystats[counter]++;
+
+ if (is_zone && zone != NULL) {
+ isc_uint64_t *zonestats = dns_zone_getstatscounters(zone);
+ if (zonestats != NULL)
+ zonestats[counter]++;
+ }
+}
static inline void
query_maybeputqname(ns_client_t *client) {
dns_rdataset_isassociated(sigrdataset))
dns_rdataset_disassociate(sigrdataset);
if (is_zone) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_delegate);
+ count_query(zone, is_zone, dns_statscounter_referral);
if (USECACHE(client)) {
/*
* Either the answer is in the cache, or we
* query counter.
*/
if (result == ISC_R_SUCCESS)
- ns_server_querycount(zone, is_zone, dns_zonecount_success);
+ count_query(zone, is_zone, dns_statscounter_success);
cleanup:
if (dns_rdataset_isassociated(&zrdataset)) {
*/
dbuf = query_getnamebuf(client);
if (dbuf == NULL) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
fname = query_newname(client, dbuf, &b);
if (fname == NULL) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone,
+ dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
tname = dns_fixedname_name(&event->foundname);
result = dns_name_concatenate(tname, NULL, fname, NULL);
if (result != ISC_R_SUCCESS) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
result = query_getdb(client, client->query.qname, 0, &zone, &db,
&version, &is_zone);
if (result != ISC_R_SUCCESS) {
- ns_server_querycount(NULL, ISC_FALSE,
- dns_zonecount_failure);
+ count_query(NULL, ISC_FALSE, dns_statscounter_failure);
if (result == DNS_R_REFUSED)
QUERY_ERROR(DNS_R_REFUSED);
else
type = qtype;
else {
CTRACE("find_query: REFUSED: qcount != 1");
- ns_server_querycount(zone, is_zone, dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_REFUSED);
goto cleanup;
}
result = query_checktype(qtype);
if (result != ISC_R_SUCCESS) {
CTRACE("find_query: non supported query type");
- ns_server_querycount(zone, is_zone, dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(result);
goto cleanup;
}
*/
dbuf = query_getnamebuf(client);
if (dbuf == NULL) {
- ns_server_querycount(zone, is_zone, dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
fname = query_newname(client, dbuf, &b);
rdataset = query_newrdataset(client);
if (fname == NULL || rdataset == NULL) {
- ns_server_querycount(zone, is_zone, dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
if (WANTDNSSEC(client)) {
sigrdataset = query_newrdataset(client);
if (sigrdataset == NULL) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
result = dns_name_concatenate(client->query.qname,
NULL, fname, NULL);
if (result != ISC_R_SUCCESS) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
CTRACE("query_find: resume");
switch (result) {
case ISC_R_SUCCESS:
- ns_server_querycount(zone, is_zone,
- dns_zonecount_success);
+ count_query(zone, is_zone, dns_statscounter_success);
/*
* This case is handled in the main line below.
*/
*/
INSIST(!is_zone);
INSIST(client->view->hints != NULL);
- ns_server_querycount(zone, is_zone, dns_zonecount_delegate);
+ count_query(zone, is_zone, dns_statscounter_referral);
if (db != NULL)
dns_db_detach(&db);
dns_db_attach(client->view->hints, &db);
* We can't even find the hints for the root
* nameservers!
*/
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
/*
* Recurse!
*/
- ns_server_querycount(zone, is_zone,
- dns_zonecount_recurse);
+ count_query(zone, is_zone,
+ dns_statscounter_recursion);
if (type == dns_rdatatype_key)
result = query_recurse(client, qtype,
NULL, NULL);
client->query.attributes |=
NS_QUERYATTR_RECURSING;
else {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone,
+ dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
}
} else {
/*
* This is the best answer.
*/
- ns_server_querycount(zone, is_zone,
- dns_zonecount_delegate);
+ count_query(zone, is_zone,
+ dns_statscounter_referral);
client->query.gluedb = zdb;
client->query.attributes |=
NS_QUERYATTR_CACHEGLUEOK;
goto cleanup;
case DNS_R_NXRRSET:
INSIST(is_zone);
- ns_server_querycount(zone, is_zone, dns_zonecount_nxrrset);
+ count_query(zone, is_zone, dns_statscounter_nxrrset);
if (dns_rdataset_isassociated(rdataset)) {
/*
* If we've got a NXT record, we need to save the
*/
result = query_addsoa(client, db, ISC_FALSE);
if (result != ISC_R_SUCCESS) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone,
+ dns_statscounter_failure);
QUERY_ERROR(result);
goto cleanup;
}
goto cleanup;
case DNS_R_NXDOMAIN:
INSIST(is_zone);
- ns_server_querycount(zone, is_zone, dns_zonecount_nxdomain);
+ count_query(zone, is_zone, dns_statscounter_nxdomain);
if (client->query.restarts > 0) {
/*
* We hit a dead end following a CNAME or DNAME.
else
result = query_addsoa(client, db, ISC_FALSE);
if (result != ISC_R_SUCCESS) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone,
+ dns_statscounter_failure);
QUERY_ERROR(result);
goto cleanup;
}
goto cleanup;
case DNS_R_NCACHENXDOMAIN:
INSIST(!is_zone);
- ns_server_querycount(NULL, is_zone, dns_zonecount_nxdomain);
+ count_query(NULL, is_zone, dns_statscounter_nxdomain);
goto ncachenxrrset;
case DNS_R_NCACHENXRRSET:
INSIST(!is_zone);
- ns_server_querycount(NULL, is_zone, dns_zonecount_nxrrset);
+ count_query(NULL, is_zone, dns_statscounter_nxrrset);
ncachenxrrset:
authoritative = ISC_FALSE;
/*
/*
* Something has gone wrong.
*/
- ns_server_querycount(zone, is_zone, dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
rdsiter = NULL;
result = dns_db_allrdatasets(db, node, version, 0, &rdsiter);
if (result != ISC_R_SUCCESS) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone,
+ dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
/*
* Something went wrong.
*/
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone,
+ dns_statscounter_failure);
result = DNS_R_SERVFAIL;
}
}
dns_rdatasetiter_destroy(&rdsiter);
if (result != ISC_R_NOMORE) {
- ns_server_querycount(zone, is_zone,
- dns_zonecount_failure);
+ count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL);
goto cleanup;
}
ns_client_attach(client, &qclient);
query_find(qclient, NULL);
}
+
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: server.c,v 1.266 2000/12/01 08:58:10 marka Exp $ */
+/* $Id: server.c,v 1.267 2000/12/01 23:49:49 gson Exp $ */
#include <config.h>
#include <dns/rdatastruct.h>
#include <dns/resolver.h>
#include <dns/rootns.h>
+#include <dns/stats.h>
#include <dns/tkey.h>
#include <dns/view.h>
#include <dns/zone.h>
RWUNLOCK(&server->conflock, isc_rwlocktype_read);
}
-static void
-ns_server_freestatsfile(ns_server_t *serv) {
- if (serv->statsfile != NULL)
- isc_mem_free(serv->mctx, serv->statsfile);
- serv->statsfile = NULL;
-}
-
-static void
-ns_server_setstatsfile(const char *name, ns_server_t *serv) {
- int len;
-
- ns_server_freestatsfile(serv);
- len = strlen(name);
- serv->statsfile = isc_mem_allocate(serv->mctx, len + 1);
- if (serv->statsfile == NULL)
- fatal("allocate memory for server stats", ISC_R_NOMEMORY);
- strcpy(serv->statsfile, name);
-}
-
-
-static isc_result_t
-ns_server_openstatsfile(ns_server_t *serv) {
- isc_result_t result;
- const char *defname = "named.stats";
- union { char *nc;
- const char *cc; } deconst;
-
- if (serv->statsfile == NULL)
- deconst.cc = defname;
- else
- deconst.nc = serv->statsfile;
- result = isc_stdio_open(deconst.nc, "a", &serv->statsfp);
- return (result);
-}
-
static isc_result_t
-ns_server_closestatsfile(ns_server_t *serv) {
- isc_result_t result = ISC_R_SUCCESS;
-
- if (serv->statsfp != NULL)
- result = isc_stdio_close(serv->statsfp);
- serv->statsfp = NULL;
- return (result);
-}
+setstatsfile(ns_server_t *server, const char *name) {
+ char *p;
-static void
-ns_server_zeroglobal(ns_server_t *serv) {
- int i;
+ REQUIRE(name != NULL);
- for (i = 0; i < DNS_ZONE_COUNTSIZE; i++)
- serv->globalcount[i] = 0;
+ p = isc_mem_strdup(server->mctx, name);
+ if (p == NULL)
+ return (ISC_R_NOMEMORY);
+ if (server->statsfile != NULL)
+ isc_mem_free(server->mctx, server->statsfile);
+ server->statsfile = p;
+ return (ISC_R_SUCCESS);
}
#define SETLIMIT(cfgvar, resource, description) \
NS_LOGMODULE_SERVER, \
result == ISC_R_SUCCESS ? \
ISC_LOG_DEBUG(1) : ISC_LOG_WARNING, \
- "set maximum " description " to %" \
+ "set maximum " description " to %" \
ISC_PRINT_QUADFORMAT "d: %s", value, \
isc_result_totext(result)); \
}
else
ns_os_writepidfile(ns_g_defaultpidfile);
- if (dns_c_ctx_getstatsfilename(cctx, &statsfilename) != ISC_R_NOTFOUND)
- ns_server_setstatsfile(statsfilename, server);
+ result = dns_c_ctx_getstatsfilename(cctx, &statsfilename);
+ if (result == ISC_R_NOTFOUND) {
+ CHECKM(setstatsfile(server, "named.stats"), "strdup");
+ } else {
+ CHECKM(setstatsfile(server, statsfilename), "strdup");
+ }
cleanup:
ns_aclconfctx_destroy(&aclconfctx);
CHECKFATAL(dns_loadmgr_create(ns_g_mctx, &server->loadmgr),
"dns_loadmgr_create");
- server->statsfile = NULL;
- server->statsfp = NULL;
- ns_server_zeroglobal(server);
+ server->statsfile = isc_mem_strdup(server->mctx, "named.stats");
+ CHECKFATAL(server->statsfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS,
+ "isc_mem_strdup");
+ server->querystats = NULL;
+ CHECKFATAL(dns_stats_alloccounters(ns_g_mctx, &server->querystats),
+ "dns_stats_alloccounters");
server->flushonshutdown = ISC_FALSE;
server->log_queries = ISC_FALSE;
ns_server_t *server = *serverp;
REQUIRE(NS_SERVER_VALID(server));
- ns_server_freestatsfile(server);
+ dns_stats_freecounters(server->mctx, &server->querystats);
+ isc_mem_free(server->mctx, server->statsfile);
dns_loadmgr_detach(&server->loadmgr);
dns_zonemgr_detach(&server->zonemgr);
return (ISC_R_SUCCESS);
}
-void
-ns_server_querycount(dns_zone_t *zone, isc_boolean_t is_zone,
- dns_zonecount_t counter)
-{
- REQUIRE(counter < DNS_ZONE_COUNTSIZE);
-
- ns_g_server->globalcount[counter]++;
- if (is_zone && zone != NULL && !dns_zone_hascounts(zone))
- dns_zone_count(zone, counter);
-}
-
-/*
- * Dump the current statistics to a file
- *
- * XXXMWS this should really be done asynchronously
- */
isc_result_t
ns_server_dumpstats(ns_server_t *server) {
isc_result_t result;
- dns_zone_t *zone = NULL, *next = NULL;
- char zonestore[DNS_NAME_FORMATSIZE];
- dns_view_t *zoneview = NULL;
- char *viewname;
+ dns_zone_t *zone;
isc_stdtime_t now;
- FILE *fp;
+ FILE *fp = NULL;
int i;
- int numbercounters;
+ int ncounters;
isc_stdtime_get(&now);
- result = ns_server_openstatsfile(server);
- if (result != ISC_R_SUCCESS) {
- isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
- NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
- "could not open statistics dump file: %s",
- isc_result_totext(result));
- return (result);
- }
- numbercounters = dns_zone_numbercounters();
- fp = server->statsfp;
- fprintf(fp, "+++ Statistics Dump +++ (%ld)\n",
- (long)now);
- for (i = 0; i < numbercounters; i++)
- fprintf(fp, "%s %ld\n", dns_zonecount_names[i],
- (long)server->globalcount[i]);
+
+ CHECKM(isc_stdio_open(server->statsfile, "a", &fp),
+ "could not open statistics dump file");
+
+ ncounters = dns_stats_ncounters();
+ fprintf(fp, "+++ Statistics Dump +++ (%lu)\n", (unsigned long)now);
+
+ for (i = 0; i < ncounters; i++)
+ fprintf(fp, "%s %" ISC_PRINT_QUADFORMAT "d\n",
+ dns_statscounter_names[i],
+ server->querystats[i]);
+
dns_zonemgr_lockconf(server->zonemgr, isc_rwlocktype_read);
- dns_zone_first(server->zonemgr, &zone);
- while (zone != NULL) {
- dns_name_format(dns_zone_getorigin(zone),
- zonestore, sizeof(zonestore));
- zoneview = dns_zone_getview(zone);
- viewname = zoneview->name;
- if (dns_zone_hascounts(zone)) {
- for (i = 0; i < numbercounters; i++)
- fprintf(fp, "%s %ld %s:%s\n",
- dns_zonecount_names[i],
- (long)dns_zone_getcounts(zone, i),
- viewname, zonestore);
+ for (result = dns_zone_first(server->zonemgr, &zone);
+ result == ISC_R_SUCCESS;
+ result = dns_zone_next(zone, &zone))
+ {
+ isc_uint64_t *zonestats = dns_zone_getstatscounters(zone);
+ if (zonestats != NULL) {
+ char zonename[DNS_NAME_FORMATSIZE];
+ dns_view_t *view;
+ char *viewname;
+
+ dns_name_format(dns_zone_getorigin(zone),
+ zonename, sizeof(zonename));
+ view = dns_zone_getview(zone);
+ viewname = view->name;
+ for (i = 0; i < ncounters; i++) {
+ fprintf(fp, "%s %" ISC_PRINT_QUADFORMAT
+ "d %s",
+ dns_statscounter_names[i],
+ zonestats[i],
+ zonename);
+ if (strcmp(viewname, "_default") != 0)
+ fprintf(fp, " %s", viewname);
+ fprintf(fp, "\n");
+ }
}
- dns_zone_next(zone, &next);
- zone = next;
- next = NULL;
}
- fprintf(fp, "--- Statistics Dump --- (%ld)\n", (long)now);
+ if (result == ISC_R_NOMORE)
+ result = ISC_R_SUCCESS;
+ CHECK(result);
+
+ fprintf(fp, "--- Statistics Dump --- (%lu)\n", (unsigned long)now);
dns_zonemgr_unlockconf(server->zonemgr, isc_rwlocktype_read);
- ns_server_closestatsfile(server);
- return (ISC_R_SUCCESS);
+
+ cleanup:
+ if (fp != NULL)
+ (void)isc_stdio_close(fp);
+ return (result);
}
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: zoneconf.c,v 1.75 2000/12/01 18:22:14 gson Exp $ */
+/* $Id: zoneconf.c,v 1.76 2000/12/01 23:49:50 gson Exp $ */
#include <config.h>
result = dns_c_ctx_getstatistics(cctx, &statistics);
if (result != ISC_R_SUCCESS)
statistics = ISC_FALSE;
- if (statistics)
- dns_zone_startcounting(zone);
- else
- dns_zone_stopcounting(zone);
+ dns_zone_setstatistics(zone, statistics);
#ifndef NOMINUM_PUBLIC
if (czone->ztype != dns_c_zone_stub) {
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-# $Id: Makefile.in,v 1.113 2000/11/17 19:04:45 gson Exp $
+# $Id: Makefile.in,v 1.114 2000/12/01 23:49:53 gson Exp $
srcdir = @srcdir@
VPATH = @srcdir@
rbt.@O@ rbtdb.@O@ rbtdb64.@O@ rdata.@O@ rdatalist.@O@ \
rdataset.@O@ rdatasetiter.@O@ rdataslab.@O@ request.@O@ \
resolver.@O@ result.@O@ rootns.@O@ sdb.@O@ ssu.@O@ \
- tcpmsg.@O@ time.@O@ timer.@O@ tkey.@O@ \
+ stats.@O@ tcpmsg.@O@ time.@O@ timer.@O@ tkey.@O@ \
tsig.@O@ ttl.@O@ validator.@O@ \
version.@O@ view.@O@ xfrin.@O@ zone.@O@ zt.@O@ \
${DSTOBJS} @DST_OPENSSL_OBJS@ ${CONFOBJS}
rbt.c rbtdb.c rbtdb64.c rdata.c rdatalist.c \
rdataset.c rdatasetiter.c rdataslab.c request.c \
resolver.c result.c rootns.c sdb.c ssu.c \
- tcpmsg.c time.c timer.c tkey.c \
+ stats.c tcpmsg.c time.c timer.c tkey.c \
tsig.c ttl.c validator.c \
version.c view.c xfrin.c zone.c zt.c
--- /dev/null
+/*
+ * Copyright (C) 2000 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM 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.
+ */
+
+/* $Id: stats.h,v 1.1 2000/12/01 23:49:58 gson Exp $ */
+
+#ifndef DNS_STATS_H
+#define DNS_STATS_H 1
+
+#include <dns/types.h>
+
+/*
+ * Query statistics counter types.
+ */
+typedef enum {
+ dns_statscounter_success = 0, /* Successful lookup */
+ dns_statscounter_referral = 1, /* Referral result */
+ dns_statscounter_nxrrset = 2, /* NXRRSET result */
+ dns_statscounter_nxdomain = 3, /* NXDOMAIN result */
+ dns_statscounter_recursion = 4, /* Recursion was used */
+ dns_statscounter_failure = 5 /* Some other failure */
+} dns_statscounter_t;
+
+#define DNS_STATS_NCOUNTERS 6
+
+extern const char *dns_statscounter_names[];
+
+isc_result_t
+dns_stats_alloccounters(isc_mem_t *mctx, isc_uint64_t **ctrp);
+/*
+ * Allocate an array of query statistics counters from the memory
+ * context 'mctx'.
+ */
+
+void
+dns_stats_freecounters(isc_mem_t *mctx, isc_uint64_t **ctrp);
+/*
+ * Free an array of query statistics counters allocated from the memory
+ * context 'mctx'.
+ */
+
+unsigned int
+dns_stats_ncounters(void);
+/*
+ * Return the number of query statistics counters.
+ */
+
+ISC_LANG_ENDDECLS
+
+#endif /* DNS_STATS_H */
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: zone.h,v 1.92 2000/11/25 02:43:56 marka Exp $ */
+/* $Id: zone.h,v 1.93 2000/12/01 23:49:57 gson Exp $ */
#ifndef DNS_ZONE_H
#define DNS_ZONE_H 1
dns_zone_stub
} dns_zonetype_t;
-typedef enum {
- dns_zonecount_success = 0, /* Successful lookups */
- dns_zonecount_delegate = 1, /* Delegation result */
- dns_zonecount_nxrrset = 2, /* NXRRSET result */
- dns_zonecount_nxdomain = 3, /* NXDOMAIN result */
- dns_zonecount_recurse = 4, /* Recursion was used */
- dns_zonecount_failure = 5 /* Some other failure */
-} dns_zonecount_t;
-
-extern const char *dns_zonecount_names[];
-
-#define DNS_ZONE_COUNTSIZE 6
+#define DNS_STATS_NCOUNTERS 6
#define DNS_ZONEOPT_SERVERS 0x00000001U /* perform server checks */
#define DNS_ZONEOPT_PARENTS 0x00000002U /* perform parent checks */
* 'zone' to be a valid zone.
*/
-void
-dns_zone_count(dns_zone_t *zone, dns_zonecount_t counter);
-/*
- * Increment a zone statistics counter.
- *
- * Requires:
- * zone be a valid zone.
- * MAY be safely called even if zone doesn't have counters
- * counter be a valid counter ID
- */
-
-isc_uint64_t
-dns_zone_getcounts(dns_zone_t *zone, dns_zonecount_t counter);
+isc_result_t
+dns_zone_setstatistics(dns_zone_t *zone, isc_boolean_t on);
/*
- * Return the value of a zone statistics counter.
+ * Make the zone keep or not keep an array of statistics
+ * counter.
*
* Requires:
* zone be a valid zone.
- * MAY be safely called even if zone doesn't have statistics counters
- * counter be a valid counter ID
- *
- * Returns:
- * count if the zone has counters
- * 0 if the zone does not have counters
*/
-void
-dns_zone_resetcounts(dns_zone_t *zone);
+isc_uint64_t *
+dns_zone_getstatscounters(dns_zone_t *zone);
/*
- * Reset the statistics counters of 'zone'.
- *
* Requires:
* zone be a valid zone.
- * MAY be safely called even if zone doesn't have statistics counters
- */
-
-int
-dns_zone_numbercounters(void);
-/*
- * Return the number of statistics counters per zone.
- *
- * Use this instead of DNS_ZONE_COUNTSIZE if possible, to ensure
- * binary compatibility if the number of counters is changed in
- * future library releases.
- */
-
-isc_boolean_t
-dns_zone_hascounts(dns_zone_t *zone);
-/*
- * Return ISC_TRUE iff the zone has statistics counters.
- *
- * Requires:
- * zone be a valid zone.
- */
-
-isc_result_t
-dns_zone_startcounting(dns_zone_t *zone);
-/*
- * Start maintaining statistics counters for 'zone'.
- *
- * Requires:
- * zone be a valid zone.
- * MAY be safely called even if zone already has statistics counters
*
* Returns:
- * ISC_R_NOMEMORY -- memory allocation failed.
- * ISC_R_SUCCESS -- Success
- */
-
-void
-dns_zone_stopcounting(dns_zone_t *zone);
-/*
- * Stop maintaining statistics counters for 'zone'.
- *
- * Requires:
- * zone be a valid zone.
- * MAY be safely called even if zone doesn't have statistics counters
+ * A pointer to the zone's array of statistics counters,
+ * or NULL if it has none.
*/
void
--- /dev/null
+/*
+ * Copyright (C) 2000 Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and 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 INTERNET SOFTWARE CONSORTIUM
+ * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+ * INTERNET SOFTWARE CONSORTIUM 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.
+ */
+
+/* $Id: stats.c,v 1.1 2000/12/01 23:49:54 gson Exp $ */
+
+#include <config.h>
+
+#include <isc/mem.h>
+
+#include <dns/stats.h>
+
+const char *dns_statscounter_names[DNS_STATS_NCOUNTERS] = {
+ "success",
+ "referral",
+ "nxrrset",
+ "nxdomain",
+ "recursion",
+ "failure"
+};
+
+isc_result_t
+dns_stats_alloccounters(isc_mem_t *mctx, isc_uint64_t **ctrp) {
+ int i;
+ isc_uint64_t *p =
+ isc_mem_get(mctx, DNS_STATS_NCOUNTERS * sizeof(isc_uint64_t));
+ if (p == NULL)
+ return (ISC_R_NOMEMORY);
+ for (i = 0; i < DNS_STATS_NCOUNTERS; i++)
+ p[i] = 0;
+ *ctrp = p;
+ return (ISC_R_SUCCESS);
+}
+
+void
+dns_stats_freecounters(isc_mem_t *mctx, isc_uint64_t **ctrp) {
+ isc_mem_put(mctx, *ctrp, DNS_STATS_NCOUNTERS * sizeof(isc_uint64_t));
+ *ctrp = NULL;
+}
+
+unsigned int
+dns_stats_ncounters(void) {
+ return (DNS_STATS_NCOUNTERS);
+}
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/* $Id: zone.c,v 1.264 2000/12/01 03:20:00 marka Exp $ */
+/* $Id: zone.c,v 1.265 2000/12/01 23:49:55 gson Exp $ */
#include <config.h>
#include <dns/request.h>
#include <dns/resolver.h>
#include <dns/result.h>
+#include <dns/stats.h>
#include <dns/ssu.h>
#include <dns/tsig.h>
#include <dns/xfrin.h>
ISC_LINK(dns_zone_t) statelink;
dns_zonelist_t *statelist;
/*
- * Optional per-zone statistics counters
+ * Optional per-zone statistics counters (NULL if not present).
*/
isc_uint64_t *counters;
};
isc_event_t *event;
};
-/*
- * Names of the zone counters
- */
-const char *dns_zonecount_names[] = {
- "SUCCESS",
- "DELEGATION",
- "NXRRSET",
- "NXDOMAIN",
- "RECURSION",
- "SERVFAIL" };
-
static isc_result_t zone_settimer(dns_zone_t *, isc_stdtime_t);
static void cancel_refresh(dns_zone_t *);
isc_mem_free(zone->mctx, zone->journal);
zone->journal = NULL;
if (zone->counters != NULL)
- isc_mem_put(zone->mctx, zone->counters,
- DNS_ZONE_COUNTSIZE * sizeof(isc_uint64_t));
- zone->counters = NULL;
+ dns_stats_freecounters(zone->mctx, &zone->counters);
if (zone->db != NULL)
dns_db_detach(&zone->db);
zone_freedbargs(zone);
return (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_FORCELOAD));
}
-void
-dns_zone_count(dns_zone_t *zone, dns_zonecount_t counter) {
- REQUIRE(counter < DNS_ZONE_COUNTSIZE);
-
- LOCK(&zone->lock);
- if (zone->counters != NULL)
- zone->counters[counter]++;
- UNLOCK(&zone->lock);
-}
-
-isc_uint64_t
-dns_zone_getcounts(dns_zone_t *zone, dns_zonecount_t counter) {
- isc_uint64_t count = 0;
- REQUIRE(DNS_ZONE_VALID(zone));
- REQUIRE(counter < DNS_ZONE_COUNTSIZE);
-
- LOCK(&zone->lock);
- if (zone->counters != NULL)
- count = zone->counters[counter];
- UNLOCK(&zone->lock);
- return (count);
-}
-
-int
-dns_zone_numbercounters(void) {
- return (DNS_ZONE_COUNTSIZE);
-}
-
-void
-dns_zone_resetcounts(dns_zone_t *zone) {
- int i;
-
- REQUIRE(DNS_ZONE_VALID(zone));
-
- LOCK(&zone->lock);
- if (zone->counters != NULL)
- for (i = 0; i < DNS_ZONE_COUNTSIZE; i++)
- zone->counters[i] = 0;
- UNLOCK(&zone->lock);
-}
-
-isc_boolean_t
-dns_zone_hascounts(dns_zone_t *zone) {
- isc_boolean_t hascount = ISC_FALSE;
- REQUIRE(DNS_ZONE_VALID(zone));
-
- LOCK(&zone->lock);
- if (zone->counters != NULL)
- hascount = ISC_TRUE;
- UNLOCK(&zone->lock);
- return (hascount);
-}
-
isc_result_t
-dns_zone_startcounting(dns_zone_t *zone) {
- isc_result_t result = ISC_R_SUCCESS;
- int i;
-
- REQUIRE(DNS_ZONE_VALID(zone));
-
+dns_zone_setstatistics(dns_zone_t *zone, isc_boolean_t on) {
+ isc_result_t result = ISC_R_SUCCESS;
LOCK(&zone->lock);
- if (zone->counters != NULL)
- goto done;
-
- zone->counters = isc_mem_get(zone->mctx, sizeof(isc_uint64_t) *
- DNS_ZONE_COUNTSIZE);
- if (zone->counters == NULL)
- result = ISC_R_NOMEMORY;
- else
- for (i = 0; i < DNS_ZONE_COUNTSIZE; i++)
- zone->counters[i] = 0;
+ if (on) {
+ if (zone->counters != NULL)
+ goto done;
+ result = dns_stats_alloccounters(zone->mctx, &zone->counters);
+ } else {
+ if (zone->counters == NULL)
+ goto done;
+ dns_stats_freecounters(zone->mctx, &zone->counters);
+ }
done:
UNLOCK(&zone->lock);
- return (ISC_R_SUCCESS);
+ return (result);
}
-void
-dns_zone_stopcounting(dns_zone_t *zone) {
- REQUIRE(DNS_ZONE_VALID(zone));
-
- LOCK(&zone->lock);
- if (zone->counters == NULL)
- goto done;
-
- isc_mem_put(zone->mctx, zone->counters,
- sizeof(isc_uint64_t) * DNS_ZONE_COUNTSIZE);
- zone->counters = NULL;
- done:
- UNLOCK(&zone->lock);
- return;
+isc_uint64_t *
+dns_zone_getstatscounters(dns_zone_t *zone) {
+ return (zone->counters);
}
void
./lib/dns/include/dns/secalg.h C 1999,2000
./lib/dns/include/dns/secproto.h C 1999,2000
./lib/dns/include/dns/ssu.h C 2000
+./lib/dns/include/dns/stats.h C 2000
./lib/dns/include/dns/tcpmsg.h C 1999,2000
./lib/dns/include/dns/time.h C 1999,2000
./lib/dns/include/dns/timer.h C 2000
./lib/dns/sec/openssl/include/openssl/Makefile.in MAKE 1998,1999,2000
./lib/dns/sec/rename.h C 2000
./lib/dns/ssu.c C 2000
+./lib/dns/stats.c C 2000
./lib/dns/tcpmsg.c C 1999,2000
./lib/dns/time.c C 1998,1999,2000
./lib/dns/timer.c C 2000