tlsa_52.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012, 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$ */
00018 
00019 /* rfc6698.txt */
00020 
00021 #ifndef RDATA_GENERIC_TLSA_52_C
00022 #define RDATA_GENERIC_TLSA_52_C
00023 
00024 #define RRTYPE_TLSA_ATTRIBUTES 0
00025 
00026 static inline isc_result_t
00027 fromtext_tlsa(ARGS_FROMTEXT) {
00028         isc_token_t token;
00029 
00030         REQUIRE(type == 52);
00031 
00032         UNUSED(type);
00033         UNUSED(rdclass);
00034         UNUSED(origin);
00035         UNUSED(options);
00036         UNUSED(callbacks);
00037 
00038         /*
00039          * Certificate Usage.
00040          */
00041         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00042                                       ISC_FALSE));
00043         if (token.value.as_ulong > 0xffU)
00044                 RETTOK(ISC_R_RANGE);
00045         RETERR(uint8_tobuffer(token.value.as_ulong, target));
00046 
00047         /*
00048          * Selector.
00049          */
00050         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00051                                       ISC_FALSE));
00052         if (token.value.as_ulong > 0xffU)
00053                 RETTOK(ISC_R_RANGE);
00054         RETERR(uint8_tobuffer(token.value.as_ulong, target));
00055 
00056         /*
00057          * Matching type.
00058          */
00059         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00060                                       ISC_FALSE));
00061         if (token.value.as_ulong > 0xffU)
00062                 RETTOK(ISC_R_RANGE);
00063         RETERR(uint8_tobuffer(token.value.as_ulong, target));
00064 
00065         /*
00066          * Certificate Association Data.
00067          */
00068         return (isc_hex_tobuffer(lexer, target, -1));
00069 }
00070 
00071 static inline isc_result_t
00072 totext_tlsa(ARGS_TOTEXT) {
00073         isc_region_t sr;
00074         char buf[sizeof("64000 ")];
00075         unsigned int n;
00076 
00077         REQUIRE(rdata->type == 52);
00078         REQUIRE(rdata->length != 0);
00079 
00080         UNUSED(tctx);
00081 
00082         dns_rdata_toregion(rdata, &sr);
00083 
00084         /*
00085          * Certificate Usage.
00086          */
00087         n = uint8_fromregion(&sr);
00088         isc_region_consume(&sr, 1);
00089         sprintf(buf, "%u ", n);
00090         RETERR(str_totext(buf, target));
00091 
00092         /*
00093          * Selector.
00094          */
00095         n = uint8_fromregion(&sr);
00096         isc_region_consume(&sr, 1);
00097         sprintf(buf, "%u ", n);
00098         RETERR(str_totext(buf, target));
00099 
00100         /*
00101          * Matching type.
00102          */
00103         n = uint8_fromregion(&sr);
00104         isc_region_consume(&sr, 1);
00105         sprintf(buf, "%u", n);
00106         RETERR(str_totext(buf, target));
00107 
00108         /*
00109          * Certificate Association Data.
00110          */
00111         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00112                 RETERR(str_totext(" (", target));
00113         RETERR(str_totext(tctx->linebreak, target));
00114         if (tctx->width == 0) /* No splitting */
00115                 RETERR(isc_hex_totext(&sr, 0, "", target));
00116         else
00117                 RETERR(isc_hex_totext(&sr, tctx->width - 2,
00118                                       tctx->linebreak, target));
00119         if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00120                 RETERR(str_totext(" )", target));
00121         return (ISC_R_SUCCESS);
00122 }
00123 
00124 static inline isc_result_t
00125 fromwire_tlsa(ARGS_FROMWIRE) {
00126         isc_region_t sr;
00127 
00128         REQUIRE(type == 52);
00129 
00130         UNUSED(type);
00131         UNUSED(rdclass);
00132         UNUSED(dctx);
00133         UNUSED(options);
00134 
00135         isc_buffer_activeregion(source, &sr);
00136 
00137         if (sr.length < 3)
00138                 return (ISC_R_UNEXPECTEDEND);
00139 
00140         isc_buffer_forward(source, sr.length);
00141         return (mem_tobuffer(target, sr.base, sr.length));
00142 }
00143 
00144 static inline isc_result_t
00145 towire_tlsa(ARGS_TOWIRE) {
00146         isc_region_t sr;
00147 
00148         REQUIRE(rdata->type == 52);
00149         REQUIRE(rdata->length != 0);
00150 
00151         UNUSED(cctx);
00152 
00153         dns_rdata_toregion(rdata, &sr);
00154         return (mem_tobuffer(target, sr.base, sr.length));
00155 }
00156 
00157 static inline int
00158 compare_tlsa(ARGS_COMPARE) {
00159         isc_region_t r1;
00160         isc_region_t r2;
00161 
00162         REQUIRE(rdata1->type == rdata2->type);
00163         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00164         REQUIRE(rdata1->type == 52);
00165         REQUIRE(rdata1->length != 0);
00166         REQUIRE(rdata2->length != 0);
00167 
00168         dns_rdata_toregion(rdata1, &r1);
00169         dns_rdata_toregion(rdata2, &r2);
00170         return (isc_region_compare(&r1, &r2));
00171 }
00172 
00173 static inline isc_result_t
00174 fromstruct_tlsa(ARGS_FROMSTRUCT) {
00175         dns_rdata_tlsa_t *tlsa = source;
00176 
00177         REQUIRE(type == 52);
00178         REQUIRE(source != NULL);
00179         REQUIRE(tlsa->common.rdtype == type);
00180         REQUIRE(tlsa->common.rdclass == rdclass);
00181 
00182         UNUSED(type);
00183         UNUSED(rdclass);
00184 
00185         RETERR(uint8_tobuffer(tlsa->usage, target));
00186         RETERR(uint8_tobuffer(tlsa->selector, target));
00187         RETERR(uint8_tobuffer(tlsa->match, target));
00188 
00189         return (mem_tobuffer(target, tlsa->data, tlsa->length));
00190 }
00191 
00192 static inline isc_result_t
00193 tostruct_tlsa(ARGS_TOSTRUCT) {
00194         dns_rdata_tlsa_t *tlsa = target;
00195         isc_region_t region;
00196 
00197         REQUIRE(rdata->type == 52);
00198         REQUIRE(target != NULL);
00199         REQUIRE(rdata->length != 0);
00200 
00201         tlsa->common.rdclass = rdata->rdclass;
00202         tlsa->common.rdtype = rdata->type;
00203         ISC_LINK_INIT(&tlsa->common, link);
00204 
00205         dns_rdata_toregion(rdata, &region);
00206 
00207         tlsa->usage = uint8_fromregion(&region);
00208         isc_region_consume(&region, 1);
00209         tlsa->selector = uint8_fromregion(&region);
00210         isc_region_consume(&region, 1);
00211         tlsa->match = uint8_fromregion(&region);
00212         isc_region_consume(&region, 1);
00213         tlsa->length = region.length;
00214 
00215         tlsa->data = mem_maybedup(mctx, region.base, region.length);
00216         if (tlsa->data == NULL)
00217                 return (ISC_R_NOMEMORY);
00218 
00219         tlsa->mctx = mctx;
00220         return (ISC_R_SUCCESS);
00221 }
00222 
00223 static inline void
00224 freestruct_tlsa(ARGS_FREESTRUCT) {
00225         dns_rdata_tlsa_t *tlsa = source;
00226 
00227         REQUIRE(tlsa != NULL);
00228         REQUIRE(tlsa->common.rdtype == 52);
00229 
00230         if (tlsa->mctx == NULL)
00231                 return;
00232 
00233         if (tlsa->data != NULL)
00234                 isc_mem_free(tlsa->mctx, tlsa->data);
00235         tlsa->mctx = NULL;
00236 }
00237 
00238 static inline isc_result_t
00239 additionaldata_tlsa(ARGS_ADDLDATA) {
00240         REQUIRE(rdata->type == 52);
00241 
00242         UNUSED(rdata);
00243         UNUSED(add);
00244         UNUSED(arg);
00245 
00246         return (ISC_R_SUCCESS);
00247 }
00248 
00249 static inline isc_result_t
00250 digest_tlsa(ARGS_DIGEST) {
00251         isc_region_t r;
00252 
00253         REQUIRE(rdata->type == 52);
00254 
00255         dns_rdata_toregion(rdata, &r);
00256 
00257         return ((digest)(arg, &r));
00258 }
00259 
00260 static inline isc_boolean_t
00261 checkowner_tlsa(ARGS_CHECKOWNER) {
00262 
00263         REQUIRE(type == 52);
00264 
00265         UNUSED(name);
00266         UNUSED(type);
00267         UNUSED(rdclass);
00268         UNUSED(wildcard);
00269 
00270         return (ISC_TRUE);
00271 }
00272 
00273 static inline isc_boolean_t
00274 checknames_tlsa(ARGS_CHECKNAMES) {
00275 
00276         REQUIRE(rdata->type == 52);
00277 
00278         UNUSED(rdata);
00279         UNUSED(owner);
00280         UNUSED(bad);
00281 
00282         return (ISC_TRUE);
00283 }
00284 
00285 static inline int
00286 casecompare_tlsa(ARGS_COMPARE) {
00287         return (compare_tlsa(rdata1, rdata2));
00288 }
00289 
00290 #endif  /* RDATA_GENERIC_TLSA_52_C */

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