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