From 47d89fcd4fb850b066f87dc3313afe1cfe92cd99 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Fri, 12 Dec 2008 04:41:25 +0000 Subject: [PATCH] 2512. [func] Print a summary of the cached records which make up the negative response. [RT #18885] --- CHANGES | 3 +++ lib/dns/masterdump.c | 61 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 4e729e2f38..b85fb93640 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +2512. [func] Print a summary of the cached records which make up + the negative response. [RT #18885] + 2511. [cleanup] dns_rdata_tofmttext() add const to linebreak. [RT #18885] diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index 3d46458204..6e6a16a8d6 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: masterdump.c,v 1.94 2008/09/24 02:46:22 marka Exp $ */ +/* $Id: masterdump.c,v 1.95 2008/12/12 04:41:25 marka Exp $ */ /*! \file */ @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,11 @@ return (_r); \ } while (0) +#define CHECK(x) do { \ + if ((x) != ISC_R_SUCCESS) \ + goto cleanup; \ + } while (0) + struct dns_master_style { unsigned int flags; /* DNS_STYLEFLAG_* */ unsigned int ttl_column; @@ -336,6 +342,52 @@ str_totext(const char *source, isc_buffer_t *target) { return (ISC_R_SUCCESS); } +static isc_result_t +ncache_summary(dns_rdataset_t *rdataset, isc_boolean_t omit_final_dot, + isc_buffer_t *target) +{ + isc_result_t result = ISC_R_SUCCESS; + dns_rdataset_t rds; + dns_name_t name; + + dns_rdataset_init(&rds); + dns_name_init(&name, NULL); + + do { + dns_ncache_current(rdataset, &name, &rds); + for (result = dns_rdataset_first(&rds); + result == ISC_R_SUCCESS; + result = dns_rdataset_next(&rds)) { + CHECK(str_totext("; ", target)); + CHECK(dns_name_totext(&name, omit_final_dot, target)); + CHECK(str_totext(" ", target)); + CHECK(dns_rdatatype_totext(rds.type, target)); + if (rds.type == dns_rdatatype_rrsig) { + CHECK(str_totext(" ", target)); + CHECK(dns_rdatatype_totext(rds.covers, target)); + CHECK(str_totext(" ...\n", target)); + } else { + dns_rdata_t rdata = DNS_RDATA_INIT; + dns_rdataset_current(&rds, &rdata); + CHECK(str_totext(" ", target)); + CHECK(dns_rdata_tofmttext(&rdata, dns_rootname, + 0, 0, " ", target)); + CHECK(str_totext("\n", target)); + } + } + dns_rdataset_disassociate(&rds); + result = dns_rdataset_next(rdataset); + } while (result == ISC_R_SUCCESS); + + if (result == ISC_R_NOMORE) + result = ISC_R_SUCCESS; + cleanup: + if (dns_rdataset_isassociated(&rds)) + dns_rdataset_disassociate(&rds); + + return (result); +} + /* * Convert 'rdataset' to master file text format according to 'ctx', * storing the result in 'target'. If 'owner_name' is NULL, it @@ -464,6 +516,13 @@ rdataset_totext(dns_rdataset_t *rdataset, RETERR(str_totext(";-$NXDOMAIN\n", target)); else RETERR(str_totext(";-$NXRRSET\n", target)); + /* + * Print a summary of the cached records which make + * up the negative response. + */ + RETERR(ncache_summary(rdataset, omit_final_dot, + target)); + break; } else { dns_rdata_t rdata = DNS_RDATA_INIT; isc_region_t r;