"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/rdata/generic/nxt_30.c" (7 Sep 2020, 7939 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 "nxt_30.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 /* RFC2535 */
   13 
   14 #ifndef RDATA_GENERIC_NXT_30_C
   15 #define RDATA_GENERIC_NXT_30_C
   16 
   17 /*
   18  * The attributes do not include DNS_RDATATYPEATTR_SINGLETON
   19  * because we must be able to handle a parent/child NXT pair.
   20  */
   21 #define RRTYPE_NXT_ATTRIBUTES (0)
   22 
   23 static inline isc_result_t
   24 fromtext_nxt(ARGS_FROMTEXT) {
   25     isc_token_t token;
   26     dns_name_t name;
   27     isc_buffer_t buffer;
   28     char *e;
   29     unsigned char bm[8*1024]; /* 64k bits */
   30     dns_rdatatype_t covered;
   31     dns_rdatatype_t maxcovered = 0;
   32     bool first = true;
   33     long n;
   34 
   35     REQUIRE(type == dns_rdatatype_nxt);
   36 
   37     UNUSED(type);
   38     UNUSED(rdclass);
   39     UNUSED(callbacks);
   40 
   41     /*
   42      * Next domain.
   43      */
   44     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   45                       false));
   46     dns_name_init(&name, NULL);
   47     buffer_fromregion(&buffer, &token.value.as_region);
   48     if (origin == NULL)
   49         origin = dns_rootname;
   50     RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
   51 
   52     memset(bm, 0, sizeof(bm));
   53     do {
   54         RETERR(isc_lex_getmastertoken(lexer, &token,
   55                           isc_tokentype_string, true));
   56         if (token.type != isc_tokentype_string)
   57             break;
   58         n = strtol(DNS_AS_STR(token), &e, 10);
   59         if (e != DNS_AS_STR(token) && *e == '\0') {
   60             covered = (dns_rdatatype_t)n;
   61         } else if (dns_rdatatype_fromtext(&covered,
   62                 &token.value.as_textregion) == DNS_R_UNKNOWN)
   63             RETTOK(DNS_R_UNKNOWN);
   64         /*
   65          * NXT is only specified for types 1..127.
   66          */
   67         if (covered < 1 || covered > 127)
   68             return (ISC_R_RANGE);
   69         if (first || covered > maxcovered)
   70             maxcovered = covered;
   71         first = false;
   72         bm[covered/8] |= (0x80>>(covered%8));
   73     } while (1);
   74     isc_lex_ungettoken(lexer, &token);
   75     if (first)
   76         return (ISC_R_SUCCESS);
   77     n = (maxcovered + 8) / 8;
   78     return (mem_tobuffer(target, bm, n));
   79 }
   80 
   81 static inline isc_result_t
   82 totext_nxt(ARGS_TOTEXT) {
   83     isc_region_t sr;
   84     unsigned int i, j;
   85     dns_name_t name;
   86     dns_name_t prefix;
   87     bool sub;
   88 
   89     REQUIRE(rdata->type == dns_rdatatype_nxt);
   90     REQUIRE(rdata->length != 0);
   91 
   92     dns_name_init(&name, NULL);
   93     dns_name_init(&prefix, NULL);
   94     dns_rdata_toregion(rdata, &sr);
   95     dns_name_fromregion(&name, &sr);
   96     isc_region_consume(&sr, name_length(&name));
   97     sub = name_prefix(&name, tctx->origin, &prefix);
   98     RETERR(dns_name_totext(&prefix, sub, target));
   99 
  100     for (i = 0; i < sr.length; i++) {
  101         if (sr.base[i] != 0)
  102             for (j = 0; j < 8; j++)
  103                 if ((sr.base[i] & (0x80 >> j)) != 0) {
  104                     dns_rdatatype_t t = i * 8 + j;
  105                     RETERR(str_totext(" ", target));
  106                     if (dns_rdatatype_isknown(t)) {
  107                         RETERR(dns_rdatatype_totext(t,
  108                                       target));
  109                     } else {
  110                         char buf[sizeof("65535")];
  111                         snprintf(buf, sizeof(buf),
  112                              "%u", t);
  113                         RETERR(str_totext(buf,
  114                                   target));
  115                     }
  116                 }
  117     }
  118     return (ISC_R_SUCCESS);
  119 }
  120 
  121 static inline isc_result_t
  122 fromwire_nxt(ARGS_FROMWIRE) {
  123     isc_region_t sr;
  124     dns_name_t name;
  125 
  126     REQUIRE(type == dns_rdatatype_nxt);
  127 
  128     UNUSED(type);
  129     UNUSED(rdclass);
  130 
  131     dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
  132 
  133     dns_name_init(&name, NULL);
  134     RETERR(dns_name_fromwire(&name, source, dctx, options, target));
  135 
  136     isc_buffer_activeregion(source, &sr);
  137     if (sr.length > 0 && ((sr.base[0] & 0x80) != 0 || sr.length > 16 ||
  138                   sr.base[sr.length - 1] == 0))
  139     {
  140         return (DNS_R_BADBITMAP);
  141     }
  142     RETERR(mem_tobuffer(target, sr.base, sr.length));
  143     isc_buffer_forward(source, sr.length);
  144     return (ISC_R_SUCCESS);
  145 }
  146 
  147 static inline isc_result_t
  148 towire_nxt(ARGS_TOWIRE) {
  149     isc_region_t sr;
  150     dns_name_t name;
  151     dns_offsets_t offsets;
  152 
  153     REQUIRE(rdata->type == dns_rdatatype_nxt);
  154     REQUIRE(rdata->length != 0);
  155 
  156     dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
  157     dns_name_init(&name, offsets);
  158     dns_rdata_toregion(rdata, &sr);
  159     dns_name_fromregion(&name, &sr);
  160     isc_region_consume(&sr, name_length(&name));
  161     RETERR(dns_name_towire(&name, cctx, target));
  162 
  163     return (mem_tobuffer(target, sr.base, sr.length));
  164 }
  165 
  166 static inline int
  167 compare_nxt(ARGS_COMPARE) {
  168     isc_region_t r1;
  169     isc_region_t r2;
  170     dns_name_t name1;
  171     dns_name_t name2;
  172     int order;
  173 
  174     REQUIRE(rdata1->type == rdata2->type);
  175     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  176     REQUIRE(rdata1->type == dns_rdatatype_nxt);
  177     REQUIRE(rdata1->length != 0);
  178     REQUIRE(rdata2->length != 0);
  179 
  180     dns_name_init(&name1, NULL);
  181     dns_name_init(&name2, NULL);
  182     dns_rdata_toregion(rdata1, &r1);
  183     dns_rdata_toregion(rdata2, &r2);
  184     dns_name_fromregion(&name1, &r1);
  185     dns_name_fromregion(&name2, &r2);
  186     order = dns_name_rdatacompare(&name1, &name2);
  187     if (order != 0)
  188         return (order);
  189 
  190     isc_region_consume(&r1, name_length(&name1));
  191     isc_region_consume(&r2, name_length(&name2));
  192 
  193     return (isc_region_compare(&r1, &r2));
  194 }
  195 
  196 static inline isc_result_t
  197 fromstruct_nxt(ARGS_FROMSTRUCT) {
  198     dns_rdata_nxt_t *nxt;
  199     isc_region_t region;
  200 
  201     REQUIRE(type == dns_rdatatype_nxt);
  202     REQUIRE(((dns_rdata_nxt_t *)source) != NULL);
  203     nxt = source;
  204     REQUIRE(nxt->common.rdtype == type);
  205     REQUIRE(nxt->common.rdclass == rdclass);
  206     REQUIRE(nxt->typebits != NULL || nxt->len == 0);
  207 
  208     if (nxt->typebits != NULL && (nxt->typebits[0] & 0x80) == 0) {
  209         REQUIRE(nxt->len <= 16);
  210         REQUIRE(nxt->typebits[nxt->len - 1] != 0);
  211     }
  212 
  213     UNUSED(type);
  214     UNUSED(rdclass);
  215 
  216     dns_name_toregion(&nxt->next, &region);
  217     RETERR(isc_buffer_copyregion(target, &region));
  218 
  219     return (mem_tobuffer(target, nxt->typebits, nxt->len));
  220 }
  221 
  222 static inline isc_result_t
  223 tostruct_nxt(ARGS_TOSTRUCT) {
  224     isc_region_t region;
  225     dns_rdata_nxt_t *nxt;
  226     dns_name_t name;
  227 
  228     REQUIRE(((dns_rdata_nxt_t *)target) != NULL);
  229     REQUIRE(rdata->type == dns_rdatatype_nxt);
  230     REQUIRE(rdata->length != 0);
  231 
  232     nxt = target;
  233 
  234     nxt->common.rdclass = rdata->rdclass;
  235     nxt->common.rdtype = rdata->type;
  236     ISC_LINK_INIT(&nxt->common, link);
  237 
  238     dns_name_init(&name, NULL);
  239     dns_rdata_toregion(rdata, &region);
  240     dns_name_fromregion(&name, &region);
  241     isc_region_consume(&region, name_length(&name));
  242     dns_name_init(&nxt->next, NULL);
  243     RETERR(name_duporclone(&name, mctx, &nxt->next));
  244 
  245     nxt->len = region.length;
  246     nxt->typebits = mem_maybedup(mctx, region.base, region.length);
  247     if (nxt->typebits == NULL)
  248         goto cleanup;
  249 
  250     nxt->mctx = mctx;
  251     return (ISC_R_SUCCESS);
  252 
  253  cleanup:
  254     if (mctx != NULL)
  255         dns_name_free(&nxt->next, mctx);
  256     return (ISC_R_NOMEMORY);
  257 }
  258 
  259 static inline void
  260 freestruct_nxt(ARGS_FREESTRUCT) {
  261     dns_rdata_nxt_t *nxt;
  262 
  263     REQUIRE(((dns_rdata_nxt_t *)source) != NULL);
  264     REQUIRE(((dns_rdata_nxt_t *)source)->common.rdtype ==
  265         dns_rdatatype_nxt);
  266 
  267     nxt = source;
  268 
  269     if (nxt->mctx == NULL)
  270         return;
  271 
  272     dns_name_free(&nxt->next, nxt->mctx);
  273     if (nxt->typebits != NULL)
  274         isc_mem_free(nxt->mctx, nxt->typebits);
  275     nxt->mctx = NULL;
  276 }
  277 
  278 static inline isc_result_t
  279 additionaldata_nxt(ARGS_ADDLDATA) {
  280     REQUIRE(rdata->type == dns_rdatatype_nxt);
  281 
  282     UNUSED(rdata);
  283     UNUSED(add);
  284     UNUSED(arg);
  285 
  286     return (ISC_R_SUCCESS);
  287 }
  288 
  289 static inline isc_result_t
  290 digest_nxt(ARGS_DIGEST) {
  291     isc_region_t r;
  292     dns_name_t name;
  293     isc_result_t result;
  294 
  295     REQUIRE(rdata->type == dns_rdatatype_nxt);
  296 
  297     dns_rdata_toregion(rdata, &r);
  298     dns_name_init(&name, NULL);
  299     dns_name_fromregion(&name, &r);
  300     result = dns_name_digest(&name, digest, arg);
  301     if (result != ISC_R_SUCCESS)
  302         return (result);
  303     isc_region_consume(&r, name_length(&name));
  304 
  305     return ((digest)(arg, &r));
  306 }
  307 
  308 static inline bool
  309 checkowner_nxt(ARGS_CHECKOWNER) {
  310 
  311     REQUIRE(type == dns_rdatatype_nxt);
  312 
  313     UNUSED(name);
  314     UNUSED(type);
  315     UNUSED(rdclass);
  316     UNUSED(wildcard);
  317 
  318     return (true);
  319 }
  320 
  321 static inline bool
  322 checknames_nxt(ARGS_CHECKNAMES) {
  323 
  324     REQUIRE(rdata->type == dns_rdatatype_nxt);
  325 
  326     UNUSED(rdata);
  327     UNUSED(owner);
  328     UNUSED(bad);
  329 
  330     return (true);
  331 }
  332 
  333 static inline int
  334 casecompare_nxt(ARGS_COMPARE) {
  335     return (compare_nxt(rdata1, rdata2));
  336 }
  337 #endif  /* RDATA_GENERIC_NXT_30_C */