1 /* $NetBSD: l64_106.c,v 1.9 2025/01/26 16:25:31 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_L64_106_C 17 #define RDATA_GENERIC_L64_106_C 18 19 #include <string.h> 20 21 #include <isc/net.h> 22 23 #define RRTYPE_L64_ATTRIBUTES (0) 24 25 static isc_result_t 26 fromtext_l64(ARGS_FROMTEXT) { 27 isc_token_t token; 28 unsigned char locator[NS_LOCATORSZ]; 29 30 REQUIRE(type == dns_rdatatype_l64); 31 32 UNUSED(type); 33 UNUSED(rdclass); 34 UNUSED(origin); 35 UNUSED(options); 36 UNUSED(callbacks); 37 38 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, 39 false)); 40 if (token.value.as_ulong > 0xffffU) { 41 RETTOK(ISC_R_RANGE); 42 } 43 RETERR(uint16_tobuffer(token.value.as_ulong, target)); 44 45 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, 46 false)); 47 48 if (locator_pton(DNS_AS_STR(token), locator) != 1) { 49 RETTOK(DNS_R_SYNTAX); 50 } 51 return mem_tobuffer(target, locator, NS_LOCATORSZ); 52 } 53 54 static isc_result_t 55 totext_l64(ARGS_TOTEXT) { 56 isc_region_t region; 57 char buf[sizeof("xxxx:xxxx:xxxx:xxxx")]; 58 unsigned short num; 59 60 REQUIRE(rdata->type == dns_rdatatype_l64); 61 REQUIRE(rdata->length == 10); 62 63 UNUSED(tctx); 64 65 dns_rdata_toregion(rdata, ®ion); 66 num = uint16_fromregion(®ion); 67 isc_region_consume(®ion, 2); 68 snprintf(buf, sizeof(buf), "%u", num); 69 RETERR(str_totext(buf, target)); 70 71 RETERR(str_totext(" ", target)); 72 73 snprintf(buf, sizeof(buf), "%x:%x:%x:%x", 74 region.base[0] << 8 | region.base[1], 75 region.base[2] << 8 | region.base[3], 76 region.base[4] << 8 | region.base[5], 77 region.base[6] << 8 | region.base[7]); 78 return str_totext(buf, target); 79 } 80 81 static isc_result_t 82 fromwire_l64(ARGS_FROMWIRE) { 83 isc_region_t sregion; 84 85 REQUIRE(type == dns_rdatatype_l64); 86 87 UNUSED(type); 88 UNUSED(rdclass); 89 UNUSED(dctx); 90 91 isc_buffer_activeregion(source, &sregion); 92 if (sregion.length != 10) { 93 return DNS_R_FORMERR; 94 } 95 isc_buffer_forward(source, sregion.length); 96 return mem_tobuffer(target, sregion.base, sregion.length); 97 } 98 99 static isc_result_t 100 towire_l64(ARGS_TOWIRE) { 101 REQUIRE(rdata->type == dns_rdatatype_l64); 102 REQUIRE(rdata->length == 10); 103 104 UNUSED(cctx); 105 106 return mem_tobuffer(target, rdata->data, rdata->length); 107 } 108 109 static int 110 compare_l64(ARGS_COMPARE) { 111 isc_region_t region1; 112 isc_region_t region2; 113 114 REQUIRE(rdata1->type == rdata2->type); 115 REQUIRE(rdata1->rdclass == rdata2->rdclass); 116 REQUIRE(rdata1->type == dns_rdatatype_l64); 117 REQUIRE(rdata1->length == 10); 118 REQUIRE(rdata2->length == 10); 119 120 dns_rdata_toregion(rdata1, ®ion1); 121 dns_rdata_toregion(rdata2, ®ion2); 122 return isc_region_compare(®ion1, ®ion2); 123 } 124 125 static isc_result_t 126 fromstruct_l64(ARGS_FROMSTRUCT) { 127 dns_rdata_l64_t *l64 = source; 128 129 REQUIRE(type == dns_rdatatype_l64); 130 REQUIRE(l64 != NULL); 131 REQUIRE(l64->common.rdtype == type); 132 REQUIRE(l64->common.rdclass == rdclass); 133 134 UNUSED(type); 135 UNUSED(rdclass); 136 137 RETERR(uint16_tobuffer(l64->pref, target)); 138 return mem_tobuffer(target, l64->l64, sizeof(l64->l64)); 139 } 140 141 static isc_result_t 142 tostruct_l64(ARGS_TOSTRUCT) { 143 isc_region_t region; 144 dns_rdata_l64_t *l64 = target; 145 146 REQUIRE(rdata->type == dns_rdatatype_l64); 147 REQUIRE(l64 != NULL); 148 REQUIRE(rdata->length == 10); 149 150 UNUSED(mctx); 151 152 l64->common.rdclass = rdata->rdclass; 153 l64->common.rdtype = rdata->type; 154 ISC_LINK_INIT(&l64->common, link); 155 156 dns_rdata_toregion(rdata, ®ion); 157 l64->pref = uint16_fromregion(®ion); 158 memmove(l64->l64, region.base, region.length); 159 return ISC_R_SUCCESS; 160 } 161 162 static void 163 freestruct_l64(ARGS_FREESTRUCT) { 164 dns_rdata_l64_t *l64 = source; 165 166 REQUIRE(l64 != NULL); 167 REQUIRE(l64->common.rdtype == dns_rdatatype_l64); 168 169 return; 170 } 171 172 static isc_result_t 173 additionaldata_l64(ARGS_ADDLDATA) { 174 REQUIRE(rdata->type == dns_rdatatype_l64); 175 REQUIRE(rdata->length == 10); 176 177 UNUSED(rdata); 178 UNUSED(owner); 179 UNUSED(add); 180 UNUSED(arg); 181 182 return ISC_R_SUCCESS; 183 } 184 185 static isc_result_t 186 digest_l64(ARGS_DIGEST) { 187 isc_region_t r; 188 189 REQUIRE(rdata->type == dns_rdatatype_l64); 190 REQUIRE(rdata->length == 10); 191 192 dns_rdata_toregion(rdata, &r); 193 194 return (digest)(arg, &r); 195 } 196 197 static bool 198 checkowner_l64(ARGS_CHECKOWNER) { 199 REQUIRE(type == dns_rdatatype_l64); 200 201 UNUSED(name); 202 UNUSED(type); 203 UNUSED(rdclass); 204 UNUSED(wildcard); 205 206 return true; 207 } 208 209 static bool 210 checknames_l64(ARGS_CHECKNAMES) { 211 REQUIRE(rdata->type == dns_rdatatype_l64); 212 REQUIRE(rdata->length == 10); 213 214 UNUSED(rdata); 215 UNUSED(owner); 216 UNUSED(bad); 217 218 return true; 219 } 220 221 static int 222 casecompare_l64(ARGS_COMPARE) { 223 return compare_l64(rdata1, rdata2); 224 } 225 226 #endif /* RDATA_GENERIC_L64_106_C */ 227