Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / ptr_12.c
blob9aa8225957faa0abeb86c083e2992119dd139cfd
1 /* $NetBSD: ptr_12.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: ptr_12.c,v 1.45 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Thu Mar 16 14:05:12 PST 2000 by explorer */
24 #ifndef RDATA_GENERIC_PTR_12_C
25 #define RDATA_GENERIC_PTR_12_C
27 #define RRTYPE_PTR_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_ptr(ARGS_FROMTEXT) {
31 isc_token_t token;
32 dns_name_t name;
33 isc_buffer_t buffer;
35 REQUIRE(type == 12);
37 UNUSED(type);
38 UNUSED(rdclass);
39 UNUSED(callbacks);
41 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
42 ISC_FALSE));
44 dns_name_init(&name, NULL);
45 buffer_fromregion(&buffer, &token.value.as_region);
46 origin = (origin != NULL) ? origin : dns_rootname;
47 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
48 if (rdclass == dns_rdataclass_in &&
49 (options & DNS_RDATA_CHECKNAMES) != 0 &&
50 (options & DNS_RDATA_CHECKREVERSE) != 0) {
51 isc_boolean_t ok;
52 ok = dns_name_ishostname(&name, ISC_FALSE);
53 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
54 RETTOK(DNS_R_BADNAME);
55 if (!ok && callbacks != NULL)
56 warn_badname(&name, lexer, callbacks);
58 return (ISC_R_SUCCESS);
61 static inline isc_result_t
62 totext_ptr(ARGS_TOTEXT) {
63 isc_region_t region;
64 dns_name_t name;
65 dns_name_t prefix;
66 isc_boolean_t sub;
68 REQUIRE(rdata->type == 12);
69 REQUIRE(rdata->length != 0);
71 dns_name_init(&name, NULL);
72 dns_name_init(&prefix, NULL);
74 dns_rdata_toregion(rdata, &region);
75 dns_name_fromregion(&name, &region);
77 sub = name_prefix(&name, tctx->origin, &prefix);
79 return (dns_name_totext(&prefix, sub, target));
82 static inline isc_result_t
83 fromwire_ptr(ARGS_FROMWIRE) {
84 dns_name_t name;
86 REQUIRE(type == 12);
88 UNUSED(type);
89 UNUSED(rdclass);
91 dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
93 dns_name_init(&name, NULL);
94 return (dns_name_fromwire(&name, source, dctx, options, target));
97 static inline isc_result_t
98 towire_ptr(ARGS_TOWIRE) {
99 dns_name_t name;
100 dns_offsets_t offsets;
101 isc_region_t region;
103 REQUIRE(rdata->type == 12);
104 REQUIRE(rdata->length != 0);
106 dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
108 dns_name_init(&name, offsets);
109 dns_rdata_toregion(rdata, &region);
110 dns_name_fromregion(&name, &region);
112 return (dns_name_towire(&name, cctx, target));
115 static inline int
116 compare_ptr(ARGS_COMPARE) {
117 dns_name_t name1;
118 dns_name_t name2;
119 isc_region_t region1;
120 isc_region_t region2;
122 REQUIRE(rdata1->type == rdata2->type);
123 REQUIRE(rdata1->rdclass == rdata2->rdclass);
124 REQUIRE(rdata1->type == 12);
125 REQUIRE(rdata1->length != 0);
126 REQUIRE(rdata2->length != 0);
128 dns_name_init(&name1, NULL);
129 dns_name_init(&name2, NULL);
131 dns_rdata_toregion(rdata1, &region1);
132 dns_rdata_toregion(rdata2, &region2);
134 dns_name_fromregion(&name1, &region1);
135 dns_name_fromregion(&name2, &region2);
137 return (dns_name_rdatacompare(&name1, &name2));
140 static inline isc_result_t
141 fromstruct_ptr(ARGS_FROMSTRUCT) {
142 dns_rdata_ptr_t *ptr = source;
143 isc_region_t region;
145 REQUIRE(type == 12);
146 REQUIRE(source != NULL);
147 REQUIRE(ptr->common.rdtype == type);
148 REQUIRE(ptr->common.rdclass == rdclass);
150 UNUSED(type);
151 UNUSED(rdclass);
153 dns_name_toregion(&ptr->ptr, &region);
154 return (isc_buffer_copyregion(target, &region));
157 static inline isc_result_t
158 tostruct_ptr(ARGS_TOSTRUCT) {
159 isc_region_t region;
160 dns_rdata_ptr_t *ptr = target;
161 dns_name_t name;
163 REQUIRE(rdata->type == 12);
164 REQUIRE(target != NULL);
165 REQUIRE(rdata->length != 0);
167 ptr->common.rdclass = rdata->rdclass;
168 ptr->common.rdtype = rdata->type;
169 ISC_LINK_INIT(&ptr->common, link);
171 dns_name_init(&name, NULL);
172 dns_rdata_toregion(rdata, &region);
173 dns_name_fromregion(&name, &region);
174 dns_name_init(&ptr->ptr, NULL);
175 RETERR(name_duporclone(&name, mctx, &ptr->ptr));
176 ptr->mctx = mctx;
177 return (ISC_R_SUCCESS);
180 static inline void
181 freestruct_ptr(ARGS_FREESTRUCT) {
182 dns_rdata_ptr_t *ptr = source;
184 REQUIRE(source != NULL);
185 REQUIRE(ptr->common.rdtype == 12);
187 if (ptr->mctx == NULL)
188 return;
190 dns_name_free(&ptr->ptr, ptr->mctx);
191 ptr->mctx = NULL;
194 static inline isc_result_t
195 additionaldata_ptr(ARGS_ADDLDATA) {
196 REQUIRE(rdata->type == 12);
198 UNUSED(rdata);
199 UNUSED(add);
200 UNUSED(arg);
202 return (ISC_R_SUCCESS);
205 static inline isc_result_t
206 digest_ptr(ARGS_DIGEST) {
207 isc_region_t r;
208 dns_name_t name;
210 REQUIRE(rdata->type == 12);
212 dns_rdata_toregion(rdata, &r);
213 dns_name_init(&name, NULL);
214 dns_name_fromregion(&name, &r);
216 return (dns_name_digest(&name, digest, arg));
219 static inline isc_boolean_t
220 checkowner_ptr(ARGS_CHECKOWNER) {
222 REQUIRE(type == 12);
224 UNUSED(name);
225 UNUSED(type);
226 UNUSED(rdclass);
227 UNUSED(wildcard);
229 return (ISC_TRUE);
232 static unsigned char ip6_arpa_data[] = "\003IP6\004ARPA";
233 static unsigned char ip6_arpa_offsets[] = { 0, 4, 9 };
234 static const dns_name_t ip6_arpa =
236 DNS_NAME_MAGIC,
237 ip6_arpa_data, 10, 3,
238 DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
239 ip6_arpa_offsets, NULL,
240 {(void *)-1, (void *)-1},
241 {NULL, NULL}
244 static unsigned char ip6_int_data[] = "\003IP6\003INT";
245 static unsigned char ip6_int_offsets[] = { 0, 4, 8 };
246 static const dns_name_t ip6_int =
248 DNS_NAME_MAGIC,
249 ip6_int_data, 9, 3,
250 DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
251 ip6_int_offsets, NULL,
252 {(void *)-1, (void *)-1},
253 {NULL, NULL}
256 static unsigned char in_addr_arpa_data[] = "\007IN-ADDR\004ARPA";
257 static unsigned char in_addr_arpa_offsets[] = { 0, 8, 13 };
258 static const dns_name_t in_addr_arpa =
260 DNS_NAME_MAGIC,
261 in_addr_arpa_data, 14, 3,
262 DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
263 in_addr_arpa_offsets, NULL,
264 {(void *)-1, (void *)-1},
265 {NULL, NULL}
268 static inline isc_boolean_t
269 checknames_ptr(ARGS_CHECKNAMES) {
270 isc_region_t region;
271 dns_name_t name;
273 REQUIRE(rdata->type == 12);
275 if (rdata->rdclass != dns_rdataclass_in)
276 return (ISC_TRUE);
278 if (dns_name_issubdomain(owner, &in_addr_arpa) ||
279 dns_name_issubdomain(owner, &ip6_arpa) ||
280 dns_name_issubdomain(owner, &ip6_int)) {
281 dns_rdata_toregion(rdata, &region);
282 dns_name_init(&name, NULL);
283 dns_name_fromregion(&name, &region);
284 if (!dns_name_ishostname(&name, ISC_FALSE)) {
285 if (bad != NULL)
286 dns_name_clone(&name, bad);
287 return (ISC_FALSE);
290 return (ISC_TRUE);
293 static inline int
294 casecompare_ptr(ARGS_COMPARE) {
295 return (compare_ptr(rdata1, rdata2));
297 #endif /* RDATA_GENERIC_PTR_12_C */