srv_33.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1999-2001, 2003  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: srv_33.c,v 1.47 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* Reviewed: Fri Mar 17 13:01:00 PST 2000 by bwelling */
00021 
00022 /* RFC2782 */
00023 
00024 #ifndef RDATA_IN_1_SRV_33_C
00025 #define RDATA_IN_1_SRV_33_C
00026 
00027 #define RRTYPE_SRV_ATTRIBUTES (0)
00028 
00029 static inline isc_result_t
00030 fromtext_in_srv(ARGS_FROMTEXT) {
00031         isc_token_t token;
00032         dns_name_t name;
00033         isc_buffer_t buffer;
00034         isc_boolean_t ok;
00035 
00036         REQUIRE(type == 33);
00037         REQUIRE(rdclass == 1);
00038 
00039         UNUSED(type);
00040         UNUSED(rdclass);
00041         UNUSED(callbacks);
00042 
00043         /*
00044          * Priority.
00045          */
00046         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00047                                       ISC_FALSE));
00048         if (token.value.as_ulong > 0xffffU)
00049                 RETTOK(ISC_R_RANGE);
00050         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00051 
00052         /*
00053          * Weight.
00054          */
00055         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00056                                       ISC_FALSE));
00057         if (token.value.as_ulong > 0xffffU)
00058                 RETTOK(ISC_R_RANGE);
00059         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00060 
00061         /*
00062          * Port.
00063          */
00064         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00065                                       ISC_FALSE));
00066         if (token.value.as_ulong > 0xffffU)
00067                 RETTOK(ISC_R_RANGE);
00068         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00069 
00070         /*
00071          * Target.
00072          */
00073         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00074                                       ISC_FALSE));
00075         dns_name_init(&name, NULL);
00076         buffer_fromregion(&buffer, &token.value.as_region);
00077         origin = (origin != NULL) ? origin : dns_rootname;
00078         RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
00079         ok = ISC_TRUE;
00080         if ((options & DNS_RDATA_CHECKNAMES) != 0)
00081                 ok = dns_name_ishostname(&name, ISC_FALSE);
00082         if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
00083                 RETTOK(DNS_R_BADNAME);
00084         if (!ok && callbacks != NULL)
00085                 warn_badname(&name, lexer, callbacks);
00086         return (ISC_R_SUCCESS);
00087 }
00088 
00089 static inline isc_result_t
00090 totext_in_srv(ARGS_TOTEXT) {
00091         isc_region_t region;
00092         dns_name_t name;
00093         dns_name_t prefix;
00094         isc_boolean_t sub;
00095         char buf[sizeof("64000")];
00096         unsigned short num;
00097 
00098         REQUIRE(rdata->type == 33);
00099         REQUIRE(rdata->rdclass == 1);
00100         REQUIRE(rdata->length != 0);
00101 
00102         dns_name_init(&name, NULL);
00103         dns_name_init(&prefix, NULL);
00104 
00105         /*
00106          * Priority.
00107          */
00108         dns_rdata_toregion(rdata, &region);
00109         num = uint16_fromregion(&region);
00110         isc_region_consume(&region, 2);
00111         sprintf(buf, "%u", num);
00112         RETERR(str_totext(buf, target));
00113         RETERR(str_totext(" ", target));
00114 
00115         /*
00116          * Weight.
00117          */
00118         num = uint16_fromregion(&region);
00119         isc_region_consume(&region, 2);
00120         sprintf(buf, "%u", num);
00121         RETERR(str_totext(buf, target));
00122         RETERR(str_totext(" ", target));
00123 
00124         /*
00125          * Port.
00126          */
00127         num = uint16_fromregion(&region);
00128         isc_region_consume(&region, 2);
00129         sprintf(buf, "%u", num);
00130         RETERR(str_totext(buf, target));
00131         RETERR(str_totext(" ", target));
00132 
00133         /*
00134          * Target.
00135          */
00136         dns_name_fromregion(&name, &region);
00137         sub = name_prefix(&name, tctx->origin, &prefix);
00138         return (dns_name_totext(&prefix, sub, target));
00139 }
00140 
00141 static inline isc_result_t
00142 fromwire_in_srv(ARGS_FROMWIRE) {
00143         dns_name_t name;
00144         isc_region_t sr;
00145 
00146         REQUIRE(type == 33);
00147         REQUIRE(rdclass == 1);
00148 
00149         UNUSED(type);
00150         UNUSED(rdclass);
00151 
00152         dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
00153 
00154         dns_name_init(&name, NULL);
00155 
00156         /*
00157          * Priority, weight, port.
00158          */
00159         isc_buffer_activeregion(source, &sr);
00160         if (sr.length < 6)
00161                 return (ISC_R_UNEXPECTEDEND);
00162         RETERR(mem_tobuffer(target, sr.base, 6));
00163         isc_buffer_forward(source, 6);
00164 
00165         /*
00166          * Target.
00167          */
00168         return (dns_name_fromwire(&name, source, dctx, options, target));
00169 }
00170 
00171 static inline isc_result_t
00172 towire_in_srv(ARGS_TOWIRE) {
00173         dns_name_t name;
00174         dns_offsets_t offsets;
00175         isc_region_t sr;
00176 
00177         REQUIRE(rdata->type == 33);
00178         REQUIRE(rdata->length != 0);
00179 
00180         dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
00181         /*
00182          * Priority, weight, port.
00183          */
00184         dns_rdata_toregion(rdata, &sr);
00185         RETERR(mem_tobuffer(target, sr.base, 6));
00186         isc_region_consume(&sr, 6);
00187 
00188         /*
00189          * Target.
00190          */
00191         dns_name_init(&name, offsets);
00192         dns_name_fromregion(&name, &sr);
00193         return (dns_name_towire(&name, cctx, target));
00194 }
00195 
00196 static inline int
00197 compare_in_srv(ARGS_COMPARE) {
00198         dns_name_t name1;
00199         dns_name_t name2;
00200         isc_region_t region1;
00201         isc_region_t region2;
00202         int order;
00203 
00204         REQUIRE(rdata1->type == rdata2->type);
00205         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00206         REQUIRE(rdata1->type == 33);
00207         REQUIRE(rdata1->rdclass == 1);
00208         REQUIRE(rdata1->length != 0);
00209         REQUIRE(rdata2->length != 0);
00210 
00211         /*
00212          * Priority, weight, port.
00213          */
00214         order = memcmp(rdata1->data, rdata2->data, 6);
00215         if (order != 0)
00216                 return (order < 0 ? -1 : 1);
00217 
00218         /*
00219          * Target.
00220          */
00221         dns_name_init(&name1, NULL);
00222         dns_name_init(&name2, NULL);
00223 
00224         dns_rdata_toregion(rdata1, &region1);
00225         dns_rdata_toregion(rdata2, &region2);
00226 
00227         isc_region_consume(&region1, 6);
00228         isc_region_consume(&region2, 6);
00229 
00230         dns_name_fromregion(&name1, &region1);
00231         dns_name_fromregion(&name2, &region2);
00232 
00233         return (dns_name_rdatacompare(&name1, &name2));
00234 }
00235 
00236 static inline isc_result_t
00237 fromstruct_in_srv(ARGS_FROMSTRUCT) {
00238         dns_rdata_in_srv_t *srv = source;
00239         isc_region_t region;
00240 
00241         REQUIRE(type == 33);
00242         REQUIRE(rdclass == 1);
00243         REQUIRE(source != NULL);
00244         REQUIRE(srv->common.rdtype == type);
00245         REQUIRE(srv->common.rdclass == rdclass);
00246 
00247         UNUSED(type);
00248         UNUSED(rdclass);
00249 
00250         RETERR(uint16_tobuffer(srv->priority, target));
00251         RETERR(uint16_tobuffer(srv->weight, target));
00252         RETERR(uint16_tobuffer(srv->port, target));
00253         dns_name_toregion(&srv->target, &region);
00254         return (isc_buffer_copyregion(target, &region));
00255 }
00256 
00257 static inline isc_result_t
00258 tostruct_in_srv(ARGS_TOSTRUCT) {
00259         isc_region_t region;
00260         dns_rdata_in_srv_t *srv = target;
00261         dns_name_t name;
00262 
00263         REQUIRE(rdata->rdclass == 1);
00264         REQUIRE(rdata->type == 33);
00265         REQUIRE(target != NULL);
00266         REQUIRE(rdata->length != 0);
00267 
00268         srv->common.rdclass = rdata->rdclass;
00269         srv->common.rdtype = rdata->type;
00270         ISC_LINK_INIT(&srv->common, link);
00271 
00272         dns_name_init(&name, NULL);
00273         dns_rdata_toregion(rdata, &region);
00274         srv->priority = uint16_fromregion(&region);
00275         isc_region_consume(&region, 2);
00276         srv->weight = uint16_fromregion(&region);
00277         isc_region_consume(&region, 2);
00278         srv->port = uint16_fromregion(&region);
00279         isc_region_consume(&region, 2);
00280         dns_name_fromregion(&name, &region);
00281         dns_name_init(&srv->target, NULL);
00282         RETERR(name_duporclone(&name, mctx, &srv->target));
00283         srv->mctx = mctx;
00284         return (ISC_R_SUCCESS);
00285 }
00286 
00287 static inline void
00288 freestruct_in_srv(ARGS_FREESTRUCT) {
00289         dns_rdata_in_srv_t *srv = source;
00290 
00291         REQUIRE(source != NULL);
00292         REQUIRE(srv->common.rdclass == 1);
00293         REQUIRE(srv->common.rdtype == 33);
00294 
00295         if (srv->mctx == NULL)
00296                 return;
00297 
00298         dns_name_free(&srv->target, srv->mctx);
00299         srv->mctx = NULL;
00300 }
00301 
00302 static inline isc_result_t
00303 additionaldata_in_srv(ARGS_ADDLDATA) {
00304         dns_name_t name;
00305         dns_offsets_t offsets;
00306         isc_region_t region;
00307 
00308         REQUIRE(rdata->type == 33);
00309         REQUIRE(rdata->rdclass == 1);
00310 
00311         dns_name_init(&name, offsets);
00312         dns_rdata_toregion(rdata, &region);
00313         isc_region_consume(&region, 6);
00314         dns_name_fromregion(&name, &region);
00315 
00316         return ((add)(arg, &name, dns_rdatatype_a));
00317 }
00318 
00319 static inline isc_result_t
00320 digest_in_srv(ARGS_DIGEST) {
00321         isc_region_t r1, r2;
00322         dns_name_t name;
00323 
00324         REQUIRE(rdata->type == 33);
00325         REQUIRE(rdata->rdclass == 1);
00326 
00327         dns_rdata_toregion(rdata, &r1);
00328         r2 = r1;
00329         isc_region_consume(&r2, 6);
00330         r1.length = 6;
00331         RETERR((digest)(arg, &r1));
00332         dns_name_init(&name, NULL);
00333         dns_name_fromregion(&name, &r2);
00334         return (dns_name_digest(&name, digest, arg));
00335 }
00336 
00337 static inline isc_boolean_t
00338 checkowner_in_srv(ARGS_CHECKOWNER) {
00339 
00340         REQUIRE(type == 33);
00341         REQUIRE(rdclass == 1);
00342 
00343         UNUSED(name);
00344         UNUSED(type);
00345         UNUSED(rdclass);
00346         UNUSED(wildcard);
00347 
00348         return (ISC_TRUE);
00349 }
00350 
00351 static inline isc_boolean_t
00352 checknames_in_srv(ARGS_CHECKNAMES) {
00353         isc_region_t region;
00354         dns_name_t name;
00355 
00356         REQUIRE(rdata->type == 33);
00357         REQUIRE(rdata->rdclass == 1);
00358 
00359         UNUSED(owner);
00360 
00361         dns_rdata_toregion(rdata, &region);
00362         isc_region_consume(&region, 6);
00363         dns_name_init(&name, NULL);
00364         dns_name_fromregion(&name, &region);
00365         if (!dns_name_ishostname(&name, ISC_FALSE)) {
00366                 if (bad != NULL)
00367                         dns_name_clone(&name, bad);
00368                 return (ISC_FALSE);
00369         }
00370         return (ISC_TRUE);
00371 }
00372 
00373 static inline int
00374 casecompare_in_srv(ARGS_COMPARE) {
00375         return (compare_in_srv(rdata1, rdata2));
00376 }
00377 
00378 #endif  /* RDATA_IN_1_SRV_33_C */

Generated on Tue Apr 28 17:41:00 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha