afsdb_18.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2009, 2014  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: afsdb_18.c,v 1.49 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* Reviewed: Wed Mar 15 14:59:00 PST 2000 by explorer */
00021 
00022 /* RFC1183 */
00023 
00024 #ifndef RDATA_GENERIC_AFSDB_18_C
00025 #define RDATA_GENERIC_AFSDB_18_C
00026 
00027 #define RRTYPE_AFSDB_ATTRIBUTES (0)
00028 
00029 static inline isc_result_t
00030 fromtext_afsdb(ARGS_FROMTEXT) {
00031         isc_token_t token;
00032         isc_buffer_t buffer;
00033         dns_name_t name;
00034         isc_boolean_t ok;
00035 
00036         REQUIRE(type == 18);
00037 
00038         UNUSED(type);
00039         UNUSED(rdclass);
00040         UNUSED(callbacks);
00041 
00042         /*
00043          * Subtype.
00044          */
00045         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00046                                       ISC_FALSE));
00047         if (token.value.as_ulong > 0xffffU)
00048                 RETTOK(ISC_R_RANGE);
00049         RETERR(uint16_tobuffer(token.value.as_ulong, target));
00050 
00051         /*
00052          * Hostname.
00053          */
00054         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00055                                       ISC_FALSE));
00056         dns_name_init(&name, NULL);
00057         buffer_fromregion(&buffer, &token.value.as_region);
00058         origin = (origin != NULL) ? origin : dns_rootname;
00059         RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
00060         ok = ISC_TRUE;
00061         if ((options & DNS_RDATA_CHECKNAMES) != 0)
00062                 ok = dns_name_ishostname(&name, ISC_FALSE);
00063         if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
00064                 RETTOK(DNS_R_BADNAME);
00065         if (!ok && callbacks != NULL)
00066                 warn_badname(&name, lexer, callbacks);
00067         return (ISC_R_SUCCESS);
00068 }
00069 
00070 static inline isc_result_t
00071 totext_afsdb(ARGS_TOTEXT) {
00072         dns_name_t name;
00073         dns_name_t prefix;
00074         isc_region_t region;
00075         char buf[sizeof("64000 ")];
00076         isc_boolean_t sub;
00077         unsigned int num;
00078 
00079         REQUIRE(rdata->type == 18);
00080         REQUIRE(rdata->length != 0);
00081 
00082         dns_name_init(&name, NULL);
00083         dns_name_init(&prefix, NULL);
00084 
00085         dns_rdata_toregion(rdata, &region);
00086         num = uint16_fromregion(&region);
00087         isc_region_consume(&region, 2);
00088         sprintf(buf, "%u ", num);
00089         RETERR(str_totext(buf, target));
00090         dns_name_fromregion(&name, &region);
00091         sub = name_prefix(&name, tctx->origin, &prefix);
00092         return (dns_name_totext(&prefix, sub, target));
00093 }
00094 
00095 static inline isc_result_t
00096 fromwire_afsdb(ARGS_FROMWIRE) {
00097         dns_name_t name;
00098         isc_region_t sr;
00099         isc_region_t tr;
00100 
00101         REQUIRE(type == 18);
00102 
00103         UNUSED(type);
00104         UNUSED(rdclass);
00105 
00106         dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
00107 
00108         dns_name_init(&name, NULL);
00109 
00110         isc_buffer_activeregion(source, &sr);
00111         isc_buffer_availableregion(target, &tr);
00112         if (tr.length < 2)
00113                 return (ISC_R_NOSPACE);
00114         if (sr.length < 2)
00115                 return (ISC_R_UNEXPECTEDEND);
00116         memmove(tr.base, sr.base, 2);
00117         isc_buffer_forward(source, 2);
00118         isc_buffer_add(target, 2);
00119         return (dns_name_fromwire(&name, source, dctx, options, target));
00120 }
00121 
00122 static inline isc_result_t
00123 towire_afsdb(ARGS_TOWIRE) {
00124         isc_region_t tr;
00125         isc_region_t sr;
00126         dns_name_t name;
00127         dns_offsets_t offsets;
00128 
00129         REQUIRE(rdata->type == 18);
00130         REQUIRE(rdata->length != 0);
00131 
00132         dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
00133         isc_buffer_availableregion(target, &tr);
00134         dns_rdata_toregion(rdata, &sr);
00135         if (tr.length < 2)
00136                 return (ISC_R_NOSPACE);
00137         memmove(tr.base, sr.base, 2);
00138         isc_region_consume(&sr, 2);
00139         isc_buffer_add(target, 2);
00140 
00141         dns_name_init(&name, offsets);
00142         dns_name_fromregion(&name, &sr);
00143 
00144         return (dns_name_towire(&name, cctx, target));
00145 }
00146 
00147 static inline int
00148 compare_afsdb(ARGS_COMPARE) {
00149         int result;
00150         dns_name_t name1;
00151         dns_name_t name2;
00152         isc_region_t region1;
00153         isc_region_t region2;
00154 
00155         REQUIRE(rdata1->type == rdata2->type);
00156         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00157         REQUIRE(rdata1->type == 18);
00158         REQUIRE(rdata1->length != 0);
00159         REQUIRE(rdata2->length != 0);
00160 
00161         result = memcmp(rdata1->data, rdata2->data, 2);
00162         if (result != 0)
00163                 return (result < 0 ? -1 : 1);
00164 
00165         dns_name_init(&name1, NULL);
00166         dns_name_init(&name2, NULL);
00167 
00168         dns_rdata_toregion(rdata1, &region1);
00169         dns_rdata_toregion(rdata2, &region2);
00170 
00171         isc_region_consume(&region1, 2);
00172         isc_region_consume(&region2, 2);
00173 
00174         dns_name_fromregion(&name1, &region1);
00175         dns_name_fromregion(&name2, &region2);
00176 
00177         return (dns_name_rdatacompare(&name1, &name2));
00178 }
00179 
00180 static inline isc_result_t
00181 fromstruct_afsdb(ARGS_FROMSTRUCT) {
00182         dns_rdata_afsdb_t *afsdb = source;
00183         isc_region_t region;
00184 
00185         REQUIRE(type == 18);
00186         REQUIRE(source != NULL);
00187         REQUIRE(afsdb->common.rdclass == rdclass);
00188         REQUIRE(afsdb->common.rdtype == type);
00189 
00190         UNUSED(type);
00191         UNUSED(rdclass);
00192 
00193         RETERR(uint16_tobuffer(afsdb->subtype, target));
00194         dns_name_toregion(&afsdb->server, &region);
00195         return (isc_buffer_copyregion(target, &region));
00196 }
00197 
00198 static inline isc_result_t
00199 tostruct_afsdb(ARGS_TOSTRUCT) {
00200         isc_region_t region;
00201         dns_rdata_afsdb_t *afsdb = target;
00202         dns_name_t name;
00203 
00204         REQUIRE(rdata->type == 18);
00205         REQUIRE(target != NULL);
00206         REQUIRE(rdata->length != 0);
00207 
00208         afsdb->common.rdclass = rdata->rdclass;
00209         afsdb->common.rdtype = rdata->type;
00210         ISC_LINK_INIT(&afsdb->common, link);
00211 
00212         dns_name_init(&afsdb->server, NULL);
00213 
00214         dns_rdata_toregion(rdata, &region);
00215 
00216         afsdb->subtype = uint16_fromregion(&region);
00217         isc_region_consume(&region, 2);
00218 
00219         dns_name_init(&name, NULL);
00220         dns_name_fromregion(&name, &region);
00221 
00222         RETERR(name_duporclone(&name, mctx, &afsdb->server));
00223         afsdb->mctx = mctx;
00224         return (ISC_R_SUCCESS);
00225 }
00226 
00227 static inline void
00228 freestruct_afsdb(ARGS_FREESTRUCT) {
00229         dns_rdata_afsdb_t *afsdb = source;
00230 
00231         REQUIRE(source != NULL);
00232         REQUIRE(afsdb->common.rdtype == 18);
00233 
00234         if (afsdb->mctx == NULL)
00235                 return;
00236 
00237         dns_name_free(&afsdb->server, afsdb->mctx);
00238         afsdb->mctx = NULL;
00239 }
00240 
00241 static inline isc_result_t
00242 additionaldata_afsdb(ARGS_ADDLDATA) {
00243         dns_name_t name;
00244         dns_offsets_t offsets;
00245         isc_region_t region;
00246 
00247         REQUIRE(rdata->type == 18);
00248 
00249         dns_name_init(&name, offsets);
00250         dns_rdata_toregion(rdata, &region);
00251         isc_region_consume(&region, 2);
00252         dns_name_fromregion(&name, &region);
00253 
00254         return ((add)(arg, &name, dns_rdatatype_a));
00255 }
00256 
00257 static inline isc_result_t
00258 digest_afsdb(ARGS_DIGEST) {
00259         isc_region_t r1, r2;
00260         dns_name_t name;
00261 
00262         REQUIRE(rdata->type == 18);
00263 
00264         dns_rdata_toregion(rdata, &r1);
00265         r2 = r1;
00266         isc_region_consume(&r2, 2);
00267         r1.length = 2;
00268         RETERR((digest)(arg, &r1));
00269         dns_name_init(&name, NULL);
00270         dns_name_fromregion(&name, &r2);
00271 
00272         return (dns_name_digest(&name, digest, arg));
00273 }
00274 
00275 static inline isc_boolean_t
00276 checkowner_afsdb(ARGS_CHECKOWNER) {
00277 
00278         REQUIRE(type == 18);
00279 
00280         UNUSED(name);
00281         UNUSED(type);
00282         UNUSED(rdclass);
00283         UNUSED(wildcard);
00284 
00285         return (ISC_TRUE);
00286 }
00287 
00288 static inline isc_boolean_t
00289 checknames_afsdb(ARGS_CHECKNAMES) {
00290         isc_region_t region;
00291         dns_name_t name;
00292 
00293         REQUIRE(rdata->type == 18);
00294 
00295         UNUSED(owner);
00296 
00297         dns_rdata_toregion(rdata, &region);
00298         isc_region_consume(&region, 2);
00299         dns_name_init(&name, NULL);
00300         dns_name_fromregion(&name, &region);
00301         if (!dns_name_ishostname(&name, ISC_FALSE)) {
00302                 if (bad != NULL)
00303                         dns_name_clone(&name, bad);
00304                 return (ISC_FALSE);
00305         }
00306         return (ISC_TRUE);
00307 }
00308 
00309 static inline int
00310 casecompare_afsdb(ARGS_COMPARE) {
00311         return (compare_afsdb(rdata1, rdata2));
00312 }
00313 #endif  /* RDATA_GENERIC_AFSDB_18_C */

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