ptr_12.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2001  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: ptr_12.c,v 1.45 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* Reviewed: Thu Mar 16 14:05:12 PST 2000 by explorer */
00021 
00022 #ifndef RDATA_GENERIC_PTR_12_C
00023 #define RDATA_GENERIC_PTR_12_C
00024 
00025 #define RRTYPE_PTR_ATTRIBUTES (0)
00026 
00027 static inline isc_result_t
00028 fromtext_ptr(ARGS_FROMTEXT) {
00029         isc_token_t token;
00030         dns_name_t name;
00031         isc_buffer_t buffer;
00032 
00033         REQUIRE(type == 12);
00034 
00035         UNUSED(type);
00036         UNUSED(rdclass);
00037         UNUSED(callbacks);
00038 
00039         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00040                                       ISC_FALSE));
00041 
00042         dns_name_init(&name, NULL);
00043         buffer_fromregion(&buffer, &token.value.as_region);
00044         origin = (origin != NULL) ? origin : dns_rootname;
00045         RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
00046         if (rdclass == dns_rdataclass_in &&
00047             (options & DNS_RDATA_CHECKNAMES) != 0 &&
00048             (options & DNS_RDATA_CHECKREVERSE) != 0) {
00049                 isc_boolean_t ok;
00050                 ok = dns_name_ishostname(&name, ISC_FALSE);
00051                 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
00052                         RETTOK(DNS_R_BADNAME);
00053                 if (!ok && callbacks != NULL)
00054                         warn_badname(&name, lexer, callbacks);
00055         }
00056         return (ISC_R_SUCCESS);
00057 }
00058 
00059 static inline isc_result_t
00060 totext_ptr(ARGS_TOTEXT) {
00061         isc_region_t region;
00062         dns_name_t name;
00063         dns_name_t prefix;
00064         isc_boolean_t sub;
00065 
00066         REQUIRE(rdata->type == 12);
00067         REQUIRE(rdata->length != 0);
00068 
00069         dns_name_init(&name, NULL);
00070         dns_name_init(&prefix, NULL);
00071 
00072         dns_rdata_toregion(rdata, &region);
00073         dns_name_fromregion(&name, &region);
00074 
00075         sub = name_prefix(&name, tctx->origin, &prefix);
00076 
00077         return (dns_name_totext(&prefix, sub, target));
00078 }
00079 
00080 static inline isc_result_t
00081 fromwire_ptr(ARGS_FROMWIRE) {
00082         dns_name_t name;
00083 
00084         REQUIRE(type == 12);
00085 
00086         UNUSED(type);
00087         UNUSED(rdclass);
00088 
00089         dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
00090 
00091         dns_name_init(&name, NULL);
00092         return (dns_name_fromwire(&name, source, dctx, options, target));
00093 }
00094 
00095 static inline isc_result_t
00096 towire_ptr(ARGS_TOWIRE) {
00097         dns_name_t name;
00098         dns_offsets_t offsets;
00099         isc_region_t region;
00100 
00101         REQUIRE(rdata->type == 12);
00102         REQUIRE(rdata->length != 0);
00103 
00104         dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
00105 
00106         dns_name_init(&name, offsets);
00107         dns_rdata_toregion(rdata, &region);
00108         dns_name_fromregion(&name, &region);
00109 
00110         return (dns_name_towire(&name, cctx, target));
00111 }
00112 
00113 static inline int
00114 compare_ptr(ARGS_COMPARE) {
00115         dns_name_t name1;
00116         dns_name_t name2;
00117         isc_region_t region1;
00118         isc_region_t region2;
00119 
00120         REQUIRE(rdata1->type == rdata2->type);
00121         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00122         REQUIRE(rdata1->type == 12);
00123         REQUIRE(rdata1->length != 0);
00124         REQUIRE(rdata2->length != 0);
00125 
00126         dns_name_init(&name1, NULL);
00127         dns_name_init(&name2, NULL);
00128 
00129         dns_rdata_toregion(rdata1, &region1);
00130         dns_rdata_toregion(rdata2, &region2);
00131 
00132         dns_name_fromregion(&name1, &region1);
00133         dns_name_fromregion(&name2, &region2);
00134 
00135         return (dns_name_rdatacompare(&name1, &name2));
00136 }
00137 
00138 static inline isc_result_t
00139 fromstruct_ptr(ARGS_FROMSTRUCT) {
00140         dns_rdata_ptr_t *ptr = source;
00141         isc_region_t region;
00142 
00143         REQUIRE(type == 12);
00144         REQUIRE(source != NULL);
00145         REQUIRE(ptr->common.rdtype == type);
00146         REQUIRE(ptr->common.rdclass == rdclass);
00147 
00148         UNUSED(type);
00149         UNUSED(rdclass);
00150 
00151         dns_name_toregion(&ptr->ptr, &region);
00152         return (isc_buffer_copyregion(target, &region));
00153 }
00154 
00155 static inline isc_result_t
00156 tostruct_ptr(ARGS_TOSTRUCT) {
00157         isc_region_t region;
00158         dns_rdata_ptr_t *ptr = target;
00159         dns_name_t name;
00160 
00161         REQUIRE(rdata->type == 12);
00162         REQUIRE(target != NULL);
00163         REQUIRE(rdata->length != 0);
00164 
00165         ptr->common.rdclass = rdata->rdclass;
00166         ptr->common.rdtype = rdata->type;
00167         ISC_LINK_INIT(&ptr->common, link);
00168 
00169         dns_name_init(&name, NULL);
00170         dns_rdata_toregion(rdata, &region);
00171         dns_name_fromregion(&name, &region);
00172         dns_name_init(&ptr->ptr, NULL);
00173         RETERR(name_duporclone(&name, mctx, &ptr->ptr));
00174         ptr->mctx = mctx;
00175         return (ISC_R_SUCCESS);
00176 }
00177 
00178 static inline void
00179 freestruct_ptr(ARGS_FREESTRUCT) {
00180         dns_rdata_ptr_t *ptr = source;
00181 
00182         REQUIRE(source != NULL);
00183         REQUIRE(ptr->common.rdtype == 12);
00184 
00185         if (ptr->mctx == NULL)
00186                 return;
00187 
00188         dns_name_free(&ptr->ptr, ptr->mctx);
00189         ptr->mctx = NULL;
00190 }
00191 
00192 static inline isc_result_t
00193 additionaldata_ptr(ARGS_ADDLDATA) {
00194         REQUIRE(rdata->type == 12);
00195 
00196         UNUSED(rdata);
00197         UNUSED(add);
00198         UNUSED(arg);
00199 
00200         return (ISC_R_SUCCESS);
00201 }
00202 
00203 static inline isc_result_t
00204 digest_ptr(ARGS_DIGEST) {
00205         isc_region_t r;
00206         dns_name_t name;
00207 
00208         REQUIRE(rdata->type == 12);
00209 
00210         dns_rdata_toregion(rdata, &r);
00211         dns_name_init(&name, NULL);
00212         dns_name_fromregion(&name, &r);
00213 
00214         return (dns_name_digest(&name, digest, arg));
00215 }
00216 
00217 static inline isc_boolean_t
00218 checkowner_ptr(ARGS_CHECKOWNER) {
00219 
00220         REQUIRE(type == 12);
00221 
00222         UNUSED(name);
00223         UNUSED(type);
00224         UNUSED(rdclass);
00225         UNUSED(wildcard);
00226 
00227         return (ISC_TRUE);
00228 }
00229 
00230 static unsigned char ip6_arpa_data[]  = "\003IP6\004ARPA";
00231 static unsigned char ip6_arpa_offsets[] = { 0, 4, 9 };
00232 static const dns_name_t ip6_arpa =
00233 {
00234         DNS_NAME_MAGIC,
00235         ip6_arpa_data, 10, 3,
00236         DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
00237         ip6_arpa_offsets, NULL,
00238         {(void *)-1, (void *)-1},
00239         {NULL, NULL}
00240 };
00241 
00242 static unsigned char ip6_int_data[]  = "\003IP6\003INT";
00243 static unsigned char ip6_int_offsets[] = { 0, 4, 8 };
00244 static const dns_name_t ip6_int =
00245 {
00246         DNS_NAME_MAGIC,
00247         ip6_int_data, 9, 3,
00248         DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
00249         ip6_int_offsets, NULL,
00250         {(void *)-1, (void *)-1},
00251         {NULL, NULL}
00252 };
00253 
00254 static unsigned char in_addr_arpa_data[]  = "\007IN-ADDR\004ARPA";
00255 static unsigned char in_addr_arpa_offsets[] = { 0, 8, 13 };
00256 static const dns_name_t in_addr_arpa =
00257 {
00258         DNS_NAME_MAGIC,
00259         in_addr_arpa_data, 14, 3,
00260         DNS_NAMEATTR_READONLY | DNS_NAMEATTR_ABSOLUTE,
00261         in_addr_arpa_offsets, NULL,
00262         {(void *)-1, (void *)-1},
00263         {NULL, NULL}
00264 };
00265 
00266 static inline isc_boolean_t
00267 checknames_ptr(ARGS_CHECKNAMES) {
00268         isc_region_t region;
00269         dns_name_t name;
00270 
00271         REQUIRE(rdata->type == 12);
00272 
00273         if (rdata->rdclass != dns_rdataclass_in)
00274             return (ISC_TRUE);
00275 
00276         if (dns_name_issubdomain(owner, &in_addr_arpa) ||
00277             dns_name_issubdomain(owner, &ip6_arpa) ||
00278             dns_name_issubdomain(owner, &ip6_int)) {
00279                 dns_rdata_toregion(rdata, &region);
00280                 dns_name_init(&name, NULL);
00281                 dns_name_fromregion(&name, &region);
00282                 if (!dns_name_ishostname(&name, ISC_FALSE)) {
00283                         if (bad != NULL)
00284                                 dns_name_clone(&name, bad);
00285                         return (ISC_FALSE);
00286                 }
00287         }
00288         return (ISC_TRUE);
00289 }
00290 
00291 static inline int
00292 casecompare_ptr(ARGS_COMPARE) {
00293         return (compare_ptr(rdata1, rdata2));
00294 }
00295 #endif  /* RDATA_GENERIC_PTR_12_C */

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