1 /* $NetBSD: srv_33.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: srv_33.c,v 1.47 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Fri Mar 17 13:01:00 PST 2000 by bwelling */
26 #ifndef RDATA_IN_1_SRV_33_C
27 #define RDATA_IN_1_SRV_33_C
29 #define RRTYPE_SRV_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_in_srv(ARGS_FROMTEXT
) {
39 REQUIRE(rdclass
== 1);
48 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
50 if (token
.value
.as_ulong
> 0xffffU
)
52 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
57 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
59 if (token
.value
.as_ulong
> 0xffffU
)
61 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
66 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
68 if (token
.value
.as_ulong
> 0xffffU
)
70 RETERR(uint16_tobuffer(token
.value
.as_ulong
, target
));
75 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
77 dns_name_init(&name
, NULL
);
78 buffer_fromregion(&buffer
, &token
.value
.as_region
);
79 origin
= (origin
!= NULL
) ? origin
: dns_rootname
;
80 RETTOK(dns_name_fromtext(&name
, &buffer
, origin
, options
, target
));
82 if ((options
& DNS_RDATA_CHECKNAMES
) != 0)
83 ok
= dns_name_ishostname(&name
, ISC_FALSE
);
84 if (!ok
&& (options
& DNS_RDATA_CHECKNAMESFAIL
) != 0)
85 RETTOK(DNS_R_BADNAME
);
86 if (!ok
&& callbacks
!= NULL
)
87 warn_badname(&name
, lexer
, callbacks
);
88 return (ISC_R_SUCCESS
);
91 static inline isc_result_t
92 totext_in_srv(ARGS_TOTEXT
) {
97 char buf
[sizeof("64000")];
100 REQUIRE(rdata
->type
== 33);
101 REQUIRE(rdata
->rdclass
== 1);
102 REQUIRE(rdata
->length
!= 0);
104 dns_name_init(&name
, NULL
);
105 dns_name_init(&prefix
, NULL
);
110 dns_rdata_toregion(rdata
, ®ion
);
111 num
= uint16_fromregion(®ion
);
112 isc_region_consume(®ion
, 2);
113 sprintf(buf
, "%u", num
);
114 RETERR(str_totext(buf
, target
));
115 RETERR(str_totext(" ", target
));
120 num
= uint16_fromregion(®ion
);
121 isc_region_consume(®ion
, 2);
122 sprintf(buf
, "%u", num
);
123 RETERR(str_totext(buf
, target
));
124 RETERR(str_totext(" ", target
));
129 num
= uint16_fromregion(®ion
);
130 isc_region_consume(®ion
, 2);
131 sprintf(buf
, "%u", num
);
132 RETERR(str_totext(buf
, target
));
133 RETERR(str_totext(" ", target
));
138 dns_name_fromregion(&name
, ®ion
);
139 sub
= name_prefix(&name
, tctx
->origin
, &prefix
);
140 return (dns_name_totext(&prefix
, sub
, target
));
143 static inline isc_result_t
144 fromwire_in_srv(ARGS_FROMWIRE
) {
149 REQUIRE(rdclass
== 1);
154 dns_decompress_setmethods(dctx
, DNS_COMPRESS_NONE
);
156 dns_name_init(&name
, NULL
);
159 * Priority, weight, port.
161 isc_buffer_activeregion(source
, &sr
);
163 return (ISC_R_UNEXPECTEDEND
);
164 RETERR(mem_tobuffer(target
, sr
.base
, 6));
165 isc_buffer_forward(source
, 6);
170 return (dns_name_fromwire(&name
, source
, dctx
, options
, target
));
173 static inline isc_result_t
174 towire_in_srv(ARGS_TOWIRE
) {
176 dns_offsets_t offsets
;
179 REQUIRE(rdata
->type
== 33);
180 REQUIRE(rdata
->length
!= 0);
182 dns_compress_setmethods(cctx
, DNS_COMPRESS_NONE
);
184 * Priority, weight, port.
186 dns_rdata_toregion(rdata
, &sr
);
187 RETERR(mem_tobuffer(target
, sr
.base
, 6));
188 isc_region_consume(&sr
, 6);
193 dns_name_init(&name
, offsets
);
194 dns_name_fromregion(&name
, &sr
);
195 return (dns_name_towire(&name
, cctx
, target
));
199 compare_in_srv(ARGS_COMPARE
) {
202 isc_region_t region1
;
203 isc_region_t region2
;
206 REQUIRE(rdata1
->type
== rdata2
->type
);
207 REQUIRE(rdata1
->rdclass
== rdata2
->rdclass
);
208 REQUIRE(rdata1
->type
== 33);
209 REQUIRE(rdata1
->rdclass
== 1);
210 REQUIRE(rdata1
->length
!= 0);
211 REQUIRE(rdata2
->length
!= 0);
214 * Priority, weight, port.
216 order
= memcmp(rdata1
->data
, rdata2
->data
, 6);
218 return (order
< 0 ? -1 : 1);
223 dns_name_init(&name1
, NULL
);
224 dns_name_init(&name2
, NULL
);
226 dns_rdata_toregion(rdata1
, ®ion1
);
227 dns_rdata_toregion(rdata2
, ®ion2
);
229 isc_region_consume(®ion1
, 6);
230 isc_region_consume(®ion2
, 6);
232 dns_name_fromregion(&name1
, ®ion1
);
233 dns_name_fromregion(&name2
, ®ion2
);
235 return (dns_name_rdatacompare(&name1
, &name2
));
238 static inline isc_result_t
239 fromstruct_in_srv(ARGS_FROMSTRUCT
) {
240 dns_rdata_in_srv_t
*srv
= source
;
244 REQUIRE(rdclass
== 1);
245 REQUIRE(source
!= NULL
);
246 REQUIRE(srv
->common
.rdtype
== type
);
247 REQUIRE(srv
->common
.rdclass
== rdclass
);
252 RETERR(uint16_tobuffer(srv
->priority
, target
));
253 RETERR(uint16_tobuffer(srv
->weight
, target
));
254 RETERR(uint16_tobuffer(srv
->port
, target
));
255 dns_name_toregion(&srv
->target
, ®ion
);
256 return (isc_buffer_copyregion(target
, ®ion
));
259 static inline isc_result_t
260 tostruct_in_srv(ARGS_TOSTRUCT
) {
262 dns_rdata_in_srv_t
*srv
= target
;
265 REQUIRE(rdata
->rdclass
== 1);
266 REQUIRE(rdata
->type
== 33);
267 REQUIRE(target
!= NULL
);
268 REQUIRE(rdata
->length
!= 0);
270 srv
->common
.rdclass
= rdata
->rdclass
;
271 srv
->common
.rdtype
= rdata
->type
;
272 ISC_LINK_INIT(&srv
->common
, link
);
274 dns_name_init(&name
, NULL
);
275 dns_rdata_toregion(rdata
, ®ion
);
276 srv
->priority
= uint16_fromregion(®ion
);
277 isc_region_consume(®ion
, 2);
278 srv
->weight
= uint16_fromregion(®ion
);
279 isc_region_consume(®ion
, 2);
280 srv
->port
= uint16_fromregion(®ion
);
281 isc_region_consume(®ion
, 2);
282 dns_name_fromregion(&name
, ®ion
);
283 dns_name_init(&srv
->target
, NULL
);
284 RETERR(name_duporclone(&name
, mctx
, &srv
->target
));
286 return (ISC_R_SUCCESS
);
290 freestruct_in_srv(ARGS_FREESTRUCT
) {
291 dns_rdata_in_srv_t
*srv
= source
;
293 REQUIRE(source
!= NULL
);
294 REQUIRE(srv
->common
.rdclass
== 1);
295 REQUIRE(srv
->common
.rdtype
== 33);
297 if (srv
->mctx
== NULL
)
300 dns_name_free(&srv
->target
, srv
->mctx
);
304 static inline isc_result_t
305 additionaldata_in_srv(ARGS_ADDLDATA
) {
307 dns_offsets_t offsets
;
310 REQUIRE(rdata
->type
== 33);
311 REQUIRE(rdata
->rdclass
== 1);
313 dns_name_init(&name
, offsets
);
314 dns_rdata_toregion(rdata
, ®ion
);
315 isc_region_consume(®ion
, 6);
316 dns_name_fromregion(&name
, ®ion
);
318 return ((add
)(arg
, &name
, dns_rdatatype_a
));
321 static inline isc_result_t
322 digest_in_srv(ARGS_DIGEST
) {
326 REQUIRE(rdata
->type
== 33);
327 REQUIRE(rdata
->rdclass
== 1);
329 dns_rdata_toregion(rdata
, &r1
);
331 isc_region_consume(&r2
, 6);
333 RETERR((digest
)(arg
, &r1
));
334 dns_name_init(&name
, NULL
);
335 dns_name_fromregion(&name
, &r2
);
336 return (dns_name_digest(&name
, digest
, arg
));
339 static inline isc_boolean_t
340 checkowner_in_srv(ARGS_CHECKOWNER
) {
343 REQUIRE(rdclass
== 1);
353 static inline isc_boolean_t
354 checknames_in_srv(ARGS_CHECKNAMES
) {
358 REQUIRE(rdata
->type
== 33);
359 REQUIRE(rdata
->rdclass
== 1);
363 dns_rdata_toregion(rdata
, ®ion
);
364 isc_region_consume(®ion
, 6);
365 dns_name_init(&name
, NULL
);
366 dns_name_fromregion(&name
, ®ion
);
367 if (!dns_name_ishostname(&name
, ISC_FALSE
)) {
369 dns_name_clone(&name
, bad
);
376 casecompare_in_srv(ARGS_COMPARE
) {
377 return (compare_in_srv(rdata1
, rdata2
));
380 #endif /* RDATA_IN_1_SRV_33_C */