PageRenderTime 67ms CodeModel.GetById 19ms app.highlight 43ms RepoModel.GetById 1ms app.codeStats 1ms

/contrib/bind9/lib/dns/rdata/generic/ptr_12.c

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