1 /* $NetBSD: cname_5.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: cname_5.c,v 1.49 2009/12/04 22:06:37 tbox Exp */
22 /* reviewed: Wed Mar 15 16:48:45 PST 2000 by brister */
24 #ifndef RDATA_GENERIC_CNAME_5_C
25 #define RDATA_GENERIC_CNAME_5_C
27 #define RRTYPE_CNAME_ATTRIBUTES \
28 (DNS_RDATATYPEATTR_EXCLUSIVE | DNS_RDATATYPEATTR_SINGLETON)
30 static inline isc_result_t
31 fromtext_cname(ARGS_FROMTEXT
) {
42 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
45 dns_name_init(&name
, NULL
);
46 buffer_fromregion(&buffer
, &token
.value
.as_region
);
47 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
48 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
49 return (ISC_R_SUCCESS
);
52 static inline isc_result_t
53 totext_cname(ARGS_TOTEXT
) {
59 REQUIRE(rdata
->type
== 5);
60 REQUIRE(rdata
->length
!= 0);
62 dns_name_init(&name
, NULL
);
63 dns_name_init(&prefix
, NULL
);
65 dns_rdata_toregion(rdata
, ®ion
);
66 dns_name_fromregion(&name
, ®ion
);
68 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
70 return (dns_name_totext(&prefix
, sub
, target
));
73 static inline isc_result_t
74 fromwire_cname(ARGS_FROMWIRE
) {
82 dns_decompress_setmethods(dctx
, DNS_COMPRESS_GLOBAL14
);
84 dns_name_init(&name
, NULL
);
85 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
88 static inline isc_result_t
89 towire_cname(ARGS_TOWIRE
) {
91 dns_offsets_t offsets
;
94 REQUIRE(rdata
->type
== 5);
95 REQUIRE(rdata
->length
!= 0);
97 dns_compress_setmethods(cctx
, DNS_COMPRESS_GLOBAL14
);
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_cname(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
== 5);
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_cname(ARGS_FROMSTRUCT
) {
133 dns_rdata_cname_t
*cname
= source
;
137 REQUIRE(source
!= NULL
);
138 REQUIRE(cname
->common
.rdtype
== type
);
139 REQUIRE(cname
->common
.rdclass
== rdclass
);
144 dns_name_toregion(&cname
->cname
, ®ion
);
145 return (isc_buffer_copyregion(target
, ®ion
));
148 static inline isc_result_t
149 tostruct_cname(ARGS_TOSTRUCT
) {
151 dns_rdata_cname_t
*cname
= target
;
154 REQUIRE(rdata
->type
== 5);
155 REQUIRE(target
!= NULL
);
156 REQUIRE(rdata
->length
!= 0);
158 cname
->common
.rdclass
= rdata
->rdclass
;
159 cname
->common
.rdtype
= rdata
->type
;
160 ISC_LINK_INIT(&cname
->common
, link
);
162 dns_name_init(&name
, NULL
);
163 dns_rdata_toregion(rdata
, ®ion
);
164 dns_name_fromregion(&name
, ®ion
);
165 dns_name_init(&cname
->cname
, NULL
);
166 RETERR(name_duporclone(&name
, mctx
, &cname
->cname
));
168 return (ISC_R_SUCCESS
);
172 freestruct_cname(ARGS_FREESTRUCT
) {
173 dns_rdata_cname_t
*cname
= source
;
175 REQUIRE(source
!= NULL
);
177 if (cname
->mctx
== NULL
)
180 dns_name_free(&cname
->cname
, cname
->mctx
);
184 static inline isc_result_t
185 additionaldata_cname(ARGS_ADDLDATA
) {
190 REQUIRE(rdata
->type
== 5);
192 return (ISC_R_SUCCESS
);
195 static inline isc_result_t
196 digest_cname(ARGS_DIGEST
) {
200 REQUIRE(rdata
->type
== 5);
202 dns_rdata_toregion(rdata
, &r
);
203 dns_name_init(&name
, NULL
);
204 dns_name_fromregion(&name
, &r
);
206 return (dns_name_digest(&name
, digest
, arg
));
209 static inline isc_boolean_t
210 checkowner_cname(ARGS_CHECKOWNER
) {
222 static inline isc_boolean_t
223 checknames_cname(ARGS_CHECKNAMES
) {
225 REQUIRE(rdata
->type
== 5);
235 casecompare_cname(ARGS_COMPARE
) {
236 return (compare_cname(rdata1
, rdata2
));
239 #endif /* RDATA_GENERIC_CNAME_5_C */