From dd3520ae41e92433fd25b46f44ca97811bbdf49b Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 9 Dec 2020 16:32:11 +1100 Subject: [PATCH] Improve the diagnostic 'rndc retransfer' error message --- bin/named/server.c | 68 +++++++------------------------------ lib/dns/include/dns/zone.h | 6 ++++ lib/dns/win32/libdns.def.in | 1 + lib/dns/zone.c | 26 ++++++++++++++ 4 files changed, 46 insertions(+), 55 deletions(-) diff --git a/bin/named/server.c b/bin/named/server.c index 19a0693fc5..93f5ab839b 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -7493,36 +7493,12 @@ portset_fromconf(isc_portset_t *portset, const cfg_obj_t *ports, static isc_result_t removed(dns_zone_t *zone, void *uap) { - const char *type; - if (dns_zone_getview(zone) != uap) { return (ISC_R_SUCCESS); } - switch (dns_zone_gettype(zone)) { - case dns_zone_master: - type = "primary"; - break; - case dns_zone_slave: - type = "secondary"; - break; - case dns_zone_mirror: - type = "mirror"; - break; - case dns_zone_stub: - type = "stub"; - break; - case dns_zone_staticstub: - type = "static-stub"; - break; - case dns_zone_redirect: - type = "redirect"; - break; - default: - type = "other"; - break; - } - dns_zone_log(zone, ISC_LOG_INFO, "(%s) removed", type); + dns_zone_log(zone, ISC_LOG_INFO, "(%s) removed", + dns_zonetype_name(dns_zone_gettype(zone))); return (ISC_R_SUCCESS); } @@ -10792,7 +10768,16 @@ named_server_retransfercommand(named_server_t *server, isc_lex_t *lex, { dns_zone_forcereload(zone); } else { - result = ISC_R_NOTFOUND; + (void)putstr(text, "retransfer: inappropriate zone type: "); + (void)putstr(text, dns_zonetype_name(type)); + if (type == dns_zone_redirect) { + type = dns_zone_getredirecttype(zone); + (void)putstr(text, "("); + (void)putstr(text, dns_zonetype_name(type)); + (void)putstr(text, ")"); + } + (void)putnull(text); + result = ISC_R_FAILURE; } dns_zone_detach(&zone); return (result); @@ -15161,34 +15146,7 @@ named_server_zonestatus(named_server_t *server, isc_lex_t *lex, zonetype = dns_zone_gettype(zone); } - switch (zonetype) { - case dns_zone_master: - type = "primary"; - break; - case dns_zone_slave: - type = "secondary"; - break; - case dns_zone_mirror: - type = "mirror"; - break; - case dns_zone_stub: - type = "stub"; - break; - case dns_zone_staticstub: - type = "staticstub"; - break; - case dns_zone_redirect: - type = "redirect"; - break; - case dns_zone_key: - type = "key"; - break; - case dns_zone_dlz: - type = "dlz"; - break; - default: - type = "unknown"; - } + type = dns_zonetype_name(zonetype); /* Serial number */ result = dns_zone_getserial(mayberaw, &serial); diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 8cee35515f..ec9991a78f 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -2585,4 +2585,10 @@ dns_zone_verifydb(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver); * \li #DNS_R_VERIFYFAILURE any other case */ +const char * +dns_zonetype_name(dns_zonetype_t type); +/*%< + * Return the name of the zone type 'type'. + */ + #endif /* DNS_ZONE_H */ diff --git a/lib/dns/win32/libdns.def.in b/lib/dns/win32/libdns.def.in index 917484d1ec..ce495393c2 100644 --- a/lib/dns/win32/libdns.def.in +++ b/lib/dns/win32/libdns.def.in @@ -1397,6 +1397,7 @@ dns_zonemgr_shutdown dns_zonemgr_unreachable dns_zonemgr_unreachableadd dns_zonemgr_unreachabledel +dns_zonetype_name dns_zoneverify_dnssec dns_zt_apply dns_zt_asyncload diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 967603ddcf..1406a0e116 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -15629,6 +15629,32 @@ dns_zone_gettype(dns_zone_t *zone) { return (zone->type); } +const char * +dns_zonetype_name(dns_zonetype_t type) { + switch (type) { + case dns_zone_none: + return ("none"); + case dns_zone_master: + return ("primary"); + case dns_zone_slave: + return ("secondary"); + case dns_zone_mirror: + return ("mirror"); + case dns_zone_stub: + return ("stub"); + case dns_zone_staticstub: + return ("static-stub"); + case dns_zone_key: + return ("key"); + case dns_zone_dlz: + return ("dlz"); + case dns_zone_redirect: + return ("redirect"); + default: + return ("unknown"); + } +} + dns_zonetype_t dns_zone_getredirecttype(dns_zone_t *zone) { REQUIRE(DNS_ZONE_VALID(zone));