2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

rewrite statschannel to use netmgr

modify isc_httpd to use the network manager instead of the
isc_socket API.

also cleaned up bin/named/statschannel.c to use CHECK.
This commit is contained in:
Evan Hunt 2020-07-09 19:36:10 -07:00
parent d8e6b32a18
commit 69c1ee1ce9
4 changed files with 438 additions and 743 deletions

View File

@ -22,7 +22,6 @@
#include <isc/socket.h> #include <isc/socket.h>
#include <isc/stats.h> #include <isc/stats.h>
#include <isc/string.h> #include <isc/string.h>
#include <isc/task.h>
#include <isc/util.h> #include <isc/util.h>
#include <dns/cache.h> #include <dns/cache.h>
@ -54,6 +53,14 @@
#include "xsl_p.h" #include "xsl_p.h"
#define CHECK(m) \
do { \
result = (m); \
if (result != ISC_R_SUCCESS) { \
goto cleanup; \
} \
} while (0)
struct named_statschannel { struct named_statschannel {
/* Unlocked */ /* Unlocked */
isc_httpdmgr_t *httpdmgr; isc_httpdmgr_t *httpdmgr;
@ -174,7 +181,7 @@ static const char *gluecachestats_xmldesc[dns_gluecachestatscounter_max];
do { \ do { \
xmlrc = (a); \ xmlrc = (a); \
if (xmlrc < 0) \ if (xmlrc < 0) \
goto error; \ goto cleanup; \
} while (0) } while (0)
/*% /*%
@ -1424,7 +1431,7 @@ dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg,
} }
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
error: cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at dump_counters()"); "failed at dump_counters()");
@ -1486,7 +1493,7 @@ rdtypestat_dump(dns_rdatastatstype_t type, uint64_t val, void *arg) {
} }
return; return;
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
error: cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at rdtypestat_dump()"); "failed at rdtypestat_dump()");
@ -1574,7 +1581,7 @@ rdatasetstats_dump(dns_rdatastatstype_t type, uint64_t val, void *arg) {
} }
return; return;
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
error: cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at rdatasetstats_dump()"); "failed at rdatasetstats_dump()");
@ -1629,7 +1636,7 @@ opcodestat_dump(dns_opcode_t code, uint64_t val, void *arg) {
return; return;
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
error: cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at opcodestat_dump()"); "failed at opcodestat_dump()");
@ -1685,7 +1692,7 @@ rcodestat_dump(dns_rcode_t code, uint64_t val, void *arg) {
return; return;
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
error: cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at rcodestat_dump()"); "failed at rcodestat_dump()");
@ -1738,7 +1745,7 @@ dnssecsignstat_dump(dns_keytag_t tag, uint64_t val, void *arg) {
} }
return; return;
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
error: cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at dnssecsignstat_dump()"); "failed at dnssecsignstat_dump()");
@ -1772,6 +1779,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
int xmlrc; int xmlrc;
stats_dumparg_t dumparg; stats_dumparg_t dumparg;
const char *ztype; const char *ztype;
isc_time_t timestamp;
statlevel = dns_zone_getstatlevel(zone); statlevel = dns_zone_getstatlevel(zone);
if (statlevel == dns_zonestat_none) { if (statlevel == dns_zonestat_none) {
@ -1814,12 +1822,8 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
* master zones, only include the loaded time. For slave zones, also * master zones, only include the loaded time. For slave zones, also
* include the expires and refresh times. * include the expires and refresh times.
*/ */
isc_time_t timestamp;
result = dns_zone_getloadtime(zone, &timestamp); CHECK(dns_zone_getloadtime(zone, &timestamp));
if (result != ISC_R_SUCCESS) {
goto error;
}
isc_time_formatISO8601(&timestamp, buf, 64); isc_time_formatISO8601(&timestamp, buf, 64);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "loaded")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "loaded"));
@ -1827,19 +1831,13 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
if (dns_zone_gettype(zone) == dns_zone_slave) { if (dns_zone_gettype(zone) == dns_zone_slave) {
result = dns_zone_getexpiretime(zone, &timestamp); CHECK(dns_zone_getexpiretime(zone, &timestamp));
if (result != ISC_R_SUCCESS) {
goto error;
}
isc_time_formatISO8601(&timestamp, buf, 64); isc_time_formatISO8601(&timestamp, buf, 64);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "expires")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "expires"));
TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR buf)); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR buf));
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
result = dns_zone_getrefreshtime(zone, &timestamp); CHECK(dns_zone_getrefreshtime(zone, &timestamp));
if (result != ISC_R_SUCCESS) {
goto error;
}
isc_time_formatISO8601(&timestamp, buf, 64); isc_time_formatISO8601(&timestamp, buf, 64);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "refresh")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "refresh"));
TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR buf)); TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR buf));
@ -1862,14 +1860,11 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
ISC_XMLCHAR "type", ISC_XMLCHAR "type",
ISC_XMLCHAR "rcode")); ISC_XMLCHAR "rcode"));
result = dump_counters(zonestats, isc_statsformat_xml, CHECK(dump_counters(zonestats, isc_statsformat_xml,
writer, NULL, nsstats_xmldesc, writer, NULL, nsstats_xmldesc,
ns_statscounter_max, ns_statscounter_max, nsstats_index,
nsstats_index, nsstat_values, nsstat_values,
ISC_STATSDUMP_VERBOSE); ISC_STATSDUMP_VERBOSE));
if (result != ISC_R_SUCCESS) {
goto error;
}
/* counters type="rcode"*/ /* counters type="rcode"*/
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
} }
@ -1882,15 +1877,12 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
writer, ISC_XMLCHAR "type", writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "gluecache")); ISC_XMLCHAR "gluecache"));
result = dump_counters( CHECK(dump_counters(
gluecachestats, isc_statsformat_xml, writer, gluecachestats, isc_statsformat_xml, writer,
NULL, gluecachestats_xmldesc, NULL, gluecachestats_xmldesc,
dns_gluecachestatscounter_max, dns_gluecachestatscounter_max,
gluecachestats_index, gluecachestats_values, gluecachestats_index, gluecachestats_values,
ISC_STATSDUMP_VERBOSE); ISC_STATSDUMP_VERBOSE));
if (result != ISC_R_SUCCESS) {
goto error;
}
/* counters type="rcode"*/ /* counters type="rcode"*/
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
} }
@ -1906,9 +1898,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
dumparg.result = ISC_R_SUCCESS; dumparg.result = ISC_R_SUCCESS;
dns_rdatatypestats_dump(rcvquerystats, rdtypestat_dump, dns_rdatatypestats_dump(rcvquerystats, rdtypestat_dump,
&dumparg, 0); &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { CHECK(dumparg.result);
goto error;
}
/* counters type="qtype"*/ /* counters type="qtype"*/
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
@ -1927,9 +1917,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
dns_dnssecsignstats_dump( dns_dnssecsignstats_dump(
dnssecsignstats, dns_dnssecsignstats_sign, dnssecsignstats, dns_dnssecsignstats_sign,
dnssecsignstat_dump, &dumparg, 0); dnssecsignstat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { CHECK(dumparg.result);
goto error;
}
/* counters type="dnssec-sign"*/ /* counters type="dnssec-sign"*/
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
@ -1945,9 +1933,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
dns_dnssecsignstats_dump( dns_dnssecsignstats_dump(
dnssecsignstats, dns_dnssecsignstats_refresh, dnssecsignstats, dns_dnssecsignstats_refresh,
dnssecsignstat_dump, &dumparg, 0); dnssecsignstat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { CHECK(dumparg.result);
goto error;
}
/* counters type="dnssec-refresh"*/ /* counters type="dnssec-refresh"*/
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
@ -1957,7 +1943,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
TRY0(xmlTextWriterEndElement(writer)); /* zone */ TRY0(xmlTextWriterEndElement(writer)); /* zone */
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
error: cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"Failed at zone_xmlrender()"); "Failed at zone_xmlrender()");
@ -1999,7 +1985,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
writer = xmlNewTextWriterDoc(&doc, 0); writer = xmlNewTextWriterDoc(&doc, 0);
if (writer == NULL) { if (writer == NULL) {
goto error; goto cleanup;
} }
TRY0(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL)); TRY0(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL));
TRY0(xmlTextWriterWritePI(writer, ISC_XMLCHAR "xml-stylesheet", TRY0(xmlTextWriterWritePI(writer, ISC_XMLCHAR "xml-stylesheet",
@ -2037,9 +2023,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dns_opcodestats_dump(server->sctx->opcodestats, opcodestat_dump, dns_opcodestats_dump(server->sctx->opcodestats, opcodestat_dump,
&dumparg, ISC_STATSDUMP_VERBOSE); &dumparg, ISC_STATSDUMP_VERBOSE);
if (dumparg.result != ISC_R_SUCCESS) { CHECK(dumparg.result);
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
@ -2049,9 +2033,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dns_rcodestats_dump(server->sctx->rcodestats, rcodestat_dump, dns_rcodestats_dump(server->sctx->rcodestats, rcodestat_dump,
&dumparg, ISC_STATSDUMP_VERBOSE); &dumparg, ISC_STATSDUMP_VERBOSE);
if (dumparg.result != ISC_R_SUCCESS) { CHECK(dumparg.result);
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
@ -2062,23 +2044,19 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dumparg.result = ISC_R_SUCCESS; dumparg.result = ISC_R_SUCCESS;
dns_rdatatypestats_dump(server->sctx->rcvquerystats, dns_rdatatypestats_dump(server->sctx->rcvquerystats,
rdtypestat_dump, &dumparg, 0); rdtypestat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { CHECK(dumparg.result);
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* counters */ TRY0(xmlTextWriterEndElement(writer)); /* counters */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "nsstat")); ISC_XMLCHAR "nsstat"));
result = dump_counters(ns_stats_get(server->sctx->nsstats), CHECK(dump_counters(ns_stats_get(server->sctx->nsstats),
isc_statsformat_xml, writer, NULL, isc_statsformat_xml, writer, NULL,
nsstats_xmldesc, ns_statscounter_max, nsstats_xmldesc, ns_statscounter_max,
nsstats_index, nsstat_values, nsstats_index, nsstat_values,
ISC_STATSDUMP_VERBOSE); ISC_STATSDUMP_VERBOSE));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* /nsstat */ TRY0(xmlTextWriterEndElement(writer)); /* /nsstat */
@ -2086,14 +2064,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "zonestat")); ISC_XMLCHAR "zonestat"));
result = dump_counters(server->zonestats, isc_statsformat_xml, CHECK(dump_counters(server->zonestats, isc_statsformat_xml,
writer, NULL, zonestats_xmldesc, writer, NULL, zonestats_xmldesc,
dns_zonestatscounter_max, dns_zonestatscounter_max, zonestats_index,
zonestats_index, zonestat_values, zonestat_values, ISC_STATSDUMP_VERBOSE));
ISC_STATSDUMP_VERBOSE);
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* /zonestat */ TRY0(xmlTextWriterEndElement(writer)); /* /zonestat */
@ -2104,13 +2078,11 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "resstat")); ISC_XMLCHAR "resstat"));
result = dump_counters( CHECK(dump_counters(server->resolverstats, isc_statsformat_xml,
server->resolverstats, isc_statsformat_xml, writer, writer, NULL, resstats_xmldesc,
NULL, resstats_xmldesc, dns_resstatscounter_max, dns_resstatscounter_max, resstats_index,
resstats_index, resstat_values, 0); resstat_values, 0));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* resstat */ TRY0(xmlTextWriterEndElement(writer)); /* resstat */
#ifdef HAVE_DNSTAP #ifdef HAVE_DNSTAP
@ -2127,9 +2099,8 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dnstapstats_xmldesc, dns_dnstapcounter_max, dnstapstats_xmldesc, dns_dnstapcounter_max,
dnstapstats_index, dnstapstat_values, 0); dnstapstats_index, dnstapstat_values, 0);
isc_stats_detach(&dnstapstats); isc_stats_detach(&dnstapstats);
if (result != ISC_R_SUCCESS) { CHECK(result);
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* dnstap */ TRY0(xmlTextWriterEndElement(writer)); /* dnstap */
} }
#endif /* ifdef HAVE_DNSTAP */ #endif /* ifdef HAVE_DNSTAP */
@ -2140,14 +2111,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "sockstat")); ISC_XMLCHAR "sockstat"));
result = dump_counters(server->sockstats, isc_statsformat_xml, CHECK(dump_counters(server->sockstats, isc_statsformat_xml,
writer, NULL, sockstats_xmldesc, writer, NULL, sockstats_xmldesc,
isc_sockstatscounter_max, isc_sockstatscounter_max, sockstats_index,
sockstats_index, sockstat_values, sockstat_values, ISC_STATSDUMP_VERBOSE));
ISC_STATSDUMP_VERBOSE);
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* /sockstat */ TRY0(xmlTextWriterEndElement(writer)); /* /sockstat */
} }
@ -2161,13 +2128,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "request-size")); ISC_XMLCHAR "request-size"));
result = dump_counters( CHECK(dump_counters(
server->sctx->udpinstats4, isc_statsformat_xml, writer, server->sctx->udpinstats4, isc_statsformat_xml, writer,
NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max, NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max,
udpinsizestats_index, udpinsizestat_values, 0); udpinsizestats_index, udpinsizestat_values, 0));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */ TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
@ -2175,13 +2139,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "response-size")); ISC_XMLCHAR "response-size"));
result = dump_counters( CHECK(dump_counters(
server->sctx->udpoutstats4, isc_statsformat_xml, writer, server->sctx->udpoutstats4, isc_statsformat_xml, writer,
NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max, NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max,
udpoutsizestats_index, udpoutsizestat_values, 0); udpoutsizestats_index, udpoutsizestat_values, 0));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */ TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterEndElement(writer)); /* </udp> */ TRY0(xmlTextWriterEndElement(writer)); /* </udp> */
@ -2191,27 +2152,20 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "request-size")); ISC_XMLCHAR "request-size"));
result = dump_counters( CHECK(dump_counters(
server->sctx->tcpinstats4, isc_statsformat_xml, writer, server->sctx->tcpinstats4, isc_statsformat_xml, writer,
NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max, NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max,
tcpinsizestats_index, tcpinsizestat_values, 0); tcpinsizestats_index, tcpinsizestat_values, 0));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */ TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "response-size")); ISC_XMLCHAR "response-size"));
result = dump_counters( CHECK(dump_counters(
server->sctx->tcpoutstats4, isc_statsformat_xml, writer, server->sctx->tcpoutstats4, isc_statsformat_xml, writer,
NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max, NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max,
tcpoutsizestats_index, tcpoutsizestat_values, 0); tcpoutsizestats_index, tcpoutsizestat_values, 0));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */ TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterEndElement(writer)); /* </tcp> */ TRY0(xmlTextWriterEndElement(writer)); /* </tcp> */
@ -2223,13 +2177,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "request-size")); ISC_XMLCHAR "request-size"));
result = dump_counters( CHECK(dump_counters(
server->sctx->udpinstats6, isc_statsformat_xml, writer, server->sctx->udpinstats6, isc_statsformat_xml, writer,
NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max, NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max,
udpinsizestats_index, udpinsizestat_values, 0); udpinsizestats_index, udpinsizestat_values, 0));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */ TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
@ -2237,13 +2188,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "response-size")); ISC_XMLCHAR "response-size"));
result = dump_counters( CHECK(dump_counters(
server->sctx->udpoutstats6, isc_statsformat_xml, writer, server->sctx->udpoutstats6, isc_statsformat_xml, writer,
NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max, NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max,
udpoutsizestats_index, udpoutsizestat_values, 0); udpoutsizestats_index, udpoutsizestat_values, 0));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */ TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterEndElement(writer)); /* </udp> */ TRY0(xmlTextWriterEndElement(writer)); /* </udp> */
@ -2253,13 +2201,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "request-size")); ISC_XMLCHAR "request-size"));
result = dump_counters( CHECK(dump_counters(
server->sctx->tcpinstats6, isc_statsformat_xml, writer, server->sctx->tcpinstats6, isc_statsformat_xml, writer,
NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max, NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max,
tcpinsizestats_index, tcpinsizestat_values, 0); tcpinsizestats_index, tcpinsizestat_values, 0));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */ TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
@ -2267,13 +2212,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "response-size")); ISC_XMLCHAR "response-size"));
result = dump_counters( CHECK(dump_counters(
server->sctx->tcpoutstats6, isc_statsformat_xml, writer, server->sctx->tcpoutstats6, isc_statsformat_xml, writer,
NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max, NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max,
tcpoutsizestats_index, tcpoutsizestat_values, 0); tcpoutsizestats_index, tcpoutsizestat_values, 0));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */ TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterEndElement(writer)); /* </tcp> */ TRY0(xmlTextWriterEndElement(writer)); /* </tcp> */
@ -2296,11 +2238,8 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
if ((flags & STATS_XML_ZONES) != 0) { if ((flags & STATS_XML_ZONES) != 0) {
TRY0(xmlTextWriterStartElement(writer, TRY0(xmlTextWriterStartElement(writer,
ISC_XMLCHAR "zones")); ISC_XMLCHAR "zones"));
result = dns_zt_apply(view->zonetable, true, NULL, CHECK(dns_zt_apply(view->zonetable, true, NULL,
zone_xmlrender, writer); zone_xmlrender, writer));
if (result != ISC_R_SUCCESS) {
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* /zones */ TRY0(xmlTextWriterEndElement(writer)); /* /zones */
} }
@ -2318,9 +2257,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dumparg.result = ISC_R_SUCCESS; dumparg.result = ISC_R_SUCCESS;
dns_rdatatypestats_dump(view->resquerystats, dns_rdatatypestats_dump(view->resquerystats,
rdtypestat_dump, &dumparg, 0); rdtypestat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { CHECK(dumparg.result);
goto error;
}
} }
TRY0(xmlTextWriterEndElement(writer)); TRY0(xmlTextWriterEndElement(writer));
@ -2329,14 +2266,11 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "resstats")); ISC_XMLCHAR "resstats"));
if (view->resstats != NULL) { if (view->resstats != NULL) {
result = dump_counters( CHECK(dump_counters(view->resstats, isc_statsformat_xml,
view->resstats, isc_statsformat_xml, writer, writer, NULL, resstats_xmldesc,
NULL, resstats_xmldesc, dns_resstatscounter_max, dns_resstatscounter_max,
resstats_index, resstat_values, resstats_index, resstat_values,
ISC_STATSDUMP_VERBOSE); ISC_STATSDUMP_VERBOSE));
if (result != ISC_R_SUCCESS) {
goto error;
}
} }
TRY0(xmlTextWriterEndElement(writer)); /* </resstats> */ TRY0(xmlTextWriterEndElement(writer)); /* </resstats> */
@ -2350,9 +2284,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dumparg.result = ISC_R_SUCCESS; dumparg.result = ISC_R_SUCCESS;
dns_rdatasetstats_dump(cacherrstats, rdatasetstats_dump, dns_rdatasetstats_dump(cacherrstats, rdatasetstats_dump,
&dumparg, 0); &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { CHECK(dumparg.result);
goto error;
}
TRY0(xmlTextWriterEndElement(writer)); /* cache */ TRY0(xmlTextWriterEndElement(writer)); /* cache */
} }
@ -2361,14 +2293,11 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type", TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "adbstat")); ISC_XMLCHAR "adbstat"));
if (view->adbstats != NULL) { if (view->adbstats != NULL) {
result = dump_counters( CHECK(dump_counters(view->adbstats, isc_statsformat_xml,
view->adbstats, isc_statsformat_xml, writer, writer, NULL, adbstats_xmldesc,
NULL, adbstats_xmldesc, dns_adbstats_max, dns_adbstats_max, adbstats_index,
adbstats_index, adbstat_values, adbstat_values,
ISC_STATSDUMP_VERBOSE); ISC_STATSDUMP_VERBOSE));
if (result != ISC_R_SUCCESS) {
goto error;
}
} }
TRY0(xmlTextWriterEndElement(writer)); /* </adbstats> */ TRY0(xmlTextWriterEndElement(writer)); /* </adbstats> */
@ -2411,12 +2340,12 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
xmlDocDumpFormatMemoryEnc(doc, buf, buflen, "UTF-8", 0); xmlDocDumpFormatMemoryEnc(doc, buf, buflen, "UTF-8", 0);
if (*buf == NULL) { if (*buf == NULL) {
goto error; goto cleanup;
} }
xmlFreeDoc(doc); xmlFreeDoc(doc);
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
error: cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed generating XML response"); "failed generating XML response");
@ -2573,18 +2502,11 @@ render_xml_traffic(const char *url, isc_httpdurl_t *urlinfo,
#define STATS_JSON_TRAFFIC 0x20 #define STATS_JSON_TRAFFIC 0x20
#define STATS_JSON_ALL 0xff #define STATS_JSON_ALL 0xff
#define CHECK(m) \
do { \
result = (m); \
if (result != ISC_R_SUCCESS) \
goto error; \
} while (0)
#define CHECKMEM(m) \ #define CHECKMEM(m) \
do { \ do { \
if (m == NULL) { \ if (m == NULL) { \
result = ISC_R_NOMEMORY; \ result = ISC_R_NOMEMORY; \
goto error; \ goto cleanup; \
} \ } \
} while (0) } while (0)
@ -2664,27 +2586,18 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
isc_time_t timestamp; isc_time_t timestamp;
result = dns_zone_getloadtime(zone, &timestamp); CHECK(dns_zone_getloadtime(zone, &timestamp));
if (result != ISC_R_SUCCESS) {
goto error;
}
isc_time_formatISO8601(&timestamp, buf, 64); isc_time_formatISO8601(&timestamp, buf, 64);
json_object_object_add(zoneobj, "loaded", json_object_new_string(buf)); json_object_object_add(zoneobj, "loaded", json_object_new_string(buf));
if (dns_zone_gettype(zone) == dns_zone_slave) { if (dns_zone_gettype(zone) == dns_zone_slave) {
result = dns_zone_getexpiretime(zone, &timestamp); CHECK(dns_zone_getexpiretime(zone, &timestamp));
if (result != ISC_R_SUCCESS) {
goto error;
}
isc_time_formatISO8601(&timestamp, buf, 64); isc_time_formatISO8601(&timestamp, buf, 64);
json_object_object_add(zoneobj, "expires", json_object_object_add(zoneobj, "expires",
json_object_new_string(buf)); json_object_new_string(buf));
result = dns_zone_getrefreshtime(zone, &timestamp); CHECK(dns_zone_getrefreshtime(zone, &timestamp));
if (result != ISC_R_SUCCESS) {
goto error;
}
isc_time_formatISO8601(&timestamp, buf, 64); isc_time_formatISO8601(&timestamp, buf, 64);
json_object_object_add(zoneobj, "refresh", json_object_object_add(zoneobj, "refresh",
json_object_new_string(buf)); json_object_new_string(buf));
@ -2703,7 +2616,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
json_object *counters = json_object_new_object(); json_object *counters = json_object_new_object();
if (counters == NULL) { if (counters == NULL) {
result = ISC_R_NOMEMORY; result = ISC_R_NOMEMORY;
goto error; goto cleanup;
} }
result = dump_counters(zonestats, isc_statsformat_json, result = dump_counters(zonestats, isc_statsformat_json,
@ -2712,7 +2625,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
nsstats_index, nsstat_values, 0); nsstats_index, nsstat_values, 0);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -2728,7 +2641,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
json_object *counters = json_object_new_object(); json_object *counters = json_object_new_object();
if (counters == NULL) { if (counters == NULL) {
result = ISC_R_NOMEMORY; result = ISC_R_NOMEMORY;
goto error; goto cleanup;
} }
result = dump_counters( result = dump_counters(
@ -2738,7 +2651,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
gluecachestats_index, gluecachestats_values, 0); gluecachestats_index, gluecachestats_values, 0);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -2762,7 +2675,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
&dumparg, 0); &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -2787,7 +2700,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
dnssecsignstat_dump, &dumparg, 0); dnssecsignstat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(sign_counters); json_object_put(sign_counters);
goto error; goto cleanup;
} }
if (json_object_get_object(sign_counters)->count != 0) { if (json_object_get_object(sign_counters)->count != 0) {
@ -2809,7 +2722,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
dnssecsignstat_dump, &dumparg, 0); dnssecsignstat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(refresh_counters); json_object_put(refresh_counters);
goto error; goto cleanup;
} }
if (json_object_get_object(refresh_counters)->count != if (json_object_get_object(refresh_counters)->count !=
@ -2827,7 +2740,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
zoneobj = NULL; zoneobj = NULL;
result = ISC_R_SUCCESS; result = ISC_R_SUCCESS;
error: cleanup:
if (zoneobj != NULL) { if (zoneobj != NULL) {
json_object_put(zoneobj); json_object_put(zoneobj);
} }
@ -2912,7 +2825,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
&dumparg, ISC_STATSDUMP_VERBOSE); &dumparg, ISC_STATSDUMP_VERBOSE);
if (dumparg.result != ISC_R_SUCCESS) { if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -2931,7 +2844,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
&dumparg, ISC_STATSDUMP_VERBOSE); &dumparg, ISC_STATSDUMP_VERBOSE);
if (dumparg.result != ISC_R_SUCCESS) { if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -2950,7 +2863,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
rdtypestat_dump, &dumparg, 0); rdtypestat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) { if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -2971,7 +2884,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
nsstats_index, nsstat_values, 0); nsstats_index, nsstat_values, 0);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -2992,7 +2905,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
zonestats_index, zonestat_values, 0); zonestats_index, zonestat_values, 0);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -3014,7 +2927,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
resstats_index, resstat_values, 0); resstats_index, resstat_values, 0);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -3039,7 +2952,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
isc_stats_detach(&dnstapstats); isc_stats_detach(&dnstapstats);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -3069,12 +2982,8 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
CHECKMEM(za); CHECKMEM(za);
if ((flags & STATS_JSON_ZONES) != 0) { if ((flags & STATS_JSON_ZONES) != 0) {
result = dns_zt_apply(view->zonetable, true, CHECK(dns_zt_apply(view->zonetable, true, NULL,
NULL, zone_jsonrender, zone_jsonrender, za));
za);
if (result != ISC_R_SUCCESS) {
goto error;
}
} }
if (json_object_array_length(za) != 0) { if (json_object_array_length(za) != 0) {
@ -3107,7 +3016,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
result = dumparg.result; result = dumparg.result;
goto error; goto cleanup;
} }
json_object_object_add(res, "stats", json_object_object_add(res, "stats",
@ -3127,7 +3036,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
if (dumparg.result != ISC_R_SUCCESS) { if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
result = dumparg.result; result = dumparg.result;
goto error; goto cleanup;
} }
json_object_object_add(res, "qtypes", json_object_object_add(res, "qtypes",
@ -3147,7 +3056,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
if (dumparg.result != ISC_R_SUCCESS) { if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
result = dumparg.result; result = dumparg.result;
goto error; goto cleanup;
} }
json_object_object_add(res, "cache", json_object_object_add(res, "cache",
@ -3161,7 +3070,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
counters); counters);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
json_object_object_add(res, "cachestats", json_object_object_add(res, "cachestats",
@ -3182,7 +3091,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
result = dumparg.result; result = dumparg.result;
goto error; goto cleanup;
} }
json_object_object_add(res, "adb", json_object_object_add(res, "adb",
@ -3208,7 +3117,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
sockstats_index, sockstat_values, 0); sockstats_index, sockstat_values, 0);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(counters); json_object_put(counters);
goto error; goto cleanup;
} }
if (json_object_get_object(counters)->count != 0) { if (json_object_get_object(counters)->count != 0) {
@ -3224,7 +3133,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
result = isc_socketmgr_renderjson(named_g_socketmgr, sockets); result = isc_socketmgr_renderjson(named_g_socketmgr, sockets);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(sockets); json_object_put(sockets);
goto error; goto cleanup;
} }
json_object_object_add(bindstats, "socketmgr", sockets); json_object_object_add(bindstats, "socketmgr", sockets);
@ -3237,7 +3146,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
result = isc_taskmgr_renderjson(named_g_taskmgr, tasks); result = isc_taskmgr_renderjson(named_g_taskmgr, tasks);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(tasks); json_object_put(tasks);
goto error; goto cleanup;
} }
json_object_object_add(bindstats, "taskmgr", tasks); json_object_object_add(bindstats, "taskmgr", tasks);
@ -3250,7 +3159,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
result = isc_mem_renderjson(memory); result = isc_mem_renderjson(memory);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
json_object_put(memory); json_object_put(memory);
goto error; goto cleanup;
} }
json_object_object_add(bindstats, "memory", memory); json_object_object_add(bindstats, "memory", memory);
@ -3375,7 +3284,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
result = ISC_R_SUCCESS; result = ISC_R_SUCCESS;
error: cleanup:
if (udpreq4 != NULL) { if (udpreq4 != NULL) {
json_object_put(udpreq4); json_object_put(udpreq4);
} }
@ -3654,7 +3563,7 @@ client_ok(const isc_sockaddr_t *fromaddr, void *arg) {
static void static void
destroy_listener(void *arg) { destroy_listener(void *arg) {
named_statschannel_t *listener = arg; named_statschannel_t *listener = (named_statschannel_t *)arg;
REQUIRE(listener != NULL); REQUIRE(listener != NULL);
REQUIRE(!ISC_LINK_LINKED(listener, link)); REQUIRE(!ISC_LINK_LINKED(listener, link));
@ -3672,22 +3581,15 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp,
isc_sockaddr_t *addr, cfg_aclconfctx_t *aclconfctx, isc_sockaddr_t *addr, cfg_aclconfctx_t *aclconfctx,
const char *socktext) { const char *socktext) {
isc_result_t result; isc_result_t result;
named_statschannel_t *listener; named_statschannel_t *listener = NULL;
isc_task_t *task = NULL; const cfg_obj_t *allow = NULL;
isc_socket_t *sock = NULL;
const cfg_obj_t *allow;
dns_acl_t *new_acl = NULL; dns_acl_t *new_acl = NULL;
int pf;
listener = isc_mem_get(server->mctx, sizeof(*listener)); listener = isc_mem_get(server->mctx, sizeof(*listener));
*listener = (named_statschannel_t){ .address = *addr };
listener->httpdmgr = NULL;
listener->address = *addr;
listener->acl = NULL;
listener->mctx = NULL;
ISC_LINK_INIT(listener, link); ISC_LINK_INIT(listener, link);
isc_mutex_init(&listener->lock); isc_mutex_init(&listener->lock);
isc_mem_attach(server->mctx, &listener->mctx); isc_mem_attach(server->mctx, &listener->mctx);
allow = cfg_tuple_get(listen_params, "allow"); allow = cfg_tuple_get(listen_params, "allow");
@ -3698,82 +3600,65 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp,
} else { } else {
result = dns_acl_any(listener->mctx, &new_acl); result = dns_acl_any(listener->mctx, &new_acl);
} }
if (result != ISC_R_SUCCESS) { CHECK(result);
goto cleanup;
}
dns_acl_attach(new_acl, &listener->acl); dns_acl_attach(new_acl, &listener->acl);
dns_acl_detach(&new_acl); dns_acl_detach(&new_acl);
result = isc_task_create(named_g_taskmgr, 0, &task); pf = isc_sockaddr_pf(&listener->address);
if (result != ISC_R_SUCCESS) { if ((pf == AF_INET && isc_net_probeipv4() != ISC_R_SUCCESS) ||
goto cleanup; (pf == AF_INET6 && isc_net_probeipv6() != ISC_R_SUCCESS))
} {
isc_task_setname(task, "statchannel", NULL); CHECK(ISC_R_FAMILYNOSUPPORT);
result = isc_socket_create(named_g_socketmgr, isc_sockaddr_pf(addr),
isc_sockettype_tcp, &sock);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
isc_socket_setname(sock, "statchannel", NULL);
#ifndef ISC_ALLOW_MAPPED
isc_socket_ipv6only(sock, true);
#endif /* ifndef ISC_ALLOW_MAPPED */
result = isc_socket_bind(sock, addr, ISC_SOCKET_REUSEADDRESS);
if (result != ISC_R_SUCCESS) {
goto cleanup;
} }
result = isc_httpdmgr_create(server->mctx, sock, task, client_ok, CHECK(isc_httpdmgr_create(named_g_nm, server->mctx, addr, client_ok,
destroy_listener, listener, destroy_listener, listener,
named_g_timermgr, &listener->httpdmgr); &listener->httpdmgr));
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
#ifdef HAVE_LIBXML2 #ifdef HAVE_LIBXML2
isc_httpdmgr_addurl(listener->httpdmgr, "/", render_xml_all, server); isc_httpdmgr_addurl(listener->httpdmgr, "/", false, render_xml_all,
isc_httpdmgr_addurl(listener->httpdmgr, "/xml", render_xml_all, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3", render_xml_all,
server); server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/status", isc_httpdmgr_addurl(listener->httpdmgr, "/xml", false, render_xml_all,
server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3", false,
render_xml_all, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/status", false,
render_xml_status, server); render_xml_status, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/server", isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/server", false,
render_xml_server, server); render_xml_server, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/zones", isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/zones", false,
render_xml_zones, server); render_xml_zones, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/net", render_xml_net, isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/net", false,
server); render_xml_net, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/tasks", isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/tasks", false,
render_xml_tasks, server); render_xml_tasks, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/mem", render_xml_mem, isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/mem", false,
server); render_xml_mem, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/traffic", isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/traffic", false,
render_xml_traffic, server); render_xml_traffic, server);
#endif /* ifdef HAVE_LIBXML2 */ #endif /* ifdef HAVE_LIBXML2 */
#ifdef HAVE_JSON_C #ifdef HAVE_JSON_C
isc_httpdmgr_addurl(listener->httpdmgr, "/json", render_json_all, isc_httpdmgr_addurl(listener->httpdmgr, "/json", false, render_json_all,
server); server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1", render_json_all, isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1", false,
server); render_json_all, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/status", isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/status", false,
render_json_status, server); render_json_status, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/server", isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/server", false,
render_json_server, server); render_json_server, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/zones", isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/zones", false,
render_json_zones, server); render_json_zones, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/tasks", isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/tasks", false,
render_json_tasks, server); render_json_tasks, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/net", render_json_net, isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/net", false,
server); render_json_net, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/mem", render_json_mem, isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/mem", false,
server); render_json_mem, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/traffic", isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/traffic", false,
render_json_traffic, server); render_json_traffic, server);
#endif /* ifdef HAVE_JSON_C */ #endif /* ifdef HAVE_JSON_C */
isc_httpdmgr_addurl2(listener->httpdmgr, "/bind9.xsl", true, render_xsl, isc_httpdmgr_addurl(listener->httpdmgr, "/bind9.xsl", true, render_xsl,
server); server);
*listenerp = listener; *listenerp = listener;
@ -3781,21 +3666,14 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp,
NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE, NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE,
"statistics channel listening on %s", socktext); "statistics channel listening on %s", socktext);
return (ISC_R_SUCCESS);
cleanup: cleanup:
if (result != ISC_R_SUCCESS) {
if (listener->acl != NULL) { if (listener->acl != NULL) {
dns_acl_detach(&listener->acl); dns_acl_detach(&listener->acl);
} }
isc_mutex_destroy(&listener->lock); isc_mutex_destroy(&listener->lock);
isc_mem_putanddetach(&listener->mctx, listener, isc_mem_putanddetach(&listener->mctx, listener, sizeof(*listener));
sizeof(*listener));
}
if (task != NULL) {
isc_task_detach(&task);
}
if (sock != NULL) {
isc_socket_detach(&sock);
}
return (result); return (result);
} }

File diff suppressed because it is too large Load Diff

View File

@ -42,41 +42,21 @@ struct isc_httpdurl {
#define HTTPD_EVENTCLASS ISC_EVENTCLASS(4300) #define HTTPD_EVENTCLASS ISC_EVENTCLASS(4300)
#define HTTPD_SHUTDOWN (HTTPD_EVENTCLASS + 0x0001) #define HTTPD_SHUTDOWN (HTTPD_EVENTCLASS + 0x0001)
#define ISC_HTTPDMGR_FLAGSHUTTINGDOWN 0x00000001 #define ISC_HTTPDMGR_SHUTTINGDOWN 0x00000001
/*
* Create a new http daemon which will send, once every time period,
* a http-like header followed by HTTP data.
*/
isc_result_t isc_result_t
isc_httpdmgr_create(isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task, isc_httpdmgr_create(isc_nm_t *nm, isc_mem_t *mctx, isc_sockaddr_t *addr,
isc_httpdclientok_t * client_ok, isc_httpdclientok_t * client_ok,
isc_httpdondestroy_t *ondestory, void *cb_arg, isc_httpdondestroy_t *ondestroy, void *cb_arg,
isc_timermgr_t *tmgr, isc_httpdmgr_t **httpdp); isc_httpdmgr_t **httpdmgrp);
void void
isc_httpdmgr_shutdown(isc_httpdmgr_t **httpdp); isc_httpdmgr_shutdown(isc_httpdmgr_t **httpdp);
isc_result_t isc_result_t
isc_httpdmgr_addurl(isc_httpdmgr_t *httpdmgr, const char *url, isc_httpdmgr_addurl(isc_httpdmgr_t *httpdmgr, const char *url, bool isstatic,
isc_httpdaction_t *func, void *arg); isc_httpdaction_t *func, void *arg);
isc_result_t
isc_httpdmgr_addurl2(isc_httpdmgr_t *httpdmgr, const char *url, bool isstatic,
isc_httpdaction_t *func, void *arg);
isc_result_t
isc_httpd_response(isc_httpd_t *httpd);
isc_result_t
isc_httpd_addheader(isc_httpd_t *httpd, const char *name, const char *val);
isc_result_t
isc_httpd_addheaderuint(isc_httpd_t *httpd, const char *name, int val);
isc_result_t
isc_httpd_endheaders(isc_httpd_t *httpd);
void void
isc_httpd_setfinishhook(void (*fn)(void)); isc_httpd_setfinishhook(void (*fn)(void));

View File

@ -291,13 +291,8 @@ isc_ht_iter_delcurrent_next
isc_ht_iter_destroy isc_ht_iter_destroy
isc_ht_iter_first isc_ht_iter_first
isc_ht_iter_next isc_ht_iter_next
isc_httpd_addheader
isc_httpd_addheaderuint
isc_httpd_endheaders
isc_httpd_response
isc_httpd_setfinishhook isc_httpd_setfinishhook
isc_httpdmgr_addurl isc_httpdmgr_addurl
isc_httpdmgr_addurl2
isc_httpdmgr_create isc_httpdmgr_create
isc_httpdmgr_shutdown isc_httpdmgr_shutdown
isc_interfaceiter_create isc_interfaceiter_create