"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/dns/rdata/generic/lp_107.c" (4 Sep 2020, 6161 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 "lp_107.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_LP_107_C
   13 #define RDATA_GENERIC_LP_107_C
   14 
   15 #include <string.h>
   16 
   17 #include <isc/net.h>
   18 
   19 #define RRTYPE_LP_ATTRIBUTES (0)
   20 
   21 static inline isc_result_t
   22 fromtext_lp(ARGS_FROMTEXT) {
   23     isc_token_t token;
   24     dns_name_t name;
   25     isc_buffer_t buffer;
   26 
   27     REQUIRE(type == dns_rdatatype_lp);
   28 
   29     UNUSED(type);
   30     UNUSED(rdclass);
   31     UNUSED(callbacks);
   32 
   33     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   34                       false));
   35     if (token.value.as_ulong > 0xffffU) {
   36         RETTOK(ISC_R_RANGE);
   37     }
   38     RETERR(uint16_tobuffer(token.value.as_ulong, target));
   39 
   40     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   41                       false));
   42 
   43     dns_name_init(&name, NULL);
   44     buffer_fromregion(&buffer, &token.value.as_region);
   45     if (origin == NULL) {
   46         origin = dns_rootname;
   47     }
   48     return (dns_name_fromtext(&name, &buffer, origin, options, target));
   49 }
   50 
   51 static inline isc_result_t
   52 totext_lp(ARGS_TOTEXT) {
   53     isc_region_t region;
   54     dns_name_t name;
   55     dns_name_t prefix;
   56     bool sub;
   57     char buf[sizeof("64000")];
   58     unsigned short num;
   59 
   60     REQUIRE(rdata->type == dns_rdatatype_lp);
   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_lp(ARGS_FROMWIRE) {
   81     dns_name_t name;
   82     isc_region_t sregion;
   83 
   84     REQUIRE(type == dns_rdatatype_lp);
   85 
   86     UNUSED(type);
   87     UNUSED(rdclass);
   88 
   89     dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
   90 
   91     dns_name_init(&name, NULL);
   92 
   93     isc_buffer_activeregion(source, &sregion);
   94     if (sregion.length < 2) {
   95         return (ISC_R_UNEXPECTEDEND);
   96     }
   97     RETERR(mem_tobuffer(target, sregion.base, 2));
   98     isc_buffer_forward(source, 2);
   99     return (dns_name_fromwire(&name, source, dctx, options, target));
  100 }
  101 
  102 static inline isc_result_t
  103 towire_lp(ARGS_TOWIRE) {
  104     REQUIRE(rdata->type == dns_rdatatype_lp);
  105     REQUIRE(rdata->length != 0);
  106 
  107     UNUSED(cctx);
  108 
  109     return (mem_tobuffer(target, rdata->data, rdata->length));
  110 }
  111 
  112 static inline int
  113 compare_lp(ARGS_COMPARE) {
  114     isc_region_t region1;
  115     isc_region_t region2;
  116 
  117     REQUIRE(rdata1->type == rdata2->type);
  118     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  119     REQUIRE(rdata1->type == dns_rdatatype_lp);
  120     REQUIRE(rdata1->length != 0);
  121     REQUIRE(rdata2->length != 0);
  122 
  123     dns_rdata_toregion(rdata1, &region1);
  124     dns_rdata_toregion(rdata2, &region2);
  125 
  126     return (isc_region_compare(&region1, &region2));
  127 }
  128 
  129 static inline isc_result_t
  130 fromstruct_lp(ARGS_FROMSTRUCT) {
  131     dns_rdata_lp_t *lp = source;
  132     isc_region_t region;
  133 
  134     REQUIRE(type == dns_rdatatype_lp);
  135     REQUIRE(lp != NULL);
  136     REQUIRE(lp->common.rdtype == type);
  137     REQUIRE(lp->common.rdclass == rdclass);
  138 
  139     UNUSED(type);
  140     UNUSED(rdclass);
  141 
  142     RETERR(uint16_tobuffer(lp->pref, target));
  143     dns_name_toregion(&lp->lp, &region);
  144     return (isc_buffer_copyregion(target, &region));
  145 }
  146 
  147 static inline isc_result_t
  148 tostruct_lp(ARGS_TOSTRUCT) {
  149     isc_region_t region;
  150     dns_rdata_lp_t *lp = target;
  151     dns_name_t name;
  152 
  153     REQUIRE(rdata->type == dns_rdatatype_lp);
  154     REQUIRE(lp != NULL);
  155     REQUIRE(rdata->length != 0);
  156 
  157     lp->common.rdclass = rdata->rdclass;
  158     lp->common.rdtype = rdata->type;
  159     ISC_LINK_INIT(&lp->common, link);
  160 
  161     dns_name_init(&name, NULL);
  162     dns_rdata_toregion(rdata, &region);
  163     lp->pref = uint16_fromregion(&region);
  164     isc_region_consume(&region, 2);
  165     dns_name_fromregion(&name, &region);
  166     dns_name_init(&lp->lp, NULL);
  167     RETERR(name_duporclone(&name, mctx, &lp->lp));
  168     lp->mctx = mctx;
  169     return (ISC_R_SUCCESS);
  170 }
  171 
  172 static inline void
  173 freestruct_lp(ARGS_FREESTRUCT) {
  174     dns_rdata_lp_t *lp = source;
  175 
  176     REQUIRE(lp != NULL);
  177     REQUIRE(lp->common.rdtype == dns_rdatatype_lp);
  178 
  179     if (lp->mctx == NULL) {
  180         return;
  181     }
  182 
  183     dns_name_free(&lp->lp, lp->mctx);
  184     lp->mctx = NULL;
  185 }
  186 
  187 static inline isc_result_t
  188 additionaldata_lp(ARGS_ADDLDATA) {
  189     dns_name_t name;
  190     dns_offsets_t offsets;
  191     isc_region_t region;
  192     isc_result_t result;
  193 
  194     REQUIRE(rdata->type == dns_rdatatype_lp);
  195 
  196     dns_name_init(&name, offsets);
  197     dns_rdata_toregion(rdata, &region);
  198     isc_region_consume(&region, 2);
  199     dns_name_fromregion(&name, &region);
  200 
  201     result = (add)(arg, &name, dns_rdatatype_l32);
  202     if (result != ISC_R_SUCCESS) {
  203         return (result);
  204     }
  205     return ((add)(arg, &name, dns_rdatatype_l64));
  206 }
  207 
  208 static inline isc_result_t
  209 digest_lp(ARGS_DIGEST) {
  210     isc_region_t region;
  211 
  212     REQUIRE(rdata->type == dns_rdatatype_lp);
  213 
  214     dns_rdata_toregion(rdata, &region);
  215     return ((digest)(arg, &region));
  216 }
  217 
  218 static inline bool
  219 checkowner_lp(ARGS_CHECKOWNER) {
  220     REQUIRE(type == dns_rdatatype_lp);
  221 
  222     UNUSED(type);
  223     UNUSED(rdclass);
  224     UNUSED(name);
  225     UNUSED(wildcard);
  226 
  227     return (true);
  228 }
  229 
  230 static inline bool
  231 checknames_lp(ARGS_CHECKNAMES) {
  232     REQUIRE(rdata->type == dns_rdatatype_lp);
  233 
  234     UNUSED(bad);
  235     UNUSED(owner);
  236 
  237     return (true);
  238 }
  239 
  240 static inline int
  241 casecompare_lp(ARGS_COMPARE) {
  242     dns_name_t name1;
  243     dns_name_t name2;
  244     isc_region_t region1;
  245     isc_region_t region2;
  246     int order;
  247 
  248     REQUIRE(rdata1->type == rdata2->type);
  249     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  250     REQUIRE(rdata1->type == dns_rdatatype_lp);
  251     REQUIRE(rdata1->length != 0);
  252     REQUIRE(rdata2->length != 0);
  253 
  254     order = memcmp(rdata1->data, rdata2->data, 2);
  255     if (order != 0) {
  256         return (order < 0 ? -1 : 1);
  257     }
  258 
  259     dns_name_init(&name1, NULL);
  260     dns_name_init(&name2, NULL);
  261 
  262     dns_rdata_toregion(rdata1, &region1);
  263     dns_rdata_toregion(rdata2, &region2);
  264 
  265     isc_region_consume(&region1, 2);
  266     isc_region_consume(&region2, 2);
  267 
  268     dns_name_fromregion(&name1, &region1);
  269     dns_name_fromregion(&name2, &region2);
  270 
  271     return (dns_name_rdatacompare(&name1, &name2));
  272 }
  273 
  274 #endif /* RDATA_GENERIC_LP_107_C */