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