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