"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/dns/rdata/generic/nsec_47.c" (4 Sep 2020, 6686 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.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 "nsec_47.c" see the Fossies "Dox" file reference documentation.

    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 /* RFC 3845 */
   13 
   14 #ifndef RDATA_GENERIC_NSEC_47_C
   15 #define RDATA_GENERIC_NSEC_47_C
   16 
   17 /*
   18  * The attributes do not include DNS_RDATATYPEATTR_SINGLETON
   19  * because we must be able to handle a parent/child NSEC pair.
   20  */
   21 #define RRTYPE_NSEC_ATTRIBUTES                                      \
   22     (DNS_RDATATYPEATTR_DNSSEC | DNS_RDATATYPEATTR_ZONECUTAUTH | \
   23      DNS_RDATATYPEATTR_ATCNAME)
   24 
   25 static inline isc_result_t
   26 fromtext_nsec(ARGS_FROMTEXT) {
   27     isc_token_t token;
   28     dns_name_t name;
   29     isc_buffer_t buffer;
   30 
   31     REQUIRE(type == dns_rdatatype_nsec);
   32 
   33     UNUSED(type);
   34     UNUSED(rdclass);
   35     UNUSED(callbacks);
   36 
   37     /*
   38      * Next domain.
   39      */
   40     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   41                       false));
   42     dns_name_init(&name, NULL);
   43     buffer_fromregion(&buffer, &token.value.as_region);
   44     if (origin == NULL) {
   45         origin = dns_rootname;
   46     }
   47     RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
   48 
   49     return (typemap_fromtext(lexer, target, false));
   50 }
   51 
   52 static inline isc_result_t
   53 totext_nsec(ARGS_TOTEXT) {
   54     isc_region_t sr;
   55     dns_name_t name;
   56 
   57     REQUIRE(rdata->type == dns_rdatatype_nsec);
   58     REQUIRE(rdata->length != 0);
   59 
   60     UNUSED(tctx);
   61 
   62     dns_name_init(&name, NULL);
   63     dns_rdata_toregion(rdata, &sr);
   64     dns_name_fromregion(&name, &sr);
   65     isc_region_consume(&sr, name_length(&name));
   66     RETERR(dns_name_totext(&name, false, target));
   67     /*
   68      * Don't leave a trailing space when there's no typemap present.
   69      */
   70     if (sr.length > 0) {
   71         RETERR(str_totext(" ", target));
   72     }
   73     return (typemap_totext(&sr, NULL, target));
   74 }
   75 
   76 static /* inline */ isc_result_t
   77 fromwire_nsec(ARGS_FROMWIRE) {
   78     isc_region_t sr;
   79     dns_name_t name;
   80 
   81     REQUIRE(type == dns_rdatatype_nsec);
   82 
   83     UNUSED(type);
   84     UNUSED(rdclass);
   85 
   86     dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
   87 
   88     dns_name_init(&name, NULL);
   89     RETERR(dns_name_fromwire(&name, source, dctx, options, target));
   90 
   91     isc_buffer_activeregion(source, &sr);
   92     RETERR(typemap_test(&sr, false));
   93     RETERR(mem_tobuffer(target, sr.base, sr.length));
   94     isc_buffer_forward(source, sr.length);
   95     return (ISC_R_SUCCESS);
   96 }
   97 
   98 static inline isc_result_t
   99 towire_nsec(ARGS_TOWIRE) {
  100     isc_region_t sr;
  101     dns_name_t name;
  102     dns_offsets_t offsets;
  103 
  104     REQUIRE(rdata->type == dns_rdatatype_nsec);
  105     REQUIRE(rdata->length != 0);
  106 
  107     dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
  108     dns_name_init(&name, offsets);
  109     dns_rdata_toregion(rdata, &sr);
  110     dns_name_fromregion(&name, &sr);
  111     isc_region_consume(&sr, name_length(&name));
  112     RETERR(dns_name_towire(&name, cctx, target));
  113 
  114     return (mem_tobuffer(target, sr.base, sr.length));
  115 }
  116 
  117 static inline int
  118 compare_nsec(ARGS_COMPARE) {
  119     isc_region_t r1;
  120     isc_region_t r2;
  121 
  122     REQUIRE(rdata1->type == rdata2->type);
  123     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  124     REQUIRE(rdata1->type == dns_rdatatype_nsec);
  125     REQUIRE(rdata1->length != 0);
  126     REQUIRE(rdata2->length != 0);
  127 
  128     dns_rdata_toregion(rdata1, &r1);
  129     dns_rdata_toregion(rdata2, &r2);
  130     return (isc_region_compare(&r1, &r2));
  131 }
  132 
  133 static inline isc_result_t
  134 fromstruct_nsec(ARGS_FROMSTRUCT) {
  135     dns_rdata_nsec_t *nsec = source;
  136     isc_region_t region;
  137 
  138     REQUIRE(type == dns_rdatatype_nsec);
  139     REQUIRE(nsec != NULL);
  140     REQUIRE(nsec->common.rdtype == type);
  141     REQUIRE(nsec->common.rdclass == rdclass);
  142     REQUIRE(nsec->typebits != NULL || nsec->len == 0);
  143 
  144     UNUSED(type);
  145     UNUSED(rdclass);
  146 
  147     dns_name_toregion(&nsec->next, &region);
  148     RETERR(isc_buffer_copyregion(target, &region));
  149 
  150     region.base = nsec->typebits;
  151     region.length = nsec->len;
  152     RETERR(typemap_test(&region, false));
  153     return (mem_tobuffer(target, nsec->typebits, nsec->len));
  154 }
  155 
  156 static inline isc_result_t
  157 tostruct_nsec(ARGS_TOSTRUCT) {
  158     isc_region_t region;
  159     dns_rdata_nsec_t *nsec = target;
  160     dns_name_t name;
  161 
  162     REQUIRE(rdata->type == dns_rdatatype_nsec);
  163     REQUIRE(nsec != NULL);
  164     REQUIRE(rdata->length != 0);
  165 
  166     nsec->common.rdclass = rdata->rdclass;
  167     nsec->common.rdtype = rdata->type;
  168     ISC_LINK_INIT(&nsec->common, link);
  169 
  170     dns_name_init(&name, NULL);
  171     dns_rdata_toregion(rdata, &region);
  172     dns_name_fromregion(&name, &region);
  173     isc_region_consume(&region, name_length(&name));
  174     dns_name_init(&nsec->next, NULL);
  175     RETERR(name_duporclone(&name, mctx, &nsec->next));
  176 
  177     nsec->len = region.length;
  178     nsec->typebits = mem_maybedup(mctx, region.base, region.length);
  179     if (nsec->typebits == NULL) {
  180         goto cleanup;
  181     }
  182 
  183     nsec->mctx = mctx;
  184     return (ISC_R_SUCCESS);
  185 
  186 cleanup:
  187     if (mctx != NULL) {
  188         dns_name_free(&nsec->next, mctx);
  189     }
  190     return (ISC_R_NOMEMORY);
  191 }
  192 
  193 static inline void
  194 freestruct_nsec(ARGS_FREESTRUCT) {
  195     dns_rdata_nsec_t *nsec = source;
  196 
  197     REQUIRE(nsec != NULL);
  198     REQUIRE(nsec->common.rdtype == dns_rdatatype_nsec);
  199 
  200     if (nsec->mctx == NULL) {
  201         return;
  202     }
  203 
  204     dns_name_free(&nsec->next, nsec->mctx);
  205     if (nsec->typebits != NULL) {
  206         isc_mem_free(nsec->mctx, nsec->typebits);
  207     }
  208     nsec->mctx = NULL;
  209 }
  210 
  211 static inline isc_result_t
  212 additionaldata_nsec(ARGS_ADDLDATA) {
  213     REQUIRE(rdata->type == dns_rdatatype_nsec);
  214 
  215     UNUSED(rdata);
  216     UNUSED(add);
  217     UNUSED(arg);
  218 
  219     return (ISC_R_SUCCESS);
  220 }
  221 
  222 static inline isc_result_t
  223 digest_nsec(ARGS_DIGEST) {
  224     isc_region_t r;
  225 
  226     REQUIRE(rdata->type == dns_rdatatype_nsec);
  227 
  228     dns_rdata_toregion(rdata, &r);
  229     return ((digest)(arg, &r));
  230 }
  231 
  232 static inline bool
  233 checkowner_nsec(ARGS_CHECKOWNER) {
  234     REQUIRE(type == dns_rdatatype_nsec);
  235 
  236     UNUSED(name);
  237     UNUSED(type);
  238     UNUSED(rdclass);
  239     UNUSED(wildcard);
  240 
  241     return (true);
  242 }
  243 
  244 static inline bool
  245 checknames_nsec(ARGS_CHECKNAMES) {
  246     REQUIRE(rdata->type == dns_rdatatype_nsec);
  247 
  248     UNUSED(rdata);
  249     UNUSED(owner);
  250     UNUSED(bad);
  251 
  252     return (true);
  253 }
  254 
  255 static inline int
  256 casecompare_nsec(ARGS_COMPARE) {
  257     isc_region_t region1;
  258     isc_region_t region2;
  259     dns_name_t name1;
  260     dns_name_t name2;
  261     int order;
  262 
  263     REQUIRE(rdata1->type == rdata2->type);
  264     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  265     REQUIRE(rdata1->type == dns_rdatatype_nsec);
  266     REQUIRE(rdata1->length != 0);
  267     REQUIRE(rdata2->length != 0);
  268 
  269     dns_name_init(&name1, NULL);
  270     dns_name_init(&name2, NULL);
  271 
  272     dns_rdata_toregion(rdata1, &region1);
  273     dns_rdata_toregion(rdata2, &region2);
  274 
  275     dns_name_fromregion(&name1, &region1);
  276     dns_name_fromregion(&name2, &region2);
  277 
  278     order = dns_name_rdatacompare(&name1, &name2);
  279     if (order != 0) {
  280         return (order);
  281     }
  282 
  283     isc_region_consume(&region1, name_length(&name1));
  284     isc_region_consume(&region2, name_length(&name2));
  285 
  286     return (isc_region_compare(&region1, &region2));
  287 }
  288 #endif /* RDATA_GENERIC_NSEC_47_C */