1 /* $NetBSD: dname_39.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) 1999-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: dname_39.c,v 1.40 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Wed Mar 15 16:52:38 PST 2000 by explorer */
26 #ifndef RDATA_GENERIC_DNAME_39_C
27 #define RDATA_GENERIC_DNAME_39_C
29 #define RRTYPE_DNAME_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
31 static inline isc_result_t
32 fromtext_dname(ARGS_FROMTEXT
) {
43 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
46 dns_name_init(&name
, NULL
);
47 buffer_fromregion(&buffer
, &token
.value
.as_region
);
48 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
49 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
50 return (ISC_R_SUCCESS
);
53 static inline isc_result_t
54 totext_dname(ARGS_TOTEXT
) {
60 REQUIRE(rdata
->type
== 39);
61 REQUIRE(rdata
->length
!= 0);
63 dns_name_init(&name
, NULL
);
64 dns_name_init(&prefix
, NULL
);
66 dns_rdata_toregion(rdata
, ®ion
);
67 dns_name_fromregion(&name
, ®ion
);
69 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
71 return (dns_name_totext(&prefix
, sub
, target
));
74 static inline isc_result_t
75 fromwire_dname(ARGS_FROMWIRE
) {
83 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
85 dns_name_init(&name
, NULL
);
86 return(dns_name_fromwire(&name
, source
, dctx
, options
, target
));
89 static inline isc_result_t
90 towire_dname(ARGS_TOWIRE
) {
92 dns_offsets_t offsets
;
95 REQUIRE(rdata
->type
== 39);
96 REQUIRE(rdata
->length
!= 0);
98 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
99 dns_name_init(&name
, offsets
);
100 dns_rdata_toregion(rdata
, ®ion
);
101 dns_name_fromregion(&name
, ®ion
);
103 return (dns_name_towire(&name
, cctx
, target
));
107 compare_dname(ARGS_COMPARE
) {
110 isc_region_t region1
;
111 isc_region_t region2
;
113 REQUIRE(rdata1
->type
== rdata2
->type
);
114 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
115 REQUIRE(rdata1
->type
== 39);
116 REQUIRE(rdata1
->length
!= 0);
117 REQUIRE(rdata2
->length
!= 0);
119 dns_name_init(&name1
, NULL
);
120 dns_name_init(&name2
, NULL
);
122 dns_rdata_toregion(rdata1
, ®ion1
);
123 dns_rdata_toregion(rdata2
, ®ion2
);
125 dns_name_fromregion(&name1
, ®ion1
);
126 dns_name_fromregion(&name2
, ®ion2
);
128 return (dns_name_rdatacompare(&name1
, &name2
));
131 static inline isc_result_t
132 fromstruct_dname(ARGS_FROMSTRUCT
) {
133 dns_rdata_dname_t
*dname
= source
;
137 REQUIRE(source
!= NULL
);
138 REQUIRE(dname
->common
.rdtype
== type
);
139 REQUIRE(dname
->common
.rdclass
== rdclass
);
144 dns_name_toregion(&dname
->dname
, ®ion
);
145 return (isc_buffer_copyregion(target
, ®ion
));
148 static inline isc_result_t
149 tostruct_dname(ARGS_TOSTRUCT
) {
151 dns_rdata_dname_t
*dname
= target
;
154 REQUIRE(rdata
->type
== 39);
155 REQUIRE(target
!= NULL
);
156 REQUIRE(rdata
->length
!= 0);
158 dname
->common
.rdclass
= rdata
->rdclass
;
159 dname
->common
.rdtype
= rdata
->type
;
160 ISC_LINK_INIT(&dname
->common
, link
);
162 dns_name_init(&name
, NULL
);
163 dns_rdata_toregion(rdata
, ®ion
);
164 dns_name_fromregion(&name
, ®ion
);
165 dns_name_init(&dname
->dname
, NULL
);
166 RETERR(name_duporclone(&name
, mctx
, &dname
->dname
));
168 return (ISC_R_SUCCESS
);
172 freestruct_dname(ARGS_FREESTRUCT
) {
173 dns_rdata_dname_t
*dname
= source
;
175 REQUIRE(source
!= NULL
);
176 REQUIRE(dname
->common
.rdtype
== 39);
178 if (dname
->mctx
== NULL
)
181 dns_name_free(&dname
->dname
, dname
->mctx
);
185 static inline isc_result_t
186 additionaldata_dname(ARGS_ADDLDATA
) {
191 REQUIRE(rdata
->type
== 39);
193 return (ISC_R_SUCCESS
);
196 static inline isc_result_t
197 digest_dname(ARGS_DIGEST
) {
201 REQUIRE(rdata
->type
== 39);
203 dns_rdata_toregion(rdata
, &r
);
204 dns_name_init(&name
, NULL
);
205 dns_name_fromregion(&name
, &r
);
207 return (dns_name_digest(&name
, digest
, arg
));
210 static inline isc_boolean_t
211 checkowner_dname(ARGS_CHECKOWNER
) {
223 static inline isc_boolean_t
224 checknames_dname(ARGS_CHECKNAMES
) {
226 REQUIRE(rdata
->type
== 39);
236 casecompare_dname(ARGS_COMPARE
) {
237 return (compare_dname(rdata1
, rdata2
));
239 #endif /* RDATA_GENERIC_DNAME_39_C */