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: srv_33.c,v 1.45 2007/06/19 23:47:17 tbox Exp $ */
20 /* Reviewed: Fri Mar 17 13:01:00 PST 2000 by bwelling */
24 #ifndef RDATA_IN_1_SRV_33_C
25 #define RDATA_IN_1_SRV_33_C
27 #define RRTYPE_SRV_ATTRIBUTES (0)
29 static inline isc_result_t
30 fromtext_in_srv(ARGS_FROMTEXT) {
37 REQUIRE(rdclass == 1);
46 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
48 if (token.value.as_ulong > 0xffffU)
50 RETERR(uint16_tobuffer(token.value.as_ulong, target));
55 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
57 if (token.value.as_ulong > 0xffffU)
59 RETERR(uint16_tobuffer(token.value.as_ulong, target));
64 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
66 if (token.value.as_ulong > 0xffffU)
68 RETERR(uint16_tobuffer(token.value.as_ulong, target));
73 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
75 dns_name_init(&name, NULL);
76 buffer_fromregion(&buffer, &token.value.as_region);
77 origin = (origin != NULL) ? origin : dns_rootname;
78 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
80 if ((options & DNS_RDATA_CHECKNAMES) != 0)
81 ok = dns_name_ishostname(&name, ISC_FALSE);
82 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
83 RETTOK(DNS_R_BADNAME);
84 if (!ok && callbacks != NULL)
85 warn_badname(&name, lexer, callbacks);
86 return (ISC_R_SUCCESS);
89 static inline isc_result_t
90 totext_in_srv(ARGS_TOTEXT) {
95 char buf[sizeof("64000")];
98 REQUIRE(rdata->type == 33);
99 REQUIRE(rdata->rdclass == 1);
100 REQUIRE(rdata->length != 0);
102 dns_name_init(&name, NULL);
103 dns_name_init(&prefix, NULL);
108 dns_rdata_toregion(rdata, ®ion);
109 num = uint16_fromregion(®ion);
110 isc_region_consume(®ion, 2);
111 sprintf(buf, "%u", num);
112 RETERR(str_totext(buf, target));
113 RETERR(str_totext(" ", target));
118 num = uint16_fromregion(®ion);
119 isc_region_consume(®ion, 2);
120 sprintf(buf, "%u", num);
121 RETERR(str_totext(buf, target));
122 RETERR(str_totext(" ", target));
127 num = uint16_fromregion(®ion);
128 isc_region_consume(®ion, 2);
129 sprintf(buf, "%u", num);
130 RETERR(str_totext(buf, target));
131 RETERR(str_totext(" ", target));
136 dns_name_fromregion(&name, ®ion);
137 sub = name_prefix(&name, tctx->origin, &prefix);
138 return (dns_name_totext(&prefix, sub, target));
141 static inline isc_result_t
142 fromwire_in_srv(ARGS_FROMWIRE) {
147 REQUIRE(rdclass == 1);
152 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
154 dns_name_init(&name, NULL);
157 * Priority, weight, port.
159 isc_buffer_activeregion(source, &sr);
161 return (ISC_R_UNEXPECTEDEND);
162 RETERR(mem_tobuffer(target, sr.base, 6));
163 isc_buffer_forward(source, 6);
168 return (dns_name_fromwire(&name, source, dctx, options, target));
171 static inline isc_result_t
172 towire_in_srv(ARGS_TOWIRE) {
174 dns_offsets_t offsets;
177 REQUIRE(rdata->type == 33);
178 REQUIRE(rdata->length != 0);
180 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
182 * Priority, weight, port.
184 dns_rdata_toregion(rdata, &sr);
185 RETERR(mem_tobuffer(target, sr.base, 6));
186 isc_region_consume(&sr, 6);
191 dns_name_init(&name, offsets);
192 dns_name_fromregion(&name, &sr);
193 return (dns_name_towire(&name, cctx, target));
197 compare_in_srv(ARGS_COMPARE) {
200 isc_region_t region1;
201 isc_region_t region2;
204 REQUIRE(rdata1->type == rdata2->type);
205 REQUIRE(rdata1->rdclass == rdata2->rdclass);
206 REQUIRE(rdata1->type == 33);
207 REQUIRE(rdata1->rdclass == 1);
208 REQUIRE(rdata1->length != 0);
209 REQUIRE(rdata2->length != 0);
212 * Priority, weight, port.
214 order = memcmp(rdata1->data, rdata2->data, 6);
216 return (order < 0 ? -1 : 1);
221 dns_name_init(&name1, NULL);
222 dns_name_init(&name2, NULL);
224 dns_rdata_toregion(rdata1, ®ion1);
225 dns_rdata_toregion(rdata2, ®ion2);
227 isc_region_consume(®ion1, 6);
228 isc_region_consume(®ion2, 6);
230 dns_name_fromregion(&name1, ®ion1);
231 dns_name_fromregion(&name2, ®ion2);
233 return (dns_name_rdatacompare(&name1, &name2));
236 static inline isc_result_t
237 fromstruct_in_srv(ARGS_FROMSTRUCT) {
238 dns_rdata_in_srv_t *srv = source;
242 REQUIRE(rdclass == 1);
243 REQUIRE(source != NULL);
244 REQUIRE(srv->common.rdtype == type);
245 REQUIRE(srv->common.rdclass == rdclass);
250 RETERR(uint16_tobuffer(srv->priority, target));
251 RETERR(uint16_tobuffer(srv->weight, target));
252 RETERR(uint16_tobuffer(srv->port, target));
253 dns_name_toregion(&srv->target, ®ion);
254 return (isc_buffer_copyregion(target, ®ion));
257 static inline isc_result_t
258 tostruct_in_srv(ARGS_TOSTRUCT) {
260 dns_rdata_in_srv_t *srv = target;
263 REQUIRE(rdata->rdclass == 1);
264 REQUIRE(rdata->type == 33);
265 REQUIRE(target != NULL);
266 REQUIRE(rdata->length != 0);
268 srv->common.rdclass = rdata->rdclass;
269 srv->common.rdtype = rdata->type;
270 ISC_LINK_INIT(&srv->common, link);
272 dns_name_init(&name, NULL);
273 dns_rdata_toregion(rdata, ®ion);
274 srv->priority = uint16_fromregion(®ion);
275 isc_region_consume(®ion, 2);
276 srv->weight = uint16_fromregion(®ion);
277 isc_region_consume(®ion, 2);
278 srv->port = uint16_fromregion(®ion);
279 isc_region_consume(®ion, 2);
280 dns_name_fromregion(&name, ®ion);
281 dns_name_init(&srv->target, NULL);
282 RETERR(name_duporclone(&name, mctx, &srv->target));
284 return (ISC_R_SUCCESS);
288 freestruct_in_srv(ARGS_FREESTRUCT) {
289 dns_rdata_in_srv_t *srv = source;
291 REQUIRE(source != NULL);
292 REQUIRE(srv->common.rdclass == 1);
293 REQUIRE(srv->common.rdtype == 33);
295 if (srv->mctx == NULL)
298 dns_name_free(&srv->target, srv->mctx);
302 static inline isc_result_t
303 additionaldata_in_srv(ARGS_ADDLDATA) {
305 dns_offsets_t offsets;
308 REQUIRE(rdata->type == 33);
309 REQUIRE(rdata->rdclass == 1);
311 dns_name_init(&name, offsets);
312 dns_rdata_toregion(rdata, ®ion);
313 isc_region_consume(®ion, 6);
314 dns_name_fromregion(&name, ®ion);
316 return ((add)(arg, &name, dns_rdatatype_a));
319 static inline isc_result_t
320 digest_in_srv(ARGS_DIGEST) {
324 REQUIRE(rdata->type == 33);
325 REQUIRE(rdata->rdclass == 1);
327 dns_rdata_toregion(rdata, &r1);
329 isc_region_consume(&r2, 6);
331 RETERR((digest)(arg, &r1));
332 dns_name_init(&name, NULL);
333 dns_name_fromregion(&name, &r2);
334 return (dns_name_digest(&name, digest, arg));
337 static inline isc_boolean_t
338 checkowner_in_srv(ARGS_CHECKOWNER) {
341 REQUIRE(rdclass == 1);
351 static inline isc_boolean_t
352 checknames_in_srv(ARGS_CHECKNAMES) {
356 REQUIRE(rdata->type == 33);
357 REQUIRE(rdata->rdclass == 1);
361 dns_rdata_toregion(rdata, ®ion);
362 isc_region_consume(®ion, 6);
363 dns_name_init(&name, NULL);
364 dns_name_fromregion(&name, ®ion);
365 if (!dns_name_ishostname(&name, ISC_FALSE)) {
367 dns_name_clone(&name, bad);
373 #endif /* RDATA_IN_1_SRV_33_C */