a_1.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005, 2007, 2009, 2014  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 /* $Id: a_1.c,v 1.8 2009/12/04 22:06:37 tbox Exp $ */
00018 
00019 /* by Bjorn.Victor@it.uu.se, 2005-05-07 */
00020 /* Based on generic/soa_6.c and generic/mx_15.c */
00021 
00022 #ifndef RDATA_CH_3_A_1_C
00023 #define RDATA_CH_3_A_1_C
00024 
00025 #include <isc/net.h>
00026 
00027 #define RRTYPE_A_ATTRIBUTES (0)
00028 
00029 static inline isc_result_t
00030 fromtext_ch_a(ARGS_FROMTEXT) {
00031         isc_token_t token;
00032         dns_name_t name;
00033         isc_buffer_t buffer;
00034 
00035         REQUIRE(type == 1);
00036         REQUIRE(rdclass == dns_rdataclass_ch); /* 3 */
00037 
00038         UNUSED(type);
00039         UNUSED(callbacks);
00040 
00041         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00042                                       ISC_FALSE));
00043 
00044         /* get domain name */
00045         dns_name_init(&name, NULL);
00046         buffer_fromregion(&buffer, &token.value.as_region);
00047         origin = (origin != NULL) ? origin : dns_rootname;
00048         RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
00049         if ((options & DNS_RDATA_CHECKNAMES) != 0 &&
00050             (options & DNS_RDATA_CHECKREVERSE) != 0) {
00051                 isc_boolean_t ok;
00052                 ok = dns_name_ishostname(&name, ISC_FALSE);
00053                 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
00054                         RETTOK(DNS_R_BADNAME);
00055                 if (!ok && callbacks != NULL)
00056                         warn_badname(&name, lexer, callbacks);
00057         }
00058 
00059         /* 16-bit octal address */
00060         RETERR(isc_lex_getoctaltoken(lexer, &token, ISC_FALSE));
00061         if (token.value.as_ulong > 0xffffU)
00062                 RETTOK(ISC_R_RANGE);
00063         return (uint16_tobuffer(token.value.as_ulong, target));
00064 }
00065 
00066 static inline isc_result_t
00067 totext_ch_a(ARGS_TOTEXT) {
00068         isc_region_t region;
00069         dns_name_t name;
00070         dns_name_t prefix;
00071         isc_boolean_t sub;
00072         char buf[sizeof("0177777")];
00073         isc_uint16_t addr;
00074 
00075         REQUIRE(rdata->type == 1);
00076         REQUIRE(rdata->rdclass == dns_rdataclass_ch); /* 3 */
00077         REQUIRE(rdata->length != 0);
00078 
00079         dns_name_init(&name, NULL);
00080         dns_name_init(&prefix, NULL);
00081 
00082         dns_rdata_toregion(rdata, &region);
00083         dns_name_fromregion(&name, &region);
00084         isc_region_consume(&region, name_length(&name));
00085         addr = uint16_fromregion(&region);
00086 
00087         sub = name_prefix(&name, tctx->origin, &prefix);
00088         RETERR(dns_name_totext(&prefix, sub, target));
00089 
00090         sprintf(buf, "%o", addr); /* note octal */
00091         RETERR(str_totext(" ", target));
00092         return (str_totext(buf, target));
00093 }
00094 
00095 static inline isc_result_t
00096 fromwire_ch_a(ARGS_FROMWIRE) {
00097         isc_region_t sregion;
00098         isc_region_t tregion;
00099         dns_name_t name;
00100 
00101         REQUIRE(type == 1);
00102         REQUIRE(rdclass == dns_rdataclass_ch);
00103 
00104         UNUSED(type);
00105         UNUSED(rdclass);
00106 
00107         dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
00108 
00109         dns_name_init(&name, NULL);
00110 
00111         RETERR(dns_name_fromwire(&name, source, dctx, options, target));
00112 
00113         isc_buffer_activeregion(source, &sregion);
00114         isc_buffer_availableregion(target, &tregion);
00115         if (sregion.length < 2)
00116                 return (ISC_R_UNEXPECTEDEND);
00117         if (tregion.length < 2)
00118                 return (ISC_R_NOSPACE);
00119 
00120         memmove(tregion.base, sregion.base, 2);
00121         isc_buffer_forward(source, 2);
00122         isc_buffer_add(target, 2);
00123 
00124         return (ISC_R_SUCCESS);
00125 }
00126 
00127 static inline isc_result_t
00128 towire_ch_a(ARGS_TOWIRE) {
00129         dns_name_t name;
00130         dns_offsets_t offsets;
00131         isc_region_t sregion;
00132         isc_region_t tregion;
00133 
00134         REQUIRE(rdata->type == 1);
00135         REQUIRE(rdata->rdclass == dns_rdataclass_ch);
00136         REQUIRE(rdata->length != 0);
00137 
00138         dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
00139 
00140         dns_name_init(&name, offsets);
00141 
00142         dns_rdata_toregion(rdata, &sregion);
00143 
00144         dns_name_fromregion(&name, &sregion);
00145         isc_region_consume(&sregion, name_length(&name));
00146         RETERR(dns_name_towire(&name, cctx, target));
00147 
00148         isc_buffer_availableregion(target, &tregion);
00149         if (tregion.length < 2)
00150                 return (ISC_R_NOSPACE);
00151 
00152         memmove(tregion.base, sregion.base, 2);
00153         isc_buffer_add(target, 2);
00154         return (ISC_R_SUCCESS);
00155 }
00156 
00157 static inline int
00158 compare_ch_a(ARGS_COMPARE) {
00159         dns_name_t name1;
00160         dns_name_t name2;
00161         isc_region_t region1;
00162         isc_region_t region2;
00163         int order;
00164 
00165         REQUIRE(rdata1->type == rdata2->type);
00166         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00167         REQUIRE(rdata1->type == 1);
00168         REQUIRE(rdata1->rdclass == dns_rdataclass_ch);
00169         REQUIRE(rdata1->length != 0);
00170         REQUIRE(rdata2->length != 0);
00171 
00172         dns_name_init(&name1, NULL);
00173         dns_name_init(&name2, NULL);
00174 
00175         dns_rdata_toregion(rdata1, &region1);
00176         dns_rdata_toregion(rdata2, &region2);
00177 
00178         dns_name_fromregion(&name1, &region1);
00179         dns_name_fromregion(&name2, &region2);
00180         isc_region_consume(&region1, name_length(&name1));
00181         isc_region_consume(&region2, name_length(&name2));
00182 
00183         order = dns_name_rdatacompare(&name1, &name2);
00184         if (order != 0)
00185                 return (order);
00186 
00187         order = memcmp(rdata1->data, rdata2->data, 2);
00188         if (order != 0)
00189                 order = (order < 0) ? -1 : 1;
00190         return (order);
00191 }
00192 
00193 static inline isc_result_t
00194 fromstruct_ch_a(ARGS_FROMSTRUCT) {
00195         dns_rdata_ch_a_t *a = source;
00196         isc_region_t region;
00197 
00198         REQUIRE(type == 1);
00199         REQUIRE(source != NULL);
00200         REQUIRE(a->common.rdtype == type);
00201         REQUIRE(a->common.rdclass == rdclass);
00202 
00203         UNUSED(type);
00204         UNUSED(rdclass);
00205 
00206         dns_name_toregion(&a->ch_addr_dom, &region);
00207         RETERR(isc_buffer_copyregion(target, &region));
00208 
00209         return (uint16_tobuffer(ntohs(a->ch_addr), target));
00210 }
00211 
00212 static inline isc_result_t
00213 tostruct_ch_a(ARGS_TOSTRUCT) {
00214         dns_rdata_ch_a_t *a = target;
00215         isc_region_t region;
00216         dns_name_t name;
00217 
00218         REQUIRE(rdata->type == 1);
00219         REQUIRE(rdata->rdclass == dns_rdataclass_ch);
00220         REQUIRE(rdata->length != 0);
00221 
00222         a->common.rdclass = rdata->rdclass;
00223         a->common.rdtype = rdata->type;
00224         ISC_LINK_INIT(&a->common, link);
00225 
00226         dns_rdata_toregion(rdata, &region);
00227 
00228         dns_name_init(&name, NULL);
00229         dns_name_fromregion(&name, &region);
00230         isc_region_consume(&region, name_length(&name));
00231 
00232         dns_name_init(&a->ch_addr_dom, NULL);
00233         RETERR(name_duporclone(&name, mctx, &a->ch_addr_dom));
00234         a->ch_addr = htons(uint16_fromregion(&region));
00235         a->mctx = mctx;
00236         return (ISC_R_SUCCESS);
00237 }
00238 
00239 static inline void
00240 freestruct_ch_a(ARGS_FREESTRUCT) {
00241         dns_rdata_ch_a_t *a = source;
00242 
00243         REQUIRE(source != NULL);
00244         REQUIRE(a->common.rdtype == 1);
00245 
00246         if (a->mctx == NULL)
00247                 return;
00248 
00249         dns_name_free(&a->ch_addr_dom, a->mctx);
00250         a->mctx = NULL;
00251 }
00252 
00253 static inline isc_result_t
00254 additionaldata_ch_a(ARGS_ADDLDATA) {
00255 
00256         REQUIRE(rdata->type == 1);
00257         REQUIRE(rdata->rdclass == dns_rdataclass_ch);
00258 
00259         UNUSED(rdata);
00260         UNUSED(add);
00261         UNUSED(arg);
00262 
00263         return (ISC_R_SUCCESS);
00264 }
00265 
00266 static inline isc_result_t
00267 digest_ch_a(ARGS_DIGEST) {
00268         isc_region_t r;
00269 
00270         dns_name_t name;
00271 
00272         REQUIRE(rdata->type == 1);
00273         REQUIRE(rdata->rdclass == dns_rdataclass_ch);
00274 
00275         dns_rdata_toregion(rdata, &r);
00276         dns_name_init(&name, NULL);
00277         dns_name_fromregion(&name, &r);
00278         isc_region_consume(&r, name_length(&name));
00279         RETERR(dns_name_digest(&name, digest, arg));
00280         return ((digest)(arg, &r));
00281 }
00282 
00283 static inline isc_boolean_t
00284 checkowner_ch_a(ARGS_CHECKOWNER) {
00285 
00286         REQUIRE(type == 1);
00287         REQUIRE(rdclass == dns_rdataclass_ch);
00288 
00289         UNUSED(type);
00290 
00291         return (dns_name_ishostname(name, wildcard));
00292 }
00293 
00294 static inline isc_boolean_t
00295 checknames_ch_a(ARGS_CHECKNAMES) {
00296         isc_region_t region;
00297         dns_name_t name;
00298 
00299         REQUIRE(rdata->type == 1);
00300         REQUIRE(rdata->rdclass == dns_rdataclass_ch);
00301 
00302         UNUSED(owner);
00303 
00304         dns_rdata_toregion(rdata, &region);
00305         dns_name_init(&name, NULL);
00306         dns_name_fromregion(&name, &region);
00307         if (!dns_name_ishostname(&name, ISC_FALSE)) {
00308                 if (bad != NULL)
00309                         dns_name_clone(&name, bad);
00310                 return (ISC_FALSE);
00311         }
00312 
00313         return (ISC_TRUE);
00314 }
00315 
00316 static inline int
00317 casecompare_ch_a(ARGS_COMPARE) {
00318         return (compare_ch_a(rdata1, rdata2));
00319 }
00320 #endif  /* RDATA_CH_3_A_1_C */

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