1 /* $NetBSD: dhcid_49.c,v 1.11 2026/01/29 18:37:54 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 /* RFC 4701 */ 17 18 #ifndef RDATA_IN_1_DHCID_49_C 19 #define RDATA_IN_1_DHCID_49_C 1 20 21 #define RRTYPE_DHCID_ATTRIBUTES 0 22 23 static isc_result_t 24 fromtext_in_dhcid(ARGS_FROMTEXT) { 25 REQUIRE(type == dns_rdatatype_dhcid); 26 REQUIRE(rdclass == dns_rdataclass_in); 27 28 UNUSED(type); 29 UNUSED(rdclass); 30 UNUSED(origin); 31 UNUSED(options); 32 UNUSED(callbacks); 33 34 return isc_base64_tobuffer(lexer, target, -2); 35 } 36 37 static isc_result_t 38 totext_in_dhcid(ARGS_TOTEXT) { 39 isc_region_t sr, sr2; 40 /* " ; 64000 255 64000" */ 41 char buf[5 + 3 * 11 + 1]; 42 43 REQUIRE(rdata->type == dns_rdatatype_dhcid); 44 REQUIRE(rdata->rdclass == dns_rdataclass_in); 45 REQUIRE(rdata->length != 0); 46 47 dns_rdata_toregion(rdata, &sr); 48 sr2 = sr; 49 50 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { 51 RETERR(str_totext("( " /*)*/, target)); 52 } 53 if (tctx->width == 0) { /* No splitting */ 54 RETERR(isc_base64_totext(&sr, 60, "", target)); 55 } else { 56 RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, 57 target)); 58 } 59 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { 60 RETERR(str_totext(/* ( */ " )", target)); 61 if (rdata->length > 2) { 62 snprintf(buf, sizeof(buf), " ; %u %u %u", 63 sr2.base[0] * 256U + sr2.base[1], sr2.base[2], 64 rdata->length - 3U); 65 RETERR(str_totext(buf, target)); 66 } 67 } 68 return ISC_R_SUCCESS; 69 } 70 71 static isc_result_t 72 fromwire_in_dhcid(ARGS_FROMWIRE) { 73 isc_region_t sr; 74 75 REQUIRE(type == dns_rdatatype_dhcid); 76 REQUIRE(rdclass == dns_rdataclass_in); 77 78 UNUSED(type); 79 UNUSED(rdclass); 80 UNUSED(dctx); 81 82 isc_buffer_activeregion(source, &sr); 83 if (sr.length == 0) { 84 return ISC_R_UNEXPECTEDEND; 85 } 86 87 isc_buffer_forward(source, sr.length); 88 return mem_tobuffer(target, sr.base, sr.length); 89 } 90 91 static isc_result_t 92 towire_in_dhcid(ARGS_TOWIRE) { 93 isc_region_t sr; 94 95 REQUIRE(rdata->type == dns_rdatatype_dhcid); 96 REQUIRE(rdata->rdclass == dns_rdataclass_in); 97 REQUIRE(rdata->length != 0); 98 99 UNUSED(cctx); 100 101 dns_rdata_toregion(rdata, &sr); 102 return mem_tobuffer(target, sr.base, sr.length); 103 } 104 105 static int 106 compare_in_dhcid(ARGS_COMPARE) { 107 isc_region_t r1; 108 isc_region_t r2; 109 110 REQUIRE(rdata1->type == rdata2->type); 111 REQUIRE(rdata1->rdclass == rdata2->rdclass); 112 REQUIRE(rdata1->type == dns_rdatatype_dhcid); 113 REQUIRE(rdata1->rdclass == dns_rdataclass_in); 114 REQUIRE(rdata1->length != 0); 115 REQUIRE(rdata2->length != 0); 116 117 dns_rdata_toregion(rdata1, &r1); 118 dns_rdata_toregion(rdata2, &r2); 119 return isc_region_compare(&r1, &r2); 120 } 121 122 static isc_result_t 123 fromstruct_in_dhcid(ARGS_FROMSTRUCT) { 124 dns_rdata_in_dhcid_t *dhcid = source; 125 126 REQUIRE(type == dns_rdatatype_dhcid); 127 REQUIRE(rdclass == dns_rdataclass_in); 128 REQUIRE(dhcid != NULL); 129 REQUIRE(dhcid->common.rdtype == type); 130 REQUIRE(dhcid->common.rdclass == rdclass); 131 REQUIRE(dhcid->length != 0); 132 133 UNUSED(type); 134 UNUSED(rdclass); 135 136 return mem_tobuffer(target, dhcid->dhcid, dhcid->length); 137 } 138 139 static isc_result_t 140 tostruct_in_dhcid(ARGS_TOSTRUCT) { 141 dns_rdata_in_dhcid_t *dhcid = target; 142 isc_region_t region; 143 144 REQUIRE(rdata->type == dns_rdatatype_dhcid); 145 REQUIRE(rdata->rdclass == dns_rdataclass_in); 146 REQUIRE(dhcid != NULL); 147 REQUIRE(rdata->length != 0); 148 149 DNS_RDATACOMMON_INIT(dhcid, rdata->type, rdata->rdclass); 150 151 dns_rdata_toregion(rdata, ®ion); 152 153 dhcid->dhcid = mem_maybedup(mctx, region.base, region.length); 154 dhcid->mctx = mctx; 155 return ISC_R_SUCCESS; 156 } 157 158 static void 159 freestruct_in_dhcid(ARGS_FREESTRUCT) { 160 dns_rdata_in_dhcid_t *dhcid = source; 161 162 REQUIRE(dhcid != NULL); 163 REQUIRE(dhcid->common.rdtype == dns_rdatatype_dhcid); 164 REQUIRE(dhcid->common.rdclass == dns_rdataclass_in); 165 166 if (dhcid->mctx == NULL) { 167 return; 168 } 169 170 if (dhcid->dhcid != NULL) { 171 isc_mem_free(dhcid->mctx, dhcid->dhcid); 172 } 173 dhcid->mctx = NULL; 174 } 175 176 static isc_result_t 177 additionaldata_in_dhcid(ARGS_ADDLDATA) { 178 REQUIRE(rdata->type == dns_rdatatype_dhcid); 179 REQUIRE(rdata->rdclass == dns_rdataclass_in); 180 181 UNUSED(rdata); 182 UNUSED(owner); 183 UNUSED(add); 184 UNUSED(arg); 185 186 return ISC_R_SUCCESS; 187 } 188 189 static isc_result_t 190 digest_in_dhcid(ARGS_DIGEST) { 191 isc_region_t r; 192 193 REQUIRE(rdata->type == dns_rdatatype_dhcid); 194 REQUIRE(rdata->rdclass == dns_rdataclass_in); 195 196 dns_rdata_toregion(rdata, &r); 197 198 return (digest)(arg, &r); 199 } 200 201 static bool 202 checkowner_in_dhcid(ARGS_CHECKOWNER) { 203 REQUIRE(type == dns_rdatatype_dhcid); 204 REQUIRE(rdclass == dns_rdataclass_in); 205 206 UNUSED(name); 207 UNUSED(type); 208 UNUSED(rdclass); 209 UNUSED(wildcard); 210 211 return true; 212 } 213 214 static bool 215 checknames_in_dhcid(ARGS_CHECKNAMES) { 216 REQUIRE(rdata->type == dns_rdatatype_dhcid); 217 REQUIRE(rdata->rdclass == dns_rdataclass_in); 218 219 UNUSED(rdata); 220 UNUSED(owner); 221 UNUSED(bad); 222 223 return true; 224 } 225 226 static int 227 casecompare_in_dhcid(ARGS_COMPARE) { 228 return compare_in_dhcid(rdata1, rdata2); 229 } 230 231 #endif /* RDATA_IN_1_DHCID_49_C */ 232