1 /* $NetBSD: afsdb_18.c,v 1.5 2014/12/10 04:37:58 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001, 2003 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: afsdb_18.c,v 1.49 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Wed Mar 15 14:59:00 PST 2000 by explorer */
26 #ifndef RDATA_GENERIC_AFSDB_18_C
27 #define RDATA_GENERIC_AFSDB_18_C
29 #define RRTYPE_AFSDB_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_afsdb(ARGS_FROMTEXT
) {
47 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
49 if (token
.value
.as_ulong
> 0xffffU
)
51 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
56 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
58 dns_name_init(&name
, NULL
);
59 buffer_fromregion(&buffer
, &token
.value
.as_region
);
60 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
61 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
63 if ((options
& DNS_RDATA_CHECKNAMES
) != 0)
64 ok
= dns_name_ishostname(&name
, ISC_FALSE
);
65 if (!ok
&& (options
& DNS_RDATA_CHECKNAMESFAIL
) != 0)
66 RETTOK(DNS_R_BADNAME
);
67 if (!ok
&& callbacks
!= NULL
)
68 warn_badname(&name
, lexer
, callbacks
);
69 return (ISC_R_SUCCESS
);
72 static inline isc_result_t
73 totext_afsdb(ARGS_TOTEXT
) {
77 char buf
[sizeof("64000 ")];
81 REQUIRE(rdata
->type
== 18);
82 REQUIRE(rdata
->length
!= 0);
84 dns_name_init(&name
, NULL
);
85 dns_name_init(&prefix
, NULL
);
87 dns_rdata_toregion(rdata
, ®ion
);
88 num
= uint16_fromregion(®ion
);
89 isc_region_consume(®ion
, 2);
90 sprintf(buf
, "%u ", num
);
91 RETERR(str_totext(buf
, target
));
92 dns_name_fromregion(&name
, ®ion
);
93 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
94 return (dns_name_totext(&prefix
, sub
, target
));
97 static inline isc_result_t
98 fromwire_afsdb(ARGS_FROMWIRE
) {
108 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
110 dns_name_init(&name
, NULL
);
112 isc_buffer_activeregion(source
, &sr
);
113 isc_buffer_availableregion(target
, &tr
);
115 return (ISC_R_NOSPACE
);
117 return (ISC_R_UNEXPECTEDEND
);
118 memmove(tr
.base
, sr
.base
, 2);
119 isc_buffer_forward(source
, 2);
120 isc_buffer_add(target
, 2);
121 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
124 static inline isc_result_t
125 towire_afsdb(ARGS_TOWIRE
) {
129 dns_offsets_t offsets
;
131 REQUIRE(rdata
->type
== 18);
132 REQUIRE(rdata
->length
!= 0);
134 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
135 isc_buffer_availableregion(target
, &tr
);
136 dns_rdata_toregion(rdata
, &sr
);
138 return (ISC_R_NOSPACE
);
139 memmove(tr
.base
, sr
.base
, 2);
140 isc_region_consume(&sr
, 2);
141 isc_buffer_add(target
, 2);
143 dns_name_init(&name
, offsets
);
144 dns_name_fromregion(&name
, &sr
);
146 return (dns_name_towire(&name
, cctx
, target
));
150 compare_afsdb(ARGS_COMPARE
) {
154 isc_region_t region1
;
155 isc_region_t region2
;
157 REQUIRE(rdata1
->type
== rdata2
->type
);
158 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
159 REQUIRE(rdata1
->type
== 18);
160 REQUIRE(rdata1
->length
!= 0);
161 REQUIRE(rdata2
->length
!= 0);
163 result
= memcmp(rdata1
->data
, rdata2
->data
, 2);
165 return (result
< 0 ? -1 : 1);
167 dns_name_init(&name1
, NULL
);
168 dns_name_init(&name2
, NULL
);
170 dns_rdata_toregion(rdata1
, ®ion1
);
171 dns_rdata_toregion(rdata2
, ®ion2
);
173 isc_region_consume(®ion1
, 2);
174 isc_region_consume(®ion2
, 2);
176 dns_name_fromregion(&name1
, ®ion1
);
177 dns_name_fromregion(&name2
, ®ion2
);
179 return (dns_name_rdatacompare(&name1
, &name2
));
182 static inline isc_result_t
183 fromstruct_afsdb(ARGS_FROMSTRUCT
) {
184 dns_rdata_afsdb_t
*afsdb
= source
;
188 REQUIRE(source
!= NULL
);
189 REQUIRE(afsdb
->common
.rdclass
== rdclass
);
190 REQUIRE(afsdb
->common
.rdtype
== type
);
195 RETERR(uint16_tobuffer(afsdb
->subtype
, target
));
196 dns_name_toregion(&afsdb
->server
, ®ion
);
197 return (isc_buffer_copyregion(target
, ®ion
));
200 static inline isc_result_t
201 tostruct_afsdb(ARGS_TOSTRUCT
) {
203 dns_rdata_afsdb_t
*afsdb
= target
;
206 REQUIRE(rdata
->type
== 18);
207 REQUIRE(target
!= NULL
);
208 REQUIRE(rdata
->length
!= 0);
210 afsdb
->common
.rdclass
= rdata
->rdclass
;
211 afsdb
->common
.rdtype
= rdata
->type
;
212 ISC_LINK_INIT(&afsdb
->common
, link
);
214 dns_name_init(&afsdb
->server
, NULL
);
216 dns_rdata_toregion(rdata
, ®ion
);
218 afsdb
->subtype
= uint16_fromregion(®ion
);
219 isc_region_consume(®ion
, 2);
221 dns_name_init(&name
, NULL
);
222 dns_name_fromregion(&name
, ®ion
);
224 RETERR(name_duporclone(&name
, mctx
, &afsdb
->server
));
226 return (ISC_R_SUCCESS
);
230 freestruct_afsdb(ARGS_FREESTRUCT
) {
231 dns_rdata_afsdb_t
*afsdb
= source
;
233 REQUIRE(source
!= NULL
);
234 REQUIRE(afsdb
->common
.rdtype
== 18);
236 if (afsdb
->mctx
== NULL
)
239 dns_name_free(&afsdb
->server
, afsdb
->mctx
);
243 static inline isc_result_t
244 additionaldata_afsdb(ARGS_ADDLDATA
) {
246 dns_offsets_t offsets
;
249 REQUIRE(rdata
->type
== 18);
251 dns_name_init(&name
, offsets
);
252 dns_rdata_toregion(rdata
, ®ion
);
253 isc_region_consume(®ion
, 2);
254 dns_name_fromregion(&name
, ®ion
);
256 return ((add
)(arg
, &name
, dns_rdatatype_a
));
259 static inline isc_result_t
260 digest_afsdb(ARGS_DIGEST
) {
264 REQUIRE(rdata
->type
== 18);
266 dns_rdata_toregion(rdata
, &r1
);
268 isc_region_consume(&r2
, 2);
270 RETERR((digest
)(arg
, &r1
));
271 dns_name_init(&name
, NULL
);
272 dns_name_fromregion(&name
, &r2
);
274 return (dns_name_digest(&name
, digest
, arg
));
277 static inline isc_boolean_t
278 checkowner_afsdb(ARGS_CHECKOWNER
) {
290 static inline isc_boolean_t
291 checknames_afsdb(ARGS_CHECKNAMES
) {
295 REQUIRE(rdata
->type
== 18);
299 dns_rdata_toregion(rdata
, ®ion
);
300 isc_region_consume(®ion
, 2);
301 dns_name_init(&name
, NULL
);
302 dns_name_fromregion(&name
, ®ion
);
303 if (!dns_name_ishostname(&name
, ISC_FALSE
)) {
305 dns_name_clone(&name
, bad
);
312 casecompare_afsdb(ARGS_COMPARE
) {
313 return (compare_afsdb(rdata1
, rdata2
));
315 #endif /* RDATA_GENERIC_AFSDB_18_C */