"Fossies" - the Fresh Open Source Software Archive

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