1 /* $NetBSD: kx_36.c,v 1.4 2014/12/10 04:37:59 christos Exp $ */
4 * Copyright (C) 2004, 2005, 2007, 2009 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: kx_36.c,v 1.47 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Thu Mar 16 17:24:54 PST 2000 by explorer */
26 #ifndef RDATA_IN_1_KX_36_C
27 #define RDATA_IN_1_KX_36_C
29 #define RRTYPE_KX_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_kx(ARGS_FROMTEXT
) {
38 REQUIRE(rdclass
== 1);
44 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
46 if (token
.value
.as_ulong
> 0xffffU
)
48 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
50 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
52 dns_name_init(&name
, NULL
);
53 buffer_fromregion(&buffer
, &token
.value
.as_region
);
54 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
55 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
56 return (ISC_R_SUCCESS
);
59 static inline isc_result_t
60 totext_in_kx(ARGS_TOTEXT
) {
65 char buf
[sizeof("64000")];
68 REQUIRE(rdata
->type
== 36);
69 REQUIRE(rdata
->rdclass
== 1);
70 REQUIRE(rdata
->length
!= 0);
72 dns_name_init(&name
, NULL
);
73 dns_name_init(&prefix
, NULL
);
75 dns_rdata_toregion(rdata
, ®ion
);
76 num
= uint16_fromregion(®ion
);
77 isc_region_consume(®ion
, 2);
78 sprintf(buf
, "%u", num
);
79 RETERR(str_totext(buf
, target
));
81 RETERR(str_totext(" ", target
));
83 dns_name_fromregion(&name
, ®ion
);
84 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
85 return (dns_name_totext(&prefix
, sub
, target
));
88 static inline isc_result_t
89 fromwire_in_kx(ARGS_FROMWIRE
) {
94 REQUIRE(rdclass
== 1);
99 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
101 dns_name_init(&name
, NULL
);
103 isc_buffer_activeregion(source
, &sregion
);
104 if (sregion
.length
< 2)
105 return (ISC_R_UNEXPECTEDEND
);
106 RETERR(mem_tobuffer(target
, sregion
.base
, 2));
107 isc_buffer_forward(source
, 2);
108 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
111 static inline isc_result_t
112 towire_in_kx(ARGS_TOWIRE
) {
114 dns_offsets_t offsets
;
117 REQUIRE(rdata
->type
== 36);
118 REQUIRE(rdata
->rdclass
== 1);
119 REQUIRE(rdata
->length
!= 0);
121 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
122 dns_rdata_toregion(rdata
, ®ion
);
123 RETERR(mem_tobuffer(target
, region
.base
, 2));
124 isc_region_consume(®ion
, 2);
126 dns_name_init(&name
, offsets
);
127 dns_name_fromregion(&name
, ®ion
);
129 return (dns_name_towire(&name
, cctx
, target
));
133 compare_in_kx(ARGS_COMPARE
) {
136 isc_region_t region1
;
137 isc_region_t region2
;
140 REQUIRE(rdata1
->type
== rdata2
->type
);
141 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
142 REQUIRE(rdata1
->type
== 36);
143 REQUIRE(rdata1
->rdclass
== 1);
144 REQUIRE(rdata1
->length
!= 0);
145 REQUIRE(rdata2
->length
!= 0);
147 order
= memcmp(rdata1
->data
, rdata2
->data
, 2);
149 return (order
< 0 ? -1 : 1);
151 dns_name_init(&name1
, NULL
);
152 dns_name_init(&name2
, NULL
);
154 dns_rdata_toregion(rdata1
, ®ion1
);
155 dns_rdata_toregion(rdata2
, ®ion2
);
157 isc_region_consume(®ion1
, 2);
158 isc_region_consume(®ion2
, 2);
160 dns_name_fromregion(&name1
, ®ion1
);
161 dns_name_fromregion(&name2
, ®ion2
);
163 return (dns_name_rdatacompare(&name1
, &name2
));
166 static inline isc_result_t
167 fromstruct_in_kx(ARGS_FROMSTRUCT
) {
168 dns_rdata_in_kx_t
*kx
= source
;
172 REQUIRE(rdclass
== 1);
173 REQUIRE(source
!= NULL
);
174 REQUIRE(kx
->common
.rdtype
== type
);
175 REQUIRE(kx
->common
.rdclass
== rdclass
);
180 RETERR(uint16_tobuffer(kx
->preference
, target
));
181 dns_name_toregion(&kx
->exchange
, ®ion
);
182 return (isc_buffer_copyregion(target
, ®ion
));
185 static inline isc_result_t
186 tostruct_in_kx(ARGS_TOSTRUCT
) {
188 dns_rdata_in_kx_t
*kx
= target
;
191 REQUIRE(rdata
->type
== 36);
192 REQUIRE(rdata
->rdclass
== 1);
193 REQUIRE(target
!= NULL
);
194 REQUIRE(rdata
->length
!= 0);
196 kx
->common
.rdclass
= rdata
->rdclass
;
197 kx
->common
.rdtype
= rdata
->type
;
198 ISC_LINK_INIT(&kx
->common
, link
);
200 dns_name_init(&name
, NULL
);
201 dns_rdata_toregion(rdata
, ®ion
);
203 kx
->preference
= uint16_fromregion(®ion
);
204 isc_region_consume(®ion
, 2);
206 dns_name_fromregion(&name
, ®ion
);
207 dns_name_init(&kx
->exchange
, NULL
);
208 RETERR(name_duporclone(&name
, mctx
, &kx
->exchange
));
210 return (ISC_R_SUCCESS
);
214 freestruct_in_kx(ARGS_FREESTRUCT
) {
215 dns_rdata_in_kx_t
*kx
= source
;
217 REQUIRE(source
!= NULL
);
218 REQUIRE(kx
->common
.rdclass
== 1);
219 REQUIRE(kx
->common
.rdtype
== 36);
221 if (kx
->mctx
== NULL
)
224 dns_name_free(&kx
->exchange
, kx
->mctx
);
228 static inline isc_result_t
229 additionaldata_in_kx(ARGS_ADDLDATA
) {
231 dns_offsets_t offsets
;
234 REQUIRE(rdata
->type
== 36);
235 REQUIRE(rdata
->rdclass
== 1);
237 dns_name_init(&name
, offsets
);
238 dns_rdata_toregion(rdata
, ®ion
);
239 isc_region_consume(®ion
, 2);
240 dns_name_fromregion(&name
, ®ion
);
242 return ((add
)(arg
, &name
, dns_rdatatype_a
));
245 static inline isc_result_t
246 digest_in_kx(ARGS_DIGEST
) {
250 REQUIRE(rdata
->type
== 36);
251 REQUIRE(rdata
->rdclass
== 1);
253 dns_rdata_toregion(rdata
, &r1
);
255 isc_region_consume(&r2
, 2);
257 RETERR((digest
)(arg
, &r1
));
258 dns_name_init(&name
, NULL
);
259 dns_name_fromregion(&name
, &r2
);
260 return (dns_name_digest(&name
, digest
, arg
));
263 static inline isc_boolean_t
264 checkowner_in_kx(ARGS_CHECKOWNER
) {
267 REQUIRE(rdclass
== 1);
277 static inline isc_boolean_t
278 checknames_in_kx(ARGS_CHECKNAMES
) {
280 REQUIRE(rdata
->type
== 36);
281 REQUIRE(rdata
->rdclass
== 1);
291 casecompare_in_kx(ARGS_COMPARE
) {
292 return (compare_in_kx(rdata1
, rdata2
));
295 #endif /* RDATA_IN_1_KX_36_C */