/src/bind9/lib/dns/rdata/generic/rt_21.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 | | /* RFC1183 */ |
15 | | |
16 | | #ifndef RDATA_GENERIC_RT_21_C |
17 | | #define RDATA_GENERIC_RT_21_C |
18 | | |
19 | 14.2k | #define RRTYPE_RT_ATTRIBUTES (0) |
20 | | |
21 | | static isc_result_t |
22 | 3.82k | fromtext_rt(ARGS_FROMTEXT) { |
23 | 3.82k | isc_token_t token; |
24 | 3.82k | isc_buffer_t buffer; |
25 | 3.82k | dns_fixedname_t fn; |
26 | 3.82k | dns_name_t *name = dns_fixedname_initname(&fn); |
27 | 3.82k | bool ok; |
28 | | |
29 | 3.82k | REQUIRE(type == dns_rdatatype_rt); |
30 | | |
31 | 3.82k | UNUSED(type); |
32 | 3.82k | UNUSED(rdclass); |
33 | 3.82k | UNUSED(callbacks); |
34 | | |
35 | 3.82k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
36 | 3.82k | false)); |
37 | 3.81k | if (token.value.as_ulong > 0xffffU) { |
38 | 26 | RETTOK(ISC_R_RANGE); |
39 | 26 | } |
40 | 3.78k | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
41 | | |
42 | 3.78k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
43 | 3.78k | false)); |
44 | | |
45 | 3.75k | buffer_fromregion(&buffer, &token.value.as_region); |
46 | 3.75k | if (origin == NULL) { |
47 | 3 | origin = dns_rootname; |
48 | 3 | } |
49 | | |
50 | 3.75k | RETTOK(dns_name_fromtext(name, &buffer, origin, options)); |
51 | 3.74k | RETTOK(dns_name_towire(name, NULL, target)); |
52 | | |
53 | 3.74k | ok = true; |
54 | 3.74k | if ((options & DNS_RDATA_CHECKNAMES) != 0) { |
55 | 0 | ok = dns_name_ishostname(name, false); |
56 | 0 | } |
57 | 3.74k | if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { |
58 | 0 | RETTOK(DNS_R_BADNAME); |
59 | 0 | } |
60 | 3.74k | if (!ok && callbacks != NULL) { |
61 | 0 | warn_badname(name, lexer, callbacks); |
62 | 0 | } |
63 | 3.74k | return ISC_R_SUCCESS; |
64 | 3.74k | } |
65 | | |
66 | | static isc_result_t |
67 | 1.06k | totext_rt(ARGS_TOTEXT) { |
68 | 1.06k | isc_region_t region; |
69 | 1.06k | dns_name_t name; |
70 | 1.06k | dns_name_t prefix; |
71 | 1.06k | unsigned int opts; |
72 | 1.06k | char buf[sizeof("64000")]; |
73 | 1.06k | unsigned short num; |
74 | | |
75 | 1.06k | REQUIRE(rdata->type == dns_rdatatype_rt); |
76 | 1.06k | REQUIRE(rdata->length != 0); |
77 | | |
78 | 1.06k | dns_name_init(&name); |
79 | 1.06k | dns_name_init(&prefix); |
80 | | |
81 | 1.06k | dns_rdata_toregion(rdata, ®ion); |
82 | 1.06k | num = uint16_fromregion(®ion); |
83 | 1.06k | isc_region_consume(®ion, 2); |
84 | 1.06k | snprintf(buf, sizeof(buf), "%u", num); |
85 | 1.06k | RETERR(str_totext(buf, target)); |
86 | 1.06k | RETERR(str_totext(" ", target)); |
87 | 1.06k | dns_name_fromregion(&name, ®ion); |
88 | 1.06k | opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT |
89 | 1.06k | : 0; |
90 | 1.06k | return dns_name_totext(&prefix, opts, target); |
91 | 1.06k | } |
92 | | |
93 | | static isc_result_t |
94 | 1.77k | fromwire_rt(ARGS_FROMWIRE) { |
95 | 1.77k | dns_name_t name; |
96 | 1.77k | isc_region_t sregion; |
97 | 1.77k | isc_region_t tregion; |
98 | | |
99 | 1.77k | REQUIRE(type == dns_rdatatype_rt); |
100 | | |
101 | 1.77k | UNUSED(type); |
102 | 1.77k | UNUSED(rdclass); |
103 | | |
104 | 1.77k | dctx = dns_decompress_setpermitted(dctx, false); |
105 | | |
106 | 1.77k | dns_name_init(&name); |
107 | | |
108 | 1.77k | isc_buffer_activeregion(source, &sregion); |
109 | 1.77k | isc_buffer_availableregion(target, &tregion); |
110 | 1.77k | if (tregion.length < 2) { |
111 | 196 | return ISC_R_NOSPACE; |
112 | 196 | } |
113 | 1.57k | if (sregion.length < 2) { |
114 | 10 | return ISC_R_UNEXPECTEDEND; |
115 | 10 | } |
116 | 1.56k | memmove(tregion.base, sregion.base, 2); |
117 | 1.56k | isc_buffer_forward(source, 2); |
118 | 1.56k | isc_buffer_add(target, 2); |
119 | 1.56k | return dns_name_fromwire(&name, source, dctx, target); |
120 | 1.57k | } |
121 | | |
122 | | static isc_result_t |
123 | 532 | towire_rt(ARGS_TOWIRE) { |
124 | 532 | dns_name_t name; |
125 | 532 | isc_region_t region; |
126 | 532 | isc_region_t tr; |
127 | | |
128 | 532 | REQUIRE(rdata->type == dns_rdatatype_rt); |
129 | 532 | REQUIRE(rdata->length != 0); |
130 | | |
131 | 532 | dns_compress_setpermitted(cctx, false); |
132 | 532 | isc_buffer_availableregion(target, &tr); |
133 | 532 | dns_rdata_toregion(rdata, ®ion); |
134 | 532 | if (tr.length < 2) { |
135 | 1 | return ISC_R_NOSPACE; |
136 | 1 | } |
137 | 531 | memmove(tr.base, region.base, 2); |
138 | 531 | isc_region_consume(®ion, 2); |
139 | 531 | isc_buffer_add(target, 2); |
140 | | |
141 | 531 | dns_name_init(&name); |
142 | 531 | dns_name_fromregion(&name, ®ion); |
143 | | |
144 | 531 | return dns_name_towire(&name, cctx, target); |
145 | 532 | } |
146 | | |
147 | | static int |
148 | 7.66M | compare_rt(ARGS_COMPARE) { |
149 | 7.66M | dns_name_t name1; |
150 | 7.66M | dns_name_t name2; |
151 | 7.66M | isc_region_t region1; |
152 | 7.66M | isc_region_t region2; |
153 | 7.66M | int order; |
154 | | |
155 | 7.66M | REQUIRE(rdata1->type == rdata2->type); |
156 | 7.66M | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
157 | 7.66M | REQUIRE(rdata1->type == dns_rdatatype_rt); |
158 | 7.66M | REQUIRE(rdata1->length != 0); |
159 | 7.66M | REQUIRE(rdata2->length != 0); |
160 | | |
161 | 7.66M | order = memcmp(rdata1->data, rdata2->data, 2); |
162 | 7.66M | if (order != 0) { |
163 | 7.66M | return order < 0 ? -1 : 1; |
164 | 7.66M | } |
165 | | |
166 | 1.83k | dns_name_init(&name1); |
167 | 1.83k | dns_name_init(&name2); |
168 | | |
169 | 1.83k | dns_rdata_toregion(rdata1, ®ion1); |
170 | 1.83k | dns_rdata_toregion(rdata2, ®ion2); |
171 | | |
172 | 1.83k | isc_region_consume(®ion1, 2); |
173 | 1.83k | isc_region_consume(®ion2, 2); |
174 | | |
175 | 1.83k | dns_name_fromregion(&name1, ®ion1); |
176 | 1.83k | dns_name_fromregion(&name2, ®ion2); |
177 | | |
178 | 1.83k | return dns_name_rdatacompare(&name1, &name2); |
179 | 7.66M | } |
180 | | |
181 | | static isc_result_t |
182 | 0 | fromstruct_rt(ARGS_FROMSTRUCT) { |
183 | 0 | dns_rdata_rt_t *rt = source; |
184 | 0 | isc_region_t region; |
185 | |
|
186 | 0 | REQUIRE(type == dns_rdatatype_rt); |
187 | 0 | REQUIRE(rt != NULL); |
188 | 0 | REQUIRE(rt->common.rdtype == type); |
189 | 0 | REQUIRE(rt->common.rdclass == rdclass); |
190 | |
|
191 | 0 | UNUSED(type); |
192 | 0 | UNUSED(rdclass); |
193 | |
|
194 | 0 | RETERR(uint16_tobuffer(rt->preference, target)); |
195 | 0 | dns_name_toregion(&rt->host, ®ion); |
196 | 0 | return isc_buffer_copyregion(target, ®ion); |
197 | 0 | } |
198 | | |
199 | | static isc_result_t |
200 | 0 | tostruct_rt(ARGS_TOSTRUCT) { |
201 | 0 | isc_region_t region; |
202 | 0 | dns_rdata_rt_t *rt = target; |
203 | 0 | dns_name_t name; |
204 | |
|
205 | 0 | REQUIRE(rdata->type == dns_rdatatype_rt); |
206 | 0 | REQUIRE(rt != NULL); |
207 | 0 | REQUIRE(rdata->length != 0); |
208 | |
|
209 | 0 | DNS_RDATACOMMON_INIT(rt, rdata->type, rdata->rdclass); |
210 | |
|
211 | 0 | dns_name_init(&name); |
212 | 0 | dns_rdata_toregion(rdata, ®ion); |
213 | 0 | rt->preference = uint16_fromregion(®ion); |
214 | 0 | isc_region_consume(®ion, 2); |
215 | 0 | dns_name_fromregion(&name, ®ion); |
216 | 0 | dns_name_init(&rt->host); |
217 | 0 | name_duporclone(&name, mctx, &rt->host); |
218 | |
|
219 | 0 | rt->mctx = mctx; |
220 | 0 | return ISC_R_SUCCESS; |
221 | 0 | } |
222 | | |
223 | | static void |
224 | 0 | freestruct_rt(ARGS_FREESTRUCT) { |
225 | 0 | dns_rdata_rt_t *rt = source; |
226 | |
|
227 | 0 | REQUIRE(rt != NULL); |
228 | 0 | REQUIRE(rt->common.rdtype == dns_rdatatype_rt); |
229 | |
|
230 | 0 | if (rt->mctx == NULL) { |
231 | 0 | return; |
232 | 0 | } |
233 | | |
234 | 0 | dns_name_free(&rt->host, rt->mctx); |
235 | 0 | rt->mctx = NULL; |
236 | 0 | } |
237 | | |
238 | | static isc_result_t |
239 | 0 | additionaldata_rt(ARGS_ADDLDATA) { |
240 | 0 | dns_name_t name; |
241 | 0 | isc_region_t region; |
242 | 0 | isc_result_t result; |
243 | |
|
244 | 0 | REQUIRE(rdata->type == dns_rdatatype_rt); |
245 | |
|
246 | 0 | UNUSED(owner); |
247 | |
|
248 | 0 | dns_name_init(&name); |
249 | 0 | dns_rdata_toregion(rdata, ®ion); |
250 | 0 | isc_region_consume(®ion, 2); |
251 | 0 | dns_name_fromregion(&name, ®ion); |
252 | |
|
253 | 0 | result = (add)(arg, &name, dns_rdatatype_x25, NULL DNS__DB_FILELINE); |
254 | 0 | if (result != ISC_R_SUCCESS) { |
255 | 0 | return result; |
256 | 0 | } |
257 | 0 | result = (add)(arg, &name, dns_rdatatype_isdn, NULL DNS__DB_FILELINE); |
258 | 0 | if (result != ISC_R_SUCCESS) { |
259 | 0 | return result; |
260 | 0 | } |
261 | 0 | return (add)(arg, &name, dns_rdatatype_a, NULL DNS__DB_FILELINE); |
262 | 0 | } |
263 | | |
264 | | static isc_result_t |
265 | 0 | digest_rt(ARGS_DIGEST) { |
266 | 0 | isc_region_t r1, r2; |
267 | 0 | isc_result_t result; |
268 | 0 | dns_name_t name; |
269 | |
|
270 | 0 | REQUIRE(rdata->type == dns_rdatatype_rt); |
271 | |
|
272 | 0 | dns_rdata_toregion(rdata, &r1); |
273 | 0 | r2 = r1; |
274 | 0 | isc_region_consume(&r2, 2); |
275 | 0 | r1.length = 2; |
276 | 0 | result = (digest)(arg, &r1); |
277 | 0 | if (result != ISC_R_SUCCESS) { |
278 | 0 | return result; |
279 | 0 | } |
280 | 0 | dns_name_init(&name); |
281 | 0 | dns_name_fromregion(&name, &r2); |
282 | 0 | return dns_name_digest(&name, digest, arg); |
283 | 0 | } |
284 | | |
285 | | static bool |
286 | 0 | checkowner_rt(ARGS_CHECKOWNER) { |
287 | 0 | REQUIRE(type == dns_rdatatype_rt); |
288 | |
|
289 | 0 | UNUSED(name); |
290 | 0 | UNUSED(type); |
291 | 0 | UNUSED(rdclass); |
292 | 0 | UNUSED(wildcard); |
293 | |
|
294 | 0 | return true; |
295 | 0 | } |
296 | | |
297 | | static bool |
298 | 0 | checknames_rt(ARGS_CHECKNAMES) { |
299 | 0 | isc_region_t region; |
300 | 0 | dns_name_t name; |
301 | |
|
302 | 0 | REQUIRE(rdata->type == dns_rdatatype_rt); |
303 | |
|
304 | 0 | UNUSED(owner); |
305 | |
|
306 | 0 | dns_rdata_toregion(rdata, ®ion); |
307 | 0 | isc_region_consume(®ion, 2); |
308 | 0 | dns_name_init(&name); |
309 | 0 | dns_name_fromregion(&name, ®ion); |
310 | 0 | if (!dns_name_ishostname(&name, false)) { |
311 | 0 | if (bad != NULL) { |
312 | 0 | dns_name_clone(&name, bad); |
313 | 0 | } |
314 | 0 | return false; |
315 | 0 | } |
316 | 0 | return true; |
317 | 0 | } |
318 | | |
319 | | static int |
320 | 0 | casecompare_rt(ARGS_COMPARE) { |
321 | 0 | return compare_rt(rdata1, rdata2); |
322 | 0 | } |
323 | | |
324 | | #endif /* RDATA_GENERIC_RT_21_C */ |