diff --git a/lib/dns/include/dns/result.h b/lib/dns/include/dns/result.h index 931e8ac766..38c12664fd 100644 --- a/lib/dns/include/dns/result.h +++ b/lib/dns/include/dns/result.h @@ -28,7 +28,9 @@ #include /* Contractual promise. */ #define DNS_RESULT_ISRCODE(result) \ - (ISC_RESULTCLASS_INCLASS(ISC_RESULTCLASS_DNSRCODE, (result))) + (ISC_RESULT_INCLASS(ISC_RESULTCLASS_DNSRCODE, (result))) + +#define dns_result_totext isc_result_totext ISC_LANG_BEGINDECLS diff --git a/lib/dns/result.c b/lib/dns/result.c index eaa0c254c1..aa610be1af 100644 --- a/lib/dns/result.c +++ b/lib/dns/result.c @@ -23,7 +23,7 @@ dns_result_torcode(isc_result_t 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)); + return ((dns_rcode_t)(ISC_RESULT_VALUE(result) & 0xFFF)); } /* diff --git a/lib/dns/result_dns.c.in b/lib/dns/result_dns.c.in index b329415fe7..fac03e9706 100644 --- a/lib/dns/result_dns.c.in +++ b/lib/dns/result_dns.c.in @@ -13,8 +13,7 @@ #include - -static const char *text[DNS_R_NRESULTS] = { +static const char *dns_result_descriptions[DNS_R_NRESULTS] = { "label too long", /*%< 0 DNS_R_LABELTOOLONG */ "bad escape", /*%< 1 DNS_R_BADESCAPE */ /*! @@ -173,7 +172,7 @@ static const char *text[DNS_R_NRESULTS] = { "NSEC3 resalt", /*%< 126 DNS_R_NSEC3RESALT */ }; -static const char *ids[DNS_R_NRESULTS] = { +static const char *dns_result_ids[DNS_R_NRESULTS] = { "DNS_R_LABELTOOLONG", "DNS_R_BADESCAPE", /*! @@ -307,7 +306,7 @@ static const char *ids[DNS_R_NRESULTS] = { "DNS_R_NSEC3RESALT", }; -static const char *rcode_text[DNS_R_NRCODERESULTS] = { +static const char *dns_rcode_descriptions[DNS_R_NRCODERESULTS] = { "NOERROR", /*%< 0 DNS_R_NOERROR */ "FORMERR", /*%< 1 DNS_R_FORMERR */ "SERVFAIL", /*%< 2 DNS_R_SERVFAIL */ @@ -330,11 +329,10 @@ static const char *rcode_text[DNS_R_NRCODERESULTS] = { "BADVERS", /*%< 16 DNS_R_BADVERS */ }; -static const char *rcode_ids[DNS_R_NRCODERESULTS] = { +static const char *dns_rcode_ids[DNS_R_NRCODERESULTS] = { "DNS_R_NOERROR", "DNS_R_FORMERR", "DNS_R_SERVFAIL", "DNS_R_NXDOMAIN", "DNS_R_NOTIMP", "DNS_R_REFUSED", "DNS_R_YXDOMAIN", "DNS_R_YXRRSET", "DNS_R_NXRRSET", "DNS_R_NOTAUTH", "DNS_R_NOTZONE", "DNS_R_RCODE11", "RNS_R_RCODE12", "DNS_R_RCODE13", "DNS_R_RCODE14", "DNS_R_RCODE15", "DNS_R_BADVERS", }; - diff --git a/lib/dns/result_dst.c.in b/lib/dns/result_dst.c.in index 796c8442ee..1098b0cb91 100644 --- a/lib/dns/result_dst.c.in +++ b/lib/dns/result_dst.c.in @@ -11,7 +11,7 @@ #include -static const char *text[DST_R_NRESULTS] = { +static const char *dst_result_descriptions[DST_R_NRESULTS] = { "algorithm is unsupported", /*%< 0 */ "crypto failure", /*%< 1 */ "built with no crypto support", /*%< 2 */ @@ -37,7 +37,7 @@ static const char *text[DST_R_NRESULTS] = { "illegal operation for an external key", /*%< 22 */ }; -static const char *ids[DST_R_NRESULTS] = { +static const char *dst_result_ids[DST_R_NRESULTS] = { "DST_R_UNSUPPORTEDALG", "DST_R_CRYPTOFAILURE", "DST_R_NOCRYPTO", @@ -63,4 +63,4 @@ static const char *ids[DST_R_NRESULTS] = { "DST_R_EXTERNALKEY", }; -/*! \file */ +/*! \file */ \ No newline at end of file diff --git a/lib/dns/tkey.c b/lib/dns/tkey.c index b807e4312c..0ad821dc41 100644 --- a/lib/dns/tkey.c +++ b/lib/dns/tkey.c @@ -1241,7 +1241,7 @@ dns_tkey_processdhresponse(dns_message_t *qmsg, dns_message_t *rmsg, } if (rmsg->rcode != dns_rcode_noerror) { - return (ISC_RESULTCLASS_DNSRCODE + rmsg->rcode); + return (ISC_RESULTCODE_DNSRCODE(rmsg->rcode)); } RETERR(find_tkey(rmsg, &tkeyname, &rtkeyrdata, DNS_SECTION_ANSWER)); RETERR(dns_rdata_tostruct(&rtkeyrdata, &rtkey, NULL)); @@ -1369,7 +1369,7 @@ dns_tkey_processgssresponse(dns_message_t *qmsg, dns_message_t *rmsg, } if (rmsg->rcode != dns_rcode_noerror) { - return (ISC_RESULTCLASS_DNSRCODE + rmsg->rcode); + return (ISC_RESULTCODE_DNSRCODE(rmsg->rcode)); } RETERR(find_tkey(rmsg, &tkeyname, &rtkeyrdata, DNS_SECTION_ANSWER)); RETERR(dns_rdata_tostruct(&rtkeyrdata, &rtkey, NULL)); @@ -1442,7 +1442,7 @@ dns_tkey_processdeleteresponse(dns_message_t *qmsg, dns_message_t *rmsg, REQUIRE(rmsg != NULL); if (rmsg->rcode != dns_rcode_noerror) { - return (ISC_RESULTCLASS_DNSRCODE + rmsg->rcode); + return (ISC_RESULTCODE_DNSRCODE(rmsg->rcode)); } RETERR(find_tkey(rmsg, &tkeyname, &rtkeyrdata, DNS_SECTION_ANSWER)); @@ -1505,7 +1505,7 @@ dns_tkey_gssnegotiate(dns_message_t *qmsg, dns_message_t *rmsg, } if (rmsg->rcode != dns_rcode_noerror) { - return (ISC_RESULTCLASS_DNSRCODE + rmsg->rcode); + return (ISC_RESULTCODE_DNSRCODE(rmsg->rcode)); } RETERR(find_tkey(rmsg, &tkeyname, &rtkeyrdata, DNS_SECTION_ANSWER)); diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index c0e06cf71a..01321fc02b 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -1256,7 +1256,7 @@ xfrin_recv_done(isc_nmhandle_t *handle, isc_result_t result, { if (result == ISC_R_SUCCESS && msg->rcode != dns_rcode_noerror) { - result = ISC_RESULTCLASS_DNSRCODE + msg->rcode; /*XXX*/ + result = ISC_RESULTCODE_DNSRCODE(msg->rcode); /*XXX*/ } else if (result == ISC_R_SUCCESS && msg->opcode != dns_opcode_query) { result = DNS_R_UNEXPECTEDOPCODE; diff --git a/lib/isc/include/isc/result.h b/lib/isc/include/isc/result.h index 8bb2709649..4c100b3db5 100644 --- a/lib/isc/include/isc/result.h +++ b/lib/isc/include/isc/result.h @@ -15,81 +15,101 @@ /*! \file isc/result.h */ #include +#include #include -#define ISC_R_SUCCESS 0 /*%< success */ -#define ISC_R_NOMEMORY 1 /*%< out of memory */ -#define ISC_R_TIMEDOUT 2 /*%< timed out */ -#define ISC_R_NOTHREADS 3 /*%< no available threads */ -#define ISC_R_ADDRNOTAVAIL 4 /*%< address not available */ -#define ISC_R_ADDRINUSE 5 /*%< address in use */ -#define ISC_R_NOPERM 6 /*%< permission denied */ -#define ISC_R_NOCONN 7 /*%< no pending connections */ -#define ISC_R_NETUNREACH 8 /*%< network unreachable */ -#define ISC_R_HOSTUNREACH 9 /*%< host unreachable */ -#define ISC_R_NETDOWN 10 /*%< network down */ -#define ISC_R_HOSTDOWN 11 /*%< host down */ -#define ISC_R_CONNREFUSED 12 /*%< connection refused */ -#define ISC_R_NORESOURCES 13 /*%< not enough free resources */ -#define ISC_R_EOF 14 /*%< end of file */ -#define ISC_R_BOUND 15 /*%< socket already bound */ -#define ISC_R_RELOAD 16 /*%< reload */ -#define ISC_R_SUSPEND ISC_R_RELOAD /*%< alias of 'reload' */ -#define ISC_R_LOCKBUSY 17 /*%< lock busy */ -#define ISC_R_EXISTS 18 /*%< already exists */ -#define ISC_R_NOSPACE 19 /*%< ran out of space */ -#define ISC_R_CANCELED 20 /*%< operation canceled */ -#define ISC_R_NOTBOUND 21 /*%< socket is not bound */ -#define ISC_R_SHUTTINGDOWN 22 /*%< shutting down */ -#define ISC_R_NOTFOUND 23 /*%< not found */ -#define ISC_R_UNEXPECTEDEND 24 /*%< unexpected end of input */ -#define ISC_R_FAILURE 25 /*%< generic failure */ -#define ISC_R_IOERROR 26 /*%< I/O error */ -#define ISC_R_NOTIMPLEMENTED 27 /*%< not implemented */ -#define ISC_R_UNBALANCED 28 /*%< unbalanced parentheses */ -#define ISC_R_NOMORE 29 /*%< no more */ -#define ISC_R_INVALIDFILE 30 /*%< invalid file */ -#define ISC_R_BADBASE64 31 /*%< bad base64 encoding */ -#define ISC_R_UNEXPECTEDTOKEN 32 /*%< unexpected token */ -#define ISC_R_QUOTA 33 /*%< quota reached */ -#define ISC_R_UNEXPECTED 34 /*%< unexpected error */ -#define ISC_R_ALREADYRUNNING 35 /*%< already running */ -#define ISC_R_IGNORE 36 /*%< ignore */ -#define ISC_R_MASKNONCONTIG 37 /*%< addr mask not contiguous */ -#define ISC_R_FILENOTFOUND 38 /*%< file not found */ -#define ISC_R_FILEEXISTS 39 /*%< file already exists */ -#define ISC_R_NOTCONNECTED 40 /*%< socket is not connected */ -#define ISC_R_RANGE 41 /*%< out of range */ -#define ISC_R_NOENTROPY 42 /*%< out of entropy */ -#define ISC_R_MULTICAST 43 /*%< invalid use of multicast */ -#define ISC_R_NOTFILE 44 /*%< not a file */ -#define ISC_R_NOTDIRECTORY 45 /*%< not a directory */ -#define ISC_R_QUEUEFULL 46 /*%< queue is full */ -#define ISC_R_FAMILYMISMATCH 47 /*%< address family mismatch */ -#define ISC_R_FAMILYNOSUPPORT 48 /*%< AF not supported */ -#define ISC_R_BADHEX 49 /*%< bad hex encoding */ -#define ISC_R_TOOMANYOPENFILES 50 /*%< too many open files */ -#define ISC_R_NOTBLOCKING 51 /*%< not blocking */ -#define ISC_R_UNBALANCEDQUOTES 52 /*%< unbalanced quotes */ -#define ISC_R_INPROGRESS 53 /*%< operation in progress */ -#define ISC_R_CONNECTIONRESET 54 /*%< connection reset */ -#define ISC_R_SOFTQUOTA 55 /*%< soft quota reached */ -#define ISC_R_BADNUMBER 56 /*%< not a valid number */ -#define ISC_R_DISABLED 57 /*%< disabled */ -#define ISC_R_MAXSIZE 58 /*%< max size */ -#define ISC_R_BADADDRESSFORM 59 /*%< invalid address format */ -#define ISC_R_BADBASE32 60 /*%< bad base32 encoding */ -#define ISC_R_UNSET 61 /*%< unset */ -#define ISC_R_MULTIPLE 62 /*%< multiple */ -#define ISC_R_WOULDBLOCK 63 /*%< would block */ -#define ISC_R_COMPLETE 64 /*%< complete */ -#define ISC_R_CRYPTOFAILURE 65 /*%< cryptography library failure */ -#define ISC_R_DISCQUOTA 66 /*%< disc quota */ -#define ISC_R_DISCFULL 67 /*%< disc full */ -#define ISC_R_DEFAULT 68 /*%< default */ -#define ISC_R_IPV4PREFIX 69 /*%< IPv4 prefix */ -#define ISC_R_TLSERROR 70 /*%< TLS error */ -#define ISC_R_HTTP2ALPNERROR 71 /*%< ALPN for HTTP/2 failed */ +/* + * This file is generated at compile time from the result_*.h files + * found in sibling library source directories. + */ +#include + +#define ISC_R_SUCCESS ISC_RESULTCODE_ISC(0) /*%< success */ +#define ISC_R_NOMEMORY ISC_RESULTCODE_ISC(1) /*%< out of memory */ +#define ISC_R_TIMEDOUT ISC_RESULTCODE_ISC(2) /*%< timed out */ +#define ISC_R_NOTHREADS ISC_RESULTCODE_ISC(3) /*%< no available threads */ +#define ISC_R_ADDRNOTAVAIL ISC_RESULTCODE_ISC(4) /*%< address not available */ +#define ISC_R_ADDRINUSE ISC_RESULTCODE_ISC(5) /*%< address in use */ +#define ISC_R_NOPERM ISC_RESULTCODE_ISC(6) /*%< permission denied */ +#define ISC_R_NOCONN ISC_RESULTCODE_ISC(7) /*%< no pending connections */ +#define ISC_R_NETUNREACH ISC_RESULTCODE_ISC(8) /*%< network unreachable */ +#define ISC_R_HOSTUNREACH ISC_RESULTCODE_ISC(9) /*%< host unreachable */ +#define ISC_R_NETDOWN ISC_RESULTCODE_ISC(10) /*%< network down */ +#define ISC_R_HOSTDOWN ISC_RESULTCODE_ISC(11) /*%< host down */ +#define ISC_R_CONNREFUSED ISC_RESULTCODE_ISC(12) /*%< connection refused */ +#define ISC_R_NORESOURCES \ + ISC_RESULTCODE_ISC(13) /*%< not enough free resources */ +#define ISC_R_EOF ISC_RESULTCODE_ISC(14) /*%< end of file */ +#define ISC_R_BOUND ISC_RESULTCODE_ISC(15) /*%< socket already bound */ +#define ISC_R_RELOAD ISC_RESULTCODE_ISC(16) /*%< reload */ +#define ISC_R_SUSPEND ISC_R_RELOAD /*%< alias of 'reload' */ +#define ISC_R_LOCKBUSY ISC_RESULTCODE_ISC(17) /*%< lock busy */ +#define ISC_R_EXISTS ISC_RESULTCODE_ISC(18) /*%< already exists */ +#define ISC_R_NOSPACE ISC_RESULTCODE_ISC(19) /*%< ran out of space */ +#define ISC_R_CANCELED ISC_RESULTCODE_ISC(20) /*%< operation canceled */ +#define ISC_R_NOTBOUND ISC_RESULTCODE_ISC(21) /*%< socket is not bound */ +#define ISC_R_SHUTTINGDOWN ISC_RESULTCODE_ISC(22) /*%< shutting down */ +#define ISC_R_NOTFOUND ISC_RESULTCODE_ISC(23) /*%< not found */ +#define ISC_R_UNEXPECTEDEND \ + ISC_RESULTCODE_ISC(24) /*%< unexpected end of input */ +#define ISC_R_FAILURE ISC_RESULTCODE_ISC(25) /*%< generic failure */ +#define ISC_R_IOERROR ISC_RESULTCODE_ISC(26) /*%< I/O error */ +#define ISC_R_NOTIMPLEMENTED ISC_RESULTCODE_ISC(27) /*%< not implemented */ +#define ISC_R_UNBALANCED ISC_RESULTCODE_ISC(28) /*%< unbalanced parentheses */ +#define ISC_R_NOMORE ISC_RESULTCODE_ISC(29) /*%< no more */ +#define ISC_R_INVALIDFILE ISC_RESULTCODE_ISC(30) /*%< invalid file */ +#define ISC_R_BADBASE64 ISC_RESULTCODE_ISC(31) /*%< bad base64 encoding */ +#define ISC_R_UNEXPECTEDTOKEN ISC_RESULTCODE_ISC(32) /*%< unexpected token */ +#define ISC_R_QUOTA ISC_RESULTCODE_ISC(33) /*%< quota reached */ +#define ISC_R_UNEXPECTED ISC_RESULTCODE_ISC(34) /*%< unexpected error */ +#define ISC_R_ALREADYRUNNING ISC_RESULTCODE_ISC(35) /*%< already running */ +#define ISC_R_IGNORE ISC_RESULTCODE_ISC(36) /*%< ignore */ +#define ISC_R_MASKNONCONTIG \ + ISC_RESULTCODE_ISC(37) /*%< addr mask not contiguous */ +#define ISC_R_FILENOTFOUND ISC_RESULTCODE_ISC(38) /*%< file not found */ +#define ISC_R_FILEEXISTS ISC_RESULTCODE_ISC(39) /*%< file already exists */ +#define ISC_R_NOTCONNECTED \ + ISC_RESULTCODE_ISC(40) /*%< socket is not connected */ +#define ISC_R_RANGE ISC_RESULTCODE_ISC(41) /*%< out of range */ +#define ISC_R_NOENTROPY ISC_RESULTCODE_ISC(42) /*%< out of entropy */ +#define ISC_R_MULTICAST \ + ISC_RESULTCODE_ISC(43) /*%< invalid use of multicast \ + */ +#define ISC_R_NOTFILE ISC_RESULTCODE_ISC(44) /*%< not a file */ +#define ISC_R_NOTDIRECTORY ISC_RESULTCODE_ISC(45) /*%< not a directory */ +#define ISC_R_QUEUEFULL ISC_RESULTCODE_ISC(46) /*%< queue is full */ +#define ISC_R_FAMILYMISMATCH \ + ISC_RESULTCODE_ISC(47) /*%< address family mismatch */ +#define ISC_R_FAMILYNOSUPPORT ISC_RESULTCODE_ISC(48) /*%< AF not supported */ +#define ISC_R_BADHEX ISC_RESULTCODE_ISC(49) /*%< bad hex encoding */ +#define ISC_R_TOOMANYOPENFILES \ + ISC_RESULTCODE_ISC(50) /*%< too many open files */ +#define ISC_R_NOTBLOCKING ISC_RESULTCODE_ISC(51) /*%< not blocking */ +#define ISC_R_UNBALANCEDQUOTES \ + ISC_RESULTCODE_ISC(52) /*%< unbalanced quotes \ + */ +#define ISC_R_INPROGRESS ISC_RESULTCODE_ISC(53) /*%< operation in progress */ +#define ISC_R_CONNECTIONRESET ISC_RESULTCODE_ISC(54) /*%< connection reset */ +#define ISC_R_SOFTQUOTA ISC_RESULTCODE_ISC(55) /*%< soft quota reached */ +#define ISC_R_BADNUMBER ISC_RESULTCODE_ISC(56) /*%< not a valid number */ +#define ISC_R_DISABLED ISC_RESULTCODE_ISC(57) /*%< disabled */ +#define ISC_R_MAXSIZE ISC_RESULTCODE_ISC(58) /*%< max size */ +#define ISC_R_BADADDRESSFORM \ + ISC_RESULTCODE_ISC(59) /*%< invalid address format */ +#define ISC_R_BADBASE32 ISC_RESULTCODE_ISC(60) /*%< bad base32 encoding */ +#define ISC_R_UNSET ISC_RESULTCODE_ISC(61) /*%< unset */ +#define ISC_R_MULTIPLE ISC_RESULTCODE_ISC(62) /*%< multiple */ +#define ISC_R_WOULDBLOCK ISC_RESULTCODE_ISC(63) /*%< would block */ +#define ISC_R_COMPLETE ISC_RESULTCODE_ISC(64) /*%< complete */ +#define ISC_R_CRYPTOFAILURE \ + ISC_RESULTCODE_ISC(65) /*%< cryptography library failure */ +#define ISC_R_DISCQUOTA ISC_RESULTCODE_ISC(66) /*%< disc quota */ +#define ISC_R_DISCFULL ISC_RESULTCODE_ISC(67) /*%< disc full */ +#define ISC_R_DEFAULT ISC_RESULTCODE_ISC(68) /*%< default */ +#define ISC_R_IPV4PREFIX ISC_RESULTCODE_ISC(69) /*%< IPv4 prefix */ +#define ISC_R_TLSERROR ISC_RESULTCODE_ISC(70) /*%< TLS error */ +#define ISC_R_HTTP2ALPNERROR \ + ISC_RESULTCODE_ISC(71) /*%< ALPN for HTTP/2 failed */ /*% Not a result code: the number of results. */ #define ISC_R_NRESULTS 72 diff --git a/lib/isc/include/isc/resultclass.h b/lib/isc/include/isc/resultclass.h index 4953622e54..057c849996 100644 --- a/lib/isc/include/isc/resultclass.h +++ b/lib/isc/include/isc/resultclass.h @@ -15,27 +15,72 @@ /*! \file isc/resultclass.h * \brief Registry of Predefined Result Type Classes * - * A result class number is an unsigned 16 bit number. Each class may - * contain up to 65536 results. A result code is formed by adding the - * result number within the class to the class number multiplied by 65536. + * Error codes are organized (divided) into classes, we use an uint32_t number + * to store both the error class and the error code. * - * Classes < 1024 are reserved for ISC use. - * Result classes >= 1024 and <= 65535 are reserved for application use. + * The lower bits are used to store the error number, the upper bits are used to + * store the error class. + * + * The class number is stored into the upper ISC_RESULTCLASS_BITS bits + * of the number (see macro), thus 2^ISC_RESULTCLASS_BITS classes are available. + * + * Each class may contain up to 2^(32 - ISC_RESULTCLASS_BITS) error codes. + * + * A result code is formed by applying a binary "or" between the error code + * and the result class shifted left ISC_RESULTCLASS_BITS. + * i.e.: full_rcode = rcode | (rclass << ISC_RESULTCLASS_BITS) + * + * Some macros are provided in this header file to make the task of creating + * result codes easier. */ -#define ISC_RESULTCLASS_FROMNUM(num) ((num) << 16) -#define ISC_RESULTCLASS_TONUM(rclass) ((rclass) >> 16) -#define ISC_RESULTCLASS_SIZE 65536 -#define ISC_RESULTCLASS_INCLASS(rclass, result) \ - ((rclass) == ((result)&0xFFFF0000)) +/* Bits reserved for the error class. */ +#define ISC_RESULTCLASS_BITS (uint32_t)16u -#define ISC_RESULTCLASS_ISC ISC_RESULTCLASS_FROMNUM(0) -#define ISC_RESULTCLASS_DNS ISC_RESULTCLASS_FROMNUM(1) -#define ISC_RESULTCLASS_DST ISC_RESULTCLASS_FROMNUM(2) -#define ISC_RESULTCLASS_DNSRCODE ISC_RESULTCLASS_FROMNUM(3) -#define ISC_RESULTCLASS_OMAPI ISC_RESULTCLASS_FROMNUM(4) -#define ISC_RESULTCLASS_ISCCC ISC_RESULTCLASS_FROMNUM(5) -#define ISC_RESULTCLASS_DHCP ISC_RESULTCLASS_FROMNUM(6) -#define ISC_RESULTCLASS_PK11 ISC_RESULTCLASS_FROMNUM(7) +/* Mask used to extract the class bits within a number (using bitwise AND) */ +#define ISC_RESULTCLASS_MASK (uint32_t)(~((1u << ISC_RESULTCLASS_BITS) - 1)) -#endif /* ISC_RESULTCLASS_H */ +/* Macro used to extract the class value given a isc_result_t input */ +#define ISC_RESULT_CLASS(result) ((result) >> ISC_RESULTCLASS_BITS) + +/* Macro used to extract the error value given a isc_result_t input */ +#define ISC_RESULT_VALUE(result) ((result) & ~ISC_RESULTCLASS_MASK) + +/* Check whether result is in the same class as rclass */ +#define ISC_RESULT_INCLASS(rclass, result) \ + ((rclass) == ISC_RESULT_CLASS(result)) + +/* + * Following are macros that define result classes (or error classes) in the + * format ISC_RESULTCLASS_(CLASSNAME). + * Following each result class are macros intended to be used to create + * error codes for that class, in the format ISC_RESULTCODE_(CLASS_NAME). + * + * A library could have error codes defined like the example below: + * #define ISC_R_EOF ISC_RESULTCODE_ISC(14) + * Another library could use the same number (14) to define an error code + * without conflicting with another class, e.g: + * #define DNS_R_TEXTTOOLONG ISC_RESULTCODE_DNS(14) + * ISC_R_EOF == DNS_R_TEXTTOOLONG (false, not in the same class) + */ +#define MAKE_RCODE(rclass, rcode) (rcode | (rclass << ISC_RESULTCLASS_BITS)) +#define ISC_RESULTCLASS_ISC 0 +#define ISC_RESULTCODE_ISC(code) MAKE_RCODE(ISC_RESULTCLASS_ISC, code) +#define ISC_RESULTCLASS_DNS 1 +#define ISC_RESULTCODE_DNS(code) MAKE_RCODE(ISC_RESULTCLASS_DNS, code) +#define ISC_RESULTCLASS_DST 2 +#define ISC_RESULTCODE_DST(code) MAKE_RCODE(ISC_RESULTCLASS_DST, code) +#define ISC_RESULTCLASS_DNSRCODE 3 +#define ISC_RESULTCODE_DNSRCODE(code) MAKE_RCODE(ISC_RESULTCLASS_DNSRCODE, code) +#define ISC_RESULTCLASS_OMAPI 4 +#define ISC_RESULTCODE_OMAPI(code) MAKE_RCODE(ISC_RESULTCLASS_OMAPI, code) +#define ISC_RESULTCLASS_ISCCC 5 +#define ISC_RESULTCODE_ISCCC(code) MAKE_RCODE(ISC_RESULTCLASS_ISCCC, code) +#define ISC_RESULTCLASS_DHCP 6 +#define ISC_RESULTCODE_DHCP(code) MAKE_RCODE(ISC_RESULTCLASS_DHCP, code) +#define ISC_RESULTCLASS_PK11 7 +#define ISC_RESULTCODE_PK11(code) MAKE_RCODE(ISC_RESULTCLASS_PK11, code) + +#define ISC_RESULTCLASS_MAX 7 + +#endif /* ISC_RESULTCLASS_H */ \ No newline at end of file diff --git a/lib/isc/result.c b/lib/isc/result.c index 7cfc9312cc..baa7d91ebf 100644 --- a/lib/isc/result.c +++ b/lib/isc/result.c @@ -18,7 +18,13 @@ #include #include -static const char *description[ISC_R_NRESULTS] = { +/* + * This file is generated at compile time from the result_*.c files + * found in sibling library source directories: + */ +#include "result_ext.c" + +static const char *isc_result_descriptions[ISC_R_NRESULTS] = { "success", /*%< 0 */ "out of memory", /*%< 1 */ "timed out", /*%< 2 */ @@ -93,111 +99,120 @@ static const char *description[ISC_R_NRESULTS] = { "ALPN for HTTP/2 failed" /*%< 71 */ }; -static const char *identifier[ISC_R_NRESULTS] = { "ISC_R_SUCCESS", - "ISC_R_NOMEMORY", - "ISC_R_TIMEDOUT", - "ISC_R_NOTHREADS", - "ISC_R_ADDRNOTAVAIL", - "ISC_R_ADDRINUSE", - "ISC_R_NOPERM", - "ISC_R_NOCONN", - "ISC_R_NETUNREACH", - "ISC_R_HOSTUNREACH", - "ISC_R_NETDOWN", - "ISC_R_HOSTDOWN", - "ISC_R_CONNREFUSED", - "ISC_R_NORESOURCES", - "ISC_R_EOF", - "ISC_R_BOUND", - "ISC_R_RELOAD", - "ISC_R_LOCKBUSY", - "ISC_R_EXISTS", - "ISC_R_NOSPACE", - "ISC_R_CANCELED", - "ISC_R_NOTBOUND", - "ISC_R_SHUTTINGDOWN", - "ISC_R_NOTFOUND", - "ISC_R_UNEXPECTEDEND", - "ISC_R_FAILURE", - "ISC_R_IOERROR", - "ISC_R_NOTIMPLEMENTED", - "ISC_R_UNBALANCED", - "ISC_R_NOMORE", - "ISC_R_INVALIDFILE", - "ISC_R_BADBASE64", - "ISC_R_UNEXPECTEDTOKEN", - "ISC_R_QUOTA", - "ISC_R_UNEXPECTED", - "ISC_R_ALREADYRUNNING", - "ISC_R_IGNORE", - "ISC_R_MASKNONCONTIG", - "ISC_R_FILENOTFOUND", - "ISC_R_FILEEXISTS", - "ISC_R_NOTCONNECTED", - "ISC_R_RANGE", - "ISC_R_NOENTROPY", - "ISC_R_MULTICAST", - "ISC_R_NOTFILE", - "ISC_R_NOTDIRECTORY", - "ISC_R_QUEUEFULL", - "ISC_R_FAMILYMISMATCH", - "ISC_R_FAMILYNOSUPPORT", - "ISC_R_BADHEX", - "ISC_R_TOOMANYOPENFILES", - "ISC_R_NOTBLOCKING", - "ISC_R_UNBALANCEDQUOTES", - "ISC_R_INPROGRESS", - "ISC_R_CONNECTIONRESET", - "ISC_R_SOFTQUOTA", - "ISC_R_BADNUMBER", - "ISC_R_DISABLED", - "ISC_R_MAXSIZE", - "ISC_R_BADADDRESSFORM", - "ISC_R_BADBASE32", - "ISC_R_UNSET", - "ISC_R_MULTIPLE", - "ISC_R_WOULDBLOCK", - "ISC_R_COMPLETE", - "ISC_R_CRYPTOFAILURE", - "ISC_R_DISCQUOTA", - "ISC_R_DISCFULL", - "ISC_R_DEFAULT", - "ISC_R_IPV4PREFIX", - "ISC_R_TLSERROR", - "ISC_R_HTTP2ALPNERROR" }; +static const char *isc_result_ids[ISC_R_NRESULTS] = { "ISC_R_SUCCESS", + "ISC_R_NOMEMORY", + "ISC_R_TIMEDOUT", + "ISC_R_NOTHREADS", + "ISC_R_ADDRNOTAVAIL", + "ISC_R_ADDRINUSE", + "ISC_R_NOPERM", + "ISC_R_NOCONN", + "ISC_R_NETUNREACH", + "ISC_R_HOSTUNREACH", + "ISC_R_NETDOWN", + "ISC_R_HOSTDOWN", + "ISC_R_CONNREFUSED", + "ISC_R_NORESOURCES", + "ISC_R_EOF", + "ISC_R_BOUND", + "ISC_R_RELOAD", + "ISC_R_LOCKBUSY", + "ISC_R_EXISTS", + "ISC_R_NOSPACE", + "ISC_R_CANCELED", + "ISC_R_NOTBOUND", + "ISC_R_SHUTTINGDOWN", + "ISC_R_NOTFOUND", + "ISC_R_UNEXPECTEDEND", + "ISC_R_FAILURE", + "ISC_R_IOERROR", + "ISC_R_NOTIMPLEMENTED", + "ISC_R_UNBALANCED", + "ISC_R_NOMORE", + "ISC_R_INVALIDFILE", + "ISC_R_BADBASE64", + "ISC_R_UNEXPECTEDTOKEN", + "ISC_R_QUOTA", + "ISC_R_UNEXPECTED", + "ISC_R_ALREADYRUNNING", + "ISC_R_IGNORE", + "ISC_R_MASKNONCONTIG", + "ISC_R_FILENOTFOUND", + "ISC_R_FILEEXISTS", + "ISC_R_NOTCONNECTED", + "ISC_R_RANGE", + "ISC_R_NOENTROPY", + "ISC_R_MULTICAST", + "ISC_R_NOTFILE", + "ISC_R_NOTDIRECTORY", + "ISC_R_QUEUEFULL", + "ISC_R_FAMILYMISMATCH", + "ISC_R_FAMILYNOSUPPORT", + "ISC_R_BADHEX", + "ISC_R_TOOMANYOPENFILES", + "ISC_R_NOTBLOCKING", + "ISC_R_UNBALANCEDQUOTES", + "ISC_R_INPROGRESS", + "ISC_R_CONNECTIONRESET", + "ISC_R_SOFTQUOTA", + "ISC_R_BADNUMBER", + "ISC_R_DISABLED", + "ISC_R_MAXSIZE", + "ISC_R_BADADDRESSFORM", + "ISC_R_BADBASE32", + "ISC_R_UNSET", + "ISC_R_MULTIPLE", + "ISC_R_WOULDBLOCK", + "ISC_R_COMPLETE", + "ISC_R_CRYPTOFAILURE", + "ISC_R_DISCQUOTA", + "ISC_R_DISCFULL", + "ISC_R_DEFAULT", + "ISC_R_IPV4PREFIX", + "ISC_R_TLSERROR", + "ISC_R_HTTP2ALPNERROR" }; -static resulttable_list_t description_tables; -static resulttable_list_t identifier_tables; +static struct { + size_t nresults; /*%< total number of result codes in this class */ + const char **description_table; /*%< brief description of the result */ + const char **id_table; /*%< result id, e.g. ISC_R_NOPERM */ +} const result_classes[ISC_RESULTCLASS_MAX + 1] = { + [ISC_RESULTCLASS_ISC] = { ISC_R_NRESULTS, isc_result_descriptions, + isc_result_ids }, + [ISC_RESULTCLASS_DNS] = { DNS_R_NRESULTS, dns_result_descriptions, + dns_result_ids }, + [ISC_RESULTCLASS_DST] = { DST_R_NRESULTS, dst_result_descriptions, + dst_result_ids }, + [ISC_RESULTCLASS_DNSRCODE] = { DNS_R_NRCODERESULTS, + dns_rcode_descriptions, dns_rcode_ids }, + [ISC_RESULTCLASS_ISCCC] = { ISCCC_R_NRESULTS, isccc_result_descriptions, + isccc_result_ids }, + [ISC_RESULTCLASS_PK11] = { PK11_R_NRESULTS, pk11_result_descriptions, + pk11_result_ids } +}; -static const char * -isc_result_tomany_helper(resulttable_list_t *tables, isc_result_t result) { - resulttable *table; - const char *text; - int index; +static inline const char * +isc_result_from_table(isc_result_t result, bool description) { + uint32_t rclass = ISC_RESULT_CLASS(result); + uint32_t rindex = ISC_RESULT_VALUE(result); - text = NULL; - for (table = ISC_LIST_HEAD(*tables); table != NULL; - table = ISC_LIST_NEXT(table, link)) - { - if (result >= table->base && result <= table->last) { - index = (int)(result - table->base); - text = table->text[index]; - break; - } - } - if (text == NULL) { - text = "(result code text not available)"; + REQUIRE(rclass <= ISC_RESULTCLASS_MAX); + + if (rindex < result_classes[rclass].nresults) { + return (description ? result_classes[rclass] + .description_table[rindex] + : result_classes[rclass].id_table[rindex]); } - return (text); + return ("(result code text not available)"); } const char * isc_result_totext(isc_result_t result) { - return (isc_result_tomany_helper(&description_tables, result)); + return (isc_result_from_table(result, true)); } const char * isc_result_toid(isc_result_t result) { - return (isc_result_tomany_helper(&identifier_tables, result)); + return (isc_result_from_table(result, false)); } diff --git a/lib/isc/result_pk11.c.in b/lib/isc/result_pk11.c.in index 36edc8c4f5..0e1491d393 100644 --- a/lib/isc/result_pk11.c.in +++ b/lib/isc/result_pk11.c.in @@ -14,7 +14,7 @@ #include #include -static const char *text[PK11_R_NRESULTS] = { +static const char *pk11_result_descriptions[PK11_R_NRESULTS] = { "PKCS#11 initialization failed", /*%< 0 */ "no PKCS#11 provider", /*%< 1 */ "PKCS#11 no random service", /*%< 2 */ @@ -22,7 +22,7 @@ static const char *text[PK11_R_NRESULTS] = { "PKCS#11 no AES service", /*%< 4 */ }; -static const char *ids[PK11_R_NRESULTS] = { +static const char *pk11_result_ids[PK11_R_NRESULTS] = { "PK11_R_INITFAILED", "PK11_R_NOPROVIDER", "PK11_R_NORANDOMSERVICE", "PK11_R_NODIGESTSERVICE", "PK11_R_NOAESSERVICE", diff --git a/lib/isc/win32/libisc.vcxproj.filters.in b/lib/isc/win32/libisc.vcxproj.filters.in index c859f3e46d..a7027091d7 100644 --- a/lib/isc/win32/libisc.vcxproj.filters.in +++ b/lib/isc/win32/libisc.vcxproj.filters.in @@ -203,6 +203,9 @@ Library Header Files + + Library Header Files + Library Header Files @@ -633,9 +636,6 @@ Library Source Files - - Library Source Files - @END PKCS11 diff --git a/lib/isc/win32/libisc.vcxproj.in b/lib/isc/win32/libisc.vcxproj.in index 34af31422d..7035fe0e1d 100644 --- a/lib/isc/win32/libisc.vcxproj.in +++ b/lib/isc/win32/libisc.vcxproj.in @@ -324,6 +324,7 @@ copy InstallFiles ..\Build\Release\ + diff --git a/lib/isccc/result_isccc.c.in b/lib/isccc/result_isccc.c.in index 440ea04956..dbdb4131f6 100644 --- a/lib/isccc/result_isccc.c.in +++ b/lib/isccc/result_isccc.c.in @@ -13,7 +13,7 @@ #include -static const char *text[ISCCC_R_NRESULTS] = { +static const char *isccc_result_descriptions[ISCCC_R_NRESULTS] = { "unknown version", /* 1 */ "syntax error", /* 2 */ "bad auth", /* 3 */ @@ -22,7 +22,7 @@ static const char *text[ISCCC_R_NRESULTS] = { "duplicate" /* 6 */ }; -static const char *ids[ISCCC_R_NRESULTS] = { +static const char *isccc_result_ids[ISCCC_R_NRESULTS] = { "ISCCC_R_UNKNOWNVERSION", "ISCCC_R_SYNTAX", "ISCCC_R_BADAUTH", "ISCCC_R_EXPIRED", "ISCCC_R_CLOCKSKEW", "ISCCC_R_DUPLICATE", }; diff --git a/lib/isccc/result_isccc.h.in b/lib/isccc/result_isccc.h.in index 22264db5fc..8fd5295d9b 100644 --- a/lib/isccc/result_isccc.h.in +++ b/lib/isccc/result_isccc.h.in @@ -17,17 +17,17 @@ #include /*% Unknown Version */ -#define ISCCC_R_UNKNOWNVERSION (ISC_RESULTCLASS_ISCCC + 0) +#define ISCCC_R_UNKNOWNVERSION ISC_RESULTCODE_ISCCC(0) /*% Syntax Error */ -#define ISCCC_R_SYNTAX (ISC_RESULTCLASS_ISCCC + 1) +#define ISCCC_R_SYNTAX ISC_RESULTCODE_ISCCC(1) /*% Bad Authorization */ -#define ISCCC_R_BADAUTH (ISC_RESULTCLASS_ISCCC + 2) +#define ISCCC_R_BADAUTH ISC_RESULTCODE_ISCCC(2) /*% Expired */ -#define ISCCC_R_EXPIRED (ISC_RESULTCLASS_ISCCC + 3) +#define ISCCC_R_EXPIRED ISC_RESULTCODE_ISCCC(3) /*% Clock Skew */ -#define ISCCC_R_CLOCKSKEW (ISC_RESULTCLASS_ISCCC + 4) +#define ISCCC_R_CLOCKSKEW ISC_RESULTCODE_ISCCC(4) /*% Duplicate */ -#define ISCCC_R_DUPLICATE (ISC_RESULTCLASS_ISCCC + 5) +#define ISCCC_R_DUPLICATE ISC_RESULTCODE_ISCCC(5) #define ISCCC_R_NRESULTS 6 /*%< Number of results */