Coverage Report

Created: 2025-11-24 06:17

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