"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/dns/rdata/in_1/kx_36.c" (4 Sep 2020, 6780 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 "kx_36.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 /* RFC2230 */
   13 
   14 #ifndef RDATA_IN_1_KX_36_C
   15 #define RDATA_IN_1_KX_36_C
   16 
   17 #define RRTYPE_KX_ATTRIBUTES (0)
   18 
   19 static inline isc_result_t
   20 fromtext_in_kx(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22     dns_name_t name;
   23     isc_buffer_t buffer;
   24 
   25     REQUIRE(type == dns_rdatatype_kx);
   26     REQUIRE(rdclass == dns_rdataclass_in);
   27 
   28     UNUSED(type);
   29     UNUSED(rdclass);
   30     UNUSED(callbacks);
   31 
   32     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   33                       false));
   34     if (token.value.as_ulong > 0xffffU) {
   35         RETTOK(ISC_R_RANGE);
   36     }
   37     RETERR(uint16_tobuffer(token.value.as_ulong, target));
   38 
   39     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   40                       false));
   41     dns_name_init(&name, NULL);
   42     buffer_fromregion(&buffer, &token.value.as_region);
   43     if (origin == NULL) {
   44         origin = dns_rootname;
   45     }
   46     RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
   47     return (ISC_R_SUCCESS);
   48 }
   49 
   50 static inline isc_result_t
   51 totext_in_kx(ARGS_TOTEXT) {
   52     isc_region_t region;
   53     dns_name_t name;
   54     dns_name_t prefix;
   55     bool sub;
   56     char buf[sizeof("64000")];
   57     unsigned short num;
   58 
   59     REQUIRE(rdata->type == dns_rdatatype_kx);
   60     REQUIRE(rdata->rdclass == dns_rdataclass_in);
   61     REQUIRE(rdata->length != 0);
   62 
   63     dns_name_init(&name, NULL);
   64     dns_name_init(&prefix, NULL);
   65 
   66     dns_rdata_toregion(rdata, &region);
   67     num = uint16_fromregion(&region);
   68     isc_region_consume(&region, 2);
   69     snprintf(buf, sizeof(buf), "%u", num);
   70     RETERR(str_totext(buf, target));
   71 
   72     RETERR(str_totext(" ", target));
   73 
   74     dns_name_fromregion(&name, &region);
   75     sub = name_prefix(&name, tctx->origin, &prefix);
   76     return (dns_name_totext(&prefix, sub, target));
   77 }
   78 
   79 static inline isc_result_t
   80 fromwire_in_kx(ARGS_FROMWIRE) {
   81     dns_name_t name;
   82     isc_region_t sregion;
   83 
   84     REQUIRE(type == dns_rdatatype_kx);
   85     REQUIRE(rdclass == dns_rdataclass_in);
   86 
   87     UNUSED(type);
   88     UNUSED(rdclass);
   89 
   90     dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
   91 
   92     dns_name_init(&name, NULL);
   93 
   94     isc_buffer_activeregion(source, &sregion);
   95     if (sregion.length < 2) {
   96         return (ISC_R_UNEXPECTEDEND);
   97     }
   98     RETERR(mem_tobuffer(target, sregion.base, 2));
   99     isc_buffer_forward(source, 2);
  100     return (dns_name_fromwire(&name, source, dctx, options, target));
  101 }
  102 
  103 static inline isc_result_t
  104 towire_in_kx(ARGS_TOWIRE) {
  105     dns_name_t name;
  106     dns_offsets_t offsets;
  107     isc_region_t region;
  108 
  109     REQUIRE(rdata->type == dns_rdatatype_kx);
  110     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  111     REQUIRE(rdata->length != 0);
  112 
  113     dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
  114     dns_rdata_toregion(rdata, &region);
  115     RETERR(mem_tobuffer(target, region.base, 2));
  116     isc_region_consume(&region, 2);
  117 
  118     dns_name_init(&name, offsets);
  119     dns_name_fromregion(&name, &region);
  120 
  121     return (dns_name_towire(&name, cctx, target));
  122 }
  123 
  124 static inline int
  125 compare_in_kx(ARGS_COMPARE) {
  126     dns_name_t name1;
  127     dns_name_t name2;
  128     isc_region_t region1;
  129     isc_region_t region2;
  130     int order;
  131 
  132     REQUIRE(rdata1->type == rdata2->type);
  133     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  134     REQUIRE(rdata1->type == dns_rdatatype_kx);
  135     REQUIRE(rdata1->rdclass == dns_rdataclass_in);
  136     REQUIRE(rdata1->length != 0);
  137     REQUIRE(rdata2->length != 0);
  138 
  139     order = memcmp(rdata1->data, rdata2->data, 2);
  140     if (order != 0) {
  141         return (order < 0 ? -1 : 1);
  142     }
  143 
  144     dns_name_init(&name1, NULL);
  145     dns_name_init(&name2, NULL);
  146 
  147     dns_rdata_toregion(rdata1, &region1);
  148     dns_rdata_toregion(rdata2, &region2);
  149 
  150     isc_region_consume(&region1, 2);
  151     isc_region_consume(&region2, 2);
  152 
  153     dns_name_fromregion(&name1, &region1);
  154     dns_name_fromregion(&name2, &region2);
  155 
  156     return (dns_name_rdatacompare(&name1, &name2));
  157 }
  158 
  159 static inline isc_result_t
  160 fromstruct_in_kx(ARGS_FROMSTRUCT) {
  161     dns_rdata_in_kx_t *kx = source;
  162     isc_region_t region;
  163 
  164     REQUIRE(type == dns_rdatatype_kx);
  165     REQUIRE(rdclass == dns_rdataclass_in);
  166     REQUIRE(kx != NULL);
  167     REQUIRE(kx->common.rdtype == type);
  168     REQUIRE(kx->common.rdclass == rdclass);
  169 
  170     UNUSED(type);
  171     UNUSED(rdclass);
  172 
  173     RETERR(uint16_tobuffer(kx->preference, target));
  174     dns_name_toregion(&kx->exchange, &region);
  175     return (isc_buffer_copyregion(target, &region));
  176 }
  177 
  178 static inline isc_result_t
  179 tostruct_in_kx(ARGS_TOSTRUCT) {
  180     isc_region_t region;
  181     dns_rdata_in_kx_t *kx = target;
  182     dns_name_t name;
  183 
  184     REQUIRE(rdata->type == dns_rdatatype_kx);
  185     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  186     REQUIRE(kx != NULL);
  187     REQUIRE(rdata->length != 0);
  188 
  189     kx->common.rdclass = rdata->rdclass;
  190     kx->common.rdtype = rdata->type;
  191     ISC_LINK_INIT(&kx->common, link);
  192 
  193     dns_name_init(&name, NULL);
  194     dns_rdata_toregion(rdata, &region);
  195 
  196     kx->preference = uint16_fromregion(&region);
  197     isc_region_consume(&region, 2);
  198 
  199     dns_name_fromregion(&name, &region);
  200     dns_name_init(&kx->exchange, NULL);
  201     RETERR(name_duporclone(&name, mctx, &kx->exchange));
  202     kx->mctx = mctx;
  203     return (ISC_R_SUCCESS);
  204 }
  205 
  206 static inline void
  207 freestruct_in_kx(ARGS_FREESTRUCT) {
  208     dns_rdata_in_kx_t *kx = source;
  209 
  210     REQUIRE(kx != NULL);
  211     REQUIRE(kx->common.rdclass == dns_rdataclass_in);
  212     REQUIRE(kx->common.rdtype == dns_rdatatype_kx);
  213 
  214     if (kx->mctx == NULL) {
  215         return;
  216     }
  217 
  218     dns_name_free(&kx->exchange, kx->mctx);
  219     kx->mctx = NULL;
  220 }
  221 
  222 static inline isc_result_t
  223 additionaldata_in_kx(ARGS_ADDLDATA) {
  224     dns_name_t name;
  225     dns_offsets_t offsets;
  226     isc_region_t region;
  227 
  228     REQUIRE(rdata->type == dns_rdatatype_kx);
  229     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  230 
  231     dns_name_init(&name, offsets);
  232     dns_rdata_toregion(rdata, &region);
  233     isc_region_consume(&region, 2);
  234     dns_name_fromregion(&name, &region);
  235 
  236     return ((add)(arg, &name, dns_rdatatype_a));
  237 }
  238 
  239 static inline isc_result_t
  240 digest_in_kx(ARGS_DIGEST) {
  241     isc_region_t r1, r2;
  242     dns_name_t name;
  243 
  244     REQUIRE(rdata->type == dns_rdatatype_kx);
  245     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  246 
  247     dns_rdata_toregion(rdata, &r1);
  248     r2 = r1;
  249     isc_region_consume(&r2, 2);
  250     r1.length = 2;
  251     RETERR((digest)(arg, &r1));
  252     dns_name_init(&name, NULL);
  253     dns_name_fromregion(&name, &r2);
  254     return (dns_name_digest(&name, digest, arg));
  255 }
  256 
  257 static inline bool
  258 checkowner_in_kx(ARGS_CHECKOWNER) {
  259     REQUIRE(type == dns_rdatatype_kx);
  260     REQUIRE(rdclass == dns_rdataclass_in);
  261 
  262     UNUSED(name);
  263     UNUSED(type);
  264     UNUSED(rdclass);
  265     UNUSED(wildcard);
  266 
  267     return (true);
  268 }
  269 
  270 static inline bool
  271 checknames_in_kx(ARGS_CHECKNAMES) {
  272     REQUIRE(rdata->type == dns_rdatatype_kx);
  273     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  274 
  275     UNUSED(rdata);
  276     UNUSED(owner);
  277     UNUSED(bad);
  278 
  279     return (true);
  280 }
  281 
  282 static inline int
  283 casecompare_in_kx(ARGS_COMPARE) {
  284     return (compare_in_kx(rdata1, rdata2));
  285 }
  286 
  287 #endif /* RDATA_IN_1_KX_36_C */