nimloc_32.c revision 1.9
1/* $NetBSD: nimloc_32.c,v 1.9 2024/02/21 22:52:15 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 23static isc_result_t 24fromtext_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 37static isc_result_t 38totext_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 62static isc_result_t 63fromwire_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(options); 72 UNUSED(rdclass); 73 74 isc_buffer_activeregion(source, ®ion); 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 84static isc_result_t 85towire_in_nimloc(ARGS_TOWIRE) { 86 REQUIRE(rdata->type == dns_rdatatype_nimloc); 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 95static int 96compare_in_nimloc(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_nimloc); 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 112static isc_result_t 113fromstruct_in_nimloc(ARGS_FROMSTRUCT) { 114 dns_rdata_in_nimloc_t *nimloc = source; 115 116 REQUIRE(type == dns_rdatatype_nimloc); 117 REQUIRE(rdclass == dns_rdataclass_in); 118 REQUIRE(nimloc != NULL); 119 REQUIRE(nimloc->common.rdtype == type); 120 REQUIRE(nimloc->common.rdclass == rdclass); 121 REQUIRE(nimloc->nimloc != NULL || nimloc->nimloc_len == 0); 122 123 UNUSED(type); 124 UNUSED(rdclass); 125 126 return (mem_tobuffer(target, nimloc->nimloc, nimloc->nimloc_len)); 127} 128 129static isc_result_t 130tostruct_in_nimloc(ARGS_TOSTRUCT) { 131 dns_rdata_in_nimloc_t *nimloc = target; 132 isc_region_t r; 133 134 REQUIRE(rdata->type == dns_rdatatype_nimloc); 135 REQUIRE(rdata->rdclass == dns_rdataclass_in); 136 REQUIRE(nimloc != NULL); 137 REQUIRE(rdata->length != 0); 138 139 nimloc->common.rdclass = rdata->rdclass; 140 nimloc->common.rdtype = rdata->type; 141 ISC_LINK_INIT(&nimloc->common, link); 142 143 dns_rdata_toregion(rdata, &r); 144 nimloc->nimloc_len = r.length; 145 nimloc->nimloc = mem_maybedup(mctx, r.base, r.length); 146 if (nimloc->nimloc == NULL) { 147 return (ISC_R_NOMEMORY); 148 } 149 150 nimloc->mctx = mctx; 151 return (ISC_R_SUCCESS); 152} 153 154static void 155freestruct_in_nimloc(ARGS_FREESTRUCT) { 156 dns_rdata_in_nimloc_t *nimloc = source; 157 158 REQUIRE(nimloc != NULL); 159 REQUIRE(nimloc->common.rdclass == dns_rdataclass_in); 160 REQUIRE(nimloc->common.rdtype == dns_rdatatype_nimloc); 161 162 if (nimloc->mctx == NULL) { 163 return; 164 } 165 166 if (nimloc->nimloc != NULL) { 167 isc_mem_free(nimloc->mctx, nimloc->nimloc); 168 } 169 nimloc->mctx = NULL; 170} 171 172static isc_result_t 173additionaldata_in_nimloc(ARGS_ADDLDATA) { 174 REQUIRE(rdata->type == dns_rdatatype_nimloc); 175 REQUIRE(rdata->rdclass == dns_rdataclass_in); 176 177 UNUSED(rdata); 178 UNUSED(owner); 179 UNUSED(add); 180 UNUSED(arg); 181 182 return (ISC_R_SUCCESS); 183} 184 185static isc_result_t 186digest_in_nimloc(ARGS_DIGEST) { 187 isc_region_t r; 188 189 REQUIRE(rdata->type == dns_rdatatype_nimloc); 190 REQUIRE(rdata->rdclass == dns_rdataclass_in); 191 192 dns_rdata_toregion(rdata, &r); 193 194 return ((digest)(arg, &r)); 195} 196 197static bool 198checkowner_in_nimloc(ARGS_CHECKOWNER) { 199 REQUIRE(type == dns_rdatatype_nimloc); 200 REQUIRE(rdclass == dns_rdataclass_in); 201 202 UNUSED(name); 203 UNUSED(type); 204 UNUSED(rdclass); 205 UNUSED(wildcard); 206 207 return (true); 208} 209 210static bool 211checknames_in_nimloc(ARGS_CHECKNAMES) { 212 REQUIRE(rdata->type == dns_rdatatype_nimloc); 213 REQUIRE(rdata->rdclass == dns_rdataclass_in); 214 215 UNUSED(rdata); 216 UNUSED(owner); 217 UNUSED(bad); 218 219 return (true); 220} 221 222static int 223casecompare_in_nimloc(ARGS_COMPARE) { 224 return (compare_in_nimloc(rdata1, rdata2)); 225} 226 227#endif /* RDATA_IN_1_NIMLOC_32_C */ 228