Home | History | Annotate | Line # | Download | only in in_1
      1 /*	$NetBSD: eid_31.c,v 1.1 2024/02/18 20:57:46 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  *
      6  * SPDX-License-Identifier: MPL-2.0
      7  *
      8  * This Source Code Form is subject to the terms of the Mozilla Public
      9  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11  *
     12  * See the COPYRIGHT file distributed with this work for additional
     13  * information regarding copyright ownership.
     14  */
     15 
     16 /* http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt */
     17 
     18 #ifndef RDATA_IN_1_EID_31_C
     19 #define RDATA_IN_1_EID_31_C
     20 
     21 #define RRTYPE_EID_ATTRIBUTES (0)
     22 
     23 static isc_result_t
     24 fromtext_in_eid(ARGS_FROMTEXT) {
     25 	REQUIRE(type == dns_rdatatype_eid);
     26 	REQUIRE(rdclass == dns_rdataclass_in);
     27 
     28 	UNUSED(type);
     29 	UNUSED(origin);
     30 	UNUSED(options);
     31 	UNUSED(rdclass);
     32 	UNUSED(callbacks);
     33 
     34 	return (isc_hex_tobuffer(lexer, target, -2));
     35 }
     36 
     37 static isc_result_t
     38 totext_in_eid(ARGS_TOTEXT) {
     39 	isc_region_t region;
     40 
     41 	REQUIRE(rdata->type == dns_rdatatype_eid);
     42 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
     43 	REQUIRE(rdata->length != 0);
     44 
     45 	dns_rdata_toregion(rdata, &region);
     46 
     47 	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
     48 		RETERR(str_totext("( ", target));
     49 	}
     50 	if (tctx->width == 0) {
     51 		RETERR(isc_hex_totext(&region, 60, "", target));
     52 	} else {
     53 		RETERR(isc_hex_totext(&region, tctx->width - 2, tctx->linebreak,
     54 				      target));
     55 	}
     56 	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
     57 		RETERR(str_totext(" )", target));
     58 	}
     59 	return (ISC_R_SUCCESS);
     60 }
     61 
     62 static isc_result_t
     63 fromwire_in_eid(ARGS_FROMWIRE) {
     64 	isc_region_t region;
     65 
     66 	REQUIRE(type == dns_rdatatype_eid);
     67 	REQUIRE(rdclass == dns_rdataclass_in);
     68 
     69 	UNUSED(type);
     70 	UNUSED(dctx);
     71 	UNUSED(options);
     72 	UNUSED(rdclass);
     73 
     74 	isc_buffer_activeregion(source, &region);
     75 	if (region.length < 1) {
     76 		return (ISC_R_UNEXPECTEDEND);
     77 	}
     78 
     79 	RETERR(mem_tobuffer(target, region.base, region.length));
     80 	isc_buffer_forward(source, region.length);
     81 	return (ISC_R_SUCCESS);
     82 }
     83 
     84 static isc_result_t
     85 towire_in_eid(ARGS_TOWIRE) {
     86 	REQUIRE(rdata->type == dns_rdatatype_eid);
     87 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
     88 	REQUIRE(rdata->length != 0);
     89 
     90 	UNUSED(cctx);
     91 
     92 	return (mem_tobuffer(target, rdata->data, rdata->length));
     93 }
     94 
     95 static int
     96 compare_in_eid(ARGS_COMPARE) {
     97 	isc_region_t r1;
     98 	isc_region_t r2;
     99 
    100 	REQUIRE(rdata1->type == rdata2->type);
    101 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
    102 	REQUIRE(rdata1->type == dns_rdatatype_eid);
    103 	REQUIRE(rdata1->rdclass == dns_rdataclass_in);
    104 	REQUIRE(rdata1->length != 0);
    105 	REQUIRE(rdata2->length != 0);
    106 
    107 	dns_rdata_toregion(rdata1, &r1);
    108 	dns_rdata_toregion(rdata2, &r2);
    109 	return (isc_region_compare(&r1, &r2));
    110 }
    111 
    112 static isc_result_t
    113 fromstruct_in_eid(ARGS_FROMSTRUCT) {
    114 	dns_rdata_in_eid_t *eid = source;
    115 
    116 	REQUIRE(type == dns_rdatatype_eid);
    117 	REQUIRE(rdclass == dns_rdataclass_in);
    118 	REQUIRE(eid != NULL);
    119 	REQUIRE(eid->common.rdtype == type);
    120 	REQUIRE(eid->common.rdclass == rdclass);
    121 	REQUIRE(eid->eid != NULL || eid->eid_len == 0);
    122 
    123 	UNUSED(type);
    124 	UNUSED(rdclass);
    125 
    126 	return (mem_tobuffer(target, eid->eid, eid->eid_len));
    127 }
    128 
    129 static isc_result_t
    130 tostruct_in_eid(ARGS_TOSTRUCT) {
    131 	dns_rdata_in_eid_t *eid = target;
    132 	isc_region_t r;
    133 
    134 	REQUIRE(rdata->type == dns_rdatatype_eid);
    135 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
    136 	REQUIRE(eid != NULL);
    137 	REQUIRE(rdata->length != 0);
    138 
    139 	eid->common.rdclass = rdata->rdclass;
    140 	eid->common.rdtype = rdata->type;
    141 	ISC_LINK_INIT(&eid->common, link);
    142 
    143 	dns_rdata_toregion(rdata, &r);
    144 	eid->eid_len = r.length;
    145 	eid->eid = mem_maybedup(mctx, r.base, r.length);
    146 	if (eid->eid == NULL) {
    147 		return (ISC_R_NOMEMORY);
    148 	}
    149 
    150 	eid->mctx = mctx;
    151 	return (ISC_R_SUCCESS);
    152 }
    153 
    154 static void
    155 freestruct_in_eid(ARGS_FREESTRUCT) {
    156 	dns_rdata_in_eid_t *eid = source;
    157 
    158 	REQUIRE(eid != NULL);
    159 	REQUIRE(eid->common.rdclass == dns_rdataclass_in);
    160 	REQUIRE(eid->common.rdtype == dns_rdatatype_eid);
    161 
    162 	if (eid->mctx == NULL) {
    163 		return;
    164 	}
    165 
    166 	if (eid->eid != NULL) {
    167 		isc_mem_free(eid->mctx, eid->eid);
    168 	}
    169 	eid->mctx = NULL;
    170 }
    171 
    172 static isc_result_t
    173 additionaldata_in_eid(ARGS_ADDLDATA) {
    174 	REQUIRE(rdata->type == dns_rdatatype_eid);
    175 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
    176 
    177 	UNUSED(rdata);
    178 	UNUSED(add);
    179 	UNUSED(arg);
    180 
    181 	return (ISC_R_SUCCESS);
    182 }
    183 
    184 static isc_result_t
    185 digest_in_eid(ARGS_DIGEST) {
    186 	isc_region_t r;
    187 
    188 	REQUIRE(rdata->type == dns_rdatatype_eid);
    189 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
    190 
    191 	dns_rdata_toregion(rdata, &r);
    192 
    193 	return ((digest)(arg, &r));
    194 }
    195 
    196 static bool
    197 checkowner_in_eid(ARGS_CHECKOWNER) {
    198 	REQUIRE(type == dns_rdatatype_eid);
    199 	REQUIRE(rdclass == dns_rdataclass_in);
    200 
    201 	UNUSED(name);
    202 	UNUSED(type);
    203 	UNUSED(rdclass);
    204 	UNUSED(wildcard);
    205 
    206 	return (true);
    207 }
    208 
    209 static bool
    210 checknames_in_eid(ARGS_CHECKNAMES) {
    211 	REQUIRE(rdata->type == dns_rdatatype_eid);
    212 	REQUIRE(rdata->rdclass == dns_rdataclass_in);
    213 
    214 	UNUSED(rdata);
    215 	UNUSED(owner);
    216 	UNUSED(bad);
    217 
    218 	return (true);
    219 }
    220 
    221 static int
    222 casecompare_in_eid(ARGS_COMPARE) {
    223 	return (compare_in_eid(rdata1, rdata2));
    224 }
    225 
    226 #endif /* RDATA_IN_1_EID_31_C */
    227