1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 /* $Id: nsec_47.c,v 1.13 2020/09/14 08:40:43 florian Exp $ */
18
19 /* reviewed: Wed Mar 15 18:21:15 PST 2000 by brister */
20
21 /* RFC 3845 */
22
23 #ifndef RDATA_GENERIC_NSEC_47_C
24 #define RDATA_GENERIC_NSEC_47_C
25
26 /*
27 * The attributes do not include DNS_RDATATYPEATTR_SINGLETON
28 * because we must be able to handle a parent/child NSEC pair.
29 */
30
31 static inline isc_result_t
totext_nsec(ARGS_TOTEXT)32 totext_nsec(ARGS_TOTEXT) {
33 isc_region_t sr;
34 dns_name_t name;
35
36 REQUIRE(rdata->type == dns_rdatatype_nsec);
37 REQUIRE(rdata->length != 0);
38
39 UNUSED(tctx);
40
41 dns_name_init(&name, NULL);
42 dns_rdata_toregion(rdata, &sr);
43 dns_name_fromregion(&name, &sr);
44 isc_region_consume(&sr, name_length(&name));
45 RETERR(dns_name_totext(&name, 0, target));
46 /*
47 * Don't leave a trailing space when there's no typemap present.
48 */
49 if (sr.length > 0) {
50 RETERR(isc_str_tobuffer(" ", target));
51 }
52 return (typemap_totext(&sr, NULL, target));
53 }
54
55 static /* inline */ isc_result_t
fromwire_nsec(ARGS_FROMWIRE)56 fromwire_nsec(ARGS_FROMWIRE) {
57 isc_region_t sr;
58 dns_name_t name;
59
60 REQUIRE(type == dns_rdatatype_nsec);
61
62 UNUSED(type);
63 UNUSED(rdclass);
64
65 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
66
67 dns_name_init(&name, NULL);
68 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
69
70 isc_buffer_activeregion(source, &sr);
71 RETERR(typemap_test(&sr, 0));
72 RETERR(isc_mem_tobuffer(target, sr.base, sr.length));
73 isc_buffer_forward(source, sr.length);
74 return (ISC_R_SUCCESS);
75 }
76
77 static inline isc_result_t
towire_nsec(ARGS_TOWIRE)78 towire_nsec(ARGS_TOWIRE) {
79 isc_region_t sr;
80 dns_name_t name;
81 dns_offsets_t offsets;
82
83 REQUIRE(rdata->type == dns_rdatatype_nsec);
84 REQUIRE(rdata->length != 0);
85
86 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
87 dns_name_init(&name, offsets);
88 dns_rdata_toregion(rdata, &sr);
89 dns_name_fromregion(&name, &sr);
90 isc_region_consume(&sr, name_length(&name));
91 RETERR(dns_name_towire(&name, cctx, target));
92
93 return (isc_mem_tobuffer(target, sr.base, sr.length));
94 }
95
96 #endif /* RDATA_GENERIC_NSEC_47_C */
97