Coverage Report

Created: 2026-01-24 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bind9/lib/dns/rdata/generic/dname_39.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
/* RFC2672 */
15
16
#ifndef RDATA_GENERIC_DNAME_39_C
17
#define RDATA_GENERIC_DNAME_39_C
18
19
21.1k
#define RRTYPE_DNAME_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
20
21
static isc_result_t
22
1.71k
fromtext_dname(ARGS_FROMTEXT) {
23
1.71k
  isc_token_t token;
24
1.71k
  isc_buffer_t buffer;
25
26
1.71k
  REQUIRE(type == dns_rdatatype_dname);
27
28
1.71k
  UNUSED(type);
29
1.71k
  UNUSED(rdclass);
30
1.71k
  UNUSED(callbacks);
31
32
1.71k
  RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
33
1.71k
              false));
34
35
1.71k
  buffer_fromregion(&buffer, &token.value.as_region);
36
1.71k
  if (origin == NULL) {
37
3
    origin = dns_rootname;
38
3
  }
39
1.71k
  RETTOK(dns_name_wirefromtext(&buffer, origin, options, target));
40
1.71k
  return ISC_R_SUCCESS;
41
1.71k
}
42
43
static isc_result_t
44
2.68k
totext_dname(ARGS_TOTEXT) {
45
2.68k
  isc_region_t region;
46
2.68k
  dns_name_t name;
47
2.68k
  dns_name_t prefix;
48
2.68k
  unsigned int opts;
49
50
2.68k
  REQUIRE(rdata->type == dns_rdatatype_dname);
51
2.68k
  REQUIRE(rdata->length != 0);
52
53
2.68k
  dns_name_init(&name);
54
2.68k
  dns_name_init(&prefix);
55
56
2.68k
  dns_rdata_toregion(rdata, &region);
57
2.68k
  dns_name_fromregion(&name, &region);
58
59
2.68k
  opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT
60
2.68k
               : 0;
61
2.68k
  return dns_name_totext(&prefix, opts, target);
62
2.68k
}
63
64
static isc_result_t
65
5.05k
fromwire_dname(ARGS_FROMWIRE) {
66
5.05k
  dns_name_t name;
67
68
5.05k
  REQUIRE(type == dns_rdatatype_dname);
69
70
5.05k
  UNUSED(type);
71
5.05k
  UNUSED(rdclass);
72
73
5.05k
  dctx = dns_decompress_setpermitted(dctx, false);
74
75
5.05k
  dns_name_init(&name);
76
5.05k
  return dns_name_fromwire(&name, source, dctx, target);
77
5.05k
}
78
79
static isc_result_t
80
1.35k
towire_dname(ARGS_TOWIRE) {
81
1.35k
  dns_name_t name;
82
1.35k
  isc_region_t region;
83
84
1.35k
  REQUIRE(rdata->type == dns_rdatatype_dname);
85
1.35k
  REQUIRE(rdata->length != 0);
86
87
1.35k
  dns_compress_setpermitted(cctx, false);
88
1.35k
  dns_name_init(&name);
89
1.35k
  dns_rdata_toregion(rdata, &region);
90
1.35k
  dns_name_fromregion(&name, &region);
91
92
1.35k
  return dns_name_towire(&name, cctx, target);
93
1.35k
}
94
95
static int
96
7.00k
compare_dname(ARGS_COMPARE) {
97
7.00k
  dns_name_t name1;
98
7.00k
  dns_name_t name2;
99
7.00k
  isc_region_t region1;
100
7.00k
  isc_region_t region2;
101
102
7.00k
  REQUIRE(rdata1->type == rdata2->type);
103
7.00k
  REQUIRE(rdata1->rdclass == rdata2->rdclass);
104
7.00k
  REQUIRE(rdata1->type == dns_rdatatype_dname);
105
7.00k
  REQUIRE(rdata1->length != 0);
106
7.00k
  REQUIRE(rdata2->length != 0);
107
108
7.00k
  dns_name_init(&name1);
109
7.00k
  dns_name_init(&name2);
110
111
7.00k
  dns_rdata_toregion(rdata1, &region1);
112
7.00k
  dns_rdata_toregion(rdata2, &region2);
113
114
7.00k
  dns_name_fromregion(&name1, &region1);
115
7.00k
  dns_name_fromregion(&name2, &region2);
116
117
7.00k
  return dns_name_rdatacompare(&name1, &name2);
118
7.00k
}
119
120
static isc_result_t
121
0
fromstruct_dname(ARGS_FROMSTRUCT) {
122
0
  dns_rdata_dname_t *dname = source;
123
0
  isc_region_t region;
124
125
0
  REQUIRE(type == dns_rdatatype_dname);
126
0
  REQUIRE(dname != NULL);
127
0
  REQUIRE(dname->common.rdtype == type);
128
0
  REQUIRE(dname->common.rdclass == rdclass);
129
130
0
  UNUSED(type);
131
0
  UNUSED(rdclass);
132
133
0
  dns_name_toregion(&dname->dname, &region);
134
0
  return isc_buffer_copyregion(target, &region);
135
0
}
136
137
static isc_result_t
138
0
tostruct_dname(ARGS_TOSTRUCT) {
139
0
  isc_region_t region;
140
0
  dns_rdata_dname_t *dname = target;
141
0
  dns_name_t name;
142
143
0
  REQUIRE(rdata->type == dns_rdatatype_dname);
144
0
  REQUIRE(dname != NULL);
145
0
  REQUIRE(rdata->length != 0);
146
147
0
  DNS_RDATACOMMON_INIT(dname, rdata->type, rdata->rdclass);
148
149
0
  dns_name_init(&name);
150
0
  dns_rdata_toregion(rdata, &region);
151
0
  dns_name_fromregion(&name, &region);
152
0
  dns_name_init(&dname->dname);
153
0
  name_duporclone(&name, mctx, &dname->dname);
154
0
  dname->mctx = mctx;
155
0
  return ISC_R_SUCCESS;
156
0
}
157
158
static void
159
0
freestruct_dname(ARGS_FREESTRUCT) {
160
0
  dns_rdata_dname_t *dname = source;
161
162
0
  REQUIRE(dname != NULL);
163
0
  REQUIRE(dname->common.rdtype == dns_rdatatype_dname);
164
165
0
  if (dname->mctx == NULL) {
166
0
    return;
167
0
  }
168
169
0
  dns_name_free(&dname->dname, dname->mctx);
170
0
  dname->mctx = NULL;
171
0
}
172
173
static isc_result_t
174
0
additionaldata_dname(ARGS_ADDLDATA) {
175
0
  REQUIRE(rdata->type == dns_rdatatype_dname);
176
177
0
  UNUSED(rdata);
178
0
  UNUSED(owner);
179
0
  UNUSED(add);
180
0
  UNUSED(arg);
181
182
0
  return ISC_R_SUCCESS;
183
0
}
184
185
static isc_result_t
186
0
digest_dname(ARGS_DIGEST) {
187
0
  isc_region_t r;
188
0
  dns_name_t name;
189
190
0
  REQUIRE(rdata->type == dns_rdatatype_dname);
191
192
0
  dns_rdata_toregion(rdata, &r);
193
0
  dns_name_init(&name);
194
0
  dns_name_fromregion(&name, &r);
195
196
0
  return dns_name_digest(&name, digest, arg);
197
0
}
198
199
static bool
200
0
checkowner_dname(ARGS_CHECKOWNER) {
201
0
  REQUIRE(type == dns_rdatatype_dname);
202
203
0
  UNUSED(name);
204
0
  UNUSED(type);
205
0
  UNUSED(rdclass);
206
0
  UNUSED(wildcard);
207
208
0
  return true;
209
0
}
210
211
static bool
212
0
checknames_dname(ARGS_CHECKNAMES) {
213
0
  REQUIRE(rdata->type == dns_rdatatype_dname);
214
215
0
  UNUSED(rdata);
216
0
  UNUSED(owner);
217
0
  UNUSED(bad);
218
219
0
  return true;
220
0
}
221
222
static int
223
0
casecompare_dname(ARGS_COMPARE) {
224
0
  return compare_dname(rdata1, rdata2);
225
0
}
226
#endif /* RDATA_GENERIC_DNAME_39_C */