1 /* $NetBSD: result.c,v 1.10 2025/01/26 16:25:25 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 /*! \file */ 17 18 #include <isc/once.h> 19 #include <isc/result.h> 20 #include <isc/util.h> 21 22 #include <dns/result.h> 23 24 dns_rcode_t 25 dns_result_torcode(isc_result_t result) { 26 /* Try to supply an appropriate rcode. */ 27 switch (result) { 28 case DNS_R_NOERROR: 29 case ISC_R_SUCCESS: 30 return dns_rcode_noerror; 31 case DNS_R_FORMERR: 32 case ISC_R_BADBASE64: 33 case ISC_R_RANGE: 34 case ISC_R_UNEXPECTEDEND: 35 case DNS_R_BADAAAA: 36 case DNS_R_BADCKSUM: 37 case DNS_R_BADCLASS: 38 case DNS_R_BADLABELTYPE: 39 case DNS_R_BADPOINTER: 40 case DNS_R_BADTTL: 41 case DNS_R_BADZONE: 42 case DNS_R_EXTRADATA: 43 case DNS_R_LABELTOOLONG: 44 case DNS_R_NOREDATA: 45 case DNS_R_SYNTAX: 46 case DNS_R_TEXTTOOLONG: 47 case DNS_R_TOOMANYHOPS: 48 case DNS_R_TSIGERRORSET: 49 case DNS_R_UNKNOWN: 50 case DNS_R_NAMETOOLONG: 51 case DNS_R_OPTERR: 52 return dns_rcode_formerr; 53 case DNS_R_SERVFAIL: 54 return dns_rcode_servfail; 55 case DNS_R_NXDOMAIN: 56 return dns_rcode_nxdomain; 57 case DNS_R_NOTIMP: 58 return dns_rcode_notimp; 59 case DNS_R_REFUSED: 60 case DNS_R_DISALLOWED: 61 return dns_rcode_refused; 62 case DNS_R_YXDOMAIN: 63 return dns_rcode_yxdomain; 64 case DNS_R_YXRRSET: 65 return dns_rcode_yxrrset; 66 case DNS_R_NXRRSET: 67 return dns_rcode_nxrrset; 68 case DNS_R_NOTAUTH: 69 case DNS_R_TSIGVERIFYFAILURE: 70 case DNS_R_CLOCKSKEW: 71 return dns_rcode_notauth; 72 case DNS_R_NOTZONE: 73 return dns_rcode_notzone; 74 case DNS_R_RCODE11: 75 case DNS_R_RCODE12: 76 case DNS_R_RCODE13: 77 case DNS_R_RCODE14: 78 case DNS_R_RCODE15: 79 return result - DNS_R_NOERROR; 80 case DNS_R_BADVERS: 81 return dns_rcode_badvers; 82 case DNS_R_BADCOOKIE: 83 return dns_rcode_badcookie; 84 default: 85 return dns_rcode_servfail; 86 } 87 } 88 89 isc_result_t 90 dns_result_fromrcode(dns_rcode_t rcode) { 91 switch (rcode) { 92 case dns_rcode_noerror: 93 return DNS_R_NOERROR; 94 case dns_rcode_formerr: 95 return DNS_R_FORMERR; 96 case dns_rcode_servfail: 97 return DNS_R_SERVFAIL; 98 case dns_rcode_nxdomain: 99 return DNS_R_NXDOMAIN; 100 case dns_rcode_notimp: 101 return DNS_R_NOTIMP; 102 case dns_rcode_refused: 103 return DNS_R_REFUSED; 104 case dns_rcode_yxdomain: 105 return DNS_R_YXDOMAIN; 106 case dns_rcode_yxrrset: 107 return DNS_R_YXRRSET; 108 case dns_rcode_nxrrset: 109 return DNS_R_NXRRSET; 110 case dns_rcode_notauth: 111 return DNS_R_NOTAUTH; 112 case dns_rcode_notzone: 113 return DNS_R_NOTZONE; 114 case dns_rcode_badvers: 115 return DNS_R_BADVERS; 116 case dns_rcode_badcookie: 117 return DNS_R_BADCOOKIE; 118 default: 119 return DNS_R_SERVFAIL; 120 } 121 } 122