"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/dns/rdata/generic/tlsa_52.c" (4 Sep 2020, 7298 Bytes) of package /linux/misc/dns/bind9/9.17.5/bind-9.17.5.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "tlsa_52.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 9.17.4_vs_9.17.5.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /* rfc6698.txt */
   13 
   14 #ifndef RDATA_GENERIC_TLSA_52_C
   15 #define RDATA_GENERIC_TLSA_52_C
   16 
   17 #define RRTYPE_TLSA_ATTRIBUTES 0
   18 
   19 static inline isc_result_t
   20 generic_fromtext_tlsa(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22 
   23     UNUSED(type);
   24     UNUSED(rdclass);
   25     UNUSED(origin);
   26     UNUSED(options);
   27     UNUSED(callbacks);
   28 
   29     /*
   30      * Certificate Usage.
   31      */
   32     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   33                       false));
   34     if (token.value.as_ulong > 0xffU) {
   35         RETTOK(ISC_R_RANGE);
   36     }
   37     RETERR(uint8_tobuffer(token.value.as_ulong, target));
   38 
   39     /*
   40      * Selector.
   41      */
   42     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   43                       false));
   44     if (token.value.as_ulong > 0xffU) {
   45         RETTOK(ISC_R_RANGE);
   46     }
   47     RETERR(uint8_tobuffer(token.value.as_ulong, target));
   48 
   49     /*
   50      * Matching type.
   51      */
   52     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   53                       false));
   54     if (token.value.as_ulong > 0xffU) {
   55         RETTOK(ISC_R_RANGE);
   56     }
   57     RETERR(uint8_tobuffer(token.value.as_ulong, target));
   58 
   59     /*
   60      * Certificate Association Data.
   61      */
   62     return (isc_hex_tobuffer(lexer, target, -2));
   63 }
   64 
   65 static inline isc_result_t
   66 generic_totext_tlsa(ARGS_TOTEXT) {
   67     isc_region_t sr;
   68     char buf[sizeof("64000 ")];
   69     unsigned int n;
   70 
   71     REQUIRE(rdata->length != 0);
   72 
   73     UNUSED(tctx);
   74 
   75     dns_rdata_toregion(rdata, &sr);
   76 
   77     /*
   78      * Certificate Usage.
   79      */
   80     n = uint8_fromregion(&sr);
   81     isc_region_consume(&sr, 1);
   82     snprintf(buf, sizeof(buf), "%u ", n);
   83     RETERR(str_totext(buf, target));
   84 
   85     /*
   86      * Selector.
   87      */
   88     n = uint8_fromregion(&sr);
   89     isc_region_consume(&sr, 1);
   90     snprintf(buf, sizeof(buf), "%u ", n);
   91     RETERR(str_totext(buf, target));
   92 
   93     /*
   94      * Matching type.
   95      */
   96     n = uint8_fromregion(&sr);
   97     isc_region_consume(&sr, 1);
   98     snprintf(buf, sizeof(buf), "%u", n);
   99     RETERR(str_totext(buf, target));
  100 
  101     /*
  102      * Certificate Association Data.
  103      */
  104     if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
  105         RETERR(str_totext(" (", target));
  106     }
  107     RETERR(str_totext(tctx->linebreak, target));
  108     if (tctx->width == 0) { /* No splitting */
  109         RETERR(isc_hex_totext(&sr, 0, "", target));
  110     } else {
  111         RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak,
  112                       target));
  113     }
  114     if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
  115         RETERR(str_totext(" )", target));
  116     }
  117     return (ISC_R_SUCCESS);
  118 }
  119 
  120 static inline isc_result_t
  121 generic_fromwire_tlsa(ARGS_FROMWIRE) {
  122     isc_region_t sr;
  123 
  124     UNUSED(type);
  125     UNUSED(rdclass);
  126     UNUSED(dctx);
  127     UNUSED(options);
  128 
  129     isc_buffer_activeregion(source, &sr);
  130 
  131     /* Usage(1), Selector(1), Type(1), Data(1+) */
  132     if (sr.length < 4) {
  133         return (ISC_R_UNEXPECTEDEND);
  134     }
  135 
  136     isc_buffer_forward(source, sr.length);
  137     return (mem_tobuffer(target, sr.base, sr.length));
  138 }
  139 
  140 static inline isc_result_t
  141 fromtext_tlsa(ARGS_FROMTEXT) {
  142     REQUIRE(type == dns_rdatatype_tlsa);
  143 
  144     return (generic_fromtext_tlsa(rdclass, type, lexer, origin, options,
  145                       target, callbacks));
  146 }
  147 
  148 static inline isc_result_t
  149 totext_tlsa(ARGS_TOTEXT) {
  150     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  151 
  152     return (generic_totext_tlsa(rdata, tctx, target));
  153 }
  154 
  155 static inline isc_result_t
  156 fromwire_tlsa(ARGS_FROMWIRE) {
  157     REQUIRE(type == dns_rdatatype_tlsa);
  158 
  159     return (generic_fromwire_tlsa(rdclass, type, source, dctx, options,
  160                       target));
  161 }
  162 
  163 static inline isc_result_t
  164 towire_tlsa(ARGS_TOWIRE) {
  165     isc_region_t sr;
  166 
  167     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  168     REQUIRE(rdata->length != 0);
  169 
  170     UNUSED(cctx);
  171 
  172     dns_rdata_toregion(rdata, &sr);
  173     return (mem_tobuffer(target, sr.base, sr.length));
  174 }
  175 
  176 static inline int
  177 compare_tlsa(ARGS_COMPARE) {
  178     isc_region_t r1;
  179     isc_region_t r2;
  180 
  181     REQUIRE(rdata1->type == rdata2->type);
  182     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  183     REQUIRE(rdata1->type == dns_rdatatype_tlsa);
  184     REQUIRE(rdata1->length != 0);
  185     REQUIRE(rdata2->length != 0);
  186 
  187     dns_rdata_toregion(rdata1, &r1);
  188     dns_rdata_toregion(rdata2, &r2);
  189     return (isc_region_compare(&r1, &r2));
  190 }
  191 
  192 static inline isc_result_t
  193 generic_fromstruct_tlsa(ARGS_FROMSTRUCT) {
  194     dns_rdata_tlsa_t *tlsa = source;
  195 
  196     REQUIRE(tlsa != NULL);
  197     REQUIRE(tlsa->common.rdtype == type);
  198     REQUIRE(tlsa->common.rdclass == rdclass);
  199 
  200     UNUSED(type);
  201     UNUSED(rdclass);
  202 
  203     RETERR(uint8_tobuffer(tlsa->usage, target));
  204     RETERR(uint8_tobuffer(tlsa->selector, target));
  205     RETERR(uint8_tobuffer(tlsa->match, target));
  206 
  207     return (mem_tobuffer(target, tlsa->data, tlsa->length));
  208 }
  209 
  210 static inline isc_result_t
  211 generic_tostruct_tlsa(ARGS_TOSTRUCT) {
  212     dns_rdata_tlsa_t *tlsa = target;
  213     isc_region_t region;
  214 
  215     REQUIRE(tlsa != NULL);
  216     REQUIRE(rdata->length != 0);
  217 
  218     REQUIRE(tlsa != NULL);
  219     REQUIRE(tlsa->common.rdclass == rdata->rdclass);
  220     REQUIRE(tlsa->common.rdtype == rdata->type);
  221     REQUIRE(!ISC_LINK_LINKED(&tlsa->common, link));
  222 
  223     dns_rdata_toregion(rdata, &region);
  224 
  225     tlsa->usage = uint8_fromregion(&region);
  226     isc_region_consume(&region, 1);
  227     tlsa->selector = uint8_fromregion(&region);
  228     isc_region_consume(&region, 1);
  229     tlsa->match = uint8_fromregion(&region);
  230     isc_region_consume(&region, 1);
  231     tlsa->length = region.length;
  232 
  233     tlsa->data = mem_maybedup(mctx, region.base, region.length);
  234     if (tlsa->data == NULL) {
  235         return (ISC_R_NOMEMORY);
  236     }
  237 
  238     tlsa->mctx = mctx;
  239     return (ISC_R_SUCCESS);
  240 }
  241 
  242 static inline void
  243 generic_freestruct_tlsa(ARGS_FREESTRUCT) {
  244     dns_rdata_tlsa_t *tlsa = source;
  245 
  246     REQUIRE(tlsa != NULL);
  247 
  248     if (tlsa->mctx == NULL) {
  249         return;
  250     }
  251 
  252     if (tlsa->data != NULL) {
  253         isc_mem_free(tlsa->mctx, tlsa->data);
  254     }
  255     tlsa->mctx = NULL;
  256 }
  257 
  258 static inline isc_result_t
  259 fromstruct_tlsa(ARGS_FROMSTRUCT) {
  260     REQUIRE(type == dns_rdatatype_tlsa);
  261 
  262     return (generic_fromstruct_tlsa(rdclass, type, source, target));
  263 }
  264 
  265 static inline isc_result_t
  266 tostruct_tlsa(ARGS_TOSTRUCT) {
  267     dns_rdata_tlsa_t *tlsa = target;
  268 
  269     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  270     REQUIRE(tlsa != NULL);
  271 
  272     tlsa->common.rdclass = rdata->rdclass;
  273     tlsa->common.rdtype = rdata->type;
  274     ISC_LINK_INIT(&tlsa->common, link);
  275 
  276     return (generic_tostruct_tlsa(rdata, target, mctx));
  277 }
  278 
  279 static inline void
  280 freestruct_tlsa(ARGS_FREESTRUCT) {
  281     dns_rdata_tlsa_t *tlsa = source;
  282 
  283     REQUIRE(tlsa != NULL);
  284     REQUIRE(tlsa->common.rdtype == dns_rdatatype_tlsa);
  285 
  286     generic_freestruct_tlsa(source);
  287 }
  288 
  289 static inline isc_result_t
  290 additionaldata_tlsa(ARGS_ADDLDATA) {
  291     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  292 
  293     UNUSED(rdata);
  294     UNUSED(add);
  295     UNUSED(arg);
  296 
  297     return (ISC_R_SUCCESS);
  298 }
  299 
  300 static inline isc_result_t
  301 digest_tlsa(ARGS_DIGEST) {
  302     isc_region_t r;
  303 
  304     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  305 
  306     dns_rdata_toregion(rdata, &r);
  307 
  308     return ((digest)(arg, &r));
  309 }
  310 
  311 static inline bool
  312 checkowner_tlsa(ARGS_CHECKOWNER) {
  313     REQUIRE(type == dns_rdatatype_tlsa);
  314 
  315     UNUSED(name);
  316     UNUSED(type);
  317     UNUSED(rdclass);
  318     UNUSED(wildcard);
  319 
  320     return (true);
  321 }
  322 
  323 static inline bool
  324 checknames_tlsa(ARGS_CHECKNAMES) {
  325     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  326 
  327     UNUSED(rdata);
  328     UNUSED(owner);
  329     UNUSED(bad);
  330 
  331     return (true);
  332 }
  333 
  334 static inline int
  335 casecompare_tlsa(ARGS_COMPARE) {
  336     return (compare_tlsa(rdata1, rdata2));
  337 }
  338 
  339 #endif /* RDATA_GENERIC_TLSA_52_C */