1 1.9 christos /* $NetBSD: md_3.c,v 1.10 2026/01/29 18:37:52 christos Exp $ */ 2 1.1 christos 3 1.1 christos /* 4 1.1 christos * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 1.1 christos * 6 1.7 christos * SPDX-License-Identifier: MPL-2.0 7 1.7 christos * 8 1.1 christos * This Source Code Form is subject to the terms of the Mozilla Public 9 1.1 christos * License, v. 2.0. If a copy of the MPL was not distributed with this 10 1.6 christos * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 1.1 christos * 12 1.1 christos * See the COPYRIGHT file distributed with this work for additional 13 1.1 christos * information regarding copyright ownership. 14 1.1 christos */ 15 1.1 christos 16 1.1 christos #ifndef RDATA_GENERIC_MD_3_C 17 1.1 christos #define RDATA_GENERIC_MD_3_C 18 1.1 christos 19 1.1 christos #define RRTYPE_MD_ATTRIBUTES (0) 20 1.1 christos 21 1.7 christos static isc_result_t 22 1.1 christos fromtext_md(ARGS_FROMTEXT) { 23 1.1 christos isc_token_t token; 24 1.1 christos dns_name_t name; 25 1.1 christos isc_buffer_t buffer; 26 1.1 christos 27 1.1 christos REQUIRE(type == dns_rdatatype_md); 28 1.1 christos 29 1.1 christos UNUSED(type); 30 1.1 christos UNUSED(rdclass); 31 1.1 christos UNUSED(callbacks); 32 1.1 christos 33 1.1 christos RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, 34 1.3 christos false)); 35 1.1 christos 36 1.1 christos dns_name_init(&name, NULL); 37 1.1 christos buffer_fromregion(&buffer, &token.value.as_region); 38 1.5 christos if (origin == NULL) { 39 1.1 christos origin = dns_rootname; 40 1.5 christos } 41 1.1 christos RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); 42 1.9 christos return ISC_R_SUCCESS; 43 1.1 christos } 44 1.1 christos 45 1.7 christos static isc_result_t 46 1.1 christos totext_md(ARGS_TOTEXT) { 47 1.1 christos isc_region_t region; 48 1.1 christos dns_name_t name; 49 1.1 christos dns_name_t prefix; 50 1.9 christos unsigned int opts; 51 1.1 christos 52 1.1 christos REQUIRE(rdata->type == dns_rdatatype_md); 53 1.1 christos REQUIRE(rdata->length != 0); 54 1.1 christos 55 1.1 christos dns_name_init(&name, NULL); 56 1.1 christos dns_name_init(&prefix, NULL); 57 1.1 christos 58 1.1 christos dns_rdata_toregion(rdata, ®ion); 59 1.1 christos dns_name_fromregion(&name, ®ion); 60 1.1 christos 61 1.9 christos opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT 62 1.9 christos : 0; 63 1.9 christos return dns_name_totext(&prefix, opts, target); 64 1.1 christos } 65 1.1 christos 66 1.7 christos static isc_result_t 67 1.1 christos fromwire_md(ARGS_FROMWIRE) { 68 1.1 christos dns_name_t name; 69 1.1 christos 70 1.1 christos REQUIRE(type == dns_rdatatype_md); 71 1.1 christos 72 1.1 christos UNUSED(type); 73 1.1 christos UNUSED(rdclass); 74 1.1 christos 75 1.9 christos dctx = dns_decompress_setpermitted(dctx, true); 76 1.1 christos 77 1.1 christos dns_name_init(&name, NULL); 78 1.9 christos return dns_name_fromwire(&name, source, dctx, target); 79 1.1 christos } 80 1.1 christos 81 1.7 christos static isc_result_t 82 1.1 christos towire_md(ARGS_TOWIRE) { 83 1.1 christos dns_name_t name; 84 1.1 christos dns_offsets_t offsets; 85 1.1 christos isc_region_t region; 86 1.1 christos 87 1.1 christos REQUIRE(rdata->type == dns_rdatatype_md); 88 1.1 christos REQUIRE(rdata->length != 0); 89 1.1 christos 90 1.9 christos dns_compress_setpermitted(cctx, true); 91 1.1 christos 92 1.1 christos dns_name_init(&name, offsets); 93 1.1 christos dns_rdata_toregion(rdata, ®ion); 94 1.1 christos dns_name_fromregion(&name, ®ion); 95 1.1 christos 96 1.9 christos return dns_name_towire(&name, cctx, target, NULL); 97 1.1 christos } 98 1.1 christos 99 1.7 christos static int 100 1.1 christos compare_md(ARGS_COMPARE) { 101 1.1 christos dns_name_t name1; 102 1.1 christos dns_name_t name2; 103 1.1 christos isc_region_t region1; 104 1.1 christos isc_region_t region2; 105 1.1 christos 106 1.1 christos REQUIRE(rdata1->type == rdata2->type); 107 1.1 christos REQUIRE(rdata1->rdclass == rdata2->rdclass); 108 1.1 christos REQUIRE(rdata1->type == dns_rdatatype_md); 109 1.1 christos REQUIRE(rdata1->length != 0); 110 1.1 christos REQUIRE(rdata2->length != 0); 111 1.1 christos 112 1.1 christos dns_name_init(&name1, NULL); 113 1.1 christos dns_name_init(&name2, NULL); 114 1.1 christos 115 1.1 christos dns_rdata_toregion(rdata1, ®ion1); 116 1.1 christos dns_rdata_toregion(rdata2, ®ion2); 117 1.1 christos 118 1.1 christos dns_name_fromregion(&name1, ®ion1); 119 1.1 christos dns_name_fromregion(&name2, ®ion2); 120 1.1 christos 121 1.9 christos return dns_name_rdatacompare(&name1, &name2); 122 1.1 christos } 123 1.1 christos 124 1.7 christos static isc_result_t 125 1.1 christos fromstruct_md(ARGS_FROMSTRUCT) { 126 1.1 christos dns_rdata_md_t *md = source; 127 1.1 christos isc_region_t region; 128 1.1 christos 129 1.1 christos REQUIRE(type == dns_rdatatype_md); 130 1.4 christos REQUIRE(md != NULL); 131 1.1 christos REQUIRE(md->common.rdtype == type); 132 1.1 christos REQUIRE(md->common.rdclass == rdclass); 133 1.1 christos 134 1.1 christos UNUSED(type); 135 1.1 christos UNUSED(rdclass); 136 1.1 christos 137 1.1 christos dns_name_toregion(&md->md, ®ion); 138 1.9 christos return isc_buffer_copyregion(target, ®ion); 139 1.1 christos } 140 1.1 christos 141 1.7 christos static isc_result_t 142 1.1 christos tostruct_md(ARGS_TOSTRUCT) { 143 1.1 christos dns_rdata_md_t *md = target; 144 1.1 christos isc_region_t r; 145 1.1 christos dns_name_t name; 146 1.1 christos 147 1.1 christos REQUIRE(rdata->type == dns_rdatatype_md); 148 1.4 christos REQUIRE(md != NULL); 149 1.1 christos REQUIRE(rdata->length != 0); 150 1.1 christos 151 1.10 christos DNS_RDATACOMMON_INIT(md, rdata->type, rdata->rdclass); 152 1.1 christos 153 1.1 christos dns_name_init(&name, NULL); 154 1.1 christos dns_rdata_toregion(rdata, &r); 155 1.1 christos dns_name_fromregion(&name, &r); 156 1.1 christos dns_name_init(&md->md, NULL); 157 1.8 christos name_duporclone(&name, mctx, &md->md); 158 1.1 christos md->mctx = mctx; 159 1.9 christos return ISC_R_SUCCESS; 160 1.1 christos } 161 1.1 christos 162 1.7 christos static void 163 1.1 christos freestruct_md(ARGS_FREESTRUCT) { 164 1.1 christos dns_rdata_md_t *md = source; 165 1.1 christos 166 1.4 christos REQUIRE(md != NULL); 167 1.1 christos REQUIRE(md->common.rdtype == dns_rdatatype_md); 168 1.1 christos 169 1.5 christos if (md->mctx == NULL) { 170 1.1 christos return; 171 1.5 christos } 172 1.1 christos 173 1.1 christos dns_name_free(&md->md, md->mctx); 174 1.1 christos md->mctx = NULL; 175 1.1 christos } 176 1.1 christos 177 1.7 christos static isc_result_t 178 1.1 christos additionaldata_md(ARGS_ADDLDATA) { 179 1.1 christos dns_name_t name; 180 1.1 christos dns_offsets_t offsets; 181 1.1 christos isc_region_t region; 182 1.1 christos 183 1.1 christos REQUIRE(rdata->type == dns_rdatatype_md); 184 1.1 christos 185 1.8 christos UNUSED(owner); 186 1.8 christos 187 1.1 christos dns_name_init(&name, offsets); 188 1.1 christos dns_rdata_toregion(rdata, ®ion); 189 1.1 christos dns_name_fromregion(&name, ®ion); 190 1.1 christos 191 1.9 christos return (add)(arg, &name, dns_rdatatype_a, NULL DNS__DB_FILELINE); 192 1.1 christos } 193 1.1 christos 194 1.7 christos static isc_result_t 195 1.1 christos digest_md(ARGS_DIGEST) { 196 1.1 christos isc_region_t r; 197 1.1 christos dns_name_t name; 198 1.1 christos 199 1.1 christos REQUIRE(rdata->type == dns_rdatatype_md); 200 1.1 christos 201 1.1 christos dns_rdata_toregion(rdata, &r); 202 1.1 christos dns_name_init(&name, NULL); 203 1.1 christos dns_name_fromregion(&name, &r); 204 1.1 christos 205 1.9 christos return dns_name_digest(&name, digest, arg); 206 1.1 christos } 207 1.1 christos 208 1.7 christos static bool 209 1.1 christos checkowner_md(ARGS_CHECKOWNER) { 210 1.1 christos REQUIRE(type == dns_rdatatype_md); 211 1.1 christos 212 1.1 christos UNUSED(name); 213 1.1 christos UNUSED(type); 214 1.1 christos UNUSED(rdclass); 215 1.1 christos UNUSED(wildcard); 216 1.1 christos 217 1.9 christos return true; 218 1.1 christos } 219 1.1 christos 220 1.7 christos static bool 221 1.1 christos checknames_md(ARGS_CHECKNAMES) { 222 1.1 christos REQUIRE(rdata->type == dns_rdatatype_md); 223 1.1 christos 224 1.1 christos UNUSED(rdata); 225 1.1 christos UNUSED(owner); 226 1.1 christos UNUSED(bad); 227 1.1 christos 228 1.9 christos return true; 229 1.1 christos } 230 1.1 christos 231 1.7 christos static int 232 1.1 christos casecompare_md(ARGS_COMPARE) { 233 1.9 christos return compare_md(rdata1, rdata2); 234 1.1 christos } 235 1.1 christos 236 1.5 christos #endif /* RDATA_GENERIC_MD_3_C */ 237