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