/src/bind9/lib/dns/rdata/generic/naptr_35.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 | | /* RFC2915 */ |
15 | | |
16 | | #ifndef RDATA_GENERIC_NAPTR_35_C |
17 | | #define RDATA_GENERIC_NAPTR_35_C |
18 | | |
19 | 23.7k | #define RRTYPE_NAPTR_ATTRIBUTES (0) |
20 | | |
21 | | #include <isc/regex.h> |
22 | | |
23 | | /* |
24 | | * Check the wire format of the Regexp field. |
25 | | * Don't allow embedded NUL's. |
26 | | */ |
27 | | static isc_result_t |
28 | 15.6k | txt_valid_regex(const unsigned char *txt) { |
29 | 15.6k | unsigned int nsub = 0; |
30 | 15.6k | char regex[256]; |
31 | 15.6k | char *cp; |
32 | 15.6k | bool flags = false; |
33 | 15.6k | bool replace = false; |
34 | 15.6k | unsigned char c; |
35 | 15.6k | unsigned char delim; |
36 | 15.6k | unsigned int len; |
37 | 15.6k | int n; |
38 | | |
39 | 15.6k | len = *txt++; |
40 | 15.6k | if (len == 0U) { |
41 | 4.41k | return ISC_R_SUCCESS; |
42 | 4.41k | } |
43 | | |
44 | 11.2k | delim = *txt++; |
45 | 11.2k | len--; |
46 | | |
47 | | /* |
48 | | * Digits, backslash and flags can't be delimiters. |
49 | | */ |
50 | 11.2k | switch (delim) { |
51 | 4 | case '0': |
52 | 8 | case '1': |
53 | 12 | case '2': |
54 | 17 | case '3': |
55 | 23 | case '4': |
56 | 27 | case '5': |
57 | 31 | case '6': |
58 | 35 | case '7': |
59 | 39 | case '8': |
60 | 43 | case '9': |
61 | 47 | case '\\': |
62 | 51 | case 'i': |
63 | 56 | case 0: |
64 | 56 | return DNS_R_SYNTAX; |
65 | 11.2k | } |
66 | | |
67 | 11.2k | cp = regex; |
68 | 592k | while (len-- > 0) { |
69 | 581k | c = *txt++; |
70 | 581k | if (c == 0) { |
71 | 18 | return DNS_R_SYNTAX; |
72 | 18 | } |
73 | 581k | if (c == delim && !replace) { |
74 | 11.1k | replace = true; |
75 | 11.1k | continue; |
76 | 570k | } else if (c == delim && !flags) { |
77 | 10.8k | flags = true; |
78 | 10.8k | continue; |
79 | 559k | } else if (c == delim) { |
80 | 10 | return DNS_R_SYNTAX; |
81 | 10 | } |
82 | | /* |
83 | | * Flags are not escaped. |
84 | | */ |
85 | 559k | if (flags) { |
86 | 723 | switch (c) { |
87 | 711 | case 'i': |
88 | 711 | continue; |
89 | 12 | default: |
90 | 12 | return DNS_R_SYNTAX; |
91 | 723 | } |
92 | 723 | } |
93 | 558k | if (!replace) { |
94 | 492k | *cp++ = c; |
95 | 492k | } |
96 | 558k | if (c == '\\') { |
97 | 32.5k | if (len == 0) { |
98 | 14 | return DNS_R_SYNTAX; |
99 | 14 | } |
100 | 32.5k | c = *txt++; |
101 | 32.5k | if (c == 0) { |
102 | 4 | return DNS_R_SYNTAX; |
103 | 4 | } |
104 | 32.5k | len--; |
105 | 32.5k | if (replace) { |
106 | 17.1k | switch (c) { |
107 | 5 | case '0': |
108 | 5 | return DNS_R_SYNTAX; |
109 | 2.25k | case '1': |
110 | 2.25k | if (nsub < 1) { |
111 | 1.72k | nsub = 1; |
112 | 1.72k | } |
113 | 2.25k | break; |
114 | 1.07k | case '2': |
115 | 1.07k | if (nsub < 2) { |
116 | 382 | nsub = 2; |
117 | 382 | } |
118 | 1.07k | break; |
119 | 1.46k | case '3': |
120 | 1.46k | if (nsub < 3) { |
121 | 742 | nsub = 3; |
122 | 742 | } |
123 | 1.46k | break; |
124 | 1.64k | case '4': |
125 | 1.64k | if (nsub < 4) { |
126 | 719 | nsub = 4; |
127 | 719 | } |
128 | 1.64k | break; |
129 | 2.64k | case '5': |
130 | 2.64k | if (nsub < 5) { |
131 | 1.28k | nsub = 5; |
132 | 1.28k | } |
133 | 2.64k | break; |
134 | 1.33k | case '6': |
135 | 1.33k | if (nsub < 6) { |
136 | 912 | nsub = 6; |
137 | 912 | } |
138 | 1.33k | break; |
139 | 510 | case '7': |
140 | 510 | if (nsub < 7) { |
141 | 198 | nsub = 7; |
142 | 198 | } |
143 | 510 | break; |
144 | 1.01k | case '8': |
145 | 1.01k | if (nsub < 8) { |
146 | 260 | nsub = 8; |
147 | 260 | } |
148 | 1.01k | break; |
149 | 561 | case '9': |
150 | 561 | if (nsub < 9) { |
151 | 286 | nsub = 9; |
152 | 286 | } |
153 | 561 | break; |
154 | 17.1k | } |
155 | 17.1k | } |
156 | 32.5k | if (!replace) { |
157 | 15.4k | *cp++ = c; |
158 | 15.4k | } |
159 | 32.5k | } |
160 | 558k | } |
161 | 11.1k | if (!flags) { |
162 | 385 | return DNS_R_SYNTAX; |
163 | 385 | } |
164 | 10.7k | *cp = '\0'; |
165 | 10.7k | n = isc_regex_validate(regex); |
166 | 10.7k | if (n < 0 || nsub > (unsigned int)n) { |
167 | 1.39k | return DNS_R_SYNTAX; |
168 | 1.39k | } |
169 | 9.38k | return ISC_R_SUCCESS; |
170 | 10.7k | } |
171 | | |
172 | | static isc_result_t |
173 | 4.73k | fromtext_naptr(ARGS_FROMTEXT) { |
174 | 4.73k | isc_token_t token; |
175 | 4.73k | isc_buffer_t buffer; |
176 | 4.73k | unsigned char *regex; |
177 | | |
178 | 4.73k | REQUIRE(type == dns_rdatatype_naptr); |
179 | | |
180 | 4.73k | UNUSED(type); |
181 | 4.73k | UNUSED(rdclass); |
182 | 4.73k | UNUSED(callbacks); |
183 | | |
184 | | /* |
185 | | * Order. |
186 | | */ |
187 | 4.73k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
188 | 4.73k | false)); |
189 | 4.72k | if (token.value.as_ulong > 0xffffU) { |
190 | 27 | RETTOK(ISC_R_RANGE); |
191 | 27 | } |
192 | 4.70k | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
193 | | |
194 | | /* |
195 | | * Preference. |
196 | | */ |
197 | 4.70k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
198 | 4.70k | false)); |
199 | 4.65k | if (token.value.as_ulong > 0xffffU) { |
200 | 28 | RETTOK(ISC_R_RANGE); |
201 | 28 | } |
202 | 4.63k | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
203 | | |
204 | | /* |
205 | | * Flags. |
206 | | */ |
207 | 4.63k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, |
208 | 4.63k | false)); |
209 | 4.59k | RETTOK(txt_fromtext(&token.value.as_textregion, target)); |
210 | | |
211 | | /* |
212 | | * Service. |
213 | | */ |
214 | 4.59k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, |
215 | 4.59k | false)); |
216 | 4.58k | RETTOK(txt_fromtext(&token.value.as_textregion, target)); |
217 | | |
218 | | /* |
219 | | * Regexp. |
220 | | */ |
221 | 4.58k | regex = isc_buffer_used(target); |
222 | 4.58k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, |
223 | 4.58k | false)); |
224 | 4.57k | RETTOK(txt_fromtext(&token.value.as_textregion, target)); |
225 | 4.56k | RETTOK(txt_valid_regex(regex)); |
226 | | |
227 | | /* |
228 | | * Replacement. |
229 | | */ |
230 | 3.41k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
231 | 3.41k | false)); |
232 | 3.22k | buffer_fromregion(&buffer, &token.value.as_region); |
233 | 3.22k | if (origin == NULL) { |
234 | 3 | origin = dns_rootname; |
235 | 3 | } |
236 | 3.22k | RETTOK(dns_name_wirefromtext(&buffer, origin, options, target)); |
237 | 3.21k | return ISC_R_SUCCESS; |
238 | 3.22k | } |
239 | | |
240 | | static isc_result_t |
241 | 8.95k | totext_naptr(ARGS_TOTEXT) { |
242 | 8.95k | isc_region_t region; |
243 | 8.95k | dns_name_t name; |
244 | 8.95k | dns_name_t prefix; |
245 | 8.95k | unsigned int opts; |
246 | 8.95k | char buf[sizeof("64000")]; |
247 | 8.95k | unsigned short num; |
248 | | |
249 | 8.95k | REQUIRE(rdata->type == dns_rdatatype_naptr); |
250 | 8.95k | REQUIRE(rdata->length != 0); |
251 | | |
252 | 8.95k | dns_name_init(&name); |
253 | 8.95k | dns_name_init(&prefix); |
254 | | |
255 | 8.95k | dns_rdata_toregion(rdata, ®ion); |
256 | | |
257 | | /* |
258 | | * Order. |
259 | | */ |
260 | 8.95k | num = uint16_fromregion(®ion); |
261 | 8.95k | isc_region_consume(®ion, 2); |
262 | 8.95k | snprintf(buf, sizeof(buf), "%u", num); |
263 | 8.95k | RETERR(str_totext(buf, target)); |
264 | 8.95k | RETERR(str_totext(" ", target)); |
265 | | |
266 | | /* |
267 | | * Preference. |
268 | | */ |
269 | 8.95k | num = uint16_fromregion(®ion); |
270 | 8.95k | isc_region_consume(®ion, 2); |
271 | 8.95k | snprintf(buf, sizeof(buf), "%u", num); |
272 | 8.95k | RETERR(str_totext(buf, target)); |
273 | 8.95k | RETERR(str_totext(" ", target)); |
274 | | |
275 | | /* |
276 | | * Flags. |
277 | | */ |
278 | 8.95k | RETERR(txt_totext(®ion, true, target)); |
279 | 8.95k | RETERR(str_totext(" ", target)); |
280 | | |
281 | | /* |
282 | | * Service. |
283 | | */ |
284 | 8.95k | RETERR(txt_totext(®ion, true, target)); |
285 | 8.95k | RETERR(str_totext(" ", target)); |
286 | | |
287 | | /* |
288 | | * Regexp. |
289 | | */ |
290 | 8.95k | RETERR(txt_totext(®ion, true, target)); |
291 | 8.95k | RETERR(str_totext(" ", target)); |
292 | | |
293 | | /* |
294 | | * Replacement. |
295 | | */ |
296 | 8.95k | dns_name_fromregion(&name, ®ion); |
297 | 8.95k | opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT |
298 | 8.95k | : 0; |
299 | 8.95k | return dns_name_totext(&prefix, opts, target); |
300 | 8.95k | } |
301 | | |
302 | | static isc_result_t |
303 | 11.8k | fromwire_naptr(ARGS_FROMWIRE) { |
304 | 11.8k | dns_name_t name; |
305 | 11.8k | isc_region_t sr; |
306 | 11.8k | unsigned char *regex; |
307 | | |
308 | 11.8k | REQUIRE(type == dns_rdatatype_naptr); |
309 | | |
310 | 11.8k | UNUSED(type); |
311 | 11.8k | UNUSED(rdclass); |
312 | | |
313 | | /* |
314 | | * RFC 3597 section 4 asks receivers to decompress this type, |
315 | | * even though senders must not compress it. |
316 | | */ |
317 | 11.8k | dns_decompress_setpermitted(dctx, true); |
318 | | |
319 | 11.8k | dns_name_init(&name); |
320 | | |
321 | | /* |
322 | | * Order, preference. |
323 | | */ |
324 | 11.8k | isc_buffer_activeregion(source, &sr); |
325 | 11.8k | if (sr.length < 4) { |
326 | 12 | return ISC_R_UNEXPECTEDEND; |
327 | 12 | } |
328 | 11.8k | RETERR(mem_tobuffer(target, sr.base, 4)); |
329 | 11.7k | isc_buffer_forward(source, 4); |
330 | | |
331 | | /* |
332 | | * Flags. |
333 | | */ |
334 | 11.7k | RETERR(txt_fromwire(source, target)); |
335 | | |
336 | | /* |
337 | | * Service. |
338 | | */ |
339 | 11.6k | RETERR(txt_fromwire(source, target)); |
340 | | |
341 | | /* |
342 | | * Regexp. |
343 | | */ |
344 | 11.5k | regex = isc_buffer_used(target); |
345 | 11.5k | RETERR(txt_fromwire(source, target)); |
346 | 11.1k | RETERR(txt_valid_regex(regex)); |
347 | | |
348 | | /* |
349 | | * Replacement. |
350 | | */ |
351 | 10.3k | return dns_name_fromwire(&name, source, dctx, target); |
352 | 11.1k | } |
353 | | |
354 | | static int |
355 | 10.6k | compare_naptr(ARGS_COMPARE) { |
356 | 10.6k | dns_name_t name1; |
357 | 10.6k | dns_name_t name2; |
358 | 10.6k | isc_region_t region1; |
359 | 10.6k | isc_region_t region2; |
360 | 10.6k | int order, len; |
361 | | |
362 | 10.6k | REQUIRE(rdata1->type == rdata2->type); |
363 | 10.6k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
364 | 10.6k | REQUIRE(rdata1->type == dns_rdatatype_naptr); |
365 | 10.6k | REQUIRE(rdata1->length != 0); |
366 | 10.6k | REQUIRE(rdata2->length != 0); |
367 | | |
368 | 10.6k | dns_rdata_toregion(rdata1, ®ion1); |
369 | 10.6k | dns_rdata_toregion(rdata2, ®ion2); |
370 | | |
371 | | /* |
372 | | * Order, preference. |
373 | | */ |
374 | 10.6k | order = memcmp(region1.base, region2.base, 4); |
375 | 10.6k | if (order != 0) { |
376 | 1.51k | return order < 0 ? -1 : 1; |
377 | 1.51k | } |
378 | 9.15k | isc_region_consume(®ion1, 4); |
379 | 9.15k | isc_region_consume(®ion2, 4); |
380 | | |
381 | | /* |
382 | | * Flags. |
383 | | */ |
384 | 9.15k | len = ISC_MIN(region1.base[0], region2.base[0]); |
385 | 9.15k | order = memcmp(region1.base, region2.base, len + 1); |
386 | 9.15k | if (order != 0) { |
387 | 1.81k | return order < 0 ? -1 : 1; |
388 | 1.81k | } |
389 | 7.33k | isc_region_consume(®ion1, region1.base[0] + 1); |
390 | 7.33k | isc_region_consume(®ion2, region2.base[0] + 1); |
391 | | |
392 | | /* |
393 | | * Service. |
394 | | */ |
395 | 7.33k | len = ISC_MIN(region1.base[0], region2.base[0]); |
396 | 7.33k | order = memcmp(region1.base, region2.base, len + 1); |
397 | 7.33k | if (order != 0) { |
398 | 1.75k | return order < 0 ? -1 : 1; |
399 | 1.75k | } |
400 | 5.58k | isc_region_consume(®ion1, region1.base[0] + 1); |
401 | 5.58k | isc_region_consume(®ion2, region2.base[0] + 1); |
402 | | |
403 | | /* |
404 | | * Regexp. |
405 | | */ |
406 | 5.58k | len = ISC_MIN(region1.base[0], region2.base[0]); |
407 | 5.58k | order = memcmp(region1.base, region2.base, len + 1); |
408 | 5.58k | if (order != 0) { |
409 | 2.73k | return order < 0 ? -1 : 1; |
410 | 2.73k | } |
411 | 2.84k | isc_region_consume(®ion1, region1.base[0] + 1); |
412 | 2.84k | isc_region_consume(®ion2, region2.base[0] + 1); |
413 | | |
414 | | /* |
415 | | * Replacement. |
416 | | */ |
417 | 2.84k | dns_name_init(&name1); |
418 | 2.84k | dns_name_init(&name2); |
419 | | |
420 | 2.84k | dns_name_fromregion(&name1, ®ion1); |
421 | 2.84k | dns_name_fromregion(&name2, ®ion2); |
422 | | |
423 | 2.84k | return dns_name_rdatacompare(&name1, &name2); |
424 | 5.58k | } |
425 | | |
426 | | static isc_result_t |
427 | 0 | fromstruct_naptr(ARGS_FROMSTRUCT) { |
428 | 0 | dns_rdata_naptr_t *naptr = source; |
429 | 0 | isc_region_t region; |
430 | |
|
431 | 0 | REQUIRE(type == dns_rdatatype_naptr); |
432 | 0 | REQUIRE(naptr != NULL); |
433 | 0 | REQUIRE(naptr->common.rdtype == type); |
434 | 0 | REQUIRE(naptr->common.rdclass == rdclass); |
435 | 0 | REQUIRE(naptr->flags != NULL || naptr->flags_len == 0); |
436 | 0 | REQUIRE(naptr->service != NULL || naptr->service_len == 0); |
437 | 0 | REQUIRE(naptr->regexp != NULL || naptr->regexp_len == 0); |
438 | |
|
439 | 0 | UNUSED(type); |
440 | 0 | UNUSED(rdclass); |
441 | |
|
442 | 0 | RETERR(uint16_tobuffer(naptr->order, target)); |
443 | 0 | RETERR(uint16_tobuffer(naptr->preference, target)); |
444 | 0 | RETERR(uint8_tobuffer(naptr->flags_len, target)); |
445 | 0 | RETERR(mem_tobuffer(target, naptr->flags, naptr->flags_len)); |
446 | 0 | RETERR(uint8_tobuffer(naptr->service_len, target)); |
447 | 0 | RETERR(mem_tobuffer(target, naptr->service, naptr->service_len)); |
448 | 0 | RETERR(uint8_tobuffer(naptr->regexp_len, target)); |
449 | 0 | RETERR(mem_tobuffer(target, naptr->regexp, naptr->regexp_len)); |
450 | 0 | dns_name_toregion(&naptr->replacement, ®ion); |
451 | 0 | return isc_buffer_copyregion(target, ®ion); |
452 | 0 | } |
453 | | |
454 | | static isc_result_t |
455 | 0 | tostruct_naptr(ARGS_TOSTRUCT) { |
456 | 0 | dns_rdata_naptr_t *naptr = target; |
457 | 0 | isc_region_t r; |
458 | 0 | dns_name_t name; |
459 | |
|
460 | 0 | REQUIRE(rdata->type == dns_rdatatype_naptr); |
461 | 0 | REQUIRE(naptr != NULL); |
462 | 0 | REQUIRE(rdata->length != 0); |
463 | |
|
464 | 0 | DNS_RDATACOMMON_INIT(naptr, rdata->type, rdata->rdclass); |
465 | |
|
466 | 0 | naptr->flags = NULL; |
467 | 0 | naptr->service = NULL; |
468 | 0 | naptr->regexp = NULL; |
469 | |
|
470 | 0 | dns_rdata_toregion(rdata, &r); |
471 | |
|
472 | 0 | naptr->order = uint16_fromregion(&r); |
473 | 0 | isc_region_consume(&r, 2); |
474 | |
|
475 | 0 | naptr->preference = uint16_fromregion(&r); |
476 | 0 | isc_region_consume(&r, 2); |
477 | |
|
478 | 0 | naptr->flags_len = uint8_fromregion(&r); |
479 | 0 | isc_region_consume(&r, 1); |
480 | 0 | INSIST(naptr->flags_len <= r.length); |
481 | 0 | naptr->flags = r.base; |
482 | 0 | isc_region_consume(&r, naptr->flags_len); |
483 | |
|
484 | 0 | naptr->service_len = uint8_fromregion(&r); |
485 | 0 | isc_region_consume(&r, 1); |
486 | 0 | INSIST(naptr->service_len <= r.length); |
487 | 0 | naptr->service = r.base; |
488 | 0 | isc_region_consume(&r, naptr->service_len); |
489 | |
|
490 | 0 | naptr->regexp_len = uint8_fromregion(&r); |
491 | 0 | isc_region_consume(&r, 1); |
492 | 0 | INSIST(naptr->regexp_len <= r.length); |
493 | 0 | naptr->regexp = r.base; |
494 | 0 | isc_region_consume(&r, naptr->regexp_len); |
495 | |
|
496 | 0 | dns_name_init(&name); |
497 | 0 | dns_name_fromregion(&name, &r); |
498 | 0 | dns_name_init(&naptr->replacement); |
499 | 0 | dns_name_clone(&name, &naptr->replacement); |
500 | 0 | return ISC_R_SUCCESS; |
501 | 0 | } |
502 | | |
503 | | static isc_result_t |
504 | 0 | additionaldata_naptr(ARGS_ADDLDATA) { |
505 | 0 | dns_name_t name; |
506 | 0 | isc_region_t sr; |
507 | 0 | dns_rdatatype_t atype; |
508 | 0 | unsigned int i, flagslen; |
509 | 0 | char *cp; |
510 | |
|
511 | 0 | REQUIRE(rdata->type == dns_rdatatype_naptr); |
512 | |
|
513 | 0 | UNUSED(owner); |
514 | | |
515 | | /* |
516 | | * Order, preference. |
517 | | */ |
518 | 0 | dns_rdata_toregion(rdata, &sr); |
519 | 0 | isc_region_consume(&sr, 4); |
520 | | |
521 | | /* |
522 | | * Flags. |
523 | | */ |
524 | 0 | atype = dns_rdatatype_none; |
525 | 0 | flagslen = sr.base[0]; |
526 | 0 | cp = (char *)&sr.base[1]; |
527 | 0 | for (i = 0; i < flagslen; i++, cp++) { |
528 | 0 | if (*cp == 'S' || *cp == 's') { |
529 | 0 | atype = dns_rdatatype_srv; |
530 | 0 | break; |
531 | 0 | } |
532 | 0 | if (*cp == 'A' || *cp == 'a') { |
533 | 0 | atype = dns_rdatatype_a; |
534 | 0 | break; |
535 | 0 | } |
536 | 0 | } |
537 | 0 | isc_region_consume(&sr, flagslen + 1); |
538 | | |
539 | | /* |
540 | | * Service. |
541 | | */ |
542 | 0 | isc_region_consume(&sr, sr.base[0] + 1); |
543 | | |
544 | | /* |
545 | | * Regexp. |
546 | | */ |
547 | 0 | isc_region_consume(&sr, sr.base[0] + 1); |
548 | | |
549 | | /* |
550 | | * Replacement. |
551 | | */ |
552 | 0 | dns_name_init(&name); |
553 | 0 | dns_name_fromregion(&name, &sr); |
554 | |
|
555 | 0 | if (atype != 0) { |
556 | 0 | return (add)(arg, &name, atype, NULL DNS__DB_FILELINE); |
557 | 0 | } |
558 | | |
559 | 0 | return ISC_R_SUCCESS; |
560 | 0 | } |
561 | | |
562 | | static isc_result_t |
563 | 0 | digest_naptr(ARGS_DIGEST) { |
564 | 0 | isc_region_t r1, r2; |
565 | 0 | unsigned int length, n; |
566 | 0 | dns_name_t name; |
567 | |
|
568 | 0 | REQUIRE(rdata->type == dns_rdatatype_naptr); |
569 | |
|
570 | 0 | dns_rdata_toregion(rdata, &r1); |
571 | 0 | r2 = r1; |
572 | 0 | length = 0; |
573 | | |
574 | | /* |
575 | | * Order, preference. |
576 | | */ |
577 | 0 | length += 4; |
578 | 0 | isc_region_consume(&r2, 4); |
579 | | |
580 | | /* |
581 | | * Flags. |
582 | | */ |
583 | 0 | n = r2.base[0] + 1; |
584 | 0 | length += n; |
585 | 0 | isc_region_consume(&r2, n); |
586 | | |
587 | | /* |
588 | | * Service. |
589 | | */ |
590 | 0 | n = r2.base[0] + 1; |
591 | 0 | length += n; |
592 | 0 | isc_region_consume(&r2, n); |
593 | | |
594 | | /* |
595 | | * Regexp. |
596 | | */ |
597 | 0 | n = r2.base[0] + 1; |
598 | 0 | length += n; |
599 | 0 | isc_region_consume(&r2, n); |
600 | | |
601 | | /* |
602 | | * Digest the RR up to the replacement name. |
603 | | */ |
604 | 0 | r1.length = length; |
605 | 0 | RETERR((digest)(arg, &r1)); |
606 | | |
607 | | /* |
608 | | * Replacement. |
609 | | */ |
610 | |
|
611 | 0 | dns_name_init(&name); |
612 | 0 | dns_name_fromregion(&name, &r2); |
613 | |
|
614 | 0 | return dns_name_digest(&name, digest, arg); |
615 | 0 | } |
616 | | |
617 | | static bool |
618 | 0 | checkowner_naptr(ARGS_CHECKOWNER) { |
619 | 0 | REQUIRE(type == dns_rdatatype_naptr); |
620 | |
|
621 | 0 | UNUSED(name); |
622 | 0 | UNUSED(type); |
623 | 0 | UNUSED(rdclass); |
624 | 0 | UNUSED(wildcard); |
625 | |
|
626 | 0 | return true; |
627 | 0 | } |
628 | | |
629 | | static bool |
630 | 0 | checknames_naptr(ARGS_CHECKNAMES) { |
631 | 0 | REQUIRE(rdata->type == dns_rdatatype_naptr); |
632 | |
|
633 | 0 | UNUSED(rdata); |
634 | 0 | UNUSED(owner); |
635 | 0 | UNUSED(bad); |
636 | |
|
637 | 0 | return true; |
638 | 0 | } |
639 | | |
640 | | static int |
641 | 0 | casecompare_naptr(ARGS_COMPARE) { |
642 | 0 | return compare_naptr(rdata1, rdata2); |
643 | 0 | } |
644 | | |
645 | | #endif /* RDATA_GENERIC_NAPTR_35_C */ |