result.c revision 04b8111f2137a9cf9b0b71228f76b3e40ffa1173
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson/*
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * Copyright (C) 1998, 1999 Internet Software Consortium.
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson *
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson *
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson * SOFTWARE.
68a8db1efb0cd13e0e3d59362ab9db1a4a8bc496Andreas Gustafsson */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <config.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <stddef.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/resultclass.h>
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson#include <isc/once.h>
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson#include <isc/error.h>
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson#include <dns/result.h>
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson#include <dns/lib.h>
f642eb7b9fbca01905a68bdbb22222ebc761f840Andreas Gustafsson
f642eb7b9fbca01905a68bdbb22222ebc761f840Andreas Gustafssonstatic char *text[DNS_R_NRESULTS] = {
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "label too long", /* 0 */
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "bad escape", /* 1 */
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "bad bitstring", /* 2 */
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "bitstring too long", /* 3 */
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "empty label", /* 4 */
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "bad dotted quad", /* 5 */
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "unexpected end of input", /* 6 */
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "unknown class/type", /* 7 */
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "bad label type", /* 8 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "bad compression pointer", /* 9 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "too many hops", /* 10 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "disallowed (by application policy)", /* 11 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "extra input text", /* 12 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "extra input data", /* 13 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "text too long", /* 14 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "out of range", /* 15 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "syntax error", /* 16 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "bad checksum", /* 17 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "bad IPv6 address", /* 18 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "no owner", /* 19 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "no ttl", /* 20 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "bad class", /* 21 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "unexpected token", /* 22 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "partial match", /* 23 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "new origin", /* 24 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "unchanged", /* 25 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "bad ttl", /* 26 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "more data needed/to be rendered", /* 27 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "continue", /* 28 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "delegation", /* 29 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "glue", /* 30 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "dname", /* 31 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "cname", /* 32 */
1123872a47604644f6d74d7d8929472201db96f3Andreas Gustafsson "bad database", /* 33 */
f620c5e527746a2ec3d90a11d21abd8a114746dfTatuya JINMEI 神明達哉 "zonecut", /* 34 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "bad zone", /* 35 */
4848fe4ad2c0ba6e2e69e4a2617727f8556d79a0Andreas Gustafsson "more data", /* 36 */
"up to date", /* 37 */
"tsig verify failure", /* 38 */
"tsig error set in query", /* 39 */
};
static char *rcode_text[DNS_R_NRCODERESULTS] = {
"NOERROR", /* 0 */
"FORMERR", /* 1 */
"SERVFAIL", /* 2 */
"NXDOMAIN", /* 3 */
"NOTIMP", /* 4 */
"REFUSED", /* 5 */
"YXDOMAIN", /* 6 */
"YXRRSET", /* 7 */
"NXRRSET", /* 8 */
"NOTAUTH", /* 9 */
"NOTZONE", /* 10 */
"<rcode 11>", /* 11 */
"<rcode 12>", /* 12 */
"<rcode 13>", /* 13 */
"<rcode 14>", /* 14 */
"<rcode 15>", /* 15 */
"BADVERS", /* 16 */
};
#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);
}
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)) {
/*
* Rcodes can't be bigger than 12 bits, which is why we
* AND with 0xFFF instead of 0xFFFF.
*/
return ((dns_rcode_t)((result) & 0xFFF));
}
/*
* Try to supply an appropriate rcode.
*/
switch (result) {
case ISC_R_NOSPACE:
case ISC_R_UNEXPECTEDEND:
case ISC_R_BADBASE64:
case DNS_R_LABELTOOLONG:
case DNS_R_BADBITSTRING:
case DNS_R_BITSTRINGTOOLONG:
case DNS_R_UNEXPECTEDEND:
case DNS_R_UNKNOWN:
case DNS_R_BADLABELTYPE:
case DNS_R_BADPOINTER:
case DNS_R_TOOMANYHOPS:
case DNS_R_EXTRADATA:
case DNS_R_TEXTTOOLONG:
case DNS_R_RANGE:
case DNS_R_SYNTAX:
case DNS_R_BADCKSUM:
case DNS_R_BADAAAA:
case DNS_R_BADCLASS:
case DNS_R_BADTTL:
case DNS_R_NOREDATA:
case DNS_R_BADZONE:
case DNS_R_TSIGERRORSET:
rcode = dns_rcode_formerr;
break;
case DNS_R_DISALLOWED:
rcode = dns_rcode_refused;
break;
case DNS_R_TSIGVERIFYFAILURE:
rcode = dns_rcode_notauth;
break;
default:
rcode = dns_rcode_servfail;
}
return (rcode);
}