"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/rdata/generic/ns_2.c" (7 Sep 2020, 5607 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 "ns_2.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 #ifndef RDATA_GENERIC_NS_2_C
   13 #define RDATA_GENERIC_NS_2_C
   14 
   15 #define RRTYPE_NS_ATTRIBUTES (DNS_RDATATYPEATTR_ZONECUTAUTH)
   16 
   17 static inline isc_result_t
   18 fromtext_ns(ARGS_FROMTEXT) {
   19     isc_token_t token;
   20     dns_name_t name;
   21     isc_buffer_t buffer;
   22     bool ok;
   23 
   24     REQUIRE(type == dns_rdatatype_ns);
   25 
   26     UNUSED(type);
   27     UNUSED(rdclass);
   28     UNUSED(callbacks);
   29 
   30     RETERR(isc_lex_getmastertoken(lexer, &token,isc_tokentype_string,
   31                       false));
   32 
   33     dns_name_init(&name, NULL);
   34     buffer_fromregion(&buffer, &token.value.as_region);
   35     if (origin == NULL)
   36         origin = dns_rootname;
   37     RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
   38     ok = true;
   39     if ((options & DNS_RDATA_CHECKNAMES) != 0)
   40         ok = dns_name_ishostname(&name, false);
   41     if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
   42         RETTOK(DNS_R_BADNAME);
   43     if (!ok && callbacks != NULL)
   44         warn_badname(&name, lexer, callbacks);
   45     return (ISC_R_SUCCESS);
   46 }
   47 
   48 static inline isc_result_t
   49 totext_ns(ARGS_TOTEXT) {
   50     isc_region_t region;
   51     dns_name_t name;
   52     dns_name_t prefix;
   53     bool sub;
   54 
   55     REQUIRE(rdata->type == dns_rdatatype_ns);
   56     REQUIRE(rdata->length != 0);
   57 
   58     dns_name_init(&name, NULL);
   59     dns_name_init(&prefix, NULL);
   60 
   61     dns_rdata_toregion(rdata, &region);
   62     dns_name_fromregion(&name, &region);
   63 
   64     sub = name_prefix(&name, tctx->origin, &prefix);
   65 
   66     return (dns_name_totext(&prefix, sub, target));
   67 }
   68 
   69 static inline isc_result_t
   70 fromwire_ns(ARGS_FROMWIRE) {
   71     dns_name_t name;
   72 
   73     REQUIRE(type == dns_rdatatype_ns);
   74 
   75     UNUSED(type);
   76     UNUSED(rdclass);
   77 
   78     dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
   79 
   80     dns_name_init(&name, NULL);
   81     return (dns_name_fromwire(&name, source, dctx, options, target));
   82 }
   83 
   84 static inline isc_result_t
   85 towire_ns(ARGS_TOWIRE) {
   86     dns_name_t name;
   87     dns_offsets_t offsets;
   88     isc_region_t region;
   89 
   90     REQUIRE(rdata->type == dns_rdatatype_ns);
   91     REQUIRE(rdata->length != 0);
   92 
   93     dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
   94 
   95     dns_name_init(&name, offsets);
   96     dns_rdata_toregion(rdata, &region);
   97     dns_name_fromregion(&name, &region);
   98 
   99     return (dns_name_towire(&name, cctx, target));
  100 }
  101 
  102 static inline int
  103 compare_ns(ARGS_COMPARE) {
  104     dns_name_t name1;
  105     dns_name_t name2;
  106     isc_region_t region1;
  107     isc_region_t region2;
  108 
  109     REQUIRE(rdata1->type == rdata2->type);
  110     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  111     REQUIRE(rdata1->type == dns_rdatatype_ns);
  112     REQUIRE(rdata1->length != 0);
  113     REQUIRE(rdata2->length != 0);
  114 
  115     dns_name_init(&name1, NULL);
  116     dns_name_init(&name2, NULL);
  117 
  118     dns_rdata_toregion(rdata1, &region1);
  119     dns_rdata_toregion(rdata2, &region2);
  120 
  121     dns_name_fromregion(&name1, &region1);
  122     dns_name_fromregion(&name2, &region2);
  123 
  124     return (dns_name_rdatacompare(&name1, &name2));
  125 }
  126 
  127 static inline isc_result_t
  128 fromstruct_ns(ARGS_FROMSTRUCT) {
  129     dns_rdata_ns_t *ns;
  130     isc_region_t region;
  131 
  132     REQUIRE(type == dns_rdatatype_ns);
  133     REQUIRE(((dns_rdata_ns_t *)source) != NULL);
  134     REQUIRE(((dns_rdata_ns_t *)source)->common.rdtype == type);
  135     REQUIRE(((dns_rdata_ns_t *)source)->common.rdclass == rdclass);
  136 
  137     ns = source;
  138 
  139     UNUSED(type);
  140     UNUSED(rdclass);
  141 
  142     dns_name_toregion(&ns->name, &region);
  143     return (isc_buffer_copyregion(target, &region));
  144 }
  145 
  146 static inline isc_result_t
  147 tostruct_ns(ARGS_TOSTRUCT) {
  148     isc_region_t region;
  149     dns_rdata_ns_t *ns;
  150     dns_name_t name;
  151 
  152     REQUIRE(((dns_rdata_ns_t *)target) != NULL);
  153     REQUIRE(rdata->type == dns_rdatatype_ns);
  154     REQUIRE(rdata->length != 0);
  155 
  156     ns = target;
  157 
  158     ns->common.rdclass = rdata->rdclass;
  159     ns->common.rdtype = rdata->type;
  160     ISC_LINK_INIT(&ns->common, link);
  161 
  162     dns_name_init(&name, NULL);
  163     dns_rdata_toregion(rdata, &region);
  164     dns_name_fromregion(&name, &region);
  165     dns_name_init(&ns->name, NULL);
  166     RETERR(name_duporclone(&name, mctx, &ns->name));
  167     ns->mctx = mctx;
  168     return (ISC_R_SUCCESS);
  169 }
  170 
  171 static inline void
  172 freestruct_ns(ARGS_FREESTRUCT) {
  173     dns_rdata_ns_t *ns;
  174 
  175     REQUIRE(((dns_rdata_ns_t *)source) != NULL);
  176 
  177     ns = source;
  178 
  179     if (ns->mctx == NULL)
  180         return;
  181 
  182     dns_name_free(&ns->name, ns->mctx);
  183     ns->mctx = NULL;
  184 }
  185 
  186 static inline isc_result_t
  187 additionaldata_ns(ARGS_ADDLDATA) {
  188     dns_name_t name;
  189     dns_offsets_t offsets;
  190     isc_region_t region;
  191 
  192     REQUIRE(rdata->type == dns_rdatatype_ns);
  193 
  194     dns_name_init(&name, offsets);
  195     dns_rdata_toregion(rdata, &region);
  196     dns_name_fromregion(&name, &region);
  197 
  198     return ((add)(arg, &name, dns_rdatatype_a));
  199 }
  200 
  201 static inline isc_result_t
  202 digest_ns(ARGS_DIGEST) {
  203     isc_region_t r;
  204     dns_name_t name;
  205 
  206     REQUIRE(rdata->type == dns_rdatatype_ns);
  207 
  208     dns_rdata_toregion(rdata, &r);
  209     dns_name_init(&name, NULL);
  210     dns_name_fromregion(&name, &r);
  211 
  212     return (dns_name_digest(&name, digest, arg));
  213 }
  214 
  215 static inline bool
  216 checkowner_ns(ARGS_CHECKOWNER) {
  217 
  218     REQUIRE(type == dns_rdatatype_ns);
  219 
  220     UNUSED(name);
  221     UNUSED(type);
  222     UNUSED(rdclass);
  223     UNUSED(wildcard);
  224 
  225     return (true);
  226 }
  227 
  228 static inline bool
  229 checknames_ns(ARGS_CHECKNAMES) {
  230     isc_region_t region;
  231     dns_name_t name;
  232 
  233     REQUIRE(rdata->type == dns_rdatatype_ns);
  234 
  235     UNUSED(owner);
  236 
  237     dns_rdata_toregion(rdata, &region);
  238     dns_name_init(&name, NULL);
  239     dns_name_fromregion(&name, &region);
  240     if (!dns_name_ishostname(&name, false)) {
  241         if (bad != NULL)
  242             dns_name_clone(&name, bad);
  243         return (false);
  244     }
  245     return (true);
  246 }
  247 
  248 static inline int
  249 casecompare_ns(ARGS_COMPARE) {
  250     return (compare_ns(rdata1, rdata2));
  251 }
  252 
  253 #endif  /* RDATA_GENERIC_NS_2_C */