1 /* $NetBSD: ns_2.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: ns_2.c,v 1.48 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Wed Mar 15 18:15:00 PST 2000 by bwelling */
24 #ifndef RDATA_GENERIC_NS_2_C
25 #define RDATA_GENERIC_NS_2_C
27 #define RRTYPE_NS_ATTRIBUTES (DNS_RDATATYPEATTR_ZONECUTAUTH)
29 static inline isc_result_t
30 fromtext_ns(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
));
50 if ((options
& DNS_RDATA_CHECKNAMES
) != 0)
51 ok
= dns_name_ishostname(&name
, ISC_FALSE
);
52 if (!ok
&& (options
& DNS_RDATA_CHECKNAMESFAIL
) != 0)
53 RETTOK(DNS_R_BADNAME
);
54 if (!ok
&& callbacks
!= NULL
)
55 warn_badname(&name
, lexer
, callbacks
);
56 return (ISC_R_SUCCESS
);
59 static inline isc_result_t
60 totext_ns(ARGS_TOTEXT
) {
66 REQUIRE(rdata
->type
== 2);
67 REQUIRE(rdata
->length
!= 0);
69 dns_name_init(&name
, NULL
);
70 dns_name_init(&prefix
, NULL
);
72 dns_rdata_toregion(rdata
, ®ion
);
73 dns_name_fromregion(&name
, ®ion
);
75 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
77 return (dns_name_totext(&prefix
, sub
, target
));
80 static inline isc_result_t
81 fromwire_ns(ARGS_FROMWIRE
) {
89 dns_decompress_setmethods(dctx
, DNS_COMPRESS_GLOBAL14
);
91 dns_name_init(&name
, NULL
);
92 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
95 static inline isc_result_t
96 towire_ns(ARGS_TOWIRE
) {
98 dns_offsets_t offsets
;
101 REQUIRE(rdata
->type
== 2);
102 REQUIRE(rdata
->length
!= 0);
104 dns_compress_setmethods(cctx
, DNS_COMPRESS_GLOBAL14
);
106 dns_name_init(&name
, offsets
);
107 dns_rdata_toregion(rdata
, ®ion
);
108 dns_name_fromregion(&name
, ®ion
);
110 return (dns_name_towire(&name
, cctx
, target
));
114 compare_ns(ARGS_COMPARE
) {
117 isc_region_t region1
;
118 isc_region_t region2
;
120 REQUIRE(rdata1
->type
== rdata2
->type
);
121 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
122 REQUIRE(rdata1
->type
== 2);
123 REQUIRE(rdata1
->length
!= 0);
124 REQUIRE(rdata2
->length
!= 0);
126 dns_name_init(&name1
, NULL
);
127 dns_name_init(&name2
, NULL
);
129 dns_rdata_toregion(rdata1
, ®ion1
);
130 dns_rdata_toregion(rdata2
, ®ion2
);
132 dns_name_fromregion(&name1
, ®ion1
);
133 dns_name_fromregion(&name2
, ®ion2
);
135 return (dns_name_rdatacompare(&name1
, &name2
));
138 static inline isc_result_t
139 fromstruct_ns(ARGS_FROMSTRUCT
) {
140 dns_rdata_ns_t
*ns
= source
;
144 REQUIRE(source
!= NULL
);
145 REQUIRE(ns
->common
.rdtype
== type
);
146 REQUIRE(ns
->common
.rdclass
== rdclass
);
151 dns_name_toregion(&ns
->name
, ®ion
);
152 return (isc_buffer_copyregion(target
, ®ion
));
155 static inline isc_result_t
156 tostruct_ns(ARGS_TOSTRUCT
) {
158 dns_rdata_ns_t
*ns
= target
;
161 REQUIRE(rdata
->type
== 2);
162 REQUIRE(target
!= NULL
);
163 REQUIRE(rdata
->length
!= 0);
165 ns
->common
.rdclass
= rdata
->rdclass
;
166 ns
->common
.rdtype
= rdata
->type
;
167 ISC_LINK_INIT(&ns
->common
, link
);
169 dns_name_init(&name
, NULL
);
170 dns_rdata_toregion(rdata
, ®ion
);
171 dns_name_fromregion(&name
, ®ion
);
172 dns_name_init(&ns
->name
, NULL
);
173 RETERR(name_duporclone(&name
, mctx
, &ns
->name
));
175 return (ISC_R_SUCCESS
);
179 freestruct_ns(ARGS_FREESTRUCT
) {
180 dns_rdata_ns_t
*ns
= source
;
182 REQUIRE(source
!= NULL
);
184 if (ns
->mctx
== NULL
)
187 dns_name_free(&ns
->name
, ns
->mctx
);
191 static inline isc_result_t
192 additionaldata_ns(ARGS_ADDLDATA
) {
194 dns_offsets_t offsets
;
197 REQUIRE(rdata
->type
== 2);
199 dns_name_init(&name
, offsets
);
200 dns_rdata_toregion(rdata
, ®ion
);
201 dns_name_fromregion(&name
, ®ion
);
203 return ((add
)(arg
, &name
, dns_rdatatype_a
));
206 static inline isc_result_t
207 digest_ns(ARGS_DIGEST
) {
211 REQUIRE(rdata
->type
== 2);
213 dns_rdata_toregion(rdata
, &r
);
214 dns_name_init(&name
, NULL
);
215 dns_name_fromregion(&name
, &r
);
217 return (dns_name_digest(&name
, digest
, arg
));
220 static inline isc_boolean_t
221 checkowner_ns(ARGS_CHECKOWNER
) {
233 static inline isc_boolean_t
234 checknames_ns(ARGS_CHECKNAMES
) {
238 REQUIRE(rdata
->type
== 2);
242 dns_rdata_toregion(rdata
, ®ion
);
243 dns_name_init(&name
, NULL
);
244 dns_name_fromregion(&name
, ®ion
);
245 if (!dns_name_ishostname(&name
, ISC_FALSE
)) {
247 dns_name_clone(&name
, bad
);
254 casecompare_ns(ARGS_COMPARE
) {
255 return (compare_ns(rdata1
, rdata2
));
258 #endif /* RDATA_GENERIC_NS_2_C */