"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/rdata/generic/tlsa_52.c" (7 Sep 2020, 7493 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


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.11.22_vs_9.11.23.

    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     RETERR(uint8_tobuffer(token.value.as_ulong, target));
   37 
   38     /*
   39      * Selector.
   40      */
   41     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   42                       false));
   43     if (token.value.as_ulong > 0xffU)
   44         RETTOK(ISC_R_RANGE);
   45     RETERR(uint8_tobuffer(token.value.as_ulong, target));
   46 
   47     /*
   48      * Matching type.
   49      */
   50     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   51                       false));
   52     if (token.value.as_ulong > 0xffU)
   53         RETTOK(ISC_R_RANGE);
   54     RETERR(uint8_tobuffer(token.value.as_ulong, target));
   55 
   56     /*
   57      * Certificate Association Data.
   58      */
   59     return (isc_hex_tobuffer(lexer, target, -2));
   60 }
   61 
   62 static inline isc_result_t
   63 generic_totext_tlsa(ARGS_TOTEXT) {
   64     isc_region_t sr;
   65     char buf[sizeof("64000 ")];
   66     unsigned int n;
   67 
   68     REQUIRE(rdata->length != 0);
   69 
   70     UNUSED(tctx);
   71 
   72     dns_rdata_toregion(rdata, &sr);
   73 
   74     /*
   75      * Certificate Usage.
   76      */
   77     n = uint8_fromregion(&sr);
   78     isc_region_consume(&sr, 1);
   79     snprintf(buf, sizeof(buf), "%u ", n);
   80     RETERR(str_totext(buf, target));
   81 
   82     /*
   83      * Selector.
   84      */
   85     n = uint8_fromregion(&sr);
   86     isc_region_consume(&sr, 1);
   87     snprintf(buf, sizeof(buf), "%u ", n);
   88     RETERR(str_totext(buf, target));
   89 
   90     /*
   91      * Matching type.
   92      */
   93     n = uint8_fromregion(&sr);
   94     isc_region_consume(&sr, 1);
   95     snprintf(buf, sizeof(buf), "%u", n);
   96     RETERR(str_totext(buf, target));
   97 
   98     /*
   99      * Certificate Association Data.
  100      */
  101     if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
  102         RETERR(str_totext(" (", target));
  103     RETERR(str_totext(tctx->linebreak, target));
  104     if (tctx->width == 0) /* No splitting */
  105         RETERR(isc_hex_totext(&sr, 0, "", target));
  106     else
  107         RETERR(isc_hex_totext(&sr, tctx->width - 2,
  108                       tctx->linebreak, target));
  109     if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
  110         RETERR(str_totext(" )", target));
  111     return (ISC_R_SUCCESS);
  112 }
  113 
  114 static inline isc_result_t
  115 generic_fromwire_tlsa(ARGS_FROMWIRE) {
  116     isc_region_t sr;
  117 
  118     UNUSED(type);
  119     UNUSED(rdclass);
  120     UNUSED(dctx);
  121     UNUSED(options);
  122 
  123     isc_buffer_activeregion(source, &sr);
  124 
  125     /* Usage(1), Selector(1), Type(1), Data(1+) */
  126     if (sr.length < 4) {
  127         return (ISC_R_UNEXPECTEDEND);
  128     }
  129 
  130     isc_buffer_forward(source, sr.length);
  131     return (mem_tobuffer(target, sr.base, sr.length));
  132 }
  133 
  134 static inline isc_result_t
  135 fromtext_tlsa(ARGS_FROMTEXT) {
  136 
  137     REQUIRE(type == dns_rdatatype_tlsa);
  138 
  139     return (generic_fromtext_tlsa(rdclass, type, lexer, origin, options,
  140                       target, callbacks));
  141 }
  142 
  143 static inline isc_result_t
  144 totext_tlsa(ARGS_TOTEXT) {
  145 
  146     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  147 
  148     return (generic_totext_tlsa(rdata, tctx, target));
  149 }
  150 
  151 static inline isc_result_t
  152 fromwire_tlsa(ARGS_FROMWIRE) {
  153 
  154     REQUIRE(type == dns_rdatatype_tlsa);
  155 
  156     return (generic_fromwire_tlsa(rdclass, type, source, dctx, options,
  157                       target));
  158 }
  159 
  160 static inline isc_result_t
  161 towire_tlsa(ARGS_TOWIRE) {
  162     isc_region_t sr;
  163 
  164     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  165     REQUIRE(rdata->length != 0);
  166 
  167     UNUSED(cctx);
  168 
  169     dns_rdata_toregion(rdata, &sr);
  170     return (mem_tobuffer(target, sr.base, sr.length));
  171 }
  172 
  173 static inline int
  174 compare_tlsa(ARGS_COMPARE) {
  175     isc_region_t r1;
  176     isc_region_t r2;
  177 
  178     REQUIRE(rdata1->type == rdata2->type);
  179     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  180     REQUIRE(rdata1->type == dns_rdatatype_tlsa);
  181     REQUIRE(rdata1->length != 0);
  182     REQUIRE(rdata2->length != 0);
  183 
  184     dns_rdata_toregion(rdata1, &r1);
  185     dns_rdata_toregion(rdata2, &r2);
  186     return (isc_region_compare(&r1, &r2));
  187 }
  188 
  189 static inline isc_result_t
  190 generic_fromstruct_tlsa(ARGS_FROMSTRUCT) {
  191     dns_rdata_tlsa_t *tlsa;
  192 
  193     REQUIRE(((dns_rdata_tlsa_t *)source) != NULL);
  194     REQUIRE(((dns_rdata_tlsa_t *)source)->common.rdtype == type);
  195     REQUIRE(((dns_rdata_tlsa_t *)source)->common.rdclass == rdclass);
  196 
  197     tlsa = source;
  198 
  199     UNUSED(type);
  200     UNUSED(rdclass);
  201 
  202     RETERR(uint8_tobuffer(tlsa->usage, target));
  203     RETERR(uint8_tobuffer(tlsa->selector, target));
  204     RETERR(uint8_tobuffer(tlsa->match, target));
  205 
  206     return (mem_tobuffer(target, tlsa->data, tlsa->length));
  207 }
  208 
  209 static inline isc_result_t
  210 generic_tostruct_tlsa(ARGS_TOSTRUCT) {
  211     dns_rdata_tlsa_t *tlsa;
  212     isc_region_t region;
  213 
  214     REQUIRE(rdata->length != 0);
  215     REQUIRE(((dns_rdata_tlsa_t *)target) != NULL);
  216     REQUIRE(((dns_rdata_tlsa_t *)target)->common.rdclass == rdata->rdclass);
  217     REQUIRE(((dns_rdata_tlsa_t *)target)->common.rdtype == rdata->type);
  218     REQUIRE(!ISC_LINK_LINKED(&((dns_rdata_tlsa_t *)target)->common, link));
  219 
  220     tlsa = target;
  221 
  222     dns_rdata_toregion(rdata, &region);
  223 
  224     tlsa->usage = uint8_fromregion(&region);
  225     isc_region_consume(&region, 1);
  226     tlsa->selector = uint8_fromregion(&region);
  227     isc_region_consume(&region, 1);
  228     tlsa->match = uint8_fromregion(&region);
  229     isc_region_consume(&region, 1);
  230     tlsa->length = region.length;
  231 
  232     tlsa->data = mem_maybedup(mctx, region.base, region.length);
  233     if (tlsa->data == NULL)
  234         return (ISC_R_NOMEMORY);
  235 
  236     tlsa->mctx = mctx;
  237     return (ISC_R_SUCCESS);
  238 }
  239 
  240 static inline void
  241 generic_freestruct_tlsa(ARGS_FREESTRUCT) {
  242     dns_rdata_tlsa_t *tlsa;
  243 
  244     REQUIRE(((dns_rdata_tlsa_t *)source) != NULL);
  245 
  246     tlsa = source;
  247 
  248     if (tlsa->mctx == NULL)
  249         return;
  250 
  251     if (tlsa->data != NULL)
  252         isc_mem_free(tlsa->mctx, tlsa->data);
  253     tlsa->mctx = NULL;
  254 }
  255 
  256 static inline isc_result_t
  257 fromstruct_tlsa(ARGS_FROMSTRUCT) {
  258 
  259     REQUIRE(type == dns_rdatatype_tlsa);
  260 
  261     return (generic_fromstruct_tlsa(rdclass, type, source, target));
  262 }
  263 
  264 static inline isc_result_t
  265 tostruct_tlsa(ARGS_TOSTRUCT) {
  266     dns_rdata_tlsa_t *tlsa;
  267 
  268     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  269     REQUIRE(((dns_rdata_tlsa_t *)target) != NULL);
  270 
  271     tlsa = target;
  272 
  273     tlsa->common.rdclass = rdata->rdclass;
  274     tlsa->common.rdtype = rdata->type;
  275     ISC_LINK_INIT(&tlsa->common, link);
  276 
  277     return (generic_tostruct_tlsa(rdata, target, mctx));
  278 }
  279 
  280 static inline void
  281 freestruct_tlsa(ARGS_FREESTRUCT) {
  282     REQUIRE(((dns_rdata_tlsa_t *)source) != NULL);
  283     REQUIRE(((dns_rdata_tlsa_t *)source)->common.rdtype ==
  284         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 
  314     REQUIRE(type == dns_rdatatype_tlsa);
  315 
  316     UNUSED(name);
  317     UNUSED(type);
  318     UNUSED(rdclass);
  319     UNUSED(wildcard);
  320 
  321     return (true);
  322 }
  323 
  324 static inline bool
  325 checknames_tlsa(ARGS_CHECKNAMES) {
  326 
  327     REQUIRE(rdata->type == dns_rdatatype_tlsa);
  328 
  329     UNUSED(rdata);
  330     UNUSED(owner);
  331     UNUSED(bad);
  332 
  333     return (true);
  334 }
  335 
  336 static inline int
  337 casecompare_tlsa(ARGS_COMPARE) {
  338     return (compare_tlsa(rdata1, rdata2));
  339 }
  340 
  341 #endif  /* RDATA_GENERIC_TLSA_52_C */