1 /* $NetBSD: sink_40.c,v 1.9 2025/01/26 16:25:33 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 #ifndef RDATA_GENERIC_SINK_40_C 17 #define RDATA_GENERIC_SINK_40_C 18 19 #include <dst/dst.h> 20 21 #define RRTYPE_SINK_ATTRIBUTES (0) 22 23 static isc_result_t 24 fromtext_sink(ARGS_FROMTEXT) { 25 isc_token_t token; 26 27 REQUIRE(type == dns_rdatatype_sink); 28 29 UNUSED(type); 30 UNUSED(rdclass); 31 UNUSED(origin); 32 UNUSED(options); 33 UNUSED(callbacks); 34 35 /* meaning */ 36 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, 37 false)); 38 if (token.value.as_ulong > 0xffU) { 39 RETTOK(ISC_R_RANGE); 40 } 41 RETERR(uint8_tobuffer(token.value.as_ulong, target)); 42 43 /* coding */ 44 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, 45 false)); 46 if (token.value.as_ulong > 0xffU) { 47 RETTOK(ISC_R_RANGE); 48 } 49 RETERR(uint8_tobuffer(token.value.as_ulong, target)); 50 51 /* subcoding */ 52 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, 53 false)); 54 if (token.value.as_ulong > 0xffU) { 55 RETTOK(ISC_R_RANGE); 56 } 57 RETERR(uint8_tobuffer(token.value.as_ulong, target)); 58 59 return isc_base64_tobuffer(lexer, target, -1); 60 } 61 62 static isc_result_t 63 totext_sink(ARGS_TOTEXT) { 64 isc_region_t sr; 65 char buf[sizeof("255 255 255")]; 66 uint8_t meaning, coding, subcoding; 67 68 REQUIRE(rdata->type == dns_rdatatype_sink); 69 REQUIRE(rdata->length >= 3); 70 71 dns_rdata_toregion(rdata, &sr); 72 73 /* Meaning, Coding and Subcoding */ 74 meaning = uint8_fromregion(&sr); 75 isc_region_consume(&sr, 1); 76 coding = uint8_fromregion(&sr); 77 isc_region_consume(&sr, 1); 78 subcoding = uint8_fromregion(&sr); 79 isc_region_consume(&sr, 1); 80 snprintf(buf, sizeof(buf), "%u %u %u", meaning, coding, subcoding); 81 RETERR(str_totext(buf, target)); 82 83 if (sr.length == 0U) { 84 return ISC_R_SUCCESS; 85 } 86 87 /* data */ 88 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { 89 RETERR(str_totext(" (", target)); 90 } 91 92 RETERR(str_totext(tctx->linebreak, target)); 93 94 if (tctx->width == 0) { /* No splitting */ 95 RETERR(isc_base64_totext(&sr, 60, "", target)); 96 } else { 97 RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, 98 target)); 99 } 100 101 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { 102 RETERR(str_totext(" )", target)); 103 } 104 105 return ISC_R_SUCCESS; 106 } 107 108 static isc_result_t 109 fromwire_sink(ARGS_FROMWIRE) { 110 isc_region_t sr; 111 112 REQUIRE(type == dns_rdatatype_sink); 113 114 UNUSED(type); 115 UNUSED(rdclass); 116 UNUSED(dctx); 117 118 isc_buffer_activeregion(source, &sr); 119 if (sr.length < 3) { 120 return ISC_R_UNEXPECTEDEND; 121 } 122 123 RETERR(mem_tobuffer(target, sr.base, sr.length)); 124 isc_buffer_forward(source, sr.length); 125 return ISC_R_SUCCESS; 126 } 127 128 static isc_result_t 129 towire_sink(ARGS_TOWIRE) { 130 REQUIRE(rdata->type == dns_rdatatype_sink); 131 REQUIRE(rdata->length >= 3); 132 133 UNUSED(cctx); 134 135 return mem_tobuffer(target, rdata->data, rdata->length); 136 } 137 138 static int 139 compare_sink(ARGS_COMPARE) { 140 isc_region_t r1; 141 isc_region_t r2; 142 143 REQUIRE(rdata1->type == rdata2->type); 144 REQUIRE(rdata1->rdclass == rdata2->rdclass); 145 REQUIRE(rdata1->type == dns_rdatatype_sink); 146 REQUIRE(rdata1->length >= 3); 147 REQUIRE(rdata2->length >= 3); 148 149 dns_rdata_toregion(rdata1, &r1); 150 dns_rdata_toregion(rdata2, &r2); 151 return isc_region_compare(&r1, &r2); 152 } 153 154 static isc_result_t 155 fromstruct_sink(ARGS_FROMSTRUCT) { 156 dns_rdata_sink_t *sink = source; 157 158 REQUIRE(type == dns_rdatatype_sink); 159 REQUIRE(sink != NULL); 160 REQUIRE(sink->common.rdtype == type); 161 REQUIRE(sink->common.rdclass == rdclass); 162 163 UNUSED(type); 164 UNUSED(rdclass); 165 166 /* Meaning */ 167 RETERR(uint8_tobuffer(sink->meaning, target)); 168 169 /* Coding */ 170 RETERR(uint8_tobuffer(sink->coding, target)); 171 172 /* Subcoding */ 173 RETERR(uint8_tobuffer(sink->subcoding, target)); 174 175 /* Data */ 176 return mem_tobuffer(target, sink->data, sink->datalen); 177 } 178 179 static isc_result_t 180 tostruct_sink(ARGS_TOSTRUCT) { 181 dns_rdata_sink_t *sink = target; 182 isc_region_t sr; 183 184 REQUIRE(rdata->type == dns_rdatatype_sink); 185 REQUIRE(sink != NULL); 186 REQUIRE(rdata->length >= 3); 187 188 sink->common.rdclass = rdata->rdclass; 189 sink->common.rdtype = rdata->type; 190 ISC_LINK_INIT(&sink->common, link); 191 192 dns_rdata_toregion(rdata, &sr); 193 194 /* Meaning */ 195 sink->meaning = uint8_fromregion(&sr); 196 isc_region_consume(&sr, 1); 197 198 /* Coding */ 199 sink->coding = uint8_fromregion(&sr); 200 isc_region_consume(&sr, 1); 201 202 /* Subcoding */ 203 sink->subcoding = uint8_fromregion(&sr); 204 isc_region_consume(&sr, 1); 205 206 /* Data */ 207 sink->datalen = sr.length; 208 sink->data = mem_maybedup(mctx, sr.base, sink->datalen); 209 sink->mctx = mctx; 210 return ISC_R_SUCCESS; 211 } 212 213 static void 214 freestruct_sink(ARGS_FREESTRUCT) { 215 dns_rdata_sink_t *sink = (dns_rdata_sink_t *)source; 216 217 REQUIRE(sink != NULL); 218 REQUIRE(sink->common.rdtype == dns_rdatatype_sink); 219 220 if (sink->mctx == NULL) { 221 return; 222 } 223 224 if (sink->data != NULL) { 225 isc_mem_free(sink->mctx, sink->data); 226 } 227 sink->mctx = NULL; 228 } 229 230 static isc_result_t 231 additionaldata_sink(ARGS_ADDLDATA) { 232 REQUIRE(rdata->type == dns_rdatatype_sink); 233 234 UNUSED(rdata); 235 UNUSED(owner); 236 UNUSED(add); 237 UNUSED(arg); 238 239 return ISC_R_SUCCESS; 240 } 241 242 static isc_result_t 243 digest_sink(ARGS_DIGEST) { 244 isc_region_t r; 245 246 REQUIRE(rdata->type == dns_rdatatype_sink); 247 248 dns_rdata_toregion(rdata, &r); 249 250 return (digest)(arg, &r); 251 } 252 253 static bool 254 checkowner_sink(ARGS_CHECKOWNER) { 255 REQUIRE(type == dns_rdatatype_sink); 256 257 UNUSED(name); 258 UNUSED(type); 259 UNUSED(rdclass); 260 UNUSED(wildcard); 261 262 return true; 263 } 264 265 static bool 266 checknames_sink(ARGS_CHECKNAMES) { 267 REQUIRE(rdata->type == dns_rdatatype_sink); 268 269 UNUSED(rdata); 270 UNUSED(owner); 271 UNUSED(bad); 272 273 return true; 274 } 275 276 static int 277 casecompare_sink(ARGS_COMPARE) { 278 return compare_sink(rdata1, rdata2); 279 } 280 #endif /* RDATA_GENERIC_SINK_40_C */ 281