1 /* $NetBSD: ptr_12.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
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
) {
41 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
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) {
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
) {
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
, ®ion
);
75 dns_name_fromregion(&name
, ®ion
);
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
) {
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
) {
100 dns_offsets_t offsets
;
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
, ®ion
);
110 dns_name_fromregion(&name
, ®ion
);
112 return (dns_name_towire(&name
, cctx
, target
));
116 compare_ptr(ARGS_COMPARE
) {
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
, ®ion1
);
132 dns_rdata_toregion(rdata2
, ®ion2
);
134 dns_name_fromregion(&name1
, ®ion1
);
135 dns_name_fromregion(&name2
, ®ion2
);
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
;
146 REQUIRE(source
!= NULL
);
147 REQUIRE(ptr
->common
.rdtype
== type
);
148 REQUIRE(ptr
->common
.rdclass
== rdclass
);
153 dns_name_toregion(&ptr
->ptr
, ®ion
);
154 return (isc_buffer_copyregion(target
, ®ion
));
157 static inline isc_result_t
158 tostruct_ptr(ARGS_TOSTRUCT
) {
160 dns_rdata_ptr_t
*ptr
= target
;
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
, ®ion
);
173 dns_name_fromregion(&name
, ®ion
);
174 dns_name_init(&ptr
->ptr
, NULL
);
175 RETERR(name_duporclone(&name
, mctx
, &ptr
->ptr
));
177 return (ISC_R_SUCCESS
);
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
)
190 dns_name_free(&ptr
->ptr
, ptr
->mctx
);
194 static inline isc_result_t
195 additionaldata_ptr(ARGS_ADDLDATA
) {
196 REQUIRE(rdata
->type
== 12);
202 return (ISC_R_SUCCESS
);
205 static inline isc_result_t
206 digest_ptr(ARGS_DIGEST
) {
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
) {
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
=
237 ip6_arpa_data
, 10, 3,
238 DNS_NAMEATTR_READONLY
| DNS_NAMEATTR_ABSOLUTE
,
239 ip6_arpa_offsets
, NULL
,
240 {(void *)-1, (void *)-1},
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
=
250 DNS_NAMEATTR_READONLY
| DNS_NAMEATTR_ABSOLUTE
,
251 ip6_int_offsets
, NULL
,
252 {(void *)-1, (void *)-1},
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
=
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},
268 static inline isc_boolean_t
269 checknames_ptr(ARGS_CHECKNAMES
) {
273 REQUIRE(rdata
->type
== 12);
275 if (rdata
->rdclass
!= dns_rdataclass_in
)
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
, ®ion
);
282 dns_name_init(&name
, NULL
);
283 dns_name_fromregion(&name
, ®ion
);
284 if (!dns_name_ishostname(&name
, ISC_FALSE
)) {
286 dns_name_clone(&name
, bad
);
294 casecompare_ptr(ARGS_COMPARE
) {
295 return (compare_ptr(rdata1
, rdata2
));
297 #endif /* RDATA_GENERIC_PTR_12_C */