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: px_26.c,v 1.43 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Mon Mar 20 10:44:27 PST 2000 */
24 #ifndef RDATA_IN_1_PX_26_C
25 #define RDATA_IN_1_PX_26_C
27 #define RRTYPE_PX_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_in_px(ARGS_FROMTEXT
) {
36 REQUIRE(rdclass
== 1);
45 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
47 if (token
.value
.as_ulong
> 0xffffU
)
49 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
54 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
56 dns_name_init(&name
, NULL
);
57 buffer_fromregion(&buffer
, &token
.value
.as_region
);
58 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
59 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
64 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
66 dns_name_init(&name
, NULL
);
67 buffer_fromregion(&buffer
, &token
.value
.as_region
);
68 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
69 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
70 return (ISC_R_SUCCESS
);
73 static inline isc_result_t
74 totext_in_px(ARGS_TOTEXT
) {
79 char buf
[sizeof("64000")];
82 REQUIRE(rdata
->type
== 26);
83 REQUIRE(rdata
->rdclass
== 1);
84 REQUIRE(rdata
->length
!= 0);
86 dns_name_init(&name
, NULL
);
87 dns_name_init(&prefix
, NULL
);
92 dns_rdata_toregion(rdata
, ®ion
);
93 num
= uint16_fromregion(®ion
);
94 isc_region_consume(®ion
, 2);
95 sprintf(buf
, "%u", num
);
96 RETERR(str_totext(buf
, target
));
97 RETERR(str_totext(" ", target
));
102 dns_name_fromregion(&name
, ®ion
);
103 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
104 isc_region_consume(®ion
, name_length(&name
));
105 RETERR(dns_name_totext(&prefix
, sub
, target
));
106 RETERR(str_totext(" ", target
));
111 dns_name_fromregion(&name
, ®ion
);
112 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
113 return(dns_name_totext(&prefix
, sub
, target
));
116 static inline isc_result_t
117 fromwire_in_px(ARGS_FROMWIRE
) {
119 isc_region_t sregion
;
122 REQUIRE(rdclass
== 1);
127 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
129 dns_name_init(&name
, NULL
);
134 isc_buffer_activeregion(source
, &sregion
);
135 if (sregion
.length
< 2)
136 return (ISC_R_UNEXPECTEDEND
);
137 RETERR(mem_tobuffer(target
, sregion
.base
, 2));
138 isc_buffer_forward(source
, 2);
143 RETERR(dns_name_fromwire(&name
, source
, dctx
, options
, target
));
148 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
151 static inline isc_result_t
152 towire_in_px(ARGS_TOWIRE
) {
154 dns_offsets_t offsets
;
157 REQUIRE(rdata
->type
== 26);
158 REQUIRE(rdata
->rdclass
== 1);
159 REQUIRE(rdata
->length
!= 0);
161 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
165 dns_rdata_toregion(rdata
, ®ion
);
166 RETERR(mem_tobuffer(target
, region
.base
, 2));
167 isc_region_consume(®ion
, 2);
172 dns_name_init(&name
, offsets
);
173 dns_name_fromregion(&name
, ®ion
);
174 RETERR(dns_name_towire(&name
, cctx
, target
));
175 isc_region_consume(®ion
, name_length(&name
));
180 dns_name_init(&name
, offsets
);
181 dns_name_fromregion(&name
, ®ion
);
182 return (dns_name_towire(&name
, cctx
, target
));
186 compare_in_px(ARGS_COMPARE
) {
189 isc_region_t region1
;
190 isc_region_t region2
;
193 REQUIRE(rdata1
->type
== rdata2
->type
);
194 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
195 REQUIRE(rdata1
->type
== 26);
196 REQUIRE(rdata1
->rdclass
== 1);
197 REQUIRE(rdata1
->length
!= 0);
198 REQUIRE(rdata2
->length
!= 0);
200 order
= memcmp(rdata1
->data
, rdata2
->data
, 2);
202 return (order
< 0 ? -1 : 1);
204 dns_name_init(&name1
, NULL
);
205 dns_name_init(&name2
, NULL
);
207 dns_rdata_toregion(rdata1
, ®ion1
);
208 dns_rdata_toregion(rdata2
, ®ion2
);
210 isc_region_consume(®ion1
, 2);
211 isc_region_consume(®ion2
, 2);
213 dns_name_fromregion(&name1
, ®ion1
);
214 dns_name_fromregion(&name2
, ®ion2
);
216 order
= dns_name_rdatacompare(&name1
, &name2
);
220 isc_region_consume(®ion1
, name_length(&name1
));
221 isc_region_consume(®ion2
, name_length(&name2
));
223 dns_name_fromregion(&name1
, ®ion1
);
224 dns_name_fromregion(&name2
, ®ion2
);
226 return (dns_name_rdatacompare(&name1
, &name2
));
229 static inline isc_result_t
230 fromstruct_in_px(ARGS_FROMSTRUCT
) {
231 dns_rdata_in_px_t
*px
= source
;
235 REQUIRE(rdclass
== 1);
236 REQUIRE(source
!= NULL
);
237 REQUIRE(px
->common
.rdtype
== type
);
238 REQUIRE(px
->common
.rdclass
== rdclass
);
243 RETERR(uint16_tobuffer(px
->preference
, target
));
244 dns_name_toregion(&px
->map822
, ®ion
);
245 RETERR(isc_buffer_copyregion(target
, ®ion
));
246 dns_name_toregion(&px
->mapx400
, ®ion
);
247 return (isc_buffer_copyregion(target
, ®ion
));
250 static inline isc_result_t
251 tostruct_in_px(ARGS_TOSTRUCT
) {
252 dns_rdata_in_px_t
*px
= target
;
257 REQUIRE(rdata
->type
== 26);
258 REQUIRE(rdata
->rdclass
== 1);
259 REQUIRE(target
!= NULL
);
260 REQUIRE(rdata
->length
!= 0);
262 px
->common
.rdclass
= rdata
->rdclass
;
263 px
->common
.rdtype
= rdata
->type
;
264 ISC_LINK_INIT(&px
->common
, link
);
266 dns_name_init(&name
, NULL
);
267 dns_rdata_toregion(rdata
, ®ion
);
269 px
->preference
= uint16_fromregion(®ion
);
270 isc_region_consume(®ion
, 2);
272 dns_name_fromregion(&name
, ®ion
);
274 dns_name_init(&px
->map822
, NULL
);
275 RETERR(name_duporclone(&name
, mctx
, &px
->map822
));
276 isc_region_consume(®ion
, name_length(&px
->map822
));
278 dns_name_init(&px
->mapx400
, NULL
);
279 result
= name_duporclone(&name
, mctx
, &px
->mapx400
);
280 if (result
!= ISC_R_SUCCESS
)
287 dns_name_free(&px
->map822
, mctx
);
288 return (ISC_R_NOMEMORY
);
292 freestruct_in_px(ARGS_FREESTRUCT
) {
293 dns_rdata_in_px_t
*px
= source
;
295 REQUIRE(source
!= NULL
);
296 REQUIRE(px
->common
.rdclass
== 1);
297 REQUIRE(px
->common
.rdtype
== 26);
299 if (px
->mctx
== NULL
)
302 dns_name_free(&px
->map822
, px
->mctx
);
303 dns_name_free(&px
->mapx400
, px
->mctx
);
307 static inline isc_result_t
308 additionaldata_in_px(ARGS_ADDLDATA
) {
309 REQUIRE(rdata
->type
== 26);
310 REQUIRE(rdata
->rdclass
== 1);
316 return (ISC_R_SUCCESS
);
319 static inline isc_result_t
320 digest_in_px(ARGS_DIGEST
) {
325 REQUIRE(rdata
->type
== 26);
326 REQUIRE(rdata
->rdclass
== 1);
328 dns_rdata_toregion(rdata
, &r1
);
330 isc_region_consume(&r2
, 2);
332 result
= (digest
)(arg
, &r1
);
333 if (result
!= ISC_R_SUCCESS
)
335 dns_name_init(&name
, NULL
);
336 dns_name_fromregion(&name
, &r2
);
337 result
= dns_name_digest(&name
, digest
, arg
);
338 if (result
!= ISC_R_SUCCESS
)
340 isc_region_consume(&r2
, name_length(&name
));
341 dns_name_init(&name
, NULL
);
342 dns_name_fromregion(&name
, &r2
);
344 return (dns_name_digest(&name
, digest
, arg
));
347 static inline isc_boolean_t
348 checkowner_in_px(ARGS_CHECKOWNER
) {
351 REQUIRE(rdclass
== 1);
361 static inline isc_boolean_t
362 checknames_in_px(ARGS_CHECKNAMES
) {
364 REQUIRE(rdata
->type
== 26);
365 REQUIRE(rdata
->rdclass
== 1);
374 #endif /* RDATA_IN_1_PX_26_C */