"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/rdata/in_1/px_26.c" (7 Sep 2020, 8706 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 "px_26.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 /* RFC2163 */
   13 
   14 #ifndef RDATA_IN_1_PX_26_C
   15 #define RDATA_IN_1_PX_26_C
   16 
   17 #define RRTYPE_PX_ATTRIBUTES (0)
   18 
   19 static inline isc_result_t
   20 fromtext_in_px(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22     dns_name_t name;
   23     isc_buffer_t buffer;
   24 
   25     REQUIRE(type == dns_rdatatype_px);
   26     REQUIRE(rdclass == dns_rdataclass_in);
   27 
   28     UNUSED(type);
   29     UNUSED(rdclass);
   30     UNUSED(callbacks);
   31 
   32     if (origin == NULL)
   33         origin = dns_rootname;
   34 
   35     /*
   36      * Preference.
   37      */
   38     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   39                       false));
   40     if (token.value.as_ulong > 0xffffU)
   41         RETTOK(ISC_R_RANGE);
   42     RETERR(uint16_tobuffer(token.value.as_ulong, target));
   43 
   44     /*
   45      * MAP822.
   46      */
   47     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   48                       false));
   49     dns_name_init(&name, NULL);
   50     buffer_fromregion(&buffer, &token.value.as_region);
   51     RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
   52 
   53     /*
   54      * MAPX400.
   55      */
   56     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   57                       false));
   58     dns_name_init(&name, NULL);
   59     buffer_fromregion(&buffer, &token.value.as_region);
   60     RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
   61     return (ISC_R_SUCCESS);
   62 }
   63 
   64 static inline isc_result_t
   65 totext_in_px(ARGS_TOTEXT) {
   66     isc_region_t region;
   67     dns_name_t name;
   68     dns_name_t prefix;
   69     bool sub;
   70     char buf[sizeof("64000")];
   71     unsigned short num;
   72 
   73     REQUIRE(rdata->type == dns_rdatatype_px);
   74     REQUIRE(rdata->rdclass == dns_rdataclass_in);
   75     REQUIRE(rdata->length != 0);
   76 
   77     dns_name_init(&name, NULL);
   78     dns_name_init(&prefix, NULL);
   79 
   80     /*
   81      * Preference.
   82      */
   83     dns_rdata_toregion(rdata, &region);
   84     num = uint16_fromregion(&region);
   85     isc_region_consume(&region, 2);
   86     snprintf(buf, sizeof(buf), "%u", num);
   87     RETERR(str_totext(buf, target));
   88     RETERR(str_totext(" ", target));
   89 
   90     /*
   91      * MAP822.
   92      */
   93     dns_name_fromregion(&name, &region);
   94     sub = name_prefix(&name, tctx->origin, &prefix);
   95     isc_region_consume(&region, name_length(&name));
   96     RETERR(dns_name_totext(&prefix, sub, target));
   97     RETERR(str_totext(" ", target));
   98 
   99     /*
  100      * MAPX400.
  101      */
  102     dns_name_fromregion(&name, &region);
  103     sub = name_prefix(&name, tctx->origin, &prefix);
  104     return(dns_name_totext(&prefix, sub, target));
  105 }
  106 
  107 static inline isc_result_t
  108 fromwire_in_px(ARGS_FROMWIRE) {
  109     dns_name_t name;
  110     isc_region_t sregion;
  111 
  112     REQUIRE(type == dns_rdatatype_px);
  113     REQUIRE(rdclass == dns_rdataclass_in);
  114 
  115     UNUSED(type);
  116     UNUSED(rdclass);
  117 
  118     dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
  119 
  120     dns_name_init(&name, NULL);
  121 
  122     /*
  123      * Preference.
  124      */
  125     isc_buffer_activeregion(source, &sregion);
  126     if (sregion.length < 2)
  127         return (ISC_R_UNEXPECTEDEND);
  128     RETERR(mem_tobuffer(target, sregion.base, 2));
  129     isc_buffer_forward(source, 2);
  130 
  131     /*
  132      * MAP822.
  133      */
  134     RETERR(dns_name_fromwire(&name, source, dctx, options, target));
  135 
  136     /*
  137      * MAPX400.
  138      */
  139     return (dns_name_fromwire(&name, source, dctx, options, target));
  140 }
  141 
  142 static inline isc_result_t
  143 towire_in_px(ARGS_TOWIRE) {
  144     dns_name_t name;
  145     dns_offsets_t offsets;
  146     isc_region_t region;
  147 
  148     REQUIRE(rdata->type == dns_rdatatype_px);
  149     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  150     REQUIRE(rdata->length != 0);
  151 
  152     dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
  153     /*
  154      * Preference.
  155      */
  156     dns_rdata_toregion(rdata, &region);
  157     RETERR(mem_tobuffer(target, region.base, 2));
  158     isc_region_consume(&region, 2);
  159 
  160     /*
  161      * MAP822.
  162      */
  163     dns_name_init(&name, offsets);
  164     dns_name_fromregion(&name, &region);
  165     RETERR(dns_name_towire(&name, cctx, target));
  166     isc_region_consume(&region, name_length(&name));
  167 
  168     /*
  169      * MAPX400.
  170      */
  171     dns_name_init(&name, offsets);
  172     dns_name_fromregion(&name, &region);
  173     return (dns_name_towire(&name, cctx, target));
  174 }
  175 
  176 static inline int
  177 compare_in_px(ARGS_COMPARE) {
  178     dns_name_t name1;
  179     dns_name_t name2;
  180     isc_region_t region1;
  181     isc_region_t region2;
  182     int order;
  183 
  184     REQUIRE(rdata1->type == rdata2->type);
  185     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  186     REQUIRE(rdata1->type == dns_rdatatype_px);
  187     REQUIRE(rdata1->rdclass == dns_rdataclass_in);
  188     REQUIRE(rdata1->length != 0);
  189     REQUIRE(rdata2->length != 0);
  190 
  191     order = memcmp(rdata1->data, rdata2->data, 2);
  192     if (order != 0)
  193         return (order < 0 ? -1 : 1);
  194 
  195     dns_name_init(&name1, NULL);
  196     dns_name_init(&name2, NULL);
  197 
  198     dns_rdata_toregion(rdata1, &region1);
  199     dns_rdata_toregion(rdata2, &region2);
  200 
  201     isc_region_consume(&region1, 2);
  202     isc_region_consume(&region2, 2);
  203 
  204     dns_name_fromregion(&name1, &region1);
  205     dns_name_fromregion(&name2, &region2);
  206 
  207     order = dns_name_rdatacompare(&name1, &name2);
  208     if (order != 0)
  209         return (order);
  210 
  211     isc_region_consume(&region1, name_length(&name1));
  212     isc_region_consume(&region2, name_length(&name2));
  213 
  214     dns_name_fromregion(&name1, &region1);
  215     dns_name_fromregion(&name2, &region2);
  216 
  217     return (dns_name_rdatacompare(&name1, &name2));
  218 }
  219 
  220 static inline isc_result_t
  221 fromstruct_in_px(ARGS_FROMSTRUCT) {
  222     dns_rdata_in_px_t *px;
  223     isc_region_t region;
  224 
  225     REQUIRE(type == dns_rdatatype_px);
  226     REQUIRE(rdclass == dns_rdataclass_in);
  227     REQUIRE(((dns_rdata_in_px_t *)source) != NULL);
  228     REQUIRE(((dns_rdata_in_px_t *)source)->common.rdtype == type);
  229     REQUIRE(((dns_rdata_in_px_t *)source)->common.rdclass == rdclass);
  230 
  231     px = source;
  232 
  233     UNUSED(type);
  234     UNUSED(rdclass);
  235 
  236     RETERR(uint16_tobuffer(px->preference, target));
  237     dns_name_toregion(&px->map822, &region);
  238     RETERR(isc_buffer_copyregion(target, &region));
  239     dns_name_toregion(&px->mapx400, &region);
  240     return (isc_buffer_copyregion(target, &region));
  241 }
  242 
  243 static inline isc_result_t
  244 tostruct_in_px(ARGS_TOSTRUCT) {
  245     dns_rdata_in_px_t *px;
  246     dns_name_t name;
  247     isc_region_t region;
  248     isc_result_t result;
  249 
  250     REQUIRE(((dns_rdata_in_px_t *)target) != NULL);
  251     REQUIRE(rdata->type == dns_rdatatype_px);
  252     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  253     REQUIRE(rdata->length != 0);
  254 
  255     px = target;
  256 
  257     px->common.rdclass = rdata->rdclass;
  258     px->common.rdtype = rdata->type;
  259     ISC_LINK_INIT(&px->common, link);
  260 
  261     dns_name_init(&name, NULL);
  262     dns_rdata_toregion(rdata, &region);
  263 
  264     px->preference = uint16_fromregion(&region);
  265     isc_region_consume(&region, 2);
  266 
  267     dns_name_fromregion(&name, &region);
  268 
  269     dns_name_init(&px->map822, NULL);
  270     RETERR(name_duporclone(&name, mctx, &px->map822));
  271     isc_region_consume(&region, name_length(&px->map822));
  272 
  273     dns_name_init(&px->mapx400, NULL);
  274     result = name_duporclone(&name, mctx, &px->mapx400);
  275     if (result != ISC_R_SUCCESS)
  276         goto cleanup;
  277 
  278     px->mctx = mctx;
  279     return (result);
  280 
  281  cleanup:
  282     dns_name_free(&px->map822, mctx);
  283     return (ISC_R_NOMEMORY);
  284 }
  285 
  286 static inline void
  287 freestruct_in_px(ARGS_FREESTRUCT) {
  288     dns_rdata_in_px_t *px;
  289 
  290     REQUIRE(((dns_rdata_in_px_t *)source) != NULL);
  291     REQUIRE(((dns_rdata_in_px_t *)source)->common.rdtype ==
  292         dns_rdatatype_px);
  293     REQUIRE(((dns_rdata_in_px_t *)source)->common.rdclass ==
  294         dns_rdataclass_in);
  295 
  296     px = source;
  297 
  298     if (px->mctx == NULL)
  299         return;
  300 
  301     dns_name_free(&px->map822, px->mctx);
  302     dns_name_free(&px->mapx400, px->mctx);
  303     px->mctx = NULL;
  304 }
  305 
  306 static inline isc_result_t
  307 additionaldata_in_px(ARGS_ADDLDATA) {
  308     REQUIRE(rdata->type == dns_rdatatype_px);
  309     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  310 
  311     UNUSED(rdata);
  312     UNUSED(add);
  313     UNUSED(arg);
  314 
  315     return (ISC_R_SUCCESS);
  316 }
  317 
  318 static inline isc_result_t
  319 digest_in_px(ARGS_DIGEST) {
  320     isc_region_t r1, r2;
  321     dns_name_t name;
  322     isc_result_t result;
  323 
  324     REQUIRE(rdata->type == dns_rdatatype_px);
  325     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  326 
  327     dns_rdata_toregion(rdata, &r1);
  328     r2 = r1;
  329     isc_region_consume(&r2, 2);
  330     r1.length = 2;
  331     result = (digest)(arg, &r1);
  332     if (result != ISC_R_SUCCESS)
  333         return (result);
  334     dns_name_init(&name, NULL);
  335     dns_name_fromregion(&name, &r2);
  336     result = dns_name_digest(&name, digest, arg);
  337     if (result != ISC_R_SUCCESS)
  338         return (result);
  339     isc_region_consume(&r2, name_length(&name));
  340     dns_name_init(&name, NULL);
  341     dns_name_fromregion(&name, &r2);
  342 
  343     return (dns_name_digest(&name, digest, arg));
  344 }
  345 
  346 static inline bool
  347 checkowner_in_px(ARGS_CHECKOWNER) {
  348 
  349     REQUIRE(type == dns_rdatatype_px);
  350     REQUIRE(rdclass == dns_rdataclass_in);
  351 
  352     UNUSED(name);
  353     UNUSED(type);
  354     UNUSED(rdclass);
  355     UNUSED(wildcard);
  356 
  357     return (true);
  358 }
  359 
  360 static inline bool
  361 checknames_in_px(ARGS_CHECKNAMES) {
  362 
  363     REQUIRE(rdata->type == dns_rdatatype_px);
  364     REQUIRE(rdata->rdclass == dns_rdataclass_in);
  365 
  366     UNUSED(rdata);
  367     UNUSED(owner);
  368     UNUSED(bad);
  369 
  370     return (true);
  371 }
  372 
  373 static inline int
  374 casecompare_in_px(ARGS_COMPARE) {
  375     return (compare_in_px(rdata1, rdata2));
  376 }
  377 
  378 #endif  /* RDATA_IN_1_PX_26_C */