1 /* $NetBSD: nimloc_32.c,v 1.8 2022/09/23 12:15:31 christos Exp $ */
2
3 /*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * See the COPYRIGHT file distributed with this work for additional
13 * information regarding copyright ownership.
14 */
15
16 /* http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt */
17
18 #ifndef RDATA_IN_1_NIMLOC_32_C
19 #define RDATA_IN_1_NIMLOC_32_C
20
21 #define RRTYPE_NIMLOC_ATTRIBUTES (0)
22
23 static isc_result_t
fromtext_in_nimloc(ARGS_FROMTEXT)24 fromtext_in_nimloc(ARGS_FROMTEXT) {
25 REQUIRE(type == dns_rdatatype_nimloc);
26 REQUIRE(rdclass == dns_rdataclass_in);
27
28 UNUSED(type);
29 UNUSED(origin);
30 UNUSED(options);
31 UNUSED(rdclass);
32 UNUSED(callbacks);
33
34 return (isc_hex_tobuffer(lexer, target, -2));
35 }
36
37 static isc_result_t
totext_in_nimloc(ARGS_TOTEXT)38 totext_in_nimloc(ARGS_TOTEXT) {
39 isc_region_t region;
40
41 REQUIRE(rdata->type == dns_rdatatype_nimloc);
42 REQUIRE(rdata->rdclass == dns_rdataclass_in);
43 REQUIRE(rdata->length != 0);
44
45 dns_rdata_toregion(rdata, ®ion);
46
47 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
48 RETERR(str_totext("( ", target));
49 }
50 if (tctx->width == 0) {
51 RETERR(isc_hex_totext(®ion, 60, "", target));
52 } else {
53 RETERR(isc_hex_totext(®ion, tctx->width - 2, tctx->linebreak,
54 target));
55 }
56 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
57 RETERR(str_totext(" )", target));
58 }
59 return (ISC_R_SUCCESS);
60 }
61
62 static isc_result_t
fromwire_in_nimloc(ARGS_FROMWIRE)63 fromwire_in_nimloc(ARGS_FROMWIRE) {
64 isc_region_t region;
65
66 REQUIRE(type == dns_rdatatype_nimloc);
67 REQUIRE(rdclass == dns_rdataclass_in);
68
69 UNUSED(type);
70 UNUSED(dctx);
71 UNUSED(options);
72 UNUSED(rdclass);
73
74 isc_buffer_activeregion(source, ®ion);
75 if (region.length < 1) {
76 return (ISC_R_UNEXPECTEDEND);
77 }
78
79 RETERR(mem_tobuffer(target, region.base, region.length));
80 isc_buffer_forward(source, region.length);
81 return (ISC_R_SUCCESS);
82 }
83
84 static isc_result_t
towire_in_nimloc(ARGS_TOWIRE)85 towire_in_nimloc(ARGS_TOWIRE) {
86 REQUIRE(rdata->type == dns_rdatatype_nimloc);
87 REQUIRE(rdata->rdclass == dns_rdataclass_in);
88 REQUIRE(rdata->length != 0);
89
90 UNUSED(cctx);
91
92 return (mem_tobuffer(target, rdata->data, rdata->length));
93 }
94
95 static int
compare_in_nimloc(ARGS_COMPARE)96 compare_in_nimloc(ARGS_COMPARE) {
97 isc_region_t r1;
98 isc_region_t r2;
99
100 REQUIRE(rdata1->type == rdata2->type);
101 REQUIRE(rdata1->rdclass == rdata2->rdclass);
102 REQUIRE(rdata1->type == dns_rdatatype_nimloc);
103 REQUIRE(rdata1->rdclass == dns_rdataclass_in);
104 REQUIRE(rdata1->length != 0);
105 REQUIRE(rdata2->length != 0);
106
107 dns_rdata_toregion(rdata1, &r1);
108 dns_rdata_toregion(rdata2, &r2);
109 return (isc_region_compare(&r1, &r2));
110 }
111
112 static isc_result_t
fromstruct_in_nimloc(ARGS_FROMSTRUCT)113 fromstruct_in_nimloc(ARGS_FROMSTRUCT) {
114 dns_rdata_in_nimloc_t *nimloc = source;
115
116 REQUIRE(type == dns_rdatatype_nimloc);
117 REQUIRE(rdclass == dns_rdataclass_in);
118 REQUIRE(nimloc != NULL);
119 REQUIRE(nimloc->common.rdtype == type);
120 REQUIRE(nimloc->common.rdclass == rdclass);
121 REQUIRE(nimloc->nimloc != NULL || nimloc->nimloc_len == 0);
122
123 UNUSED(type);
124 UNUSED(rdclass);
125
126 return (mem_tobuffer(target, nimloc->nimloc, nimloc->nimloc_len));
127 }
128
129 static isc_result_t
tostruct_in_nimloc(ARGS_TOSTRUCT)130 tostruct_in_nimloc(ARGS_TOSTRUCT) {
131 dns_rdata_in_nimloc_t *nimloc = target;
132 isc_region_t r;
133
134 REQUIRE(rdata->type == dns_rdatatype_nimloc);
135 REQUIRE(rdata->rdclass == dns_rdataclass_in);
136 REQUIRE(nimloc != NULL);
137 REQUIRE(rdata->length != 0);
138
139 nimloc->common.rdclass = rdata->rdclass;
140 nimloc->common.rdtype = rdata->type;
141 ISC_LINK_INIT(&nimloc->common, link);
142
143 dns_rdata_toregion(rdata, &r);
144 nimloc->nimloc_len = r.length;
145 nimloc->nimloc = mem_maybedup(mctx, r.base, r.length);
146 if (nimloc->nimloc == NULL) {
147 return (ISC_R_NOMEMORY);
148 }
149
150 nimloc->mctx = mctx;
151 return (ISC_R_SUCCESS);
152 }
153
154 static void
freestruct_in_nimloc(ARGS_FREESTRUCT)155 freestruct_in_nimloc(ARGS_FREESTRUCT) {
156 dns_rdata_in_nimloc_t *nimloc = source;
157
158 REQUIRE(nimloc != NULL);
159 REQUIRE(nimloc->common.rdclass == dns_rdataclass_in);
160 REQUIRE(nimloc->common.rdtype == dns_rdatatype_nimloc);
161
162 if (nimloc->mctx == NULL) {
163 return;
164 }
165
166 if (nimloc->nimloc != NULL) {
167 isc_mem_free(nimloc->mctx, nimloc->nimloc);
168 }
169 nimloc->mctx = NULL;
170 }
171
172 static isc_result_t
additionaldata_in_nimloc(ARGS_ADDLDATA)173 additionaldata_in_nimloc(ARGS_ADDLDATA) {
174 REQUIRE(rdata->type == dns_rdatatype_nimloc);
175 REQUIRE(rdata->rdclass == dns_rdataclass_in);
176
177 UNUSED(rdata);
178 UNUSED(add);
179 UNUSED(arg);
180
181 return (ISC_R_SUCCESS);
182 }
183
184 static isc_result_t
digest_in_nimloc(ARGS_DIGEST)185 digest_in_nimloc(ARGS_DIGEST) {
186 isc_region_t r;
187
188 REQUIRE(rdata->type == dns_rdatatype_nimloc);
189 REQUIRE(rdata->rdclass == dns_rdataclass_in);
190
191 dns_rdata_toregion(rdata, &r);
192
193 return ((digest)(arg, &r));
194 }
195
196 static bool
checkowner_in_nimloc(ARGS_CHECKOWNER)197 checkowner_in_nimloc(ARGS_CHECKOWNER) {
198 REQUIRE(type == dns_rdatatype_nimloc);
199 REQUIRE(rdclass == dns_rdataclass_in);
200
201 UNUSED(name);
202 UNUSED(type);
203 UNUSED(rdclass);
204 UNUSED(wildcard);
205
206 return (true);
207 }
208
209 static bool
checknames_in_nimloc(ARGS_CHECKNAMES)210 checknames_in_nimloc(ARGS_CHECKNAMES) {
211 REQUIRE(rdata->type == dns_rdatatype_nimloc);
212 REQUIRE(rdata->rdclass == dns_rdataclass_in);
213
214 UNUSED(rdata);
215 UNUSED(owner);
216 UNUSED(bad);
217
218 return (true);
219 }
220
221 static int
casecompare_in_nimloc(ARGS_COMPARE)222 casecompare_in_nimloc(ARGS_COMPARE) {
223 return (compare_in_nimloc(rdata1, rdata2));
224 }
225
226 #endif /* RDATA_IN_1_NIMLOC_32_C */
227