statschannel.c revision cffe96e26744abcf33494837b234219046a631d8
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * Copyright (C) 2008 Internet Systems Consortium, Inc. ("ISC")
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * Permission to use, copy, modify, and/or distribute this software for any
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * purpose with or without fee is hereby granted, provided that the above
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * copyright notice and this permission notice appear in all copies.
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * PERFORMANCE OF THIS SOFTWARE.
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont/* $Id: statschannel.c,v 1.6 2008/03/31 05:00:29 marka Exp $ */
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont /* Unlocked */
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * Locked by channel lock: can be refererenced and modified by both
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * the server task and the channel task.
aaaf8d4f4873d21e55c3ffb4f656203d08339865Mark Andrews /* Locked by server task */
8e821eea5f57ac47a94305aa7ab0c3570d92a311Automatic Updater/* XXXMLG below here sucks. */
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont#define TRY(a) do { result = (a); INSIST(result == ISC_R_SUCCESS); } while(0);
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont#define TRY0(a) do { xmlrc = (a); INSIST(xmlrc >= 0); } while(0);
2a6d4c9948b3f4f31311bd799d114585a30419a9Automatic Updatergeneratexml(ns_server_t *server, int *buflen, xmlChar **buf) {
2a6d4c9948b3f4f31311bd799d114585a30419a9Automatic Updater char boottime[sizeof "yyyy-mm-ddThh:mm:ssZ"];
2a6d4c9948b3f4f31311bd799d114585a30419a9Automatic Updater char nowstr[sizeof "yyyy-mm-ddThh:mm:ssZ"];
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater isc_uint64_t counters[DNS_STATS_NCOUNTERS];
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User isc_time_formatISO8601(&ns_g_boottime, boottime, sizeof boottime);
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User isc_time_formatISO8601(&now, nowstr, sizeof nowstr);
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User TRY0(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL));
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User TRY0(xmlTextWriterWritePI(writer, ISC_XMLCHAR "xml-stylesheet",
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User ISC_XMLCHAR "type=\"text/xsl\" href=\"/bind9.xsl\""));
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "isc"));
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version",
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "bind"));
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "statistics"));
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "version",
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * Start by rendering the views we know of here. For each view we
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont * know of, call its rendering function.
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "views"));
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater dns_view_xmlrender(view, writer, ISC_XML_RENDERALL);
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater TRY0(xmlTextWriterEndElement(writer)); /* views */
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "socketmgr"));
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater isc_socketmgr_renderxml(ns_g_socketmgr, writer);
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater TRY0(xmlTextWriterEndElement(writer)); /* socketmgr */
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "taskmgr"));
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont TRY0(xmlTextWriterEndElement(writer)); /* taskmgr */
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "server"));
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont xmlTextWriterStartElement(writer, ISC_XMLCHAR "boot-time");
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater xmlTextWriterWriteString(writer, ISC_XMLCHAR boottime);
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont xmlTextWriterStartElement(writer, ISC_XMLCHAR "current-time");
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater xmlTextWriterWriteString(writer, ISC_XMLCHAR nowstr);
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater dns_stats_copy(server->querystats, counters);
f8e3e03cacd16ffb923a9603fca23a9e1a1fee07Automatic Updater for (i = 0; i < DNS_STATS_NCOUNTERS; i++) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater xmlTextWriterEndElement(writer); /* counters */
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater xmlTextWriterEndElement(writer); /* server */
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "memory"));
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont TRY0(xmlTextWriterEndElement(writer)); /* memory */
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont TRY0(xmlTextWriterEndElement(writer)); /* statistics */
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont TRY0(xmlTextWriterEndElement(writer)); /* bind */
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater TRY0(xmlTextWriterEndElement(writer)); /* isc */
a3f8c8e20780e488141d200acdfea6c5f3303513Automatic Updater xmlDocDumpFormatMemoryEnc(doc, buf, buflen, "UTF-8", 1);
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updaterwrap_xmlfree(isc_buffer_t *buffer, void *arg) {
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupontrender_index(const char *url, const char *querystring, void *arg,
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont unsigned int *retcode, const char **retmsg, const char **mimetype,
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont unsigned char *msg;
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater#endif /* HAVE_LIBXML2 */
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updaterrender_xsl(const char *url, const char *querystring, void *args,
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater unsigned int *retcode, const char **retmsg, const char **mimetype,
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater isc_buffer_t *b, isc_httpdfree_t **freecb,
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupontshutdown_listener(ns_statschannel_t *listener) {
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont isc_sockaddr_format(&listener->address, socktext, sizeof(socktext));
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,NS_LOGMODULE_SERVER,
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont ISC_LOG_NOTICE, "stopping statistics channel on %s",
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupontclient_ok(const isc_sockaddr_t *fromaddr, void *arg) {
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont isc_netaddr_fromsockaddr(&netaddr, fromaddr);
c7d32c0b0ff4c01f0d4479af3410d3c06044d48aAutomatic Updater if (dns_acl_match(&netaddr, NULL, listener->acl, &ns_g_server->aclenv,
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont &match, NULL) == ISC_R_SUCCESS && match > 0) {
bbbf2e27d3a981163dab139497d6b2dc85449db0Tinderbox User isc_sockaddr_format(fromaddr, socktext, sizeof(socktext));
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
90f35c2f2a1c660f3b96eec413036d238df395f6Francis Dupont "rejected statistics connection from %s", socktext);
static isc_result_t
const char *socktext)
return (ISC_R_NOMEMORY);
return (ISC_R_FAILURE);
&new_acl);
goto cleanup;
goto cleanup;
goto cleanup;
#ifndef ISC_ALLOW_MAPPED
goto cleanup;
goto cleanup;
#ifdef HAVE_LIBXML2
server);
sizeof(*listener));
return (result);
const char *socktext)
&new_acl);
* Get the list of named.conf 'statistics-channels' statements.
#ifndef HAVE_LIBXML2
&listenercfg);
sizeof(socktext));
socktext);
isc_result_t r;
socktext);
if (r != ISC_R_SUCCESS) {
isc_result_totext(r));
link);
return (ISC_R_SUCCESS);