1 1.9 christos /* $NetBSD: dname_39.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 /* RFC2672 */ 17 1.1 christos 18 1.1 christos #ifndef RDATA_GENERIC_DNAME_39_C 19 1.1 christos #define RDATA_GENERIC_DNAME_39_C 20 1.1 christos 21 1.1 christos #define RRTYPE_DNAME_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON) 22 1.1 christos 23 1.7 christos static isc_result_t 24 1.1 christos fromtext_dname(ARGS_FROMTEXT) { 25 1.1 christos isc_token_t token; 26 1.1 christos dns_name_t name; 27 1.1 christos isc_buffer_t buffer; 28 1.1 christos 29 1.1 christos REQUIRE(type == dns_rdatatype_dname); 30 1.1 christos 31 1.1 christos UNUSED(type); 32 1.1 christos UNUSED(rdclass); 33 1.1 christos UNUSED(callbacks); 34 1.1 christos 35 1.1 christos RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, 36 1.3 christos false)); 37 1.1 christos 38 1.1 christos dns_name_init(&name, NULL); 39 1.1 christos buffer_fromregion(&buffer, &token.value.as_region); 40 1.5 christos if (origin == NULL) { 41 1.1 christos origin = dns_rootname; 42 1.5 christos } 43 1.1 christos RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); 44 1.9 christos return ISC_R_SUCCESS; 45 1.1 christos } 46 1.1 christos 47 1.7 christos static isc_result_t 48 1.1 christos totext_dname(ARGS_TOTEXT) { 49 1.1 christos isc_region_t region; 50 1.1 christos dns_name_t name; 51 1.1 christos dns_name_t prefix; 52 1.9 christos unsigned int opts; 53 1.1 christos 54 1.1 christos REQUIRE(rdata->type == dns_rdatatype_dname); 55 1.1 christos REQUIRE(rdata->length != 0); 56 1.1 christos 57 1.1 christos dns_name_init(&name, NULL); 58 1.1 christos dns_name_init(&prefix, NULL); 59 1.1 christos 60 1.1 christos dns_rdata_toregion(rdata, ®ion); 61 1.1 christos dns_name_fromregion(&name, ®ion); 62 1.1 christos 63 1.9 christos opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT 64 1.9 christos : 0; 65 1.9 christos return dns_name_totext(&prefix, opts, target); 66 1.1 christos } 67 1.1 christos 68 1.7 christos static isc_result_t 69 1.1 christos fromwire_dname(ARGS_FROMWIRE) { 70 1.1 christos dns_name_t name; 71 1.1 christos 72 1.1 christos REQUIRE(type == dns_rdatatype_dname); 73 1.1 christos 74 1.1 christos UNUSED(type); 75 1.1 christos UNUSED(rdclass); 76 1.1 christos 77 1.9 christos dctx = dns_decompress_setpermitted(dctx, false); 78 1.1 christos 79 1.1 christos dns_name_init(&name, NULL); 80 1.9 christos return dns_name_fromwire(&name, source, dctx, target); 81 1.1 christos } 82 1.1 christos 83 1.7 christos static isc_result_t 84 1.1 christos towire_dname(ARGS_TOWIRE) { 85 1.1 christos dns_name_t name; 86 1.1 christos dns_offsets_t offsets; 87 1.1 christos isc_region_t region; 88 1.1 christos 89 1.1 christos REQUIRE(rdata->type == dns_rdatatype_dname); 90 1.1 christos REQUIRE(rdata->length != 0); 91 1.1 christos 92 1.9 christos dns_compress_setpermitted(cctx, false); 93 1.1 christos dns_name_init(&name, offsets); 94 1.1 christos dns_rdata_toregion(rdata, ®ion); 95 1.1 christos dns_name_fromregion(&name, ®ion); 96 1.1 christos 97 1.9 christos return dns_name_towire(&name, cctx, target, NULL); 98 1.1 christos } 99 1.1 christos 100 1.7 christos static int 101 1.1 christos compare_dname(ARGS_COMPARE) { 102 1.1 christos dns_name_t name1; 103 1.1 christos dns_name_t name2; 104 1.1 christos isc_region_t region1; 105 1.1 christos isc_region_t region2; 106 1.1 christos 107 1.1 christos REQUIRE(rdata1->type == rdata2->type); 108 1.1 christos REQUIRE(rdata1->rdclass == rdata2->rdclass); 109 1.1 christos REQUIRE(rdata1->type == dns_rdatatype_dname); 110 1.1 christos REQUIRE(rdata1->length != 0); 111 1.1 christos REQUIRE(rdata2->length != 0); 112 1.1 christos 113 1.1 christos dns_name_init(&name1, NULL); 114 1.1 christos dns_name_init(&name2, NULL); 115 1.1 christos 116 1.1 christos dns_rdata_toregion(rdata1, ®ion1); 117 1.1 christos dns_rdata_toregion(rdata2, ®ion2); 118 1.1 christos 119 1.1 christos dns_name_fromregion(&name1, ®ion1); 120 1.1 christos dns_name_fromregion(&name2, ®ion2); 121 1.1 christos 122 1.9 christos return dns_name_rdatacompare(&name1, &name2); 123 1.1 christos } 124 1.1 christos 125 1.7 christos static isc_result_t 126 1.1 christos fromstruct_dname(ARGS_FROMSTRUCT) { 127 1.1 christos dns_rdata_dname_t *dname = source; 128 1.1 christos isc_region_t region; 129 1.1 christos 130 1.1 christos REQUIRE(type == dns_rdatatype_dname); 131 1.4 christos REQUIRE(dname != NULL); 132 1.1 christos REQUIRE(dname->common.rdtype == type); 133 1.1 christos REQUIRE(dname->common.rdclass == rdclass); 134 1.1 christos 135 1.1 christos UNUSED(type); 136 1.1 christos UNUSED(rdclass); 137 1.1 christos 138 1.1 christos dns_name_toregion(&dname->dname, ®ion); 139 1.9 christos return isc_buffer_copyregion(target, ®ion); 140 1.1 christos } 141 1.1 christos 142 1.7 christos static isc_result_t 143 1.1 christos tostruct_dname(ARGS_TOSTRUCT) { 144 1.1 christos isc_region_t region; 145 1.1 christos dns_rdata_dname_t *dname = target; 146 1.1 christos dns_name_t name; 147 1.1 christos 148 1.1 christos REQUIRE(rdata->type == dns_rdatatype_dname); 149 1.4 christos REQUIRE(dname != NULL); 150 1.1 christos REQUIRE(rdata->length != 0); 151 1.1 christos 152 1.10 christos DNS_RDATACOMMON_INIT(dname, rdata->type, rdata->rdclass); 153 1.1 christos 154 1.1 christos dns_name_init(&name, NULL); 155 1.1 christos dns_rdata_toregion(rdata, ®ion); 156 1.1 christos dns_name_fromregion(&name, ®ion); 157 1.1 christos dns_name_init(&dname->dname, NULL); 158 1.8 christos name_duporclone(&name, mctx, &dname->dname); 159 1.1 christos dname->mctx = mctx; 160 1.9 christos return ISC_R_SUCCESS; 161 1.1 christos } 162 1.1 christos 163 1.7 christos static void 164 1.1 christos freestruct_dname(ARGS_FREESTRUCT) { 165 1.1 christos dns_rdata_dname_t *dname = source; 166 1.1 christos 167 1.4 christos REQUIRE(dname != NULL); 168 1.1 christos REQUIRE(dname->common.rdtype == dns_rdatatype_dname); 169 1.1 christos 170 1.5 christos if (dname->mctx == NULL) { 171 1.1 christos return; 172 1.5 christos } 173 1.1 christos 174 1.1 christos dns_name_free(&dname->dname, dname->mctx); 175 1.1 christos dname->mctx = NULL; 176 1.1 christos } 177 1.1 christos 178 1.7 christos static isc_result_t 179 1.1 christos additionaldata_dname(ARGS_ADDLDATA) { 180 1.8 christos REQUIRE(rdata->type == dns_rdatatype_dname); 181 1.8 christos 182 1.1 christos UNUSED(rdata); 183 1.8 christos UNUSED(owner); 184 1.1 christos UNUSED(add); 185 1.1 christos UNUSED(arg); 186 1.1 christos 187 1.9 christos return ISC_R_SUCCESS; 188 1.1 christos } 189 1.1 christos 190 1.7 christos static isc_result_t 191 1.1 christos digest_dname(ARGS_DIGEST) { 192 1.1 christos isc_region_t r; 193 1.1 christos dns_name_t name; 194 1.1 christos 195 1.1 christos REQUIRE(rdata->type == dns_rdatatype_dname); 196 1.1 christos 197 1.1 christos dns_rdata_toregion(rdata, &r); 198 1.1 christos dns_name_init(&name, NULL); 199 1.1 christos dns_name_fromregion(&name, &r); 200 1.1 christos 201 1.9 christos return dns_name_digest(&name, digest, arg); 202 1.1 christos } 203 1.1 christos 204 1.7 christos static bool 205 1.1 christos checkowner_dname(ARGS_CHECKOWNER) { 206 1.1 christos REQUIRE(type == dns_rdatatype_dname); 207 1.1 christos 208 1.1 christos UNUSED(name); 209 1.1 christos UNUSED(type); 210 1.1 christos UNUSED(rdclass); 211 1.1 christos UNUSED(wildcard); 212 1.1 christos 213 1.9 christos return true; 214 1.1 christos } 215 1.1 christos 216 1.7 christos static bool 217 1.1 christos checknames_dname(ARGS_CHECKNAMES) { 218 1.1 christos REQUIRE(rdata->type == dns_rdatatype_dname); 219 1.1 christos 220 1.1 christos UNUSED(rdata); 221 1.1 christos UNUSED(owner); 222 1.1 christos UNUSED(bad); 223 1.1 christos 224 1.9 christos return true; 225 1.1 christos } 226 1.1 christos 227 1.7 christos static int 228 1.1 christos casecompare_dname(ARGS_COMPARE) { 229 1.9 christos return compare_dname(rdata1, rdata2); 230 1.1 christos } 231 1.5 christos #endif /* RDATA_GENERIC_DNAME_39_C */ 232