/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 | 7.41k | #define RRTYPE_RT_ATTRIBUTES (0) |
20 | | |
21 | | static isc_result_t |
22 | 4.10k | fromtext_rt(ARGS_FROMTEXT) { |
23 | 4.10k | isc_token_t token; |
24 | 4.10k | isc_buffer_t buffer; |
25 | 4.10k | dns_fixedname_t fn; |
26 | 4.10k | dns_name_t *name = dns_fixedname_initname(&fn); |
27 | 4.10k | bool ok; |
28 | | |
29 | 4.10k | REQUIRE(type == dns_rdatatype_rt); |
30 | | |
31 | 4.10k | UNUSED(type); |
32 | 4.10k | UNUSED(rdclass); |
33 | 4.10k | UNUSED(callbacks); |
34 | | |
35 | 4.10k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
36 | 4.10k | false)); |
37 | 4.10k | if (token.value.as_ulong > 0xffffU) { |
38 | 26 | RETTOK(ISC_R_RANGE); |
39 | 26 | } |
40 | 4.07k | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
41 | | |
42 | 4.07k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
43 | 4.07k | false)); |
44 | | |
45 | 4.02k | buffer_fromregion(&buffer, &token.value.as_region); |
46 | 4.02k | if (origin == NULL) { |
47 | 2 | origin = dns_rootname; |
48 | 2 | } |
49 | | |
50 | 4.02k | RETTOK(dns_name_fromtext(name, &buffer, origin, options)); |
51 | 4.02k | RETTOK(dns_name_towire(name, NULL, target)); |
52 | | |
53 | 4.02k | ok = true; |
54 | 4.02k | if ((options & DNS_RDATA_CHECKNAMES) != 0) { |
55 | 0 | ok = dns_name_ishostname(name, false); |
56 | 0 | } |
57 | 4.02k | if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { |
58 | 0 | RETTOK(DNS_R_BADNAME); |
59 | 0 | } |
60 | 4.02k | if (!ok && callbacks != NULL) { |
61 | 0 | warn_badname(name, lexer, callbacks); |
62 | 0 | } |
63 | 4.02k | return ISC_R_SUCCESS; |
64 | 4.02k | } |
65 | | |
66 | | static isc_result_t |
67 | 832 | totext_rt(ARGS_TOTEXT) { |
68 | 832 | isc_region_t region; |
69 | 832 | dns_name_t name; |
70 | 832 | dns_name_t prefix; |
71 | 832 | unsigned int opts; |
72 | 832 | char buf[sizeof("64000")]; |
73 | 832 | unsigned short num; |
74 | | |
75 | 832 | REQUIRE(rdata->type == dns_rdatatype_rt); |
76 | 832 | REQUIRE(rdata->length != 0); |
77 | | |
78 | 832 | dns_name_init(&name); |
79 | 832 | dns_name_init(&prefix); |
80 | | |
81 | 832 | dns_rdata_toregion(rdata, ®ion); |
82 | 832 | num = uint16_fromregion(®ion); |
83 | 832 | isc_region_consume(®ion, 2); |
84 | 832 | snprintf(buf, sizeof(buf), "%u", num); |
85 | 832 | RETERR(str_totext(buf, target)); |
86 | 832 | RETERR(str_totext(" ", target)); |
87 | 832 | dns_name_fromregion(&name, ®ion); |
88 | 832 | opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT |
89 | 832 | : 0; |
90 | 832 | return dns_name_totext(&prefix, opts, target); |
91 | 832 | } |
92 | | |
93 | | static isc_result_t |
94 | 1.08k | fromwire_rt(ARGS_FROMWIRE) { |
95 | 1.08k | dns_name_t name; |
96 | 1.08k | isc_region_t sregion; |
97 | 1.08k | isc_region_t tregion; |
98 | | |
99 | 1.08k | REQUIRE(type == dns_rdatatype_rt); |
100 | | |
101 | 1.08k | UNUSED(type); |
102 | 1.08k | UNUSED(rdclass); |
103 | | |
104 | | /* |
105 | | * RFC 3597 section 4 asks receivers to decompress this type, |
106 | | * even though senders must not compress it. |
107 | | */ |
108 | 1.08k | dns_decompress_setpermitted(dctx, true); |
109 | | |
110 | 1.08k | dns_name_init(&name); |
111 | | |
112 | 1.08k | isc_buffer_activeregion(source, &sregion); |
113 | 1.08k | isc_buffer_availableregion(target, &tregion); |
114 | 1.08k | if (tregion.length < 2) { |
115 | 18 | return ISC_R_NOSPACE; |
116 | 18 | } |
117 | 1.06k | if (sregion.length < 2) { |
118 | 15 | return ISC_R_UNEXPECTEDEND; |
119 | 15 | } |
120 | 1.05k | memmove(tregion.base, sregion.base, 2); |
121 | 1.05k | isc_buffer_forward(source, 2); |
122 | 1.05k | isc_buffer_add(target, 2); |
123 | 1.05k | return dns_name_fromwire(&name, source, dctx, target); |
124 | 1.06k | } |
125 | | |
126 | | static int |
127 | 2.52M | compare_rt(ARGS_COMPARE) { |
128 | 2.52M | dns_name_t name1; |
129 | 2.52M | dns_name_t name2; |
130 | 2.52M | isc_region_t region1; |
131 | 2.52M | isc_region_t region2; |
132 | 2.52M | int order; |
133 | | |
134 | 2.52M | REQUIRE(rdata1->type == rdata2->type); |
135 | 2.52M | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
136 | 2.52M | REQUIRE(rdata1->type == dns_rdatatype_rt); |
137 | 2.52M | REQUIRE(rdata1->length != 0); |
138 | 2.52M | REQUIRE(rdata2->length != 0); |
139 | | |
140 | 2.52M | order = memcmp(rdata1->data, rdata2->data, 2); |
141 | 2.52M | if (order != 0) { |
142 | 2.52M | return order < 0 ? -1 : 1; |
143 | 2.52M | } |
144 | | |
145 | 1.43k | dns_name_init(&name1); |
146 | 1.43k | dns_name_init(&name2); |
147 | | |
148 | 1.43k | dns_rdata_toregion(rdata1, ®ion1); |
149 | 1.43k | dns_rdata_toregion(rdata2, ®ion2); |
150 | | |
151 | 1.43k | isc_region_consume(®ion1, 2); |
152 | 1.43k | isc_region_consume(®ion2, 2); |
153 | | |
154 | 1.43k | dns_name_fromregion(&name1, ®ion1); |
155 | 1.43k | dns_name_fromregion(&name2, ®ion2); |
156 | | |
157 | 1.43k | return dns_name_rdatacompare(&name1, &name2); |
158 | 2.52M | } |
159 | | |
160 | | static isc_result_t |
161 | 0 | fromstruct_rt(ARGS_FROMSTRUCT) { |
162 | 0 | dns_rdata_rt_t *rt = source; |
163 | 0 | isc_region_t region; |
164 | |
|
165 | 0 | REQUIRE(type == dns_rdatatype_rt); |
166 | 0 | REQUIRE(rt != NULL); |
167 | 0 | REQUIRE(rt->common.rdtype == type); |
168 | 0 | REQUIRE(rt->common.rdclass == rdclass); |
169 | |
|
170 | 0 | UNUSED(type); |
171 | 0 | UNUSED(rdclass); |
172 | |
|
173 | 0 | RETERR(uint16_tobuffer(rt->preference, target)); |
174 | 0 | dns_name_toregion(&rt->host, ®ion); |
175 | 0 | return isc_buffer_copyregion(target, ®ion); |
176 | 0 | } |
177 | | |
178 | | static isc_result_t |
179 | 0 | tostruct_rt(ARGS_TOSTRUCT) { |
180 | 0 | isc_region_t region; |
181 | 0 | dns_rdata_rt_t *rt = target; |
182 | 0 | dns_name_t name; |
183 | |
|
184 | 0 | REQUIRE(rdata->type == dns_rdatatype_rt); |
185 | 0 | REQUIRE(rt != NULL); |
186 | 0 | REQUIRE(rdata->length != 0); |
187 | |
|
188 | 0 | DNS_RDATACOMMON_INIT(rt, rdata->type, rdata->rdclass); |
189 | |
|
190 | 0 | dns_name_init(&name); |
191 | 0 | dns_rdata_toregion(rdata, ®ion); |
192 | 0 | rt->preference = uint16_fromregion(®ion); |
193 | 0 | isc_region_consume(®ion, 2); |
194 | 0 | dns_name_fromregion(&name, ®ion); |
195 | 0 | dns_name_init(&rt->host); |
196 | 0 | dns_name_clone(&name, &rt->host); |
197 | |
|
198 | 0 | return ISC_R_SUCCESS; |
199 | 0 | } |
200 | | |
201 | | static isc_result_t |
202 | 0 | additionaldata_rt(ARGS_ADDLDATA) { |
203 | 0 | dns_name_t name; |
204 | 0 | isc_region_t region; |
205 | |
|
206 | 0 | REQUIRE(rdata->type == dns_rdatatype_rt); |
207 | |
|
208 | 0 | UNUSED(owner); |
209 | |
|
210 | 0 | dns_name_init(&name); |
211 | 0 | dns_rdata_toregion(rdata, ®ion); |
212 | 0 | isc_region_consume(®ion, 2); |
213 | 0 | dns_name_fromregion(&name, ®ion); |
214 | |
|
215 | 0 | RETERR((add)(arg, &name, dns_rdatatype_x25, NULL DNS__DB_FILELINE)); |
216 | 0 | RETERR((add)(arg, &name, dns_rdatatype_isdn, NULL DNS__DB_FILELINE)); |
217 | 0 | return (add)(arg, &name, dns_rdatatype_a, NULL DNS__DB_FILELINE); |
218 | 0 | } |
219 | | |
220 | | static isc_result_t |
221 | 0 | digest_rt(ARGS_DIGEST) { |
222 | 0 | isc_region_t r1, r2; |
223 | 0 | dns_name_t name; |
224 | |
|
225 | 0 | REQUIRE(rdata->type == dns_rdatatype_rt); |
226 | |
|
227 | 0 | dns_rdata_toregion(rdata, &r1); |
228 | 0 | r2 = r1; |
229 | 0 | isc_region_consume(&r2, 2); |
230 | 0 | r1.length = 2; |
231 | 0 | RETERR((digest)(arg, &r1)); |
232 | 0 | dns_name_init(&name); |
233 | 0 | dns_name_fromregion(&name, &r2); |
234 | 0 | return dns_name_digest(&name, digest, arg); |
235 | 0 | } |
236 | | |
237 | | static bool |
238 | 0 | checkowner_rt(ARGS_CHECKOWNER) { |
239 | 0 | REQUIRE(type == dns_rdatatype_rt); |
240 | |
|
241 | 0 | UNUSED(name); |
242 | 0 | UNUSED(type); |
243 | 0 | UNUSED(rdclass); |
244 | 0 | UNUSED(wildcard); |
245 | |
|
246 | 0 | return true; |
247 | 0 | } |
248 | | |
249 | | static bool |
250 | 0 | checknames_rt(ARGS_CHECKNAMES) { |
251 | 0 | isc_region_t region; |
252 | 0 | dns_name_t name; |
253 | |
|
254 | 0 | REQUIRE(rdata->type == dns_rdatatype_rt); |
255 | |
|
256 | 0 | UNUSED(owner); |
257 | |
|
258 | 0 | dns_rdata_toregion(rdata, ®ion); |
259 | 0 | isc_region_consume(®ion, 2); |
260 | 0 | dns_name_init(&name); |
261 | 0 | dns_name_fromregion(&name, ®ion); |
262 | 0 | if (!dns_name_ishostname(&name, false)) { |
263 | 0 | if (bad != NULL) { |
264 | 0 | dns_name_clone(&name, bad); |
265 | 0 | } |
266 | 0 | return false; |
267 | 0 | } |
268 | 0 | return true; |
269 | 0 | } |
270 | | |
271 | | static int |
272 | 0 | casecompare_rt(ARGS_COMPARE) { |
273 | 0 | return compare_rt(rdata1, rdata2); |
274 | 0 | } |
275 | | |
276 | | #endif /* RDATA_GENERIC_RT_21_C */ |