1 /* $NetBSD: rt_21.c,v 1.5 2014/12/10 04:37:59 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: rt_21.c,v 1.48 2009/12/04 22:06:37 tbox Exp */
22 /* reviewed: Thu Mar 16 15:02:31 PST 2000 by brister */
26 #ifndef RDATA_GENERIC_RT_21_C
27 #define RDATA_GENERIC_RT_21_C
29 #define RRTYPE_RT_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_rt(ARGS_FROMTEXT
) {
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
,
53 dns_name_init(&name
, NULL
);
54 buffer_fromregion(&buffer
, &token
.value
.as_region
);
55 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
56 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
58 if ((options
& DNS_RDATA_CHECKNAMES
) != 0)
59 ok
= dns_name_ishostname(&name
, ISC_FALSE
);
60 if (!ok
&& (options
& DNS_RDATA_CHECKNAMESFAIL
) != 0)
61 RETTOK(DNS_R_BADNAME
);
62 if (!ok
&& callbacks
!= NULL
)
63 warn_badname(&name
, lexer
, callbacks
);
64 return (ISC_R_SUCCESS
);
67 static inline isc_result_t
68 totext_rt(ARGS_TOTEXT
) {
73 char buf
[sizeof("64000")];
76 REQUIRE(rdata
->type
== 21);
77 REQUIRE(rdata
->length
!= 0);
79 dns_name_init(&name
, NULL
);
80 dns_name_init(&prefix
, NULL
);
82 dns_rdata_toregion(rdata
, ®ion
);
83 num
= uint16_fromregion(®ion
);
84 isc_region_consume(®ion
, 2);
85 sprintf(buf
, "%u", num
);
86 RETERR(str_totext(buf
, target
));
87 RETERR(str_totext(" ", target
));
88 dns_name_fromregion(&name
, ®ion
);
89 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
90 return (dns_name_totext(&prefix
, sub
, target
));
93 static inline isc_result_t
94 fromwire_rt(ARGS_FROMWIRE
) {
104 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
106 dns_name_init(&name
, NULL
);
108 isc_buffer_activeregion(source
, &sregion
);
109 isc_buffer_availableregion(target
, &tregion
);
110 if (tregion
.length
< 2)
111 return (ISC_R_NOSPACE
);
112 if (sregion
.length
< 2)
113 return (ISC_R_UNEXPECTEDEND
);
114 memmove(tregion
.base
, sregion
.base
, 2);
115 isc_buffer_forward(source
, 2);
116 isc_buffer_add(target
, 2);
117 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
120 static inline isc_result_t
121 towire_rt(ARGS_TOWIRE
) {
123 dns_offsets_t offsets
;
127 REQUIRE(rdata
->type
== 21);
128 REQUIRE(rdata
->length
!= 0);
130 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
131 isc_buffer_availableregion(target
, &tr
);
132 dns_rdata_toregion(rdata
, ®ion
);
134 return (ISC_R_NOSPACE
);
135 memmove(tr
.base
, region
.base
, 2);
136 isc_region_consume(®ion
, 2);
137 isc_buffer_add(target
, 2);
139 dns_name_init(&name
, offsets
);
140 dns_name_fromregion(&name
, ®ion
);
142 return (dns_name_towire(&name
, cctx
, target
));
146 compare_rt(ARGS_COMPARE
) {
149 isc_region_t region1
;
150 isc_region_t region2
;
153 REQUIRE(rdata1
->type
== rdata2
->type
);
154 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
155 REQUIRE(rdata1
->type
== 21);
156 REQUIRE(rdata1
->length
!= 0);
157 REQUIRE(rdata2
->length
!= 0);
159 order
= memcmp(rdata1
->data
, rdata2
->data
, 2);
161 return (order
< 0 ? -1 : 1);
163 dns_name_init(&name1
, NULL
);
164 dns_name_init(&name2
, NULL
);
166 dns_rdata_toregion(rdata1
, ®ion1
);
167 dns_rdata_toregion(rdata2
, ®ion2
);
169 isc_region_consume(®ion1
, 2);
170 isc_region_consume(®ion2
, 2);
172 dns_name_fromregion(&name1
, ®ion1
);
173 dns_name_fromregion(&name2
, ®ion2
);
175 return (dns_name_rdatacompare(&name1
, &name2
));
178 static inline isc_result_t
179 fromstruct_rt(ARGS_FROMSTRUCT
) {
180 dns_rdata_rt_t
*rt
= source
;
184 REQUIRE(source
!= NULL
);
185 REQUIRE(rt
->common
.rdtype
== type
);
186 REQUIRE(rt
->common
.rdclass
== rdclass
);
191 RETERR(uint16_tobuffer(rt
->preference
, target
));
192 dns_name_toregion(&rt
->host
, ®ion
);
193 return (isc_buffer_copyregion(target
, ®ion
));
196 static inline isc_result_t
197 tostruct_rt(ARGS_TOSTRUCT
) {
199 dns_rdata_rt_t
*rt
= target
;
202 REQUIRE(rdata
->type
== 21);
203 REQUIRE(target
!= NULL
);
204 REQUIRE(rdata
->length
!= 0);
206 rt
->common
.rdclass
= rdata
->rdclass
;
207 rt
->common
.rdtype
= rdata
->type
;
208 ISC_LINK_INIT(&rt
->common
, link
);
210 dns_name_init(&name
, NULL
);
211 dns_rdata_toregion(rdata
, ®ion
);
212 rt
->preference
= uint16_fromregion(®ion
);
213 isc_region_consume(®ion
, 2);
214 dns_name_fromregion(&name
, ®ion
);
215 dns_name_init(&rt
->host
, NULL
);
216 RETERR(name_duporclone(&name
, mctx
, &rt
->host
));
219 return (ISC_R_SUCCESS
);
223 freestruct_rt(ARGS_FREESTRUCT
) {
224 dns_rdata_rt_t
*rt
= source
;
226 REQUIRE(source
!= NULL
);
227 REQUIRE(rt
->common
.rdtype
== 21);
229 if (rt
->mctx
== NULL
)
232 dns_name_free(&rt
->host
, rt
->mctx
);
236 static inline isc_result_t
237 additionaldata_rt(ARGS_ADDLDATA
) {
239 dns_offsets_t offsets
;
243 REQUIRE(rdata
->type
== 21);
245 dns_name_init(&name
, offsets
);
246 dns_rdata_toregion(rdata
, ®ion
);
247 isc_region_consume(®ion
, 2);
248 dns_name_fromregion(&name
, ®ion
);
250 result
= (add
)(arg
, &name
, dns_rdatatype_x25
);
251 if (result
!= ISC_R_SUCCESS
)
253 result
= (add
)(arg
, &name
, dns_rdatatype_isdn
);
254 if (result
!= ISC_R_SUCCESS
)
256 return ((add
)(arg
, &name
, dns_rdatatype_a
));
259 static inline isc_result_t
260 digest_rt(ARGS_DIGEST
) {
265 REQUIRE(rdata
->type
== 21);
267 dns_rdata_toregion(rdata
, &r1
);
269 isc_region_consume(&r2
, 2);
271 result
= (digest
)(arg
, &r1
);
272 if (result
!= ISC_R_SUCCESS
)
274 dns_name_init(&name
, NULL
);
275 dns_name_fromregion(&name
, &r2
);
276 return (dns_name_digest(&name
, digest
, arg
));
279 static inline isc_boolean_t
280 checkowner_rt(ARGS_CHECKOWNER
) {
292 static inline isc_boolean_t
293 checknames_rt(ARGS_CHECKNAMES
) {
297 REQUIRE(rdata
->type
== 21);
301 dns_rdata_toregion(rdata
, ®ion
);
302 isc_region_consume(®ion
, 2);
303 dns_name_init(&name
, NULL
);
304 dns_name_fromregion(&name
, ®ion
);
305 if (!dns_name_ishostname(&name
, ISC_FALSE
)) {
307 dns_name_clone(&name
, bad
);
314 casecompare_rt(ARGS_COMPARE
) {
315 return (compare_rt(rdata1
, rdata2
));
318 #endif /* RDATA_GENERIC_RT_21_C */