2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001, 2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: kx_36.c,v 1.45 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Thu Mar 16 17:24:54 PST 2000 by explorer */
24 #ifndef RDATA_IN_1_KX_36_C
25 #define RDATA_IN_1_KX_36_C
27 #define RRTYPE_KX_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_in_kx(ARGS_FROMTEXT
) {
36 REQUIRE(rdclass
== 1);
42 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
44 if (token
.value
.as_ulong
> 0xffffU
)
46 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
48 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
50 dns_name_init(&name
, NULL
);
51 buffer_fromregion(&buffer
, &token
.value
.as_region
);
52 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
53 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
54 return (ISC_R_SUCCESS
);
57 static inline isc_result_t
58 totext_in_kx(ARGS_TOTEXT
) {
63 char buf
[sizeof("64000")];
66 REQUIRE(rdata
->type
== 36);
67 REQUIRE(rdata
->rdclass
== 1);
68 REQUIRE(rdata
->length
!= 0);
70 dns_name_init(&name
, NULL
);
71 dns_name_init(&prefix
, NULL
);
73 dns_rdata_toregion(rdata
, ®ion
);
74 num
= uint16_fromregion(®ion
);
75 isc_region_consume(®ion
, 2);
76 sprintf(buf
, "%u", num
);
77 RETERR(str_totext(buf
, target
));
79 RETERR(str_totext(" ", target
));
81 dns_name_fromregion(&name
, ®ion
);
82 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
83 return (dns_name_totext(&prefix
, sub
, target
));
86 static inline isc_result_t
87 fromwire_in_kx(ARGS_FROMWIRE
) {
92 REQUIRE(rdclass
== 1);
97 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
99 dns_name_init(&name
, NULL
);
101 isc_buffer_activeregion(source
, &sregion
);
102 if (sregion
.length
< 2)
103 return (ISC_R_UNEXPECTEDEND
);
104 RETERR(mem_tobuffer(target
, sregion
.base
, 2));
105 isc_buffer_forward(source
, 2);
106 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
109 static inline isc_result_t
110 towire_in_kx(ARGS_TOWIRE
) {
112 dns_offsets_t offsets
;
115 REQUIRE(rdata
->type
== 36);
116 REQUIRE(rdata
->rdclass
== 1);
117 REQUIRE(rdata
->length
!= 0);
119 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
120 dns_rdata_toregion(rdata
, ®ion
);
121 RETERR(mem_tobuffer(target
, region
.base
, 2));
122 isc_region_consume(®ion
, 2);
124 dns_name_init(&name
, offsets
);
125 dns_name_fromregion(&name
, ®ion
);
127 return (dns_name_towire(&name
, cctx
, target
));
131 compare_in_kx(ARGS_COMPARE
) {
134 isc_region_t region1
;
135 isc_region_t region2
;
138 REQUIRE(rdata1
->type
== rdata2
->type
);
139 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
140 REQUIRE(rdata1
->type
== 36);
141 REQUIRE(rdata1
->rdclass
== 1);
142 REQUIRE(rdata1
->length
!= 0);
143 REQUIRE(rdata2
->length
!= 0);
145 order
= memcmp(rdata1
->data
, rdata2
->data
, 2);
147 return (order
< 0 ? -1 : 1);
149 dns_name_init(&name1
, NULL
);
150 dns_name_init(&name2
, NULL
);
152 dns_rdata_toregion(rdata1
, ®ion1
);
153 dns_rdata_toregion(rdata2
, ®ion2
);
155 isc_region_consume(®ion1
, 2);
156 isc_region_consume(®ion2
, 2);
158 dns_name_fromregion(&name1
, ®ion1
);
159 dns_name_fromregion(&name2
, ®ion2
);
161 return (dns_name_rdatacompare(&name1
, &name2
));
164 static inline isc_result_t
165 fromstruct_in_kx(ARGS_FROMSTRUCT
) {
166 dns_rdata_in_kx_t
*kx
= source
;
170 REQUIRE(rdclass
== 1);
171 REQUIRE(source
!= NULL
);
172 REQUIRE(kx
->common
.rdtype
== type
);
173 REQUIRE(kx
->common
.rdclass
== rdclass
);
178 RETERR(uint16_tobuffer(kx
->preference
, target
));
179 dns_name_toregion(&kx
->exchange
, ®ion
);
180 return (isc_buffer_copyregion(target
, ®ion
));
183 static inline isc_result_t
184 tostruct_in_kx(ARGS_TOSTRUCT
) {
186 dns_rdata_in_kx_t
*kx
= target
;
189 REQUIRE(rdata
->type
== 36);
190 REQUIRE(rdata
->rdclass
== 1);
191 REQUIRE(target
!= NULL
);
192 REQUIRE(rdata
->length
!= 0);
194 kx
->common
.rdclass
= rdata
->rdclass
;
195 kx
->common
.rdtype
= rdata
->type
;
196 ISC_LINK_INIT(&kx
->common
, link
);
198 dns_name_init(&name
, NULL
);
199 dns_rdata_toregion(rdata
, ®ion
);
201 kx
->preference
= uint16_fromregion(®ion
);
202 isc_region_consume(®ion
, 2);
204 dns_name_fromregion(&name
, ®ion
);
205 dns_name_init(&kx
->exchange
, NULL
);
206 RETERR(name_duporclone(&name
, mctx
, &kx
->exchange
));
208 return (ISC_R_SUCCESS
);
212 freestruct_in_kx(ARGS_FREESTRUCT
) {
213 dns_rdata_in_kx_t
*kx
= source
;
215 REQUIRE(source
!= NULL
);
216 REQUIRE(kx
->common
.rdclass
== 1);
217 REQUIRE(kx
->common
.rdtype
== 36);
219 if (kx
->mctx
== NULL
)
222 dns_name_free(&kx
->exchange
, kx
->mctx
);
226 static inline isc_result_t
227 additionaldata_in_kx(ARGS_ADDLDATA
) {
229 dns_offsets_t offsets
;
232 REQUIRE(rdata
->type
== 36);
233 REQUIRE(rdata
->rdclass
== 1);
235 dns_name_init(&name
, offsets
);
236 dns_rdata_toregion(rdata
, ®ion
);
237 isc_region_consume(®ion
, 2);
238 dns_name_fromregion(&name
, ®ion
);
240 return ((add
)(arg
, &name
, dns_rdatatype_a
));
243 static inline isc_result_t
244 digest_in_kx(ARGS_DIGEST
) {
248 REQUIRE(rdata
->type
== 36);
249 REQUIRE(rdata
->rdclass
== 1);
251 dns_rdata_toregion(rdata
, &r1
);
253 isc_region_consume(&r2
, 2);
255 RETERR((digest
)(arg
, &r1
));
256 dns_name_init(&name
, NULL
);
257 dns_name_fromregion(&name
, &r2
);
258 return (dns_name_digest(&name
, digest
, arg
));
261 static inline isc_boolean_t
262 checkowner_in_kx(ARGS_CHECKOWNER
) {
265 REQUIRE(rdclass
== 1);
275 static inline isc_boolean_t
276 checknames_in_kx(ARGS_CHECKNAMES
) {
278 REQUIRE(rdata
->type
== 36);
279 REQUIRE(rdata
->rdclass
== 1);
288 #endif /* RDATA_IN_1_KX_36_C */