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