"Fossies" - the Fresh Open Source Software Archive

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