1 /* $NetBSD: px_26.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: px_26.c,v 1.45 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Mon Mar 20 10:44:27 PST 2000 */
26 #ifndef RDATA_IN_1_PX_26_C
27 #define RDATA_IN_1_PX_26_C
29 #define RRTYPE_PX_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_px(ARGS_FROMTEXT
) {
38 REQUIRE(rdclass
== 1);
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
));
66 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
68 dns_name_init(&name
, NULL
);
69 buffer_fromregion(&buffer
, &token
.value
.as_region
);
70 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
71 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
72 return (ISC_R_SUCCESS
);
75 static inline isc_result_t
76 totext_in_px(ARGS_TOTEXT
) {
81 char buf
[sizeof("64000")];
84 REQUIRE(rdata
->type
== 26);
85 REQUIRE(rdata
->rdclass
== 1);
86 REQUIRE(rdata
->length
!= 0);
88 dns_name_init(&name
, NULL
);
89 dns_name_init(&prefix
, NULL
);
94 dns_rdata_toregion(rdata
, ®ion
);
95 num
= uint16_fromregion(®ion
);
96 isc_region_consume(®ion
, 2);
97 sprintf(buf
, "%u", num
);
98 RETERR(str_totext(buf
, target
));
99 RETERR(str_totext(" ", target
));
104 dns_name_fromregion(&name
, ®ion
);
105 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
106 isc_region_consume(®ion
, name_length(&name
));
107 RETERR(dns_name_totext(&prefix
, sub
, target
));
108 RETERR(str_totext(" ", target
));
113 dns_name_fromregion(&name
, ®ion
);
114 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
115 return(dns_name_totext(&prefix
, sub
, target
));
118 static inline isc_result_t
119 fromwire_in_px(ARGS_FROMWIRE
) {
121 isc_region_t sregion
;
124 REQUIRE(rdclass
== 1);
129 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
131 dns_name_init(&name
, NULL
);
136 isc_buffer_activeregion(source
, &sregion
);
137 if (sregion
.length
< 2)
138 return (ISC_R_UNEXPECTEDEND
);
139 RETERR(mem_tobuffer(target
, sregion
.base
, 2));
140 isc_buffer_forward(source
, 2);
145 RETERR(dns_name_fromwire(&name
, source
, dctx
, options
, target
));
150 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
153 static inline isc_result_t
154 towire_in_px(ARGS_TOWIRE
) {
156 dns_offsets_t offsets
;
159 REQUIRE(rdata
->type
== 26);
160 REQUIRE(rdata
->rdclass
== 1);
161 REQUIRE(rdata
->length
!= 0);
163 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
167 dns_rdata_toregion(rdata
, ®ion
);
168 RETERR(mem_tobuffer(target
, region
.base
, 2));
169 isc_region_consume(®ion
, 2);
174 dns_name_init(&name
, offsets
);
175 dns_name_fromregion(&name
, ®ion
);
176 RETERR(dns_name_towire(&name
, cctx
, target
));
177 isc_region_consume(®ion
, name_length(&name
));
182 dns_name_init(&name
, offsets
);
183 dns_name_fromregion(&name
, ®ion
);
184 return (dns_name_towire(&name
, cctx
, target
));
188 compare_in_px(ARGS_COMPARE
) {
191 isc_region_t region1
;
192 isc_region_t region2
;
195 REQUIRE(rdata1
->type
== rdata2
->type
);
196 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
197 REQUIRE(rdata1
->type
== 26);
198 REQUIRE(rdata1
->rdclass
== 1);
199 REQUIRE(rdata1
->length
!= 0);
200 REQUIRE(rdata2
->length
!= 0);
202 order
= memcmp(rdata1
->data
, rdata2
->data
, 2);
204 return (order
< 0 ? -1 : 1);
206 dns_name_init(&name1
, NULL
);
207 dns_name_init(&name2
, NULL
);
209 dns_rdata_toregion(rdata1
, ®ion1
);
210 dns_rdata_toregion(rdata2
, ®ion2
);
212 isc_region_consume(®ion1
, 2);
213 isc_region_consume(®ion2
, 2);
215 dns_name_fromregion(&name1
, ®ion1
);
216 dns_name_fromregion(&name2
, ®ion2
);
218 order
= dns_name_rdatacompare(&name1
, &name2
);
222 isc_region_consume(®ion1
, name_length(&name1
));
223 isc_region_consume(®ion2
, name_length(&name2
));
225 dns_name_fromregion(&name1
, ®ion1
);
226 dns_name_fromregion(&name2
, ®ion2
);
228 return (dns_name_rdatacompare(&name1
, &name2
));
231 static inline isc_result_t
232 fromstruct_in_px(ARGS_FROMSTRUCT
) {
233 dns_rdata_in_px_t
*px
= source
;
237 REQUIRE(rdclass
== 1);
238 REQUIRE(source
!= NULL
);
239 REQUIRE(px
->common
.rdtype
== type
);
240 REQUIRE(px
->common
.rdclass
== rdclass
);
245 RETERR(uint16_tobuffer(px
->preference
, target
));
246 dns_name_toregion(&px
->map822
, ®ion
);
247 RETERR(isc_buffer_copyregion(target
, ®ion
));
248 dns_name_toregion(&px
->mapx400
, ®ion
);
249 return (isc_buffer_copyregion(target
, ®ion
));
252 static inline isc_result_t
253 tostruct_in_px(ARGS_TOSTRUCT
) {
254 dns_rdata_in_px_t
*px
= target
;
259 REQUIRE(rdata
->type
== 26);
260 REQUIRE(rdata
->rdclass
== 1);
261 REQUIRE(target
!= NULL
);
262 REQUIRE(rdata
->length
!= 0);
264 px
->common
.rdclass
= rdata
->rdclass
;
265 px
->common
.rdtype
= rdata
->type
;
266 ISC_LINK_INIT(&px
->common
, link
);
268 dns_name_init(&name
, NULL
);
269 dns_rdata_toregion(rdata
, ®ion
);
271 px
->preference
= uint16_fromregion(®ion
);
272 isc_region_consume(®ion
, 2);
274 dns_name_fromregion(&name
, ®ion
);
276 dns_name_init(&px
->map822
, NULL
);
277 RETERR(name_duporclone(&name
, mctx
, &px
->map822
));
278 isc_region_consume(®ion
, name_length(&px
->map822
));
280 dns_name_init(&px
->mapx400
, NULL
);
281 result
= name_duporclone(&name
, mctx
, &px
->mapx400
);
282 if (result
!= ISC_R_SUCCESS
)
289 dns_name_free(&px
->map822
, mctx
);
290 return (ISC_R_NOMEMORY
);
294 freestruct_in_px(ARGS_FREESTRUCT
) {
295 dns_rdata_in_px_t
*px
= source
;
297 REQUIRE(source
!= NULL
);
298 REQUIRE(px
->common
.rdclass
== 1);
299 REQUIRE(px
->common
.rdtype
== 26);
301 if (px
->mctx
== NULL
)
304 dns_name_free(&px
->map822
, px
->mctx
);
305 dns_name_free(&px
->mapx400
, px
->mctx
);
309 static inline isc_result_t
310 additionaldata_in_px(ARGS_ADDLDATA
) {
311 REQUIRE(rdata
->type
== 26);
312 REQUIRE(rdata
->rdclass
== 1);
318 return (ISC_R_SUCCESS
);
321 static inline isc_result_t
322 digest_in_px(ARGS_DIGEST
) {
327 REQUIRE(rdata
->type
== 26);
328 REQUIRE(rdata
->rdclass
== 1);
330 dns_rdata_toregion(rdata
, &r1
);
332 isc_region_consume(&r2
, 2);
334 result
= (digest
)(arg
, &r1
);
335 if (result
!= ISC_R_SUCCESS
)
337 dns_name_init(&name
, NULL
);
338 dns_name_fromregion(&name
, &r2
);
339 result
= dns_name_digest(&name
, digest
, arg
);
340 if (result
!= ISC_R_SUCCESS
)
342 isc_region_consume(&r2
, name_length(&name
));
343 dns_name_init(&name
, NULL
);
344 dns_name_fromregion(&name
, &r2
);
346 return (dns_name_digest(&name
, digest
, arg
));
349 static inline isc_boolean_t
350 checkowner_in_px(ARGS_CHECKOWNER
) {
353 REQUIRE(rdclass
== 1);
363 static inline isc_boolean_t
364 checknames_in_px(ARGS_CHECKNAMES
) {
366 REQUIRE(rdata
->type
== 26);
367 REQUIRE(rdata
->rdclass
== 1);
377 casecompare_in_px(ARGS_COMPARE
) {
378 return (compare_in_px(rdata1
, rdata2
));
381 #endif /* RDATA_IN_1_PX_26_C */