2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 05:28:00 +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/stats.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/util.h>
#include <dns/cache.h>
@ -54,6 +53,14 @@
#include "xsl_p.h"
#define CHECK(m) \
do { \
result = (m); \
if (result != ISC_R_SUCCESS) { \
goto cleanup; \
} \
} while (0)
struct named_statschannel {
/* Unlocked */
isc_httpdmgr_t *httpdmgr;
@ -170,11 +177,11 @@ static const char *gluecachestats_xmldesc[dns_gluecachestatscounter_max];
#define gluecachestats_xmldesc NULL
#endif /* EXTENDED_STATS */
#define TRY0(a) \
do { \
xmlrc = (a); \
if (xmlrc < 0) \
goto error; \
#define TRY0(a) \
do { \
xmlrc = (a); \
if (xmlrc < 0) \
goto cleanup; \
} while (0)
/*%
@ -1424,7 +1431,7 @@ dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg,
}
return (ISC_R_SUCCESS);
#ifdef HAVE_LIBXML2
error:
cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at dump_counters()");
@ -1486,7 +1493,7 @@ rdtypestat_dump(dns_rdatastatstype_t type, uint64_t val, void *arg) {
}
return;
#ifdef HAVE_LIBXML2
error:
cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at rdtypestat_dump()");
@ -1574,7 +1581,7 @@ rdatasetstats_dump(dns_rdatastatstype_t type, uint64_t val, void *arg) {
}
return;
#ifdef HAVE_LIBXML2
error:
cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at rdatasetstats_dump()");
@ -1629,7 +1636,7 @@ opcodestat_dump(dns_opcode_t code, uint64_t val, void *arg) {
return;
#ifdef HAVE_LIBXML2
error:
cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at opcodestat_dump()");
@ -1685,7 +1692,7 @@ rcodestat_dump(dns_rcode_t code, uint64_t val, void *arg) {
return;
#ifdef HAVE_LIBXML2
error:
cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at rcodestat_dump()");
@ -1738,7 +1745,7 @@ dnssecsignstat_dump(dns_keytag_t tag, uint64_t val, void *arg) {
}
return;
#ifdef HAVE_LIBXML2
error:
cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"failed at dnssecsignstat_dump()");
@ -1772,6 +1779,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
int xmlrc;
stats_dumparg_t dumparg;
const char *ztype;
isc_time_t timestamp;
statlevel = dns_zone_getstatlevel(zone);
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
* include the expires and refresh times.
*/
isc_time_t timestamp;
result = dns_zone_getloadtime(zone, &timestamp);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dns_zone_getloadtime(zone, &timestamp));
isc_time_formatISO8601(&timestamp, buf, 64);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "loaded"));
@ -1827,19 +1831,13 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
TRY0(xmlTextWriterEndElement(writer));
if (dns_zone_gettype(zone) == dns_zone_slave) {
result = dns_zone_getexpiretime(zone, &timestamp);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dns_zone_getexpiretime(zone, &timestamp));
isc_time_formatISO8601(&timestamp, buf, 64);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "expires"));
TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR buf));
TRY0(xmlTextWriterEndElement(writer));
result = dns_zone_getrefreshtime(zone, &timestamp);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dns_zone_getrefreshtime(zone, &timestamp));
isc_time_formatISO8601(&timestamp, buf, 64);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "refresh"));
TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR buf));
@ -1862,14 +1860,11 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
ISC_XMLCHAR "type",
ISC_XMLCHAR "rcode"));
result = dump_counters(zonestats, isc_statsformat_xml,
writer, NULL, nsstats_xmldesc,
ns_statscounter_max,
nsstats_index, nsstat_values,
ISC_STATSDUMP_VERBOSE);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dump_counters(zonestats, isc_statsformat_xml,
writer, NULL, nsstats_xmldesc,
ns_statscounter_max, nsstats_index,
nsstat_values,
ISC_STATSDUMP_VERBOSE));
/* counters type="rcode"*/
TRY0(xmlTextWriterEndElement(writer));
}
@ -1882,15 +1877,12 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "gluecache"));
result = dump_counters(
CHECK(dump_counters(
gluecachestats, isc_statsformat_xml, writer,
NULL, gluecachestats_xmldesc,
dns_gluecachestatscounter_max,
gluecachestats_index, gluecachestats_values,
ISC_STATSDUMP_VERBOSE);
if (result != ISC_R_SUCCESS) {
goto error;
}
ISC_STATSDUMP_VERBOSE));
/* counters type="rcode"*/
TRY0(xmlTextWriterEndElement(writer));
}
@ -1906,9 +1898,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
dumparg.result = ISC_R_SUCCESS;
dns_rdatatypestats_dump(rcvquerystats, rdtypestat_dump,
&dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dumparg.result);
/* counters type="qtype"*/
TRY0(xmlTextWriterEndElement(writer));
@ -1927,9 +1917,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
dns_dnssecsignstats_dump(
dnssecsignstats, dns_dnssecsignstats_sign,
dnssecsignstat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dumparg.result);
/* counters type="dnssec-sign"*/
TRY0(xmlTextWriterEndElement(writer));
@ -1945,9 +1933,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
dns_dnssecsignstats_dump(
dnssecsignstats, dns_dnssecsignstats_refresh,
dnssecsignstat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dumparg.result);
/* counters type="dnssec-refresh"*/
TRY0(xmlTextWriterEndElement(writer));
@ -1957,7 +1943,7 @@ zone_xmlrender(dns_zone_t *zone, void *arg) {
TRY0(xmlTextWriterEndElement(writer)); /* zone */
return (ISC_R_SUCCESS);
error:
cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"Failed at zone_xmlrender()");
@ -1999,7 +1985,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
writer = xmlNewTextWriterDoc(&doc, 0);
if (writer == NULL) {
goto error;
goto cleanup;
}
TRY0(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL));
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,
&dumparg, ISC_STATSDUMP_VERBOSE);
if (dumparg.result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dumparg.result);
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,
&dumparg, ISC_STATSDUMP_VERBOSE);
if (dumparg.result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dumparg.result);
TRY0(xmlTextWriterEndElement(writer));
@ -2062,23 +2044,19 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dumparg.result = ISC_R_SUCCESS;
dns_rdatatypestats_dump(server->sctx->rcvquerystats,
rdtypestat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dumparg.result);
TRY0(xmlTextWriterEndElement(writer)); /* counters */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "nsstat"));
result = dump_counters(ns_stats_get(server->sctx->nsstats),
isc_statsformat_xml, writer, NULL,
nsstats_xmldesc, ns_statscounter_max,
nsstats_index, nsstat_values,
ISC_STATSDUMP_VERBOSE);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dump_counters(ns_stats_get(server->sctx->nsstats),
isc_statsformat_xml, writer, NULL,
nsstats_xmldesc, ns_statscounter_max,
nsstats_index, nsstat_values,
ISC_STATSDUMP_VERBOSE));
TRY0(xmlTextWriterEndElement(writer)); /* /nsstat */
@ -2086,14 +2064,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "zonestat"));
result = dump_counters(server->zonestats, isc_statsformat_xml,
writer, NULL, zonestats_xmldesc,
dns_zonestatscounter_max,
zonestats_index, zonestat_values,
ISC_STATSDUMP_VERBOSE);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dump_counters(server->zonestats, isc_statsformat_xml,
writer, NULL, zonestats_xmldesc,
dns_zonestatscounter_max, zonestats_index,
zonestat_values, ISC_STATSDUMP_VERBOSE));
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(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "resstat"));
result = dump_counters(
server->resolverstats, isc_statsformat_xml, writer,
NULL, resstats_xmldesc, dns_resstatscounter_max,
resstats_index, resstat_values, 0);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dump_counters(server->resolverstats, isc_statsformat_xml,
writer, NULL, resstats_xmldesc,
dns_resstatscounter_max, resstats_index,
resstat_values, 0));
TRY0(xmlTextWriterEndElement(writer)); /* resstat */
#ifdef HAVE_DNSTAP
@ -2127,9 +2099,8 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dnstapstats_xmldesc, dns_dnstapcounter_max,
dnstapstats_index, dnstapstat_values, 0);
isc_stats_detach(&dnstapstats);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(result);
TRY0(xmlTextWriterEndElement(writer)); /* 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",
ISC_XMLCHAR "sockstat"));
result = dump_counters(server->sockstats, isc_statsformat_xml,
writer, NULL, sockstats_xmldesc,
isc_sockstatscounter_max,
sockstats_index, sockstat_values,
ISC_STATSDUMP_VERBOSE);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dump_counters(server->sockstats, isc_statsformat_xml,
writer, NULL, sockstats_xmldesc,
isc_sockstatscounter_max, sockstats_index,
sockstat_values, ISC_STATSDUMP_VERBOSE));
TRY0(xmlTextWriterEndElement(writer)); /* /sockstat */
}
@ -2161,13 +2128,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "request-size"));
result = dump_counters(
CHECK(dump_counters(
server->sctx->udpinstats4, isc_statsformat_xml, writer,
NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max,
udpinsizestats_index, udpinsizestat_values, 0);
if (result != ISC_R_SUCCESS) {
goto error;
}
udpinsizestats_index, udpinsizestat_values, 0));
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
@ -2175,13 +2139,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "response-size"));
result = dump_counters(
CHECK(dump_counters(
server->sctx->udpoutstats4, isc_statsformat_xml, writer,
NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max,
udpoutsizestats_index, udpoutsizestat_values, 0);
if (result != ISC_R_SUCCESS) {
goto error;
}
udpoutsizestats_index, udpoutsizestat_values, 0));
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterEndElement(writer)); /* </udp> */
@ -2191,27 +2152,20 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "request-size"));
result = dump_counters(
CHECK(dump_counters(
server->sctx->tcpinstats4, isc_statsformat_xml, writer,
NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max,
tcpinsizestats_index, tcpinsizestat_values, 0);
if (result != ISC_R_SUCCESS) {
goto error;
}
tcpinsizestats_index, tcpinsizestat_values, 0));
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "response-size"));
result = dump_counters(
CHECK(dump_counters(
server->sctx->tcpoutstats4, isc_statsformat_xml, writer,
NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max,
tcpoutsizestats_index, tcpoutsizestat_values, 0);
if (result != ISC_R_SUCCESS) {
goto error;
}
tcpoutsizestats_index, tcpoutsizestat_values, 0));
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterEndElement(writer)); /* </tcp> */
@ -2223,13 +2177,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "request-size"));
result = dump_counters(
CHECK(dump_counters(
server->sctx->udpinstats6, isc_statsformat_xml, writer,
NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max,
udpinsizestats_index, udpinsizestat_values, 0);
if (result != ISC_R_SUCCESS) {
goto error;
}
udpinsizestats_index, udpinsizestat_values, 0));
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
@ -2237,13 +2188,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "response-size"));
result = dump_counters(
CHECK(dump_counters(
server->sctx->udpoutstats6, isc_statsformat_xml, writer,
NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max,
udpoutsizestats_index, udpoutsizestat_values, 0);
if (result != ISC_R_SUCCESS) {
goto error;
}
udpoutsizestats_index, udpoutsizestat_values, 0));
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterEndElement(writer)); /* </udp> */
@ -2253,13 +2201,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "request-size"));
result = dump_counters(
CHECK(dump_counters(
server->sctx->tcpinstats6, isc_statsformat_xml, writer,
NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max,
tcpinsizestats_index, tcpinsizestat_values, 0);
if (result != ISC_R_SUCCESS) {
goto error;
}
tcpinsizestats_index, tcpinsizestat_values, 0));
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
@ -2267,13 +2212,10 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "response-size"));
result = dump_counters(
CHECK(dump_counters(
server->sctx->tcpoutstats6, isc_statsformat_xml, writer,
NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max,
tcpoutsizestats_index, tcpoutsizestat_values, 0);
if (result != ISC_R_SUCCESS) {
goto error;
}
tcpoutsizestats_index, tcpoutsizestat_values, 0));
TRY0(xmlTextWriterEndElement(writer)); /* </counters> */
TRY0(xmlTextWriterEndElement(writer)); /* </tcp> */
@ -2296,11 +2238,8 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
if ((flags & STATS_XML_ZONES) != 0) {
TRY0(xmlTextWriterStartElement(writer,
ISC_XMLCHAR "zones"));
result = dns_zt_apply(view->zonetable, true, NULL,
zone_xmlrender, writer);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dns_zt_apply(view->zonetable, true, NULL,
zone_xmlrender, writer));
TRY0(xmlTextWriterEndElement(writer)); /* /zones */
}
@ -2318,9 +2257,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dumparg.result = ISC_R_SUCCESS;
dns_rdatatypestats_dump(view->resquerystats,
rdtypestat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dumparg.result);
}
TRY0(xmlTextWriterEndElement(writer));
@ -2329,14 +2266,11 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "resstats"));
if (view->resstats != NULL) {
result = dump_counters(
view->resstats, isc_statsformat_xml, writer,
NULL, resstats_xmldesc, dns_resstatscounter_max,
resstats_index, resstat_values,
ISC_STATSDUMP_VERBOSE);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dump_counters(view->resstats, isc_statsformat_xml,
writer, NULL, resstats_xmldesc,
dns_resstatscounter_max,
resstats_index, resstat_values,
ISC_STATSDUMP_VERBOSE));
}
TRY0(xmlTextWriterEndElement(writer)); /* </resstats> */
@ -2350,9 +2284,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
dumparg.result = ISC_R_SUCCESS;
dns_rdatasetstats_dump(cacherrstats, rdatasetstats_dump,
&dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dumparg.result);
TRY0(xmlTextWriterEndElement(writer)); /* cache */
}
@ -2361,14 +2293,11 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen,
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "adbstat"));
if (view->adbstats != NULL) {
result = dump_counters(
view->adbstats, isc_statsformat_xml, writer,
NULL, adbstats_xmldesc, dns_adbstats_max,
adbstats_index, adbstat_values,
ISC_STATSDUMP_VERBOSE);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dump_counters(view->adbstats, isc_statsformat_xml,
writer, NULL, adbstats_xmldesc,
dns_adbstats_max, adbstats_index,
adbstat_values,
ISC_STATSDUMP_VERBOSE));
}
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);
if (*buf == NULL) {
goto error;
goto cleanup;
}
xmlFreeDoc(doc);
return (ISC_R_SUCCESS);
error:
cleanup:
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR,
"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_ALL 0xff
#define CHECK(m) \
do { \
result = (m); \
if (result != ISC_R_SUCCESS) \
goto error; \
} while (0)
#define CHECKMEM(m) \
do { \
if (m == NULL) { \
result = ISC_R_NOMEMORY; \
goto error; \
goto cleanup; \
} \
} while (0)
@ -2664,27 +2586,18 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
isc_time_t timestamp;
result = dns_zone_getloadtime(zone, &timestamp);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dns_zone_getloadtime(zone, &timestamp));
isc_time_formatISO8601(&timestamp, buf, 64);
json_object_object_add(zoneobj, "loaded", json_object_new_string(buf));
if (dns_zone_gettype(zone) == dns_zone_slave) {
result = dns_zone_getexpiretime(zone, &timestamp);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dns_zone_getexpiretime(zone, &timestamp));
isc_time_formatISO8601(&timestamp, buf, 64);
json_object_object_add(zoneobj, "expires",
json_object_new_string(buf));
result = dns_zone_getrefreshtime(zone, &timestamp);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dns_zone_getrefreshtime(zone, &timestamp));
isc_time_formatISO8601(&timestamp, buf, 64);
json_object_object_add(zoneobj, "refresh",
json_object_new_string(buf));
@ -2703,7 +2616,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
json_object *counters = json_object_new_object();
if (counters == NULL) {
result = ISC_R_NOMEMORY;
goto error;
goto cleanup;
}
result = dump_counters(zonestats, isc_statsformat_json,
@ -2712,7 +2625,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
nsstats_index, nsstat_values, 0);
if (result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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();
if (counters == NULL) {
result = ISC_R_NOMEMORY;
goto error;
goto cleanup;
}
result = dump_counters(
@ -2738,7 +2651,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
gluecachestats_index, gluecachestats_values, 0);
if (result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
if (json_object_get_object(counters)->count != 0) {
@ -2762,7 +2675,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
&dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
if (json_object_get_object(counters)->count != 0) {
@ -2787,7 +2700,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
dnssecsignstat_dump, &dumparg, 0);
if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(sign_counters);
goto error;
goto cleanup;
}
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);
if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(refresh_counters);
goto error;
goto cleanup;
}
if (json_object_get_object(refresh_counters)->count !=
@ -2827,7 +2740,7 @@ zone_jsonrender(dns_zone_t *zone, void *arg) {
zoneobj = NULL;
result = ISC_R_SUCCESS;
error:
cleanup:
if (zoneobj != NULL) {
json_object_put(zoneobj);
}
@ -2912,7 +2825,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
&dumparg, ISC_STATSDUMP_VERBOSE);
if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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);
if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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);
if (dumparg.result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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);
if (result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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);
if (result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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);
if (result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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);
if (result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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);
if ((flags & STATS_JSON_ZONES) != 0) {
result = dns_zt_apply(view->zonetable, true,
NULL, zone_jsonrender,
za);
if (result != ISC_R_SUCCESS) {
goto error;
}
CHECK(dns_zt_apply(view->zonetable, true, NULL,
zone_jsonrender, za));
}
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) {
json_object_put(counters);
result = dumparg.result;
goto error;
goto cleanup;
}
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) {
json_object_put(counters);
result = dumparg.result;
goto error;
goto cleanup;
}
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) {
json_object_put(counters);
result = dumparg.result;
goto error;
goto cleanup;
}
json_object_object_add(res, "cache",
@ -3161,7 +3070,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg,
counters);
if (result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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) {
json_object_put(counters);
result = dumparg.result;
goto error;
goto cleanup;
}
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);
if (result != ISC_R_SUCCESS) {
json_object_put(counters);
goto error;
goto cleanup;
}
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);
if (result != ISC_R_SUCCESS) {
json_object_put(sockets);
goto error;
goto cleanup;
}
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);
if (result != ISC_R_SUCCESS) {
json_object_put(tasks);
goto error;
goto cleanup;
}
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);
if (result != ISC_R_SUCCESS) {
json_object_put(memory);
goto error;
goto cleanup;
}
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;
error:
cleanup:
if (udpreq4 != NULL) {
json_object_put(udpreq4);
}
@ -3654,7 +3563,7 @@ client_ok(const isc_sockaddr_t *fromaddr, void *arg) {
static void
destroy_listener(void *arg) {
named_statschannel_t *listener = arg;
named_statschannel_t *listener = (named_statschannel_t *)arg;
REQUIRE(listener != NULL);
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,
const char *socktext) {
isc_result_t result;
named_statschannel_t *listener;
isc_task_t *task = NULL;
isc_socket_t *sock = NULL;
const cfg_obj_t *allow;
named_statschannel_t *listener = NULL;
const cfg_obj_t *allow = NULL;
dns_acl_t *new_acl = NULL;
int pf;
listener = isc_mem_get(server->mctx, sizeof(*listener));
listener->httpdmgr = NULL;
listener->address = *addr;
listener->acl = NULL;
listener->mctx = NULL;
*listener = (named_statschannel_t){ .address = *addr };
ISC_LINK_INIT(listener, link);
isc_mutex_init(&listener->lock);
isc_mem_attach(server->mctx, &listener->mctx);
allow = cfg_tuple_get(listen_params, "allow");
@ -3698,104 +3600,80 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp,
} else {
result = dns_acl_any(listener->mctx, &new_acl);
}
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
CHECK(result);
dns_acl_attach(new_acl, &listener->acl);
dns_acl_detach(&new_acl);
result = isc_task_create(named_g_taskmgr, 0, &task);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
isc_task_setname(task, "statchannel", NULL);
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;
pf = isc_sockaddr_pf(&listener->address);
if ((pf == AF_INET && isc_net_probeipv4() != ISC_R_SUCCESS) ||
(pf == AF_INET6 && isc_net_probeipv6() != ISC_R_SUCCESS))
{
CHECK(ISC_R_FAMILYNOSUPPORT);
}
result = isc_httpdmgr_create(server->mctx, sock, task, client_ok,
destroy_listener, listener,
named_g_timermgr, &listener->httpdmgr);
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
CHECK(isc_httpdmgr_create(named_g_nm, server->mctx, addr, client_ok,
destroy_listener, listener,
&listener->httpdmgr));
#ifdef HAVE_LIBXML2
isc_httpdmgr_addurl(listener->httpdmgr, "/", render_xml_all, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml", render_xml_all, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3", render_xml_all,
isc_httpdmgr_addurl(listener->httpdmgr, "/", false, render_xml_all,
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);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/server",
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/server", false,
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);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/net", render_xml_net,
server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/tasks",
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/net", false,
render_xml_net, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/tasks", false,
render_xml_tasks, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/mem", render_xml_mem,
server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/traffic",
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/mem", false,
render_xml_mem, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/traffic", false,
render_xml_traffic, server);
#endif /* ifdef HAVE_LIBXML2 */
#ifdef HAVE_JSON_C
isc_httpdmgr_addurl(listener->httpdmgr, "/json", render_json_all,
isc_httpdmgr_addurl(listener->httpdmgr, "/json", false, render_json_all,
server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1", render_json_all,
server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/status",
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1", false,
render_json_all, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/status", false,
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);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/zones",
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/zones", false,
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);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/net", render_json_net,
server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/mem", render_json_mem,
server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/traffic",
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/net", false,
render_json_net, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/mem", false,
render_json_mem, server);
isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/traffic", false,
render_json_traffic, server);
#endif /* ifdef HAVE_JSON_C */
isc_httpdmgr_addurl2(listener->httpdmgr, "/bind9.xsl", true, render_xsl,
server);
isc_httpdmgr_addurl(listener->httpdmgr, "/bind9.xsl", true, render_xsl,
server);
*listenerp = listener;
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE,
"statistics channel listening on %s", socktext);
return (ISC_R_SUCCESS);
cleanup:
if (result != ISC_R_SUCCESS) {
if (listener->acl != NULL) {
dns_acl_detach(&listener->acl);
}
isc_mutex_destroy(&listener->lock);
isc_mem_putanddetach(&listener->mctx, listener,
sizeof(*listener));
}
if (task != NULL) {
isc_task_detach(&task);
}
if (sock != NULL) {
isc_socket_detach(&sock);
if (listener->acl != NULL) {
dns_acl_detach(&listener->acl);
}
isc_mutex_destroy(&listener->lock);
isc_mem_putanddetach(&listener->mctx, listener, sizeof(*listener));
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_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_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_httpdondestroy_t *ondestory, void *cb_arg,
isc_timermgr_t *tmgr, isc_httpdmgr_t **httpdp);
isc_httpdondestroy_t *ondestroy, void *cb_arg,
isc_httpdmgr_t **httpdmgrp);
void
isc_httpdmgr_shutdown(isc_httpdmgr_t **httpdp);
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_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
isc_httpd_setfinishhook(void (*fn)(void));

View File

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