#include <config.h>
#include <isc/once.h>
#include <isc/util.h>
#include <dns/result.h>
#include <dns/lib.h>
static const char *text[DNS_R_NRESULTS] = {
"label too long",
"bad escape",
"bad bitstring",
"bitstring too long",
"empty label",
"bad dotted quad",
"invalid NS owner name (wildcard)",
"unknown class/type",
"bad label type",
"bad compression pointer",
"too many hops",
"disallowed (by application policy)",
"extra input text",
"extra input data",
"text too long",
"not at top of zone",
"syntax error",
"bad checksum",
"bad IPv6 address",
"no owner",
"no ttl",
"bad class",
"name too long",
"partial match",
"new origin",
"unchanged",
"bad ttl",
"more data needed/to be rendered",
"continue",
"delegation",
"glue",
"dname",
"cname",
"bad database",
"zonecut",
"bad zone",
"more data",
"up to date",
"tsig verify failure",
"tsig indicates error",
"SIG failed to verify",
"SIG has expired",
"SIG validity period has not begun",
"key is unauthorized to sign data",
"invalid time",
"expected a TSIG or SIG(0)",
"did not expect a TSIG or SIG(0)",
"TKEY is unacceptable",
"hint",
"drop",
"zone not loaded",
"ncache nxdomain",
"ncache nxrrset",
"wait",
"not verified yet",
"no identity",
"no journal",
"alias",
"use TCP",
"no valid SIG",
"no valid NXT",
"not insecure",
"unknown service",
"recoverable error occurred",
"unknown opt attribute record",
"unexpected message id",
"seen include file",
"not exact",
"address blackholed",
"bad algorithm",
"invalid use of a meta type",
"CNAME and other data",
"multiple RRs of singleton type",
"hint nxrrset",
"no master file configured",
"unknown protocol",
"clocks are unsynchronized",
"IXFR failed",
"<unused 78>",
"no valid KEY",
"obsolete",
"already frozen",
"unknown flag",
"expected a response"
};
static const char *rcode_text[DNS_R_NRCODERESULTS] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMP",
"REFUSED",
"YXDOMAIN",
"YXRRSET",
"NXRRSET",
"NOTAUTH",
"NOTZONE",
"<rcode 11>",
"<rcode 12>",
"<rcode 13>",
"<rcode 14>",
"<rcode 15>",
"BADVERS",
};
#define DNS_RESULT_RESULTSET 2
#define DNS_RESULT_RCODERESULTSET 3
static isc_once_t once = ISC_ONCE_INIT;
static void
initialize_action(void) {
isc_result_t result;
result = isc_result_register(ISC_RESULTCLASS_DNS, DNS_R_NRESULTS,
text, dns_msgcat, DNS_RESULT_RESULTSET);
if (result == ISC_R_SUCCESS)
result = isc_result_register(ISC_RESULTCLASS_DNSRCODE,
DNS_R_NRCODERESULTS,
rcode_text, dns_msgcat,
DNS_RESULT_RCODERESULTSET);
if (result != ISC_R_SUCCESS)
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_result_register() failed: %u", result);
}
static void
initialize(void) {
dns_lib_initmsgcat();
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
}
const char *
dns_result_totext(isc_result_t result) {
initialize();
return (isc_result_totext(result));
}
void
dns_result_register(void) {
initialize();
}
dns_rcode_t
dns_result_torcode(isc_result_t result) {
dns_rcode_t rcode = dns_rcode_servfail;
if (DNS_RESULT_ISRCODE(result)) {
return ((dns_rcode_t)((result) & 0xFFF));
}
switch (result) {
case ISC_R_SUCCESS:
rcode = dns_rcode_noerror;
break;
case ISC_R_BADBASE64:
case ISC_R_NOSPACE:
case ISC_R_RANGE:
case ISC_R_UNEXPECTEDEND:
case DNS_R_BADAAAA:
case DNS_R_BADBITSTRING:
case DNS_R_BADCKSUM:
case DNS_R_BADCLASS:
case DNS_R_BADLABELTYPE:
case DNS_R_BADPOINTER:
case DNS_R_BADTTL:
case DNS_R_BADZONE:
case DNS_R_BITSTRINGTOOLONG:
case DNS_R_EXTRADATA:
case DNS_R_LABELTOOLONG:
case DNS_R_NOREDATA:
case DNS_R_SYNTAX:
case DNS_R_TEXTTOOLONG:
case DNS_R_TOOMANYHOPS:
case DNS_R_TSIGERRORSET:
case DNS_R_UNKNOWN:
rcode = dns_rcode_formerr;
break;
case DNS_R_DISALLOWED:
rcode = dns_rcode_refused;
break;
case DNS_R_TSIGVERIFYFAILURE:
case DNS_R_CLOCKSKEW:
rcode = dns_rcode_notauth;
break;
default:
rcode = dns_rcode_servfail;
}
return (rcode);
}