Home | History | Annotate | Line # | Download | only in generic
hinfo_13.c revision 1.1.1.6
      1 /*	$NetBSD: hinfo_13.c,v 1.1.1.6 2022/09/23 12:09:20 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 #ifndef RDATA_GENERIC_HINFO_13_C
     17 #define RDATA_GENERIC_HINFO_13_C
     18 
     19 #define RRTYPE_HINFO_ATTRIBUTES (0)
     20 
     21 static isc_result_t
     22 fromtext_hinfo(ARGS_FROMTEXT) {
     23 	isc_token_t token;
     24 	int i;
     25 
     26 	UNUSED(type);
     27 	UNUSED(rdclass);
     28 	UNUSED(origin);
     29 	UNUSED(options);
     30 	UNUSED(callbacks);
     31 
     32 	REQUIRE(type == dns_rdatatype_hinfo);
     33 
     34 	for (i = 0; i < 2; i++) {
     35 		RETERR(isc_lex_getmastertoken(lexer, &token,
     36 					      isc_tokentype_qstring, false));
     37 		RETTOK(txt_fromtext(&token.value.as_textregion, target));
     38 	}
     39 	return (ISC_R_SUCCESS);
     40 }
     41 
     42 static isc_result_t
     43 totext_hinfo(ARGS_TOTEXT) {
     44 	isc_region_t region;
     45 
     46 	UNUSED(tctx);
     47 
     48 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
     49 	REQUIRE(rdata->length != 0);
     50 
     51 	dns_rdata_toregion(rdata, &region);
     52 	RETERR(txt_totext(&region, true, target));
     53 	RETERR(str_totext(" ", target));
     54 	return (txt_totext(&region, true, target));
     55 }
     56 
     57 static isc_result_t
     58 fromwire_hinfo(ARGS_FROMWIRE) {
     59 	REQUIRE(type == dns_rdatatype_hinfo);
     60 
     61 	UNUSED(type);
     62 	UNUSED(dctx);
     63 	UNUSED(rdclass);
     64 	UNUSED(options);
     65 
     66 	RETERR(txt_fromwire(source, target));
     67 	return (txt_fromwire(source, target));
     68 }
     69 
     70 static isc_result_t
     71 towire_hinfo(ARGS_TOWIRE) {
     72 	UNUSED(cctx);
     73 
     74 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
     75 	REQUIRE(rdata->length != 0);
     76 
     77 	return (mem_tobuffer(target, rdata->data, rdata->length));
     78 }
     79 
     80 static int
     81 compare_hinfo(ARGS_COMPARE) {
     82 	isc_region_t r1;
     83 	isc_region_t r2;
     84 
     85 	REQUIRE(rdata1->type == rdata2->type);
     86 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
     87 	REQUIRE(rdata1->type == dns_rdatatype_hinfo);
     88 	REQUIRE(rdata1->length != 0);
     89 	REQUIRE(rdata2->length != 0);
     90 
     91 	dns_rdata_toregion(rdata1, &r1);
     92 	dns_rdata_toregion(rdata2, &r2);
     93 	return (isc_region_compare(&r1, &r2));
     94 }
     95 
     96 static isc_result_t
     97 fromstruct_hinfo(ARGS_FROMSTRUCT) {
     98 	dns_rdata_hinfo_t *hinfo = source;
     99 
    100 	REQUIRE(type == dns_rdatatype_hinfo);
    101 	REQUIRE(hinfo != NULL);
    102 	REQUIRE(hinfo->common.rdtype == type);
    103 	REQUIRE(hinfo->common.rdclass == rdclass);
    104 
    105 	UNUSED(type);
    106 	UNUSED(rdclass);
    107 
    108 	RETERR(uint8_tobuffer(hinfo->cpu_len, target));
    109 	RETERR(mem_tobuffer(target, hinfo->cpu, hinfo->cpu_len));
    110 	RETERR(uint8_tobuffer(hinfo->os_len, target));
    111 	return (mem_tobuffer(target, hinfo->os, hinfo->os_len));
    112 }
    113 
    114 static isc_result_t
    115 tostruct_hinfo(ARGS_TOSTRUCT) {
    116 	dns_rdata_hinfo_t *hinfo = target;
    117 	isc_region_t region;
    118 
    119 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
    120 	REQUIRE(hinfo != NULL);
    121 	REQUIRE(rdata->length != 0);
    122 
    123 	hinfo->common.rdclass = rdata->rdclass;
    124 	hinfo->common.rdtype = rdata->type;
    125 	ISC_LINK_INIT(&hinfo->common, link);
    126 
    127 	dns_rdata_toregion(rdata, &region);
    128 	hinfo->cpu_len = uint8_fromregion(&region);
    129 	isc_region_consume(&region, 1);
    130 	hinfo->cpu = mem_maybedup(mctx, region.base, hinfo->cpu_len);
    131 	if (hinfo->cpu == NULL) {
    132 		return (ISC_R_NOMEMORY);
    133 	}
    134 	isc_region_consume(&region, hinfo->cpu_len);
    135 
    136 	hinfo->os_len = uint8_fromregion(&region);
    137 	isc_region_consume(&region, 1);
    138 	hinfo->os = mem_maybedup(mctx, region.base, hinfo->os_len);
    139 	if (hinfo->os == NULL) {
    140 		goto cleanup;
    141 	}
    142 
    143 	hinfo->mctx = mctx;
    144 	return (ISC_R_SUCCESS);
    145 
    146 cleanup:
    147 	if (mctx != NULL && hinfo->cpu != NULL) {
    148 		isc_mem_free(mctx, hinfo->cpu);
    149 	}
    150 	return (ISC_R_NOMEMORY);
    151 }
    152 
    153 static void
    154 freestruct_hinfo(ARGS_FREESTRUCT) {
    155 	dns_rdata_hinfo_t *hinfo = source;
    156 
    157 	REQUIRE(hinfo != NULL);
    158 
    159 	if (hinfo->mctx == NULL) {
    160 		return;
    161 	}
    162 
    163 	if (hinfo->cpu != NULL) {
    164 		isc_mem_free(hinfo->mctx, hinfo->cpu);
    165 	}
    166 	if (hinfo->os != NULL) {
    167 		isc_mem_free(hinfo->mctx, hinfo->os);
    168 	}
    169 	hinfo->mctx = NULL;
    170 }
    171 
    172 static isc_result_t
    173 additionaldata_hinfo(ARGS_ADDLDATA) {
    174 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
    175 
    176 	UNUSED(add);
    177 	UNUSED(arg);
    178 	UNUSED(rdata);
    179 
    180 	return (ISC_R_SUCCESS);
    181 }
    182 
    183 static isc_result_t
    184 digest_hinfo(ARGS_DIGEST) {
    185 	isc_region_t r;
    186 
    187 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
    188 
    189 	dns_rdata_toregion(rdata, &r);
    190 
    191 	return ((digest)(arg, &r));
    192 }
    193 
    194 static bool
    195 checkowner_hinfo(ARGS_CHECKOWNER) {
    196 	REQUIRE(type == dns_rdatatype_hinfo);
    197 
    198 	UNUSED(name);
    199 	UNUSED(type);
    200 	UNUSED(rdclass);
    201 	UNUSED(wildcard);
    202 
    203 	return (true);
    204 }
    205 
    206 static bool
    207 checknames_hinfo(ARGS_CHECKNAMES) {
    208 	REQUIRE(rdata->type == dns_rdatatype_hinfo);
    209 
    210 	UNUSED(rdata);
    211 	UNUSED(owner);
    212 	UNUSED(bad);
    213 
    214 	return (true);
    215 }
    216 
    217 static int
    218 casecompare_hinfo(ARGS_COMPARE) {
    219 	return (compare_hinfo(rdata1, rdata2));
    220 }
    221 #endif /* RDATA_GENERIC_HINFO_13_C */
    222