1 /* $NetBSD: nimloc_32.c,v 1.10 2025/01/26 16:25:35 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_NIMLOC_32_C 19 #define RDATA_IN_1_NIMLOC_32_C 20 21 #define RRTYPE_NIMLOC_ATTRIBUTES (0) 22 23 static isc_result_t 24 fromtext_in_nimloc(ARGS_FROMTEXT) { 25 REQUIRE(type == dns_rdatatype_nimloc); 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_nimloc(ARGS_TOTEXT) { 39 isc_region_t region; 40 41 REQUIRE(rdata->type == dns_rdatatype_nimloc); 42 REQUIRE(rdata->rdclass == dns_rdataclass_in); 43 REQUIRE(rdata->length != 0); 44 45 dns_rdata_toregion(rdata, ®ion); 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(®ion, 60, "", target)); 52 } else { 53 RETERR(isc_hex_totext(®ion, 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_nimloc(ARGS_FROMWIRE) { 64 isc_region_t region; 65 66 REQUIRE(type == dns_rdatatype_nimloc); 67 REQUIRE(rdclass == dns_rdataclass_in); 68 69 UNUSED(type); 70 UNUSED(dctx); 71 UNUSED(rdclass); 72 73 isc_buffer_activeregion(source, ®ion); 74 if (region.length < 1) { 75 return ISC_R_UNEXPECTEDEND; 76 } 77 78 RETERR(mem_tobuffer(target, region.base, region.length)); 79 isc_buffer_forward(source, region.length); 80 return ISC_R_SUCCESS; 81 } 82 83 static isc_result_t 84 towire_in_nimloc(ARGS_TOWIRE) { 85 REQUIRE(rdata->type == dns_rdatatype_nimloc); 86 REQUIRE(rdata->rdclass == dns_rdataclass_in); 87 REQUIRE(rdata->length != 0); 88 89 UNUSED(cctx); 90 91 return mem_tobuffer(target, rdata->data, rdata->length); 92 } 93 94 static int 95 compare_in_nimloc(ARGS_COMPARE) { 96 isc_region_t r1; 97 isc_region_t r2; 98 99 REQUIRE(rdata1->type == rdata2->type); 100 REQUIRE(rdata1->rdclass == rdata2->rdclass); 101 REQUIRE(rdata1->type == dns_rdatatype_nimloc); 102 REQUIRE(rdata1->rdclass == dns_rdataclass_in); 103 REQUIRE(rdata1->length != 0); 104 REQUIRE(rdata2->length != 0); 105 106 dns_rdata_toregion(rdata1, &r1); 107 dns_rdata_toregion(rdata2, &r2); 108 return isc_region_compare(&r1, &r2); 109 } 110 111 static isc_result_t 112 fromstruct_in_nimloc(ARGS_FROMSTRUCT) { 113 dns_rdata_in_nimloc_t *nimloc = source; 114 115 REQUIRE(type == dns_rdatatype_nimloc); 116 REQUIRE(rdclass == dns_rdataclass_in); 117 REQUIRE(nimloc != NULL); 118 REQUIRE(nimloc->common.rdtype == type); 119 REQUIRE(nimloc->common.rdclass == rdclass); 120 REQUIRE(nimloc->nimloc != NULL || nimloc->nimloc_len == 0); 121 122 UNUSED(type); 123 UNUSED(rdclass); 124 125 return mem_tobuffer(target, nimloc->nimloc, nimloc->nimloc_len); 126 } 127 128 static isc_result_t 129 tostruct_in_nimloc(ARGS_TOSTRUCT) { 130 dns_rdata_in_nimloc_t *nimloc = target; 131 isc_region_t r; 132 133 REQUIRE(rdata->type == dns_rdatatype_nimloc); 134 REQUIRE(rdata->rdclass == dns_rdataclass_in); 135 REQUIRE(nimloc != NULL); 136 REQUIRE(rdata->length != 0); 137 138 nimloc->common.rdclass = rdata->rdclass; 139 nimloc->common.rdtype = rdata->type; 140 ISC_LINK_INIT(&nimloc->common, link); 141 142 dns_rdata_toregion(rdata, &r); 143 nimloc->nimloc_len = r.length; 144 nimloc->nimloc = mem_maybedup(mctx, r.base, r.length); 145 nimloc->mctx = mctx; 146 return ISC_R_SUCCESS; 147 } 148 149 static void 150 freestruct_in_nimloc(ARGS_FREESTRUCT) { 151 dns_rdata_in_nimloc_t *nimloc = source; 152 153 REQUIRE(nimloc != NULL); 154 REQUIRE(nimloc->common.rdclass == dns_rdataclass_in); 155 REQUIRE(nimloc->common.rdtype == dns_rdatatype_nimloc); 156 157 if (nimloc->mctx == NULL) { 158 return; 159 } 160 161 if (nimloc->nimloc != NULL) { 162 isc_mem_free(nimloc->mctx, nimloc->nimloc); 163 } 164 nimloc->mctx = NULL; 165 } 166 167 static isc_result_t 168 additionaldata_in_nimloc(ARGS_ADDLDATA) { 169 REQUIRE(rdata->type == dns_rdatatype_nimloc); 170 REQUIRE(rdata->rdclass == dns_rdataclass_in); 171 172 UNUSED(rdata); 173 UNUSED(owner); 174 UNUSED(add); 175 UNUSED(arg); 176 177 return ISC_R_SUCCESS; 178 } 179 180 static isc_result_t 181 digest_in_nimloc(ARGS_DIGEST) { 182 isc_region_t r; 183 184 REQUIRE(rdata->type == dns_rdatatype_nimloc); 185 REQUIRE(rdata->rdclass == dns_rdataclass_in); 186 187 dns_rdata_toregion(rdata, &r); 188 189 return (digest)(arg, &r); 190 } 191 192 static bool 193 checkowner_in_nimloc(ARGS_CHECKOWNER) { 194 REQUIRE(type == dns_rdatatype_nimloc); 195 REQUIRE(rdclass == dns_rdataclass_in); 196 197 UNUSED(name); 198 UNUSED(type); 199 UNUSED(rdclass); 200 UNUSED(wildcard); 201 202 return true; 203 } 204 205 static bool 206 checknames_in_nimloc(ARGS_CHECKNAMES) { 207 REQUIRE(rdata->type == dns_rdatatype_nimloc); 208 REQUIRE(rdata->rdclass == dns_rdataclass_in); 209 210 UNUSED(rdata); 211 UNUSED(owner); 212 UNUSED(bad); 213 214 return true; 215 } 216 217 static int 218 casecompare_in_nimloc(ARGS_COMPARE) { 219 return compare_in_nimloc(rdata1, rdata2); 220 } 221 222 #endif /* RDATA_IN_1_NIMLOC_32_C */ 223